Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.ntp; | 5 package org.chromium.chrome.browser.ntp; |
| 6 | 6 |
| 7 import android.animation.Animator; | 7 import android.animation.Animator; |
| 8 import android.animation.ObjectAnimator; | 8 import android.animation.ObjectAnimator; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 11 import android.graphics.Bitmap.Config; | 11 import android.graphics.Bitmap.Config; |
| 12 import android.graphics.BitmapFactory; | 12 import android.graphics.BitmapFactory; |
| 13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
| 14 import android.graphics.Matrix; | 14 import android.graphics.Matrix; |
| 15 import android.graphics.Paint; | 15 import android.graphics.Paint; |
| 16 import android.graphics.drawable.Drawable; | 16 import android.graphics.drawable.Drawable; |
| 17 import android.text.TextUtils; | 17 import android.text.TextUtils; |
| 18 import android.util.AttributeSet; | 18 import android.util.AttributeSet; |
| 19 import android.util.Property; | 19 import android.util.Property; |
| 20 import android.view.Gravity; | 20 import android.view.Gravity; |
| 21 import android.view.View; | 21 import android.view.View; |
| 22 import android.view.View.OnClickListener; | 22 import android.view.View.OnClickListener; |
| 23 import android.widget.FrameLayout; | 23 import android.widget.FrameLayout; |
| 24 | 24 |
| 25 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
| 26 import org.chromium.chrome.browser.ntp.LogoBridge.Logo; | 26 import org.chromium.chrome.browser.ntp.LogoBridge.Logo; |
| 27 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | 27 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; |
| 28 import org.chromium.chrome.browser.widget.LoadingView; | 28 import org.chromium.chrome.browser.widget.LoadingView; |
| 29 | 29 |
| 30 import java.lang.ref.WeakReference; | 30 import java.lang.ref.WeakReference; |
| 31 | 31 |
| 32 import jp.tomorrowkey.android.gifplayer.BaseGifDrawable; | 32 import jp.tomorrowkey.android.gifplayer.BaseGifDrawable; |
| 33 import jp.tomorrowkey.android.gifplayer.BaseGifImage; | 33 import jp.tomorrowkey.android.gifplayer.BaseGifImage; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * This view shows the default search provider's logo and fades in a new logo if one becomes | 36 * This view shows the default search provider's logo and fades in a new logo if one becomes |
| 37 * available. It also maintains a {@link BaseGifDrawable} that will be played wh en the user clicks | 37 * available. It also maintains a {@link BaseGifDrawable} that will be played wh en the user clicks |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 60 | 60 |
| 61 private LoadingView mLoadingView; | 61 private LoadingView mLoadingView; |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * A measure from 0 to 1 of how much the new logo has faded in. 0 shows the old logo, 1 shows | 64 * A measure from 0 to 1 of how much the new logo has faded in. 0 shows the old logo, 1 shows |
| 65 * the new logo, and intermediate values show the new logo cross-fading in o ver the old logo. | 65 * the new logo, and intermediate values show the new logo cross-fading in o ver the old logo. |
| 66 * Set to 0 when not transitioning. | 66 * Set to 0 when not transitioning. |
| 67 */ | 67 */ |
| 68 private float mTransitionAmount; | 68 private float mTransitionAmount; |
| 69 | 69 |
| 70 private NewTabPageManager mManager; | 70 private LogoManager mManager; |
| 71 | 71 |
| 72 private final Property<LogoView, Float> mTransitionProperty = | 72 private final Property<LogoView, Float> mTransitionProperty = |
| 73 new Property<LogoView, Float>(Float.class, "") { | 73 new Property<LogoView, Float>(Float.class, "") { |
| 74 @Override | 74 @Override |
| 75 public Float get(LogoView logoView) { | 75 public Float get(LogoView logoView) { |
| 76 return logoView.mTransitionAmount; | 76 return logoView.mTransitionAmount; |
| 77 } | 77 } |
| 78 | 78 |
| 79 @Override | 79 @Override |
| 80 public void set(LogoView logoView, Float amount) { | 80 public void set(LogoView logoView, Float amount) { |
| 81 assert amount >= 0f; | 81 assert amount >= 0f; |
| 82 assert amount <= 1f; | 82 assert amount <= 1f; |
| 83 if (logoView.mTransitionAmount != amount) { | 83 if (logoView.mTransitionAmount != amount) { |
| 84 logoView.mTransitionAmount = amount; | 84 logoView.mTransitionAmount = amount; |
| 85 invalidate(); | 85 invalidate(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Manages the {@link LogoView} shown on an NTP. | |
| 92 */ | |
| 93 public interface LogoManager { | |
|
Michael van Ouwerkerk
2017/02/28 13:36:15
Can we rename this to Delegate and refer to LogoVi
Theresa
2017/02/28 17:02:23
Done.
| |
| 94 /** | |
| 95 * Called when the user clicks on the logo. | |
| 96 * @param isAnimatedLogoShowing Whether the animated GIF logo is playing . | |
| 97 */ | |
| 98 void onLogoClicked(boolean isAnimatedLogoShowing); | |
| 99 | |
| 100 /** | |
| 101 * Gets the default search provider's logo and calls logoObserver with t he result. | |
| 102 * @param logoObserver The callback to notify when the logo is available . | |
| 103 */ | |
| 104 void getSearchProviderLogo(LogoObserver logoObserver); | |
| 105 } | |
| 106 | |
| 107 /** | |
| 91 * Constructor used to inflate a LogoView from XML. | 108 * Constructor used to inflate a LogoView from XML. |
| 92 */ | 109 */ |
| 93 public LogoView(Context context, AttributeSet attrs) { | 110 public LogoView(Context context, AttributeSet attrs) { |
| 94 super(context, attrs); | 111 super(context, attrs); |
| 95 | 112 |
| 96 mLogo = getDefaultLogo(); | 113 mLogo = getDefaultLogo(); |
| 97 mLogoMatrix = new Matrix(); | 114 mLogoMatrix = new Matrix(); |
| 98 mLogoIsDefault = true; | 115 mLogoIsDefault = true; |
| 99 | 116 |
| 100 mPaint = new Paint(); | 117 mPaint = new Paint(); |
| 101 mPaint.setFilterBitmap(true); | 118 mPaint.setFilterBitmap(true); |
| 102 | 119 |
| 103 // Mark this view as non-clickable so that accessibility will ignore it. When a non-default | 120 // Mark this view as non-clickable so that accessibility will ignore it. When a non-default |
| 104 // logo is shown, this view will be marked clickable again. | 121 // logo is shown, this view will be marked clickable again. |
| 105 setOnClickListener(this); | 122 setOnClickListener(this); |
| 106 setClickable(false); | 123 setClickable(false); |
| 107 setWillNotDraw(false); | 124 setWillNotDraw(false); |
| 108 | 125 |
| 109 mLoadingView = new LoadingView(getContext()); | 126 mLoadingView = new LoadingView(getContext()); |
| 110 LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutPara ms.WRAP_CONTENT); | 127 LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutPara ms.WRAP_CONTENT); |
| 111 lp.gravity = Gravity.CENTER; | 128 lp.gravity = Gravity.CENTER; |
| 112 mLoadingView.setLayoutParams(lp); | 129 mLoadingView.setLayoutParams(lp); |
| 113 mLoadingView.setVisibility(View.GONE); | 130 mLoadingView.setVisibility(View.GONE); |
| 114 addView(mLoadingView); | 131 addView(mLoadingView); |
| 115 } | 132 } |
| 116 | 133 |
| 117 /** | 134 /** |
| 118 * Sets the NewTabPageManager to notify when the logo is pressed. | 135 * Sets the LogoManager to notify when the logo is pressed. |
| 119 */ | 136 */ |
| 120 public void setMananger(NewTabPageManager manager) { | 137 public void setMananger(LogoManager manager) { |
| 121 mManager = manager; | 138 mManager = manager; |
| 122 } | 139 } |
| 123 | 140 |
| 124 /** | 141 /** |
| 125 * Jumps to the end of the logo cross-fading animation, if any. | 142 * Jumps to the end of the logo cross-fading animation, if any. |
| 126 */ | 143 */ |
| 127 public void endFadeAnimation() { | 144 public void endFadeAnimation() { |
| 128 if (mFadeAnimation != null) { | 145 if (mFadeAnimation != null) { |
| 129 mFadeAnimation.end(); | 146 mFadeAnimation.end(); |
| 130 mFadeAnimation = null; | 147 mFadeAnimation = null; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 } | 336 } |
| 320 } | 337 } |
| 321 | 338 |
| 322 @Override | 339 @Override |
| 323 public void onClick(View view) { | 340 public void onClick(View view) { |
| 324 if (view == this && mManager != null && !isTransitioning()) { | 341 if (view == this && mManager != null && !isTransitioning()) { |
| 325 mManager.onLogoClicked(isAnimatedLogoShowing()); | 342 mManager.onLogoClicked(isAnimatedLogoShowing()); |
| 326 } | 343 } |
| 327 } | 344 } |
| 328 } | 345 } |
| OLD | NEW |