Commit f5726ed5 authored by Pedro Amaral's avatar Pedro Amaral Committed by Commit Bot

Use accessor methods for accessing ToolbarLayout state

ToolbarLayout has protected fields and protected getters. This seems
redundant so this CL makes the fields private and makes other
classes use the getter methods.

Change-Id: Icbab2351080ba65e1a12c70b80eee7bab5ba560a
Reviewed-on: https://chromium-review.googlesource.com/1112354
Commit-Queue: Pedro Amaral <amaralp@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569811}
parent ef6f6227
...@@ -488,7 +488,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -488,7 +488,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
} }
private void updateButtonsTint() { private void updateButtonsTint() {
mMenuButton.setTint(mUseDarkColors ? mDarkModeTint : mLightModeTint); getMenuButton().setTint(mUseDarkColors ? mDarkModeTint : mLightModeTint);
updateButtonTint(mCloseButton); updateButtonTint(mCloseButton);
int numCustomActionButtons = mCustomActionButtons.getChildCount(); int numCustomActionButtons = mCustomActionButtons.getChildCount();
for (int i = 0; i < numCustomActionButtons; i++) { for (int i = 0; i < numCustomActionButtons; i++) {
...@@ -791,7 +791,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -791,7 +791,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override @Override
public View getMenuButtonWrapper() { public View getMenuButtonWrapper() {
// This class has no menu button wrapper, so return the menu button instead. // This class has no menu button wrapper, so return the menu button instead.
return mMenuButton; return getMenuButton();
} }
@Override @Override
......
...@@ -68,10 +68,10 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -68,10 +68,10 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/** /**
* The ImageButton view that represents the menu button. * The ImageButton view that represents the menu button.
*/ */
protected TintedImageButton mMenuButton; private TintedImageButton mMenuButton;
protected ImageView mMenuBadge; private ImageView mMenuBadge;
protected View mMenuButtonWrapper; private View mMenuButtonWrapper;
protected AppMenuButtonHelper mAppMenuButtonHelper; private AppMenuButtonHelper mAppMenuButtonHelper;
protected final ColorStateList mDarkModeTint; protected final ColorStateList mDarkModeTint;
protected final ColorStateList mLightModeTint; protected final ColorStateList mLightModeTint;
...@@ -298,12 +298,19 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -298,12 +298,19 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
} }
/** /**
* @return The view containing the menu button. * @return The {@link TintedImageButton} containing the menu button.
*/ */
protected View getMenuButton() { protected TintedImageButton getMenuButton() {
return mMenuButton; return mMenuButton;
} }
/**
* @return The view containing the menu badge.
*/
protected View getMenuBadge() {
return mMenuBadge;
}
/** /**
* @return The {@link ProgressBar} this layout uses. * @return The {@link ProgressBar} this layout uses.
*/ */
......
...@@ -380,7 +380,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -380,7 +380,7 @@ public class ToolbarPhone extends ToolbarLayout
setLayoutTransition(null); setLayoutTransition(null);
mMenuButtonWrapper.setVisibility(View.VISIBLE); getMenuButtonWrapper().setVisibility(View.VISIBLE);
inflateTabSwitchingResources(); inflateTabSwitchingResources();
setWillNotDraw(false); setWillNotDraw(false);
...@@ -487,8 +487,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -487,8 +487,9 @@ public class ToolbarPhone extends ToolbarLayout
mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() { mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
public View getNextFocusForward() { public View getNextFocusForward() {
if (mMenuButton != null && mMenuButton.isShown()) { final TintedImageButton menuButton = getMenuButton();
return mMenuButton; if (menuButton != null && menuButton.isShown()) {
return menuButton;
} else { } else {
return getCurrentTabView(); return getCurrentTabView();
} }
...@@ -525,7 +526,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -525,7 +526,7 @@ public class ToolbarPhone extends ToolbarLayout
if (FeatureUtilities.isNewTabPageButtonEnabled()) changeIconToNTPIcon(mHomeButton); if (FeatureUtilities.isNewTabPageButtonEnabled()) changeIconToNTPIcon(mHomeButton);
} }
mMenuButton.setOnKeyListener(new KeyboardNavigationListener() { getMenuButton().setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
public View getNextFocusForward() { public View getNextFocusForward() {
return getCurrentTabView(); return getCurrentTabView();
...@@ -538,7 +539,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -538,7 +539,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
protected boolean handleEnterKeyPress() { protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(mMenuButton); return getMenuButtonHelper().onEnterKeyPress(getMenuButton());
} }
}); });
onHomeButtonUpdate(HomepageManager.isHomepageEnabled()); onHomeButtonUpdate(HomepageManager.isHomepageEnabled());
...@@ -1382,11 +1383,12 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1382,11 +1383,12 @@ public class ToolbarPhone extends ToolbarLayout
// Draw the menu button if necessary. // Draw the menu button if necessary.
if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null
&& mUrlExpansionPercent != 1f) { && mUrlExpansionPercent != 1f) {
mTabSwitcherAnimationMenuDrawable.setBounds( final TintedImageButton menuButton = getMenuButton();
mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(), mTabSwitcherAnimationMenuDrawable.setBounds(menuButton.getPaddingLeft(),
mMenuButton.getWidth() - mMenuButton.getPaddingRight(), menuButton.getPaddingTop(),
mMenuButton.getHeight() - mMenuButton.getPaddingBottom()); menuButton.getWidth() - menuButton.getPaddingRight(),
translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas); menuButton.getHeight() - menuButton.getPaddingBottom());
translateCanvasToView(mToolbarButtonsContainer, menuButton, canvas);
mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha); mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha);
int color = mUseLightDrawablesForTextureCapture int color = mUseLightDrawablesForTextureCapture
? mLightModeDefaultColor ? mLightModeDefaultColor
...@@ -1400,11 +1402,11 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1400,11 +1402,11 @@ public class ToolbarPhone extends ToolbarLayout
? mTabSwitcherAnimationMenuBadgeLightDrawable ? mTabSwitcherAnimationMenuBadgeLightDrawable
: mTabSwitcherAnimationMenuBadgeDarkDrawable; : mTabSwitcherAnimationMenuBadgeDarkDrawable;
if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) { if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) {
badgeDrawable.setBounds( final View menuBadge = getMenuBadge();
mMenuBadge.getPaddingLeft(), mMenuBadge.getPaddingTop(), badgeDrawable.setBounds(menuBadge.getPaddingLeft(), menuBadge.getPaddingTop(),
mMenuBadge.getWidth() - mMenuBadge.getPaddingRight(), menuBadge.getWidth() - menuBadge.getPaddingRight(),
mMenuBadge.getHeight() - mMenuBadge.getPaddingBottom()); menuBadge.getHeight() - menuBadge.getPaddingBottom());
translateCanvasToView(mToolbarButtonsContainer, mMenuBadge, canvas); translateCanvasToView(mToolbarButtonsContainer, menuBadge, canvas);
badgeDrawable.setAlpha(rgbAlpha); badgeDrawable.setAlpha(rgbAlpha);
badgeDrawable.draw(canvas); badgeDrawable.draw(canvas);
} }
...@@ -2081,12 +2083,12 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2081,12 +2083,12 @@ public class ToolbarPhone extends ToolbarLayout
URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density; URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density;
animator = ObjectAnimator.ofFloat( animator = ObjectAnimator.ofFloat(
mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX); getMenuButtonWrapper(), TRANSLATION_X, toolbarButtonTranslationX);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator); animators.add(animator);
animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0); animator = ObjectAnimator.ofFloat(getMenuButtonWrapper(), ALPHA, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator); animators.add(animator);
...@@ -2118,13 +2120,13 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2118,13 +2120,13 @@ public class ToolbarPhone extends ToolbarLayout
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator); animators.add(animator);
animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0); animator = ObjectAnimator.ofFloat(getMenuButtonWrapper(), TRANSLATION_X, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS); animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator); animators.add(animator);
animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1); animator = ObjectAnimator.ofFloat(getMenuButtonWrapper(), ALPHA, 1);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS); animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
...@@ -2620,7 +2622,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2620,7 +2622,7 @@ public class ToolbarPhone extends ToolbarLayout
} }
} }
mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint); getMenuButton().setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
if (mLocationBar.useModernDesign()) { if (mLocationBar.useModernDesign()) {
updateModernLocationBarColor(getLocationBarColorForToolbarColor(currentPrimaryColor)); updateModernLocationBarColor(getLocationBarColorForToolbarColor(currentPrimaryColor));
} }
...@@ -2699,8 +2701,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2699,8 +2701,8 @@ public class ToolbarPhone extends ToolbarLayout
super.showAppMenuUpdateBadge(); super.showAppMenuUpdateBadge();
// Set up variables. // Set up variables.
if (!mBrowsingModeViews.contains(mMenuBadge)) { if (!mBrowsingModeViews.contains(getMenuBadge())) {
mBrowsingModeViews.add(mMenuBadge); mBrowsingModeViews.add(getMenuBadge());
} }
// Finish any in-progress animations and set the TabSwitcherAnimationMenuBadgeDrawables. // Finish any in-progress animations and set the TabSwitcherAnimationMenuBadgeDrawables.
...@@ -2720,8 +2722,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2720,8 +2722,8 @@ public class ToolbarPhone extends ToolbarLayout
public void removeAppMenuUpdateBadge(boolean animate) { public void removeAppMenuUpdateBadge(boolean animate) {
super.removeAppMenuUpdateBadge(animate); super.removeAppMenuUpdateBadge(animate);
if (mBrowsingModeViews.contains(mMenuBadge)) { if (mBrowsingModeViews.contains(getMenuBadge())) {
mBrowsingModeViews.remove(mMenuBadge); mBrowsingModeViews.remove(getMenuBadge());
mTabSwitcherAnimationMenuBadgeDarkDrawable = null; mTabSwitcherAnimationMenuBadgeDarkDrawable = null;
mTabSwitcherAnimationMenuBadgeLightDrawable = null; mTabSwitcherAnimationMenuBadgeLightDrawable = null;
} }
......
...@@ -115,12 +115,12 @@ public class ToolbarTablet ...@@ -115,12 +115,12 @@ public class ToolbarTablet
mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button); mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button);
mMenuButton = (TintedImageButton) findViewById(R.id.menu_button); final View menuButtonWrapper = getMenuButtonWrapper();
mMenuButtonWrapper.setVisibility(View.VISIBLE); menuButtonWrapper.setVisibility(View.VISIBLE);
if (mAccessibilitySwitcherButton.getVisibility() == View.GONE if (mAccessibilitySwitcherButton.getVisibility() == View.GONE
&& mMenuButtonWrapper.getVisibility() == View.GONE) { && menuButtonWrapper.getVisibility() == View.GONE) {
ViewCompat.setPaddingRelative((View) mMenuButtonWrapper.getParent(), 0, 0, ViewCompat.setPaddingRelative((View) menuButtonWrapper.getParent(), 0, 0,
getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_end_padding), 0); getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_end_padding), 0);
} }
...@@ -235,7 +235,7 @@ public class ToolbarTablet ...@@ -235,7 +235,7 @@ public class ToolbarTablet
mBookmarkButton.setOnClickListener(this); mBookmarkButton.setOnClickListener(this);
mBookmarkButton.setOnLongClickListener(this); mBookmarkButton.setOnLongClickListener(this);
mMenuButton.setOnKeyListener(new KeyboardNavigationListener() { getMenuButton().setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
public View getNextFocusForward() { public View getNextFocusForward() {
return getCurrentTabView(); return getCurrentTabView();
...@@ -248,7 +248,7 @@ public class ToolbarTablet ...@@ -248,7 +248,7 @@ public class ToolbarTablet
@Override @Override
protected boolean handleEnterKeyPress() { protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(mMenuButton); return getMenuButtonHelper().onEnterKeyPress(getMenuButton());
} }
}); });
if (HomepageManager.isHomepageEnabled()) { if (HomepageManager.isHomepageEnabled()) {
...@@ -380,7 +380,7 @@ public class ToolbarTablet ...@@ -380,7 +380,7 @@ public class ToolbarTablet
getProgressBar().setThemeColor( getProgressBar().setThemeColor(
ApiCompatibilityUtils.getColor(getResources(), colorResource), isIncognito()); ApiCompatibilityUtils.getColor(getResources(), colorResource), isIncognito());
mMenuButton.setTint(incognito ? mLightModeTint : mDarkModeTint); getMenuButton().setTint(incognito ? mLightModeTint : mDarkModeTint);
mHomeButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mHomeButton.setTint(incognito ? mLightModeTint : mDarkModeTint);
mBackButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mBackButton.setTint(incognito ? mLightModeTint : mDarkModeTint);
mForwardButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mForwardButton.setTint(incognito ? mLightModeTint : mDarkModeTint);
...@@ -502,7 +502,7 @@ public class ToolbarTablet ...@@ -502,7 +502,7 @@ public class ToolbarTablet
mReloadButton.setEnabled(false); mReloadButton.setEnabled(false);
mLocationBar.getContainerView().setVisibility(View.INVISIBLE); mLocationBar.getContainerView().setVisibility(View.INVISIBLE);
if (mShowMenuBadge) { if (mShowMenuBadge) {
mMenuBadge.setVisibility(View.GONE); getMenuBadge().setVisibility(View.GONE);
setMenuButtonContentDescription(false); setMenuButtonContentDescription(false);
} }
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment