Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchImageControl.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchImageControl.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchImageControl.java |
| index e2f24f919c82a9f714f6427260b7226de6869112..4e923cfaed93e7c7fca57622875f073ab426920e 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchImageControl.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchImageControl.java |
| @@ -22,7 +22,7 @@ public class ContextualSearchImageControl |
| * Animation properties. |
| */ |
| protected enum AnimationType { |
| - THUMBNAIL_VISIBILITY |
| + STATIC_IMAGE_VISIBILITY |
| } |
| /** The current context. */ |
| @@ -62,84 +62,78 @@ public class ContextualSearchImageControl |
| } |
| // ============================================================================================ |
| - // Thumbnail |
| + // Static Icon |
| // ============================================================================================ |
| /** |
| - * The URL of the thumbnail to display. |
| + * The resource id of the static icon to display. |
| */ |
| - private String mThumbnailUrl; |
| + private int mStaticIconResourceId; |
| /** |
| - * The height and width of the thumbnail. |
| + * Whether the static icon is visible. |
| */ |
| - private int mThumbnailSize; |
| + private boolean mStaticIconVisible; |
| /** |
| - * Whether the thumbnail is visible. |
| + * @param resId The resource id of the static icon to display. |
| */ |
| - private boolean mThumbnailVisible; |
| + public void setStaticIconResourceId(int resId) { |
| + mStaticIconResourceId = resId; |
| + mStaticIconVisible = true; |
| + animateStaticImageVisibility(true); |
| + } |
| /** |
| - * The thumbnail visibility percentage, which dictates how and where to draw the thumbnail. |
| - * The thumbnail is not visible at all at 0.f and completely visible at 1.f. |
| + * @return The resource id of the static icon to display. |
| */ |
| - private float mThumbnailVisibilityPercentage = 0.f; |
| + public int getStaticIconResourceId() { |
| + return mStaticIconResourceId; |
| + } |
| /** |
| - * @param thumbnailUrl The URL of the thumbnail to display |
| + * @return Whether the static icon is visible. |
| */ |
| - public void setThumbnailUrl(String thumbnailUrl) { |
| - mThumbnailUrl = thumbnailUrl; |
| + public boolean getStaticIconVisible() { |
| + return mStaticIconVisible; |
| } |
| + // ============================================================================================ |
| + // Thumbnail |
| + // ============================================================================================ |
| + |
| /** |
| - * @return The URL used to fetch a thumbnail to display in the Bar. Will return an empty string |
| - * if no thumbnail is available. |
| + * The URL of the thumbnail to display. |
| */ |
| - public String getThumbnailUrl() { |
| - return mThumbnailUrl != null ? mThumbnailUrl : ""; |
| - } |
| + private String mThumbnailUrl; |
| /** |
| - * Hides the thumbnail if it is visible and makes the icon sprite visible. Also resets the |
| - * thumbnail URL. |
| - * @param animate Whether hiding the thumbnail should be animated. |
| + * Whether the thumbnail is visible. |
| */ |
| - public void hideThumbnail(boolean animate) { |
| - getIconSpriteControl().setIsVisible(true); |
| - if (mThumbnailVisible && animate) { |
| - animateThumbnailVisibility(false); |
| - } else { |
| - mOverlayPanelAnimation.cancelAnimation(this, AnimationType.THUMBNAIL_VISIBILITY); |
| - onThumbnailHidden(); |
| - } |
| - } |
| + private boolean mThumbnailVisible; |
| /** |
| - * @return The height and width of the thumbnail in px. |
| + * @param thumbnailUrl The URL of the thumbnail to display |
| */ |
| - public int getThumbnailSize() { |
| - if (mThumbnailSize == 0) { |
| - mThumbnailSize = mContext.getResources().getDimensionPixelSize( |
| - R.dimen.contextual_search_thumbnail_size); |
| - } |
| - return mThumbnailSize; |
| + public void setThumbnailUrl(String thumbnailUrl) { |
| + // If a static icon is showing, the thumbnail should not be shown. |
| + if (mStaticIconVisible) return; |
|
Donn Denman
2016/10/24 23:56:20
Nit: add a blank line after (since there's a retur
Theresa
2016/10/25 00:32:48
Done.
|
| + mThumbnailUrl = thumbnailUrl; |
| } |
| /** |
| - * @return Whether the thumbnail is visible. |
| + * @return The URL used to fetch a thumbnail to display in the Bar. Will return an empty string |
| + * if no thumbnail is available. |
| */ |
| - public boolean getThumbnailVisible() { |
| - return mThumbnailVisible; |
| + public String getThumbnailUrl() { |
| + return mThumbnailUrl != null ? mThumbnailUrl : ""; |
| } |
| /** |
| - * @return The thumbnail visibility percentage, which dictates how and where to draw the |
| - * thumbnail. The thumbnail is not visible at all at 0.f and completely visible at 1.f. |
| + * @return Whether the thumbnail is visible. |
| */ |
| - public float getThumbnailVisibilityPercentage() { |
| - return mThumbnailVisibilityPercentage; |
| + public boolean getThumbnailVisible() { |
| + return mThumbnailVisible; |
| } |
| /** |
| @@ -154,52 +148,105 @@ public class ContextualSearchImageControl |
| // TODO(twellington): if the icon sprite is animating wait to start the thumbnail visibility |
| // animation. |
| - animateThumbnailVisibility(true); |
| + animateStaticImageVisibility(true); |
| + } |
| + |
| + // ============================================================================================ |
| + // Static Image -- either a thumbnail or static icon |
| + // ============================================================================================ |
| + |
| + /** |
| + * The height and width of the static image. |
| + */ |
| + private int mStaticImageSize; |
| + |
| + /** |
| + * The static image visibility percentage, which dictates how and where to draw the static |
| + * image. The static image is not visible at all at 0.f and completely visible at 1.f. |
| + */ |
| + private float mStaticImageVisibilityPercentage = 0.f; |
| + |
| + /** |
| + * Hides the static image if it is visible and makes the icon sprite visible. Also resets the |
| + * thumbnail URL and static icon resource id. |
| + * @param animate Whether hiding the thumbnail should be animated. |
| + */ |
| + public void hideStaticIcon(boolean animate) { |
| + getIconSpriteControl().setIsVisible(true); |
| + if ((mThumbnailVisible || mStaticIconVisible) && animate) { |
| + animateStaticImageVisibility(false); |
| + } else { |
| + mOverlayPanelAnimation.cancelAnimation(this, AnimationType.STATIC_IMAGE_VISIBILITY); |
| + onStaticImageHidden(); |
| + } |
| + } |
| + |
| + /** |
| + * @return The height and width of the thumbnail in px. |
|
Donn Denman
2016/10/24 23:56:20
Nit: change thumbnail to static image.
Theresa
2016/10/25 00:32:48
Done.
|
| + */ |
| + public int getStaticImageSize() { |
| + if (mStaticImageSize == 0) { |
| + mStaticImageSize = mContext.getResources().getDimensionPixelSize( |
| + R.dimen.contextual_search_static_image_size); |
| + } |
| + return mStaticImageSize; |
| } |
| - private void onThumbnailHidden() { |
| + /** |
| + * @return The static image visibility percentage, which dictates how and where to draw the |
| + * static image. The static image is not visible at all at 0.f and completely visible at |
| + * 1.f. The static image may be either a thumbnail or static icon. |
| + */ |
| + public float getStaticImageVisibilityPercentage() { |
| + return mStaticImageVisibilityPercentage; |
| + } |
| + |
| + private void onStaticImageHidden() { |
|
Donn Denman
2016/10/24 23:56:20
Nit: add javadoc.
Theresa
2016/10/25 00:32:48
Done.
|
| + mStaticIconResourceId = 0; |
| + mStaticIconVisible = false; |
| + |
| mThumbnailUrl = ""; |
| mThumbnailVisible = false; |
| getIconSpriteControl().setIsVisible(true); |
| - mThumbnailVisibilityPercentage = 0.f; |
| + mStaticImageVisibilityPercentage = 0.f; |
| } |
| // ============================================================================================ |
| // Thumbnail Animation |
| // ============================================================================================ |
| - private Interpolator mThumbnailVisibilityInterpolator; |
| + private Interpolator mStaticImageVisibilityInterpolator; |
| - private void animateThumbnailVisibility(boolean visible) { |
| - if (mThumbnailVisibilityInterpolator == null) { |
| - mThumbnailVisibilityInterpolator = PathInterpolatorCompat.create(0.4f, 0.f, 0.6f, 1.f); |
| + private void animateStaticImageVisibility(boolean visible) { |
| + if (mStaticImageVisibilityInterpolator == null) { |
| + mStaticImageVisibilityInterpolator = |
| + PathInterpolatorCompat.create(0.4f, 0.f, 0.6f, 1.f); |
| } |
| - mOverlayPanelAnimation.cancelAnimation(this, AnimationType.THUMBNAIL_VISIBILITY); |
| + mOverlayPanelAnimation.cancelAnimation(this, AnimationType.STATIC_IMAGE_VISIBILITY); |
| float endValue = visible ? 1.f : 0.f; |
| - mOverlayPanelAnimation.addToAnimation(this, AnimationType.THUMBNAIL_VISIBILITY, |
| - mThumbnailVisibilityPercentage, endValue, |
| + mOverlayPanelAnimation.addToAnimation(this, AnimationType.STATIC_IMAGE_VISIBILITY, |
| + mStaticImageVisibilityPercentage, endValue, |
| OverlayPanelAnimation.BASE_ANIMATION_DURATION_MS, 0, false, |
| - mThumbnailVisibilityInterpolator); |
| + mStaticImageVisibilityInterpolator); |
| } |
| @Override |
| public void setProperty(AnimationType prop, float val) { |
| - if (prop == AnimationType.THUMBNAIL_VISIBILITY) { |
| - mThumbnailVisibilityPercentage = val; |
| + if (prop == AnimationType.STATIC_IMAGE_VISIBILITY) { |
| + mStaticImageVisibilityPercentage = val; |
| } |
| } |
| @Override |
| public void onPropertyAnimationFinished(AnimationType prop) { |
| - if (prop == AnimationType.THUMBNAIL_VISIBILITY) { |
| - if (mThumbnailVisibilityPercentage == 0.f) { |
| - onThumbnailHidden(); |
| + if (prop == AnimationType.STATIC_IMAGE_VISIBILITY) { |
| + if (mStaticImageVisibilityPercentage == 0.f) { |
| + onStaticImageHidden(); |
| } else { |
| getIconSpriteControl().setIsVisible(false); |
| } |
| } |
| } |
| - |
| } |