| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java
|
| index 94a7f3df7f0e7521d7ddb30dcf304a1a0a6a6cda..95c39fbd3de76b772e2755e95e09ec2f6bf24ecf 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java
|
| @@ -8,15 +8,18 @@ import android.animation.Animator;
|
| import android.animation.ObjectAnimator;
|
| import android.content.Context;
|
| import android.graphics.Bitmap;
|
| +import android.graphics.Bitmap.Config;
|
| import android.graphics.BitmapFactory;
|
| import android.graphics.Canvas;
|
| import android.graphics.Matrix;
|
| import android.graphics.Paint;
|
| +import android.graphics.drawable.Drawable;
|
| import android.text.TextUtils;
|
| import android.util.AttributeSet;
|
| import android.util.Property;
|
| import android.view.View;
|
| import android.view.View.OnClickListener;
|
| +import android.widget.ImageView;
|
|
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ntp.LogoBridge.Logo;
|
| @@ -24,6 +27,9 @@ import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
|
|
|
| import java.lang.ref.WeakReference;
|
|
|
| +import jp.tomorrowkey.android.gifplayer.BaseGifDrawable;
|
| +import jp.tomorrowkey.android.gifplayer.BaseGifImage;
|
| +
|
| /**
|
| * This view shows the default search provider's logo and fades in a new logo if one becomes
|
| * available.
|
| @@ -36,14 +42,20 @@ public class LogoView extends View implements OnClickListener {
|
| // The default logo is shared across all NTPs.
|
| private static WeakReference<Bitmap> sDefaultLogo;
|
|
|
| - private Paint mPaint;
|
| + // mLogo and mNewLogo are remembered for cross fading animation.
|
| private Bitmap mLogo;
|
| private Bitmap mNewLogo;
|
| + private ObjectAnimator mAnimation;
|
| +
|
| + private BaseGifDrawable mGifDrawable;
|
| + private Paint mPaint;
|
| private Matrix mLogoMatrix;
|
| private Matrix mNewLogoMatrix;
|
| private boolean mLogoIsDefault;
|
| private boolean mNewLogoIsDefault;
|
| - private ObjectAnimator mAnimation;
|
| +
|
| + // The Logo object representing the latest logo this view is showing.
|
| + private Logo mCurrentLogo;
|
|
|
| /**
|
| * A measure from 0 to 1 of how much the new logo has faded in. 0 shows the old logo, 1 shows
|
| @@ -114,6 +126,9 @@ public class LogoView extends View implements OnClickListener {
|
| * @param logo The new logo to fade in. May be null to reset to the default logo.
|
| */
|
| public void updateLogo(Logo logo) {
|
| + if (mCurrentLogo != null && mCurrentLogo.equals(logo)) return;
|
| + mCurrentLogo = logo;
|
| +
|
| if (logo == null) {
|
| updateLogo(getDefaultLogo(), null, true);
|
| } else {
|
| @@ -165,6 +180,20 @@ public class LogoView extends View implements OnClickListener {
|
| }
|
|
|
| /**
|
| + * Updates the GIF contained in this View and starts playing it.
|
| + */
|
| + void updateGif(BaseGifImage gifImage) {
|
| + mGifDrawable = new BaseGifDrawable(gifImage, Config.ARGB_8888);
|
| + // Set callback here to ensure #invalidateDrawable() is called.
|
| + mGifDrawable.setCallback(this);
|
| + invalidate();
|
| + }
|
| +
|
| + boolean isGifPlaying() {
|
| + return mGifDrawable == null ? false : mGifDrawable.isRunning();
|
| + }
|
| +
|
| + /**
|
| * @return Whether a new logo is currently fading in over the old logo.
|
| */
|
| private boolean isTransitioning() {
|
| @@ -194,6 +223,11 @@ public class LogoView extends View implements OnClickListener {
|
| matrix.postTranslate(imageOffsetX, imageOffsetY);
|
| }
|
|
|
| + @Override
|
| + protected boolean verifyDrawable(Drawable who) {
|
| + return (who == mGifDrawable) || super.verifyDrawable(who);
|
| + }
|
| +
|
| /**
|
| * @return The default logo.
|
| */
|
| @@ -206,21 +240,38 @@ public class LogoView extends View implements OnClickListener {
|
| return defaultLogo;
|
| }
|
|
|
| + /**
|
| + * @see ImageView#invalidateDrawable(Drawable)
|
| + */
|
| + @Override
|
| + public void invalidateDrawable(Drawable drawable) {
|
| + if (drawable == mGifDrawable) invalidate();
|
| + else super.invalidateDrawable(drawable);
|
| + }
|
| +
|
| @Override
|
| protected void onDraw(Canvas canvas) {
|
| - if (mLogo != null && mTransitionAmount < 0.5f) {
|
| - mPaint.setAlpha((int) (255 * 2 * (0.5f - mTransitionAmount)));
|
| - canvas.save();
|
| - canvas.concat(mLogoMatrix);
|
| - canvas.drawBitmap(mLogo, 0, 0, mPaint);
|
| - canvas.restore();
|
| - }
|
| + if (mGifDrawable == null) {
|
| + if (mLogo != null && mTransitionAmount < 0.5f) {
|
| + mPaint.setAlpha((int) (255 * 2 * (0.5f - mTransitionAmount)));
|
| + canvas.save();
|
| + canvas.concat(mLogoMatrix);
|
| + canvas.drawBitmap(mLogo, 0, 0, mPaint);
|
| + canvas.restore();
|
| + }
|
|
|
| - if (mNewLogo != null && mTransitionAmount > 0.5f) {
|
| - mPaint.setAlpha((int) (255 * 2 * (mTransitionAmount - 0.5f)));
|
| + if (mNewLogo != null && mTransitionAmount > 0.5f) {
|
| + mPaint.setAlpha((int) (255 * 2 * (mTransitionAmount - 0.5f)));
|
| + canvas.save();
|
| + canvas.concat(mNewLogoMatrix);
|
| + canvas.drawBitmap(mNewLogo, 0, 0, mPaint);
|
| + canvas.restore();
|
| + }
|
| + } else {
|
| + // Gif drawable is present, draw animation instead.
|
| canvas.save();
|
| - canvas.concat(mNewLogoMatrix);
|
| - canvas.drawBitmap(mNewLogo, 0, 0, mPaint);
|
| + canvas.concat(mLogoMatrix);
|
| + mGifDrawable.draw(canvas);
|
| canvas.restore();
|
| }
|
| }
|
|
|