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;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.view.ViewGroup;
import android.view.Window;
......@@ -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.OverviewModeObserver;
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.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
......@@ -53,7 +51,7 @@ class TabbedNavigationBarColorController implements VrModeObserver {
private @Nullable OverviewModeObserver mOverviewModeObserver;
private CallbackController mCallbackController = new CallbackController();
private boolean mUseLightNavigation;
private boolean mForceDarkNavigationBarColor;
private boolean mOverviewModeHiding;
private float mNavigationBarScrimFraction;
......@@ -74,16 +72,14 @@ class TabbedNavigationBarColorController implements VrModeObserver {
mResources = mRootView.getResources();
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
// to register observers and manipulate coloring.
// If we're not using a light navigation bar, it will always be the same dark color so
// there's no need to register observers and manipulate coloring.
if (!mResources.getBoolean(R.bool.window_light_navigation_bar)) {
mTabModelSelector = null;
mTabModelSelectorObserver = null;
return;
}
mUseLightNavigation = true;
mTabModelSelector = tabModelSelector;
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override
......@@ -155,7 +151,7 @@ class TabbedNavigationBarColorController implements VrModeObserver {
public void onExitVr() {
// 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.
UiUtils.setNavigationBarIconColor(mRootView, mUseLightNavigation);
UiUtils.setNavigationBarIconColor(mRootView, !mForceDarkNavigationBarColor);
}
@Override
......@@ -166,57 +162,44 @@ class TabbedNavigationBarColorController implements VrModeObserver {
boolean overviewVisible = mOverviewModeBehavior != null
&& mOverviewModeBehavior.overviewVisible() && !mOverviewModeHiding;
boolean useLightNavigation;
if (ChromeFeatureList.isInitialized()
&& (ChromeFeatureList.isEnabled(ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID)
|| DeviceClassManager.enableAccessibilityLayout()
|| TabUiFeatureUtilities.isGridTabSwitcherEnabled())) {
useLightNavigation = !mTabModelSelector.isIncognitoSelected();
boolean forceDarkNavigation;
if (DeviceClassManager.enableAccessibilityLayout()
|| TabUiFeatureUtilities.isGridTabSwitcherEnabled()) {
forceDarkNavigation = mTabModelSelector.isIncognitoSelected();
} else {
useLightNavigation = !mTabModelSelector.isIncognitoSelected() || overviewVisible;
forceDarkNavigation = mTabModelSelector.isIncognitoSelected() && !overviewVisible;
}
useLightNavigation &= !UiUtils.isSystemUiThemingDisabled();
if (mUseLightNavigation == useLightNavigation) return;
mUseLightNavigation = useLightNavigation;
forceDarkNavigation &= !UiUtils.isSystemUiThemingDisabled();
mWindow.setNavigationBarColor(useLightNavigation ? ApiCompatibilityUtils.getColor(
mResources, R.color.bottom_system_nav_color)
: Color.BLACK);
if (mForceDarkNavigationBarColor == forceDarkNavigation) return;
setNavigationBarColor(useLightNavigation);
mForceDarkNavigationBarColor = forceDarkNavigation;
UiUtils.setNavigationBarIconColor(mRootView, useLightNavigation);
mWindow.setNavigationBarColor(getNavigationBarColor(mForceDarkNavigationBarColor));
setNavigationBarDividerColor();
UiUtils.setNavigationBarIconColor(mRootView, !mForceDarkNavigationBarColor);
}
@SuppressLint("NewApi")
private void setNavigationBarColor(boolean useLightNavigation) {
private void setNavigationBarDividerColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mWindow.setNavigationBarDividerColor(useLightNavigation
? ApiCompatibilityUtils.getColor(
mResources, R.color.bottom_system_nav_divider_color)
: Color.BLACK);
mWindow.setNavigationBarDividerColor(
getNavigationBarDividerColor(mForceDarkNavigationBarColor));
}
}
/**
* Update the scrim amount on the navigation bar. Note that we only update when the navigation
* bar color is in light mode.
* Update the scrim amount on the navigation bar.
* @param fraction The scrim fraction in range [0, 1].
*/
public void setNavigationBarScrimFraction(float fraction) {
if (!mUseLightNavigation) {
return;
}
mNavigationBarScrimFraction = fraction;
mWindow.setNavigationBarColor(applyCurrentScrimToColor(
ApiCompatibilityUtils.getColor(mResources, R.color.bottom_system_nav_color)));
mWindow.setNavigationBarColor(
applyCurrentScrimToColor(getNavigationBarColor(mForceDarkNavigationBarColor)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mWindow.setNavigationBarDividerColor(
applyCurrentScrimToColor(ApiCompatibilityUtils.getColor(
mResources, R.color.bottom_system_nav_divider_color)));
mWindow.setNavigationBarDividerColor(applyCurrentScrimToColor(
getNavigationBarDividerColor(mForceDarkNavigationBarColor)));
}
// Adjust the color of navigation bar icons based on color state of the navigation bar.
......@@ -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) {
// Apply a color overlay.
float scrimColorAlpha = (mDefaultScrimColor >>> 24) / 255f;
......
......@@ -8,7 +8,7 @@ import static org.junit.Assert.assertEquals;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Color;
import android.content.res.Resources;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.view.Window;
......@@ -47,9 +47,11 @@ public class TabbedNavigationBarColorControllerTest {
public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage();
mWindow = mActivityTestRule.getActivity().getWindow();
mLightNavigationColor = ApiCompatibilityUtils.getColor(
mActivityTestRule.getActivity().getResources(), R.color.bottom_system_nav_color);
mDarkNavigationColor = Color.BLACK;
final Resources resources = mActivityTestRule.getActivity().getResources();
mLightNavigationColor =
ApiCompatibilityUtils.getColor(resources, R.color.default_bg_color_light);
mDarkNavigationColor =
ApiCompatibilityUtils.getColor(resources, R.color.default_bg_color_dark_elev_3);
}
@Test
......@@ -80,8 +82,8 @@ public class TabbedNavigationBarColorControllerTest {
ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), true, true);
assertEquals("Navigation bar should be black on incognito tabs.", mDarkNavigationColor,
mWindow.getNavigationBarColor());
assertEquals("Navigation bar should be dark_elev_3 on incognito tabs.",
mDarkNavigationColor, mWindow.getNavigationBarColor());
ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), false, true);
......
......@@ -10,8 +10,4 @@
<color name="control_highlight_color">@color/default_control_color_highlight_dark</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>
......@@ -32,6 +32,6 @@
<color name="default_favicon_background_color">@color/default_control_color_normal_light</color>
<!-- Navigation bar colors -->
<color name="bottom_system_nav_color">@color/modern_white</color>
<color name="bottom_system_nav_divider_color">@color/black_alpha_12</color>
<color name="bottom_system_nav_color">@color/toolbar_background_primary</color>
<color name="bottom_system_nav_divider_color">@color/hairline_stroke_color</color>
</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