Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java |
| index c0f587d3ca93982e64e5024eae53fa34b5846d50..37d1e8cc149ce1e4b0e3ffe72611cb7f6b619c18 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java |
| @@ -46,6 +46,7 @@ import org.chromium.base.metrics.RecordUserAction; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.compositor.Invalidator; |
| import org.chromium.chrome.browser.ntp.NewTabPage; |
| +import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; |
| import org.chromium.chrome.browser.omnibox.LocationBar; |
| import org.chromium.chrome.browser.omnibox.LocationBarPhone; |
| import org.chromium.chrome.browser.omnibox.UrlContainer; |
| @@ -182,6 +183,9 @@ public class ToolbarPhone extends ToolbarLayout |
| private ValueAnimator mBrandColorTransitionAnimation; |
| private boolean mBrandColorTransitionActive; |
| + private boolean mShowMenuBadge; |
| + private Drawable mUnbadgedMenuButtonDrawable; |
| + |
| /** |
| * Used to specify the visual state of the toolbar. |
| */ |
| @@ -283,10 +287,10 @@ public class ToolbarPhone extends ToolbarLayout |
| setLayoutTransition(null); |
| - mMenuButton.setVisibility(shouldShowMenuButton() ? View.VISIBLE : View.GONE); |
| + mMenuButtonWrapper.setVisibility(shouldShowMenuButton() ? View.VISIBLE : View.GONE); |
| if (FeatureUtilities.isDocumentMode(getContext())) { |
| ApiCompatibilityUtils.setMarginEnd( |
| - (MarginLayoutParams) mMenuButton.getLayoutParams(), |
| + (MarginLayoutParams) mMenuButtonWrapper.getLayoutParams(), |
| getResources().getDimensionPixelSize(R.dimen.document_toolbar_menu_offset)); |
| } |
| @@ -978,6 +982,18 @@ public class ToolbarPhone extends ToolbarLayout |
| mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); |
| mTabSwitcherAnimationMenuDrawable.draw(canvas); |
| } |
| + if (mShowMenuBadge) { |
| + // TODO(twellington): adjust for mUrlExpansionPercent? In what scenarios will the code |
| + // below not draw in the correct position? |
| + int previousVisibility = mMenuBadge.getVisibility(); |
| + int previousMenuBadgeAlpha = mMenuBadge.getImageAlpha(); |
| + |
| + mMenuBadge.setVisibility(View.VISIBLE); |
| + mMenuBadge.setImageAlpha(rgbAlpha); |
| + drawChild(canvas, mMenuBadge, SystemClock.uptimeMillis()); |
| + mMenuBadge.setVisibility(previousVisibility); |
| + mMenuBadge.setImageAlpha(previousMenuBadgeAlpha); |
| + } |
| canvas.restore(); |
| } |
| @@ -1377,6 +1393,13 @@ public class ToolbarPhone extends ToolbarLayout |
| setAlpha(1.f); |
| mClipRect = null; |
| mUIAnimatingTabSwitcherTransition = false; |
| + |
| + if (mShowMenuBadge && !mInTabSwitcherMode) { |
| + // If mInTabSwitcherMode is true, the menu button drawable will be updated in |
| + // #updateVisualsForToolbarState(). |
| + mMenuButton.setImageBitmap( |
| + UpdateMenuItemHelper.getInstance().getBadgedMenuButtonBitmap(getContext())); |
| + } |
| if (!mAnimateNormalToolbar) { |
| finishAnimations(); |
| updateVisualsForToolbarState(mInTabSwitcherMode); |
| @@ -1408,15 +1431,7 @@ public class ToolbarPhone extends ToolbarLayout |
| mTabSwitcherAnimationBgOverlay.setColor(getToolbarColorForVisualState( |
| mOverlayDrawablesVisualState)); |
| - if (shouldShowMenuButton()) { |
| - Resources res = getResources(); |
| - mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawable( |
| - res, R.drawable.btn_menu).mutate(); |
| - mTabSwitcherAnimationMenuDrawable.setColorFilter( |
| - isIncognito() ? mLightModeDefaultColor : mDarkModeDefaultColor, |
| - PorterDuff.Mode.SRC_IN); |
| - ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Gravity.CENTER); |
| - } |
| + setTabSwitcherAnimationMenuDrawable(); |
| } |
| @Override |
| @@ -1486,12 +1501,12 @@ public class ToolbarPhone extends ToolbarLayout |
| URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density; |
| animator = ObjectAnimator.ofFloat( |
| - mMenuButton, TRANSLATION_X, toolbarButtonTranslationX); |
| + mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX); |
| animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); |
| animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); |
| animators.add(animator); |
| - animator = ObjectAnimator.ofFloat(mMenuButton, ALPHA, 0); |
| + animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0); |
| animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); |
| animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); |
| animators.add(animator); |
| @@ -1516,13 +1531,13 @@ public class ToolbarPhone extends ToolbarLayout |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| animators.add(animator); |
| - animator = ObjectAnimator.ofFloat(mMenuButton, TRANSLATION_X, 0); |
| + animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0); |
| animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); |
| animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS); |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| animators.add(animator); |
| - animator = ObjectAnimator.ofFloat(mMenuButton, ALPHA, 1); |
| + animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1); |
| animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); |
| animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS); |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| @@ -1913,7 +1928,6 @@ public class ToolbarPhone extends ToolbarLayout |
| : R.color.progress_bar_foreground); |
| getProgressBar().setForegroundColor(progressBarForegroundColor); |
| - |
| if (mToggleTabStackButton != null) { |
| mToggleTabStackButton.setImageDrawable(mUseLightToolbarDrawables |
| ? mTabSwitcherButtonDrawableLight : mTabSwitcherButtonDrawable); |
| @@ -1924,6 +1938,13 @@ public class ToolbarPhone extends ToolbarLayout |
| } |
| if (shouldShowMenuButton()) { |
| + // Only change the menu button drawable if isInTabSwitcherMode to avoid changing |
| + // it too soon if we're in the process of existing tab switcher mode. The drawable |
| + // will be changed in #onTabSwitcherTransitionFinished if we are exiting tab switcher |
| + // mode. |
| + if (mShowMenuBadge && isInTabSwitcherMode) { |
| + mMenuButton.setImageDrawable(mUnbadgedMenuButtonDrawable); |
| + } |
| mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint); |
| } |
| if (mHomeButton.getVisibility() != GONE) { |
| @@ -1959,12 +1980,59 @@ public class ToolbarPhone extends ToolbarLayout |
| mNewTabButton.setContentDescription(newTabContentDescription); |
| } |
| - getMenuButton().setVisibility(shouldShowMenuButton() ? View.VISIBLE : View.GONE); |
| + getMenuButtonWrapper().setVisibility(shouldShowMenuButton() ? View.VISIBLE : View.GONE); |
| } |
| @Override |
| public LocationBar getLocationBar() { |
| return mPhoneLocationBar; |
| } |
| + |
| + @Override |
| + public void showAppMenuUpdateBadge() { |
| + // Set up variables. |
| + mShowMenuBadge = true; |
| + mUnbadgedMenuButtonDrawable = mMenuButton.getDrawable(); |
|
gone
2015/12/10 21:45:11
any chance the drawable will be incorrect after yo
Theresa
2015/12/11 19:44:46
Yes, it could be incorrect if showappMenuUpdateBad
|
| + if (!mBrowsingModeViews.contains(mMenuBadge)) { |
| + mBrowsingModeViews.add(mMenuBadge); |
| + } |
| + |
| + // Finish any in-progress animations and set the TabSwitcherAnimationMenuDrawable. |
| + finishAnimations(); |
| + setTabSwitcherAnimationMenuDrawable(); |
| + |
| + // Show the badge and update the menu button drawable. |
| + if (!mInTabSwitcherMode) { |
| + mMenuBadge.setVisibility(View.VISIBLE); |
| + mMenuButton.setImageBitmap( |
| + UpdateMenuItemHelper.getInstance().getBadgedMenuButtonBitmap(getContext())); |
| + } |
| + |
| + mPhoneLocationBar.showAppMenuUpdateBadge(); |
| + } |
| + |
| + @Override |
| + public void removeAppMenuUpdateBadge() { |
| + super.removeAppMenuUpdateBadge(); |
| + mPhoneLocationBar.removeAppMenuUpdateBadge(); |
| + } |
| + |
| + private void setTabSwitcherAnimationMenuDrawable() { |
| + if (shouldShowMenuButton()) { |
|
gone
2015/12/10 21:45:11
nit: early exit instead of indenting?
Theresa
2015/12/11 19:44:46
Done.
|
| + Resources res = getResources(); |
| + if (mShowMenuBadge) { |
| + mTabSwitcherAnimationMenuDrawable = new BitmapDrawable(res, |
| + UpdateMenuItemHelper.getInstance().getBadgedMenuButtonBitmap(getContext())); |
| + } else { |
| + mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawable( |
| + getResources(), R.drawable.btn_menu); |
| + } |
| + mTabSwitcherAnimationMenuDrawable.mutate(); |
| + mTabSwitcherAnimationMenuDrawable.setColorFilter( |
| + isIncognito() ? mLightModeDefaultColor : mDarkModeDefaultColor, |
| + PorterDuff.Mode.SRC_IN); |
| + ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Gravity.CENTER); |
| + } |
| + } |
| } |