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

Don't show top toolbar items when bottom toolbar is enabled

Remove the top toolbar buttons (home, tab switcher, and menu buttons)
from their parent view and set them to null. Also add a bunch of
null checks since now things can be null.

Bug: 852117
Change-Id: I620f35f81388d1f4ac8791a9eb45576566474604
Reviewed-on: https://chromium-review.googlesource.com/1105569
Commit-Queue: Pedro Amaral <amaralp@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570578}
parent 3f58aa2b
......@@ -39,6 +39,7 @@ import org.chromium.chrome.browser.omnibox.UrlBarData;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.PulseDrawable;
import org.chromium.chrome.browser.widget.ScrimView;
......@@ -153,6 +154,12 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
mMenuButton = (TintedImageButton) findViewById(R.id.menu_button);
mMenuBadge = (ImageView) findViewById(R.id.menu_badge);
mMenuButtonWrapper = findViewById(R.id.menu_button_wrapper);
if (FeatureUtilities.isBottomToolbarEnabled()) {
UiUtils.removeViewFromParent(mMenuButtonWrapper);
mMenuButtonWrapper = null;
mMenuButton = null;
mMenuBadge = null;
}
// Initialize the provider to an empty version to avoid null checking everywhere.
mToolbarDataProvider = new ToolbarDataProvider() {
......@@ -269,8 +276,10 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
mAppMenuButtonHelper = appMenuButtonHelper;
mMenuButton.setOnTouchListener(mAppMenuButtonHelper);
mMenuButton.setAccessibilityDelegate(mAppMenuButtonHelper);
if (mMenuButton != null) {
mMenuButton.setOnTouchListener(mAppMenuButtonHelper);
mMenuButton.setAccessibilityDelegate(mAppMenuButtonHelper);
}
}
/** Notified that the menu was shown. */
......@@ -816,6 +825,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
@Override
public void removeAppMenuUpdateBadge(boolean animate) {
if (mMenuBadge == null) return;
boolean wasShowingMenuBadge = mShowMenuBadge;
mShowMenuBadge = false;
setMenuButtonContentDescription(false);
......@@ -860,6 +870,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* bitmap.
*/
protected void setAppMenuUpdateBadgeToVisible(boolean animate) {
if (mMenuBadge == null || mMenuButton == null) return;
setMenuButtonContentDescription(true);
if (!animate || mIsMenuBadgeAnimationRunning) {
mMenuBadge.setVisibility(View.VISIBLE);
......@@ -904,6 +915,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param useLightDrawable Whether the light drawable should be used.
*/
protected void setAppMenuUpdateBadgeDrawable(boolean useLightDrawable) {
if (mMenuBadge == null) return;
mMenuBadge.setImageResource(useLightDrawable ? R.drawable.badge_update_light
: R.drawable.badge_update_dark);
}
......@@ -915,7 +927,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
*/
protected void setMenuButtonHighlightDrawable(boolean highlighting) {
// Return if onFinishInflate didn't finish
if (mMenuButtonWrapper == null) return;
if (mMenuButtonWrapper == null || mMenuButton == null) return;
if (highlighting) {
if (mHighlightDrawable == null) {
......@@ -937,6 +949,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param isUpdateBadgeVisible Whether the update menu badge is visible.
*/
protected void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) {
if (mMenuButton == null) return;
if (isUpdateBadgeVisible) {
mMenuButton.setContentDescription(getResources().getString(
R.string.accessibility_toolbar_btn_menu_update));
......
......@@ -1240,7 +1240,9 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
updateReloadState(tabCrashed);
updateBookmarkButtonStatus();
mToolbar.getMenuButtonWrapper().setVisibility(View.VISIBLE);
if (mToolbar.getMenuButtonWrapper() != null) {
mToolbar.getMenuButtonWrapper().setVisibility(View.VISIBLE);
}
}
private void updateBookmarkButtonStatus() {
......
......@@ -82,6 +82,7 @@ import org.chromium.chrome.browser.widget.incognitotoggle.IncognitoToggleButton;
import org.chromium.chrome.browser.widget.newtab.NewTabButton;
import org.chromium.chrome.browser.widget.textbubble.TextBubble;
import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.LocalizationUtils;
import org.chromium.ui.interpolators.BakedBezierInterpolator;
......@@ -373,6 +374,10 @@ public class ToolbarPhone extends ToolbarLayout
mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons);
mHomeButton = (TintedImageButton) findViewById(R.id.home_button);
if (FeatureUtilities.isBottomToolbarEnabled() && mHomeButton != null) {
UiUtils.removeViewFromParent(mHomeButton);
mHomeButton = null;
}
mUrlBar = (TextView) findViewById(R.id.url_bar);
......@@ -387,7 +392,7 @@ public class ToolbarPhone extends ToolbarLayout
setLayoutTransition(null);
getMenuButtonWrapper().setVisibility(View.VISIBLE);
if (getMenuButtonWrapper() != null) getMenuButtonWrapper().setVisibility(View.VISIBLE);
inflateTabSwitchingResources();
setWillNotDraw(false);
......@@ -462,14 +467,19 @@ public class ToolbarPhone extends ToolbarLayout
private void inflateTabSwitchingResources() {
mToggleTabStackButton = (ImageView) findViewById(R.id.tab_switcher_button);
mNewTabButton = (NewTabButton) findViewById(R.id.new_tab_button);
if (FeatureUtilities.isBottomToolbarEnabled()) {
UiUtils.removeViewFromParent(mToggleTabStackButton);
mToggleTabStackButton = null;
} else {
mToggleTabStackButton.setClickable(false);
mTabSwitcherButtonDrawable =
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), false);
mTabSwitcherButtonDrawableLight =
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), true);
mToggleTabStackButton.setImageDrawable(mTabSwitcherButtonDrawable);
}
mToggleTabStackButton.setClickable(false);
mTabSwitcherButtonDrawable =
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), false);
mTabSwitcherButtonDrawableLight =
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), true);
mToggleTabStackButton.setImageDrawable(mTabSwitcherButtonDrawable);
mNewTabButton = (NewTabButton) findViewById(R.id.new_tab_button);
mTabSwitcherModeViews.add(mNewTabButton);
// Ensure that the new tab button will not draw over the toolbar buttons if the
......@@ -489,24 +499,26 @@ public class ToolbarPhone extends ToolbarLayout
}
private void enableTabSwitchingResources() {
mToggleTabStackButton.setOnClickListener(this);
mToggleTabStackButton.setOnLongClickListener(this);
mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() {
@Override
public View getNextFocusForward() {
final TintedImageButton menuButton = getMenuButton();
if (menuButton != null && menuButton.isShown()) {
return menuButton;
} else {
return getCurrentTabView();
if (mToggleTabStackButton != null) {
mToggleTabStackButton.setOnClickListener(this);
mToggleTabStackButton.setOnLongClickListener(this);
mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() {
@Override
public View getNextFocusForward() {
final TintedImageButton menuButton = getMenuButton();
if (menuButton != null && menuButton.isShown()) {
return menuButton;
} else {
return getCurrentTabView();
}
}
}
@Override
public View getNextFocusBackward() {
return findViewById(R.id.url_bar);
}
});
@Override
public View getNextFocusBackward() {
return findViewById(R.id.url_bar);
}
});
}
mNewTabButton.setOnClickListener(this);
mNewTabButton.setOnLongClickListener(this);
}
......@@ -533,22 +545,23 @@ public class ToolbarPhone extends ToolbarLayout
if (FeatureUtilities.isNewTabPageButtonEnabled()) changeIconToNTPIcon(mHomeButton);
}
getMenuButton().setOnKeyListener(new KeyboardNavigationListener() {
@Override
public View getNextFocusForward() {
return getCurrentTabView();
}
if (getMenuButton() != null)
getMenuButton().setOnKeyListener(new KeyboardNavigationListener() {
@Override
public View getNextFocusForward() {
return getCurrentTabView();
}
@Override
public View getNextFocusBackward() {
return mToggleTabStackButton;
}
@Override
public View getNextFocusBackward() {
return mToggleTabStackButton;
}
@Override
protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(getMenuButton());
}
});
@Override
protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(getMenuButton());
}
});
onHomeButtonUpdate(HomepageManager.isHomepageEnabled());
if (mLocationBar.useModernDesign()) mNewTabButton.setIsModern();
......@@ -1388,9 +1401,9 @@ public class ToolbarPhone extends ToolbarLayout
}
// Draw the menu button if necessary.
if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null
final TintedImageButton menuButton = getMenuButton();
if (menuButton != null && !mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null
&& mUrlExpansionPercent != 1f) {
final TintedImageButton menuButton = getMenuButton();
mTabSwitcherAnimationMenuDrawable.setBounds(menuButton.getPaddingLeft(),
menuButton.getPaddingTop(),
menuButton.getWidth() - menuButton.getPaddingRight(),
......@@ -1408,8 +1421,10 @@ public class ToolbarPhone extends ToolbarLayout
Drawable badgeDrawable = mUseLightDrawablesForTextureCapture
? mTabSwitcherAnimationMenuBadgeLightDrawable
: mTabSwitcherAnimationMenuBadgeDarkDrawable;
if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) {
final View menuBadge = getMenuBadge();
final View menuBadge = getMenuBadge();
if (menuBadge != null && mShowMenuBadge && badgeDrawable != null
&& mUrlExpansionPercent != 1f) {
badgeDrawable.setBounds(menuBadge.getPaddingLeft(), menuBadge.getPaddingTop(),
menuBadge.getWidth() - menuBadge.getPaddingRight(),
menuBadge.getHeight() - menuBadge.getPaddingBottom());
......@@ -1780,7 +1795,9 @@ public class ToolbarPhone extends ToolbarLayout
// This is to deal with the view going invisible when resuming the activity and
// running this animation. The view is still there and clickable but does not
// render and only a layout triggers a refresh. See crbug.com/306890.
if (!mToggleTabStackButton.isEnabled()) requestLayout();
if (mToggleTabStackButton != null && !mToggleTabStackButton.isEnabled()) {
requestLayout();
}
}
});
......@@ -1963,6 +1980,7 @@ public class ToolbarPhone extends ToolbarLayout
* switcher mode.
*/
private void updateTabSwitcherButtonRipple() {
if (mToggleTabStackButton == null) return;
if (mTabSwitcherState == ENTERING_TAB_SWITCHER) {
mToggleTabStackButton.setBackgroundColor(
ApiCompatibilityUtils.getColor(getResources(), android.R.color.transparent));
......@@ -2089,16 +2107,19 @@ public class ToolbarPhone extends ToolbarLayout
float toolbarButtonTranslationX = MathUtils.flipSignIf(
URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density;
animator = ObjectAnimator.ofFloat(
getMenuButtonWrapper(), TRANSLATION_X, toolbarButtonTranslationX);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
final View menuButtonWrapper = getMenuButtonWrapper();
if (menuButtonWrapper != null) {
animator = ObjectAnimator.ofFloat(
menuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
animator = ObjectAnimator.ofFloat(getMenuButtonWrapper(), ALPHA, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
animator = ObjectAnimator.ofFloat(menuButtonWrapper, ALPHA, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
}
if (mToggleTabStackButton != null) {
animator = ObjectAnimator.ofFloat(
......@@ -2127,17 +2148,20 @@ public class ToolbarPhone extends ToolbarLayout
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator);
animator = ObjectAnimator.ofFloat(getMenuButtonWrapper(), 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);
final View menuButtonWrapper = getMenuButtonWrapper();
if (menuButtonWrapper != null) {
animator = ObjectAnimator.ofFloat(menuButtonWrapper, 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(getMenuButtonWrapper(), ALPHA, 1);
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(menuButtonWrapper, ALPHA, 1);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator);
}
if (mToggleTabStackButton != null) {
animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
......@@ -2632,7 +2656,10 @@ public class ToolbarPhone extends ToolbarLayout
}
}
getMenuButton().setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
if (getMenuButton() != null) {
getMenuButton().setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
}
if (mLocationBar.useModernDesign()) {
updateModernLocationBarColor(getLocationBarColorForToolbarColor(currentPrimaryColor));
}
......@@ -2672,7 +2699,9 @@ public class ToolbarPhone extends ToolbarLayout
mNewTabButton.setContentDescription(newTabContentDescription);
}
getMenuButtonWrapper().setVisibility(View.VISIBLE);
if (getMenuButtonWrapper() != null) {
getMenuButtonWrapper().setVisibility(View.VISIBLE);
}
if (mLocationBar.useModernDesign()) {
DrawableCompat.setTint(mLocationBarBackground,
......@@ -2708,6 +2737,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void showAppMenuUpdateBadge() {
if (getMenuBadge() == null) return;
super.showAppMenuUpdateBadge();
// Set up variables.
......@@ -2730,6 +2760,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void removeAppMenuUpdateBadge(boolean animate) {
if (getMenuBadge() == null) return;
super.removeAppMenuUpdateBadge(animate);
if (mBrowsingModeViews.contains(getMenuBadge())) {
......
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