Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4413)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/LogoView.java

Issue 1343913002: Introduce Animated Logo to Chrome on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d64a4da58ebf5fc11bedf7409941db1899cd4bc1 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.
newt (away) 2015/09/18 20:46:02 update javadoc
Ian Wen 2015/09/22 21:39:05 Done.
@@ -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;
newt (away) 2015/09/18 20:46:02 Be sure to set mLogo and mNewLogo to null once the
Ian Wen 2015/09/22 21:39:05 Done.
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;
newt (away) 2015/09/18 20:46:02 Why is this needed? To prevent the non-animated lo
Ian Wen 2015/09/22 21:39:05 Talked offline. This is trying to fix an imaginary
+ mCurrentLogo = logo;
+
if (logo == null) {
updateLogo(getDefaultLogo(), null, true);
} else {
@@ -165,6 +180,23 @@ public class LogoView extends View implements OnClickListener {
}
/**
+ * Updates the GIF contained in this View and starts playing it.
+ */
+ void updateGif(BaseGifImage gifImage) {
newt (away) 2015/09/18 20:46:02 Make this public as with the method below. Let's t
Ian Wen 2015/09/22 21:39:05 Done.
+ mGifDrawable = new BaseGifDrawable(gifImage, Config.ARGB_8888);
+ // Set callback here to ensure #invalidateDrawable() is called.
+ mGifDrawable.setCallback(this);
+ mGifDrawable.start();
+ }
+
+ /**
+ * @return Whether the GIF animation is playing and the first frame is ready.
+ */
+ boolean isGifPlaying() {
newt (away) 2015/09/18 20:46:02 What does this return after the gif stops animatin
Ian Wen 2015/09/22 21:39:05 BaseGifDrawable will always be running unless we c
+ return mGifDrawable == null ? false : mGifDrawable.isRunning() && mGifDrawable.isValid();
newt (away) 2015/09/18 20:46:02 Simpler: "return mGifDrawable != null && mGifDrawa
Ian Wen 2015/09/22 21:39:06 Done.
+ }
+
+ /**
* @return Whether a new logo is currently fading in over the old logo.
*/
private boolean isTransitioning() {
@@ -194,6 +226,11 @@ public class LogoView extends View implements OnClickListener {
matrix.postTranslate(imageOffsetX, imageOffsetY);
}
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
newt (away) 2015/09/18 20:46:01 Move this down next to invalidateDrawable(). In ge
Ian Wen 2015/09/22 21:39:05 Done.
+ return (who == mGifDrawable) || super.verifyDrawable(who);
+ }
+
/**
* @return The default logo.
*/
@@ -206,22 +243,39 @@ public class LogoView extends View implements OnClickListener {
return defaultLogo;
}
+ /**
+ * @see ImageView#invalidateDrawable(Drawable)
newt (away) 2015/09/18 20:46:02 Remove this javadoc comment and instead add an imp
Ian Wen 2015/09/22 21:39:05 Done.
+ */
+ @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)));
+ if (isGifPlaying()) {
+ // Gif drawable is present, draw animation instead.
newt (away) 2015/09/18 20:46:02 At this point we should set mLogo and mNewLogo to
Ian Wen 2015/09/22 21:39:05 Done.
canvas.save();
canvas.concat(mLogoMatrix);
newt (away) 2015/09/18 20:46:01 Rather than piggy backing on mLogoMatrix, I'd use
Ian Wen 2015/09/22 21:39:05 Done.
- canvas.drawBitmap(mLogo, 0, 0, mPaint);
+ mGifDrawable.draw(canvas);
canvas.restore();
- }
+ } else {
+ 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)));
- canvas.save();
- canvas.concat(mNewLogoMatrix);
- canvas.drawBitmap(mNewLogo, 0, 0, mPaint);
- canvas.restore();
+ 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();
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698