Commit 645f6775 authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

Update bottom navigation bar color for dark mode and incognito

Bug: 1134927
Change-Id: Icd06307a11bdfd218c77f8aaf3ab6e651bb1e978
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500483Reviewed-by: default avatarLijin Shen <lazzzis@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#822038}
parent aa74ca79
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.tabbed_mode; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.tabbed_mode;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
...@@ -25,7 +24,6 @@ import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver; ...@@ -25,7 +24,6 @@ import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
...@@ -53,7 +51,7 @@ class TabbedNavigationBarColorController implements VrModeObserver { ...@@ -53,7 +51,7 @@ class TabbedNavigationBarColorController implements VrModeObserver {
private @Nullable OverviewModeObserver mOverviewModeObserver; private @Nullable OverviewModeObserver mOverviewModeObserver;
private CallbackController mCallbackController = new CallbackController(); private CallbackController mCallbackController = new CallbackController();
private boolean mUseLightNavigation; private boolean mForceDarkNavigationBarColor;
private boolean mOverviewModeHiding; private boolean mOverviewModeHiding;
private float mNavigationBarScrimFraction; private float mNavigationBarScrimFraction;
...@@ -74,16 +72,14 @@ class TabbedNavigationBarColorController implements VrModeObserver { ...@@ -74,16 +72,14 @@ class TabbedNavigationBarColorController implements VrModeObserver {
mResources = mRootView.getResources(); mResources = mRootView.getResources();
mDefaultScrimColor = ApiCompatibilityUtils.getColor(mResources, R.color.black_alpha_65); mDefaultScrimColor = ApiCompatibilityUtils.getColor(mResources, R.color.black_alpha_65);
// If we're not using a light navigation bar, it will always be black so there's no need // If we're not using a light navigation bar, it will always be the same dark color so
// to register observers and manipulate coloring. // there's no need to register observers and manipulate coloring.
if (!mResources.getBoolean(R.bool.window_light_navigation_bar)) { if (!mResources.getBoolean(R.bool.window_light_navigation_bar)) {
mTabModelSelector = null; mTabModelSelector = null;
mTabModelSelectorObserver = null; mTabModelSelectorObserver = null;
return; return;
} }
mUseLightNavigation = true;
mTabModelSelector = tabModelSelector; mTabModelSelector = tabModelSelector;
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() { mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override @Override
...@@ -155,7 +151,7 @@ class TabbedNavigationBarColorController implements VrModeObserver { ...@@ -155,7 +151,7 @@ class TabbedNavigationBarColorController implements VrModeObserver {
public void onExitVr() { public void onExitVr() {
// The platform ignores the light navigation bar system UI flag when launching an Activity // The platform ignores the light navigation bar system UI flag when launching an Activity
// in VR mode, so we need to restore it when VR is exited. // in VR mode, so we need to restore it when VR is exited.
UiUtils.setNavigationBarIconColor(mRootView, mUseLightNavigation); UiUtils.setNavigationBarIconColor(mRootView, !mForceDarkNavigationBarColor);
} }
@Override @Override
...@@ -166,57 +162,44 @@ class TabbedNavigationBarColorController implements VrModeObserver { ...@@ -166,57 +162,44 @@ class TabbedNavigationBarColorController implements VrModeObserver {
boolean overviewVisible = mOverviewModeBehavior != null boolean overviewVisible = mOverviewModeBehavior != null
&& mOverviewModeBehavior.overviewVisible() && !mOverviewModeHiding; && mOverviewModeBehavior.overviewVisible() && !mOverviewModeHiding;
boolean useLightNavigation; boolean forceDarkNavigation;
if (ChromeFeatureList.isInitialized() if (DeviceClassManager.enableAccessibilityLayout()
&& (ChromeFeatureList.isEnabled(ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID) || TabUiFeatureUtilities.isGridTabSwitcherEnabled()) {
|| DeviceClassManager.enableAccessibilityLayout() forceDarkNavigation = mTabModelSelector.isIncognitoSelected();
|| TabUiFeatureUtilities.isGridTabSwitcherEnabled())) {
useLightNavigation = !mTabModelSelector.isIncognitoSelected();
} else { } else {
useLightNavigation = !mTabModelSelector.isIncognitoSelected() || overviewVisible; forceDarkNavigation = mTabModelSelector.isIncognitoSelected() && !overviewVisible;
} }
useLightNavigation &= !UiUtils.isSystemUiThemingDisabled(); forceDarkNavigation &= !UiUtils.isSystemUiThemingDisabled();
if (mUseLightNavigation == useLightNavigation) return;
mUseLightNavigation = useLightNavigation;
mWindow.setNavigationBarColor(useLightNavigation ? ApiCompatibilityUtils.getColor( if (mForceDarkNavigationBarColor == forceDarkNavigation) return;
mResources, R.color.bottom_system_nav_color)
: Color.BLACK);
setNavigationBarColor(useLightNavigation); mForceDarkNavigationBarColor = forceDarkNavigation;
UiUtils.setNavigationBarIconColor(mRootView, useLightNavigation); mWindow.setNavigationBarColor(getNavigationBarColor(mForceDarkNavigationBarColor));
setNavigationBarDividerColor();
UiUtils.setNavigationBarIconColor(mRootView, !mForceDarkNavigationBarColor);
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
private void setNavigationBarColor(boolean useLightNavigation) { private void setNavigationBarDividerColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mWindow.setNavigationBarDividerColor(useLightNavigation mWindow.setNavigationBarDividerColor(
? ApiCompatibilityUtils.getColor( getNavigationBarDividerColor(mForceDarkNavigationBarColor));
mResources, R.color.bottom_system_nav_divider_color)
: Color.BLACK);
} }
} }
/** /**
* Update the scrim amount on the navigation bar. Note that we only update when the navigation * Update the scrim amount on the navigation bar.
* bar color is in light mode.
* @param fraction The scrim fraction in range [0, 1]. * @param fraction The scrim fraction in range [0, 1].
*/ */
public void setNavigationBarScrimFraction(float fraction) { public void setNavigationBarScrimFraction(float fraction) {
if (!mUseLightNavigation) {
return;
}
mNavigationBarScrimFraction = fraction; mNavigationBarScrimFraction = fraction;
mWindow.setNavigationBarColor(applyCurrentScrimToColor( mWindow.setNavigationBarColor(
ApiCompatibilityUtils.getColor(mResources, R.color.bottom_system_nav_color))); applyCurrentScrimToColor(getNavigationBarColor(mForceDarkNavigationBarColor)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mWindow.setNavigationBarDividerColor( mWindow.setNavigationBarDividerColor(applyCurrentScrimToColor(
applyCurrentScrimToColor(ApiCompatibilityUtils.getColor( getNavigationBarDividerColor(mForceDarkNavigationBarColor)));
mResources, R.color.bottom_system_nav_divider_color)));
} }
// Adjust the color of navigation bar icons based on color state of the navigation bar. // Adjust the color of navigation bar icons based on color state of the navigation bar.
...@@ -227,6 +210,18 @@ class TabbedNavigationBarColorController implements VrModeObserver { ...@@ -227,6 +210,18 @@ class TabbedNavigationBarColorController implements VrModeObserver {
} }
} }
private @ColorInt int getNavigationBarColor(boolean forceDarkNavigationBar) {
return ApiCompatibilityUtils.getColor(mResources,
forceDarkNavigationBar ? R.color.toolbar_background_primary_dark
: R.color.bottom_system_nav_color);
}
private @ColorInt int getNavigationBarDividerColor(boolean forceDarkNavigationBar) {
return ApiCompatibilityUtils.getColor(mResources,
forceDarkNavigationBar ? R.color.hairline_stroke_color_dark
: R.color.bottom_system_nav_divider_color);
}
private @ColorInt int applyCurrentScrimToColor(@ColorInt int color) { private @ColorInt int applyCurrentScrimToColor(@ColorInt int color) {
// Apply a color overlay. // Apply a color overlay.
float scrimColorAlpha = (mDefaultScrimColor >>> 24) / 255f; float scrimColorAlpha = (mDefaultScrimColor >>> 24) / 255f;
......
...@@ -8,7 +8,7 @@ import static org.junit.Assert.assertEquals; ...@@ -8,7 +8,7 @@ import static org.junit.Assert.assertEquals;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.graphics.Color; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.view.Window; import android.view.Window;
...@@ -47,9 +47,11 @@ public class TabbedNavigationBarColorControllerTest { ...@@ -47,9 +47,11 @@ public class TabbedNavigationBarColorControllerTest {
public void setUp() throws InterruptedException { public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
mWindow = mActivityTestRule.getActivity().getWindow(); mWindow = mActivityTestRule.getActivity().getWindow();
mLightNavigationColor = ApiCompatibilityUtils.getColor( final Resources resources = mActivityTestRule.getActivity().getResources();
mActivityTestRule.getActivity().getResources(), R.color.bottom_system_nav_color); mLightNavigationColor =
mDarkNavigationColor = Color.BLACK; ApiCompatibilityUtils.getColor(resources, R.color.default_bg_color_light);
mDarkNavigationColor =
ApiCompatibilityUtils.getColor(resources, R.color.default_bg_color_dark_elev_3);
} }
@Test @Test
...@@ -80,8 +82,8 @@ public class TabbedNavigationBarColorControllerTest { ...@@ -80,8 +82,8 @@ public class TabbedNavigationBarColorControllerTest {
ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(), ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), true, true); mActivityTestRule.getActivity(), true, true);
assertEquals("Navigation bar should be black on incognito tabs.", mDarkNavigationColor, assertEquals("Navigation bar should be dark_elev_3 on incognito tabs.",
mWindow.getNavigationBarColor()); mDarkNavigationColor, mWindow.getNavigationBarColor());
ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(), ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), false, true); mActivityTestRule.getActivity(), false, true);
......
...@@ -10,8 +10,4 @@ ...@@ -10,8 +10,4 @@
<color name="control_highlight_color">@color/default_control_color_highlight_dark</color> <color name="control_highlight_color">@color/default_control_color_highlight_dark</color>
<color name="text_highlight_color">@color/highlight_color_on_light_text</color> <color name="text_highlight_color">@color/highlight_color_on_light_text</color>
<!-- Navigation bar colors -->
<color name="bottom_system_nav_color">@android:color/black</color>
<color name="bottom_system_nav_divider_color">@android:color/black</color>
</resources> </resources>
...@@ -32,6 +32,6 @@ ...@@ -32,6 +32,6 @@
<color name="default_favicon_background_color">@color/default_control_color_normal_light</color> <color name="default_favicon_background_color">@color/default_control_color_normal_light</color>
<!-- Navigation bar colors --> <!-- Navigation bar colors -->
<color name="bottom_system_nav_color">@color/modern_white</color> <color name="bottom_system_nav_color">@color/toolbar_background_primary</color>
<color name="bottom_system_nav_divider_color">@color/black_alpha_12</color> <color name="bottom_system_nav_divider_color">@color/hairline_stroke_color</color>
</resources> </resources>
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