@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { /** * Starting from HONEYCOMB have to turn off HW acceleration to draw * Movie on Canvas. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifMoviewView, defStyle, R.style.Widget_GifMoviewView); mMovieResourceId = array.getResourceId(R.styleable.GifMoviewView_gif, -1); mPaused = array.getBoolean(R.styleable.GifMoviewView_paused, false); array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId)); } }
public GifDrawable(Movie movie, int height, int width) { this.movie = movie; this.height = height; this.width = width; setBounds(0, 0, width, height); scaleX = scaleY = 1.0f; paint = new Paint(); handler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { if (msg.what == what && running && textView != null) { textView.invalidate(); sendEmptyMessageDelayed(what, 33); } } }; }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // 从描述文件中读出gif的值,创建出Movie实例 final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle, 0); mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = array.getBoolean(R.styleable.GifView_paused, false); array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource( mMovieResourceId)); } }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { /** * Starting from HONEYCOMB(Api Level:11) have to turn off HW acceleration to draw * Movie on Canvas. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle, R.style.Widget_GifView); //-1 is default value mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = array.getBoolean(R.styleable.GifView_paused, false); array.recycle(); if (mMovieResourceId != -1) { movie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId)); } }
@Nullable @Override @AccessoryApi public Movie startSynchronously() { try { return accessory.displayMovie( mediaData, noneNullSettable(), option.or(sDefDisplayOption), progressListener, errorListener, priority) .get(); } catch (InterruptedException | ExecutionException | CancellationException ignored) { } return null; }
@Override public void onComplete(Movie result) { callOnComplete(result); if (result == null) { return; } if (canceled) { cacheManager.cache(url, result); return; } final boolean isViewMaybeReused = option.isViewMaybeReused(); if (!isViewMaybeReused || !checkTaskDirty()) { ViewAnimator<Movie> animator = (option == null ? null : option.getAnimator()); ArrayList<MediaArt<Movie>> handlers = (option == null ? null : option.getMediaArts()); UISettingApplier.getSharedApplier().applySettings(result, handlers, settable, animator); } cacheManager.cache(url, result); }
@Override public Movie fetchFromUrl(@NonNull String url, @NonNull DecodeSpec decodeSpec, @Nullable ProgressListener<Movie> progressListener, @Nullable ErrorListener errorListener) throws Exception { super.fetchFromUrl(url, decodeSpec, progressListener, errorListener); Resources resources = this.mContext.getResources(); int resId = resources.getIdentifier(mSplitter.getRealPath(url), "drawable", this.mContext.getPackageName()); if (resId <= 0) { callOnError(errorListener, new Cause(new Resources.NotFoundException(String.format("Res of id-%s not found.", resId)))); return null; } callOnStart(progressListener); @Cleanup InputStream inputStream = resources.openRawResource(0); Movie movie = Movie.decodeStream(inputStream); callOnComplete(progressListener, movie); return movie; }
@Override public Movie fetchFromUrl(@NonNull String url, @NonNull DecodeSpec decodeSpec, @Nullable ProgressListener<Movie> progressListener, @Nullable ErrorListener errorListener) throws Exception { super.fetchFromUrl(url, decodeSpec, progressListener, errorListener); String path = mSplitter.getRealPath(url); synchronized (this) { if (mAssets == null) mAssets = mContext.getAssets(); } @Cleanup InputStream in = null; try { in = mAssets.open(path); callOnStart(progressListener); Movie result = Movie.decodeStream(in); callOnComplete(progressListener, result); return result; } catch (IOException e) { callOnError(errorListener, new Cause(e)); return null; } }
@Override public Movie fetchFromUrl(@NonNull String url, @NonNull DecodeSpec decodeSpec, @Nullable ProgressListener<Movie> progressListener, @Nullable ErrorListener errorListener) throws Exception { super.fetchFromUrl(url, decodeSpec, progressListener, errorListener); String path = mSplitter.getRealPath(url); File file = new File(path); if (!file.exists()) { callOnError(errorListener, new Cause(new FileNotFoundException(String.format("File %s not found.", url)))); return null; } callOnStart(progressListener); Movie movie = Movie.decodeFile(path); callOnComplete(progressListener, movie); return movie; }
public MovieDisplayTask(Context context, LoaderConfig loaderConfig, TaskInterrupter displayTaskMonitor, MediaData<Movie> url, DimenSpec spec, MediaQuality quality, ProgressListener<Movie> progressListener, ErrorListener errorListener, DisplayTaskRecord taskRecord) { this.mContext = context; this.mLoaderConfig = loaderConfig; this.mDisplayTaskMonitor = displayTaskMonitor; this.mMediaData = url; this.mDimenSpec = spec; this.mQuality = quality; this.mProgressListener = progressListener; this.mErrorListener = errorListener; this.mTaskRecord = taskRecord; }
/** * PowerImageView构造函数,在这里完成所有必要的初始化操作。 * * @param context */ public PowerImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PowerImageView); int resourceId = getResourceId(a, context, attrs); if (resourceId != 0) { // 当资源id不等于0时,就去获取该资源的流 InputStream is = getResources().openRawResource(resourceId); // 使用Movie类对流进行解码 mMovie = Movie.decodeStream(is); if (mMovie != null) { // 如果返回值不等于null,就说明这是一个GIF图片,下面获取是否自动播放的属性 isAutoPlay = a.getBoolean(R.styleable.PowerImageView_auto_play, false); Bitmap bitmap = BitmapFactory.decodeStream(is); mImageWidth = bitmap.getWidth(); mImageHeight = bitmap.getHeight(); bitmap.recycle(); if (!isAutoPlay) { // 当不允许自动播放的时候,得到开始播放按钮的图片,并注册点击事件 mStartButton = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); setOnClickListener(this); } } } }
@Override protected Movie doInBackground(Context... params) { Context context = null; if (params != null && params.length > 0) { context = params[0]; } if (mMovieKey == null || mDecodeSource == null) { return null; } Movie cachedMovie = MovieCacheManager.queryCachedMovie(mMovieKey); if (cachedMovie != null) { Logger.debug("SKIP DECODE EXIST MOVIE: thumbKey = %s", mMovieKey); return null; } return doDecodeMovie(context, mMovieKey, mDecodeSource); }
@Override protected Movie doDecodeMovie(Context context, String thumbKey, String decodeSource) { if (decodeSource == null) { return null; } Movie movie = null; try { movie = Movie.decodeFile(decodeSource); } catch (OutOfMemoryError e) { Logger.debug("decode movie failure: %s", e.toString()); movie = null; } /* Logger.debug("DECODE THUMB: thumb = %s, movie = %s", thumbPath, movie); */ return movie; }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { /** * Starting from HONEYCOMB(Api Level:11) have to turn off HW acceleration to draw * Movie on Canvas. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle, R.style.Widget_GifView); //-1 is default value mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = array.getBoolean(R.styleable.GifView_paused, false); mScaleToFillWidth = array.getBoolean(R.styleable.GifView_scaleToFillWidth, false); array.recycle(); if (mMovieResourceId != -1) { movie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId)); } }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // 从描述文件中读出gif的值,创建出Movie实例 final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh, defStyle, R.style.Widget_GifView); mMovieResourceId = array.getResourceId(R.styleable.PullToRefresh_ptrGifResource, -1); mPaused = array.getBoolean(R.styleable.PullToRefresh_ptrGifPaused, false); array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource( mMovieResourceId)); } }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { /** * Starting from HONEYCOMB have to turn off HW acceleration to draw * Movie on Canvas. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle, R.style.Widget_GifMoviewView); mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = array.getBoolean(R.styleable.GifView_paused, false); array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId)); } }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle, R.style.Widget_GifView); mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = array.getBoolean(R.styleable.GifView_paused, false); array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource( mMovieResourceId)); } }
public void setAnimatedGif(int rawResourceId, TYPE streachType) { setImageBitmap(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } mType = streachType; animatedGifImage = true; is = getContext().getResources().openRawResource(rawResourceId); try { mMovie = Movie.decodeStream(is); } catch (Exception e) { e.printStackTrace(); byte[] array = streamToBytes(is); mMovie = Movie.decodeByteArray(array, 0, array.length); } p = new Paint(); }
public void setAnimatedGif(String filePath, TYPE streachType) throws FileNotFoundException { setImageBitmap(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } mType = streachType; animatedGifImage = true; InputStream is; try { mMovie = Movie.decodeFile(filePath); } catch (Exception e) { e.printStackTrace(); is = new FileInputStream(filePath); byte[] array = streamToBytes(is); mMovie = Movie.decodeByteArray(array, 0, array.length); } p = new Paint(); }
/** * PowerImageView构造函数,在这里完成所有必要的初始化操作。 * * @param context */ public PowerImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PowerImageView); int resourceId = getResourceId(a, context, attrs); if (resourceId != 0) { // 当资源id不等于0时,就去获取该资源的流 InputStream is = getResources().openRawResource(resourceId); // 使用Movie类对流进行解码 mMovie = Movie.decodeStream(is); if (mMovie != null) { // 如果返回值不等于null,就说明这是一个GIF图片,下面获取是否自动播放的属性 isAutoPlay = a.getBoolean(R.styleable.PowerImageView_auto_play, false); Bitmap bitmap = BitmapFactory.decodeStream(is); mImageWidth = bitmap.getWidth(); mImageHeight = bitmap.getHeight(); bitmap.recycle(); if (!isAutoPlay) { // 当不允许自动播放的时候,得到开始播放按钮的图片,并注册点击事件 mStartButton = BitmapFactory.decodeResource(getResources(), R.drawable.start_play); setOnClickListener(this); } } } }
@SuppressLint("NewApi") private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView); mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1); mPaused = false; array.recycle(); if (mMovieResourceId != -1) { mMovie = Movie.decodeStream(getResources().openRawResource( mMovieResourceId)); } }
public void setGifResource(int movieResourceId) { this.mMovieResourceId = movieResourceId; movie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId)); mDuration = movie.duration(); if (mDuration == 0) mDuration = DEFAULT_MOVIE_VIEW_DURATION; requestLayout(); }
@Override public Movie getMovie(@RawRes int id) throws NotFoundException { int realId = getCorrespondResId(id); if (realId > 0) { return mSkinResources.getMovie(realId); } return super.getMovie(id); }
/** * 设置gif图资源 * * @param movieResId */ public void setMovieResource(int movieResId) { this.mMovieResourceId = movieResId; mMovie = Movie.decodeStream(getResources().openRawResource( mMovieResourceId)); requestLayout(); }
private void init() { setFocusable(true); mMovie = Movie.decodeStream(mInputStream); mWidth = mMovie.width(); mHeight = mMovie.height(); requestLayout(); }
public GIFView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); movie = Movie.decodeStream( context.getResources().openRawResource(+ R.drawable.dni_nfc) ); }
public GIFView(Context context, AttributeSet attrs) { super(context, attrs); movie = Movie.decodeStream( context.getResources().openRawResource(+ R.drawable.dni_nfc) ); Paint p = new Paint(); p.setAntiAlias(true); setLayerType(LAYER_TYPE_SOFTWARE, p); }
public void setByteArray(byte[] b) { if (b != null) m_movie = Movie.decodeByteArray(b, 0, b.length); if (b != null && m_movie != null) { Log.d(TAG, "decoded " + b.length + " bytes to " + m_movie.duration() + " msecs, " + m_movie.width() + "x" + m_movie.height()); invalidate(); } }
void applySettings(Movie movie, List<MediaArt<Movie>> arts, MediaHolder<Movie> mediaHolder, ViewAnimator<Movie> animator) { if (mediaHolder != null) { MovieViewSettings settings = new MovieViewSettings( animator, mediaHolder, (arts == null || arts.size() == 0 ? movie : MultipleMediaArtistCaller.call(arts, movie, mediaHolder))); mUIThreadHandler.obtainMessage(MSG_APPLY_SETTINGS, settings).sendToTarget(); } }
MovieProgressListenerDelegate(CacheManager<Movie> cacheManager, TaskManager taskManager, ProgressListener<Movie> listener, DimenSpec dimenSpec, DisplayOption<Movie> option, MediaHolder<Movie> mediaHolder, DisplayTaskRecord taskRecord, String url) { super(cacheManager, taskManager, listener, dimenSpec, option, mediaHolder, taskRecord, url); }
@Override public Movie fetchFromUrl(@NonNull String url, @NonNull DecodeSpec decodeSpec, @Nullable ProgressListener<Movie> progressListener, @Nullable ErrorListener errorListener) throws Exception { super.fetchFromUrl(url, decodeSpec, progressListener, errorListener); callOnStart(progressListener); @Cleanup InputStream inputStream = mContext.getContentResolver().openInputStream(Uri.parse(url)); Movie movie = Movie.decodeStream(inputStream); callOnComplete(progressListener, movie); return movie; }
private void callFetch() { try { MediaSource<Movie> source = mMediaData.getSource(); MediaFetcher<Movie> fetcher = source.getFetcher(mContext, mLoaderConfig); DecodeSpec decodeSpec = new DecodeSpec(mQuality, mDimenSpec); mResult = fetcher.fetchFromUrl(mMediaData.getUrl(), decodeSpec, mProgressListener, mErrorListener); } catch (InterruptedIOException | InterruptedException ignored) { LoggerManager.getLogger(getClass()).debug("Ignored error:" + ignored.getLocalizedMessage()); } catch (Exception e) { if (mErrorListener != null) mErrorListener.onError(new Cause(e)); } }
public static SubjectFactory<MovieSubject, Movie> type() { return new SubjectFactory<MovieSubject, Movie>() { @Override public MovieSubject getSubject(FailureStrategy fs, Movie that) { return new MovieSubject(fs, that); } }; }