Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java |
| index 37576468ccf7b78b8921166fcd9b0b70ff076fd4..f06f02f2ced40c4ee037ba50a140c65092c4c7f2 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java |
| @@ -4,6 +4,9 @@ |
| package org.chromium.chrome.browser.omnibox; |
| +import android.animation.Animator; |
| +import android.animation.AnimatorListenerAdapter; |
| +import android.animation.AnimatorSet; |
| import android.animation.ObjectAnimator; |
| import android.annotation.SuppressLint; |
| import android.content.Context; |
| @@ -55,6 +58,10 @@ public class LocationBarPhone extends LocationBarLayout { |
| private Runnable mKeyboardResizeModeTask; |
| private ObjectAnimator mOmniboxBackgroundAnimator; |
| + private boolean mShowMenuBadge; |
| + private AnimatorSet mMenuBadgeAnimatorSet; |
| + private boolean mIsMenuBadgeAnimationRunning; |
| + |
| /** |
| * Constructor used to inflate from XML. |
| */ |
| @@ -350,17 +357,17 @@ public class LocationBarPhone extends LocationBarLayout { |
| updateIncognitoBadgePadding(); |
| if (showMenuButtonInOmnibox()) { |
| - boolean useLightDrawables = isIncognito; |
| - if (getToolbarDataProvider().isUsingBrandColor()) { |
| - int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor(); |
| - useLightDrawables |= |
| - ColorUtils.shoudUseLightForegroundOnBackground(currentPrimaryColor); |
| - } |
| + boolean useLightDrawables = shouldUseLightDrawables(); |
| ColorStateList dark = ApiCompatibilityUtils.getColorStateList(getResources(), |
| R.color.dark_mode_tint); |
| ColorStateList white = ApiCompatibilityUtils.getColorStateList(getResources(), |
| R.color.light_mode_tint); |
| mMenuButton.setTint(useLightDrawables ? white : dark); |
| + |
| + if (mShowMenuBadge) { |
| + mMenuBadge.setImageResource(useLightDrawables ? R.drawable.badge_update_light |
| + : R.drawable.badge_update_dark); |
| + } |
| } |
| } |
| @@ -378,16 +385,104 @@ public class LocationBarPhone extends LocationBarLayout { |
| /** |
| * Displays the update app menu badge. |
| */ |
| - public void showAppMenuUpdateBadge() { |
| + public void showAppMenuUpdateBadge(boolean animate) { |
| + if (!showMenuButtonInOmnibox()) return; |
| + |
| + mShowMenuBadge = true; |
| + if (shouldUseLightDrawables()) { |
| + mMenuBadge.setImageResource(R.drawable.badge_update_light); |
|
gone
2016/02/13 00:26:15
Maybe this should mimic what's above, where it use
Theresa
2016/02/16 18:21:53
Done.
|
| + } |
| + |
| + if (!animate || mIsMenuBadgeAnimationRunning) { |
| + mMenuBadge.setVisibility(View.VISIBLE); |
| + return; |
| + } |
| + |
| + // Set initial states. |
| + mMenuBadge.setAlpha(0.f); |
| mMenuBadge.setVisibility(View.VISIBLE); |
| - mMenuButton.setImageBitmap( |
| - UpdateMenuItemHelper.getInstance().getBadgedMenuButtonBitmap(getContext())); |
| + |
| + mMenuBadgeAnimatorSet = UpdateMenuItemHelper.createShowUpdateBadgeAnimation( |
| + mMenuButton, mMenuBadge); |
| + |
| + mMenuBadgeAnimatorSet.addListener(new AnimatorListenerAdapter() { |
| + @Override |
| + public void onAnimationStart(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = true; |
| + } |
| + |
| + @Override |
| + public void onAnimationEnd(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = false; |
| + } |
| + |
| + @Override |
| + public void onAnimationCancel(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = false; |
| + } |
| + }); |
| + |
| + mMenuBadgeAnimatorSet.start(); |
| } |
| /** |
| * Remove the update menu app menu badge. |
| */ |
| - public void removeAppMenuUpdateBadge() { |
| - mMenuBadge.setVisibility(View.GONE); |
| + public void removeAppMenuUpdateBadge(boolean animate) { |
| + boolean wasShowingMenuBadge = mShowMenuBadge; |
| + mShowMenuBadge = false; |
| + if (!animate || !wasShowingMenuBadge) { |
| + if (!mIsMenuBadgeAnimationRunning && showMenuButtonInOmnibox()) { |
|
Theresa
2016/02/16 18:21:53
To document this change from patchset 3, if the an
|
| + mMenuBadge.setVisibility(View.GONE); |
| + } |
| + return; |
| + } |
| + |
| + if (mIsMenuBadgeAnimationRunning) { |
| + mMenuBadgeAnimatorSet.cancel(); |
| + } |
| + |
| + // Set initial states. |
| + mMenuButton.setAlpha(0.f); |
| + |
| + mMenuBadgeAnimatorSet = UpdateMenuItemHelper.createHideUpdateBadgeAnimation( |
| + mMenuButton, mMenuBadge); |
| + |
| + mMenuBadgeAnimatorSet.addListener(new AnimatorListenerAdapter() { |
|
gone
2016/02/13 00:26:15
Can this be combined with the three other Animator
Theresa
2016/02/16 18:21:53
LocationBarPhone isn't a Toolbar subclass which is
|
| + @Override |
| + public void onAnimationStart(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = true; |
| + } |
| + |
| + @Override |
| + public void onAnimationEnd(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = false; |
| + } |
| + |
| + @Override |
| + public void onAnimationCancel(Animator animation) { |
| + mIsMenuBadgeAnimationRunning = false; |
| + } |
| + }); |
| + |
| + mMenuBadgeAnimatorSet.start(); |
| + } |
| + |
| + public void cancelAppMenuUpdateBadgeAnimation() { |
| + if (mIsMenuBadgeAnimationRunning) { |
| + mMenuBadgeAnimatorSet.cancel(); |
| + } |
| + } |
| + |
| + private boolean shouldUseLightDrawables() { |
| + Tab tab = getCurrentTab(); |
| + boolean isIncognito = tab != null && tab.isIncognito(); |
| + boolean useLightDrawables = isIncognito; |
| + if (getToolbarDataProvider().isUsingBrandColor()) { |
| + int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor(); |
| + useLightDrawables |= |
| + ColorUtils.shoudUseLightForegroundOnBackground(currentPrimaryColor); |
| + } |
| + return useLightDrawables; |
| } |
| } |