+ if(mGifMovie == null){
+ super.onDraw(canvas);
+ } else {
+ long nowTick = android.os.SystemClock.uptimeMillis();
+ if (mLastTick == 0) {
+ mMovieRunDuration = 0;
+ } else {
+ mMovieRunDuration += nowTick - mLastTick;
+ if(mMovieRunDuration > mMovieDuration){
+ mMovieRunDuration = 0;
+ }
+ }
+
+ mGifMovie.setTime((int) mMovieRunDuration);
+
+ float scale;
+ if(mGifMovie.height() > getHeight() || mGifMovie.width() > getWidth()) {
+ scale = (1f / Math.min(canvas.getHeight() / mGifMovie.height(),
+ canvas.getWidth() / mGifMovie.width())) + 0.25f;
+ } else {
+ scale = Math.min(canvas.getHeight() / mGifMovie.height(),
+ canvas.getWidth() / mGifMovie.width());
+ }
+
+ canvas.scale(scale, scale);
+ canvas.translate(((float) getWidth() / scale - (float) mGifMovie.width()) / 2f,
+ ((float) getHeight() / scale - (float) mGifMovie.height()) /2f);
+
+ mGifMovie.draw(canvas, 0, 0);
+
+ mLastTick = nowTick;
+ invalidate();
+ }
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ if (mGifMovie == null){
+ setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
+ } else {
+ setMeasuredDimension(mMovieWidth, mMovieHeight);
+ }