Commit 6b46f0be authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Fix navigation bar icons color when toggling dark mode on OMR1

Explicitly set navigation bar icon colors for the dark mode settings
fragment to work around issue on OMR1.

Bug: 942551
Change-Id: I165119f92b78dd59167e480987754fb74ff1d5b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1549923
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#647091}
parent b3480b45
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.preferences.themes; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.preferences.themes;
import static org.chromium.chrome.browser.preferences.ChromePreferenceManager.UI_THEME_SETTING_KEY; import static org.chromium.chrome.browser.preferences.ChromePreferenceManager.UI_THEME_SETTING_KEY;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
...@@ -15,6 +16,7 @@ import android.widget.ListView; ...@@ -15,6 +16,7 @@ import android.widget.ListView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager; import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.preferences.PreferenceUtils; import org.chromium.chrome.browser.preferences.PreferenceUtils;
import org.chromium.ui.UiUtils;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -54,6 +56,15 @@ public class ThemePreferences extends PreferenceFragment { ...@@ -54,6 +56,15 @@ public class ThemePreferences extends PreferenceFragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
// On O_MR1, the flag View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR in this fragment is not
// updated to the attribute android:windowLightNavigationBar set in preference theme, so
// we set the flag explicitly to workaround the issue. See https://crbug.com/942551.
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) {
UiUtils.setNavigationBarIconColor(getActivity().getWindow().getDecorView(),
getResources().getBoolean(R.bool.window_light_navigation_bar));
}
ListView listView = getView().findViewById(android.R.id.list); ListView listView = getView().findViewById(android.R.id.list);
listView.setDivider(null); listView.setDivider(null);
} }
......
...@@ -163,7 +163,7 @@ class NavigationBarColorController implements VrModeObserver { ...@@ -163,7 +163,7 @@ class NavigationBarColorController implements VrModeObserver {
// 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.
// TODO(https://crbug.com/937946): How does this interact with immersive mode? // TODO(https://crbug.com/937946): How does this interact with immersive mode?
updateSystemUiVisibility(mUseLightNavigation); UiUtils.setNavigationBarIconColor(mRootView, mUseLightNavigation);
} }
@Override @Override
...@@ -195,7 +195,7 @@ class NavigationBarColorController implements VrModeObserver { ...@@ -195,7 +195,7 @@ class NavigationBarColorController implements VrModeObserver {
setNavigationBarColor(useLightNavigation); setNavigationBarColor(useLightNavigation);
updateSystemUiVisibility(useLightNavigation); UiUtils.setNavigationBarIconColor(mRootView, useLightNavigation);
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
...@@ -207,14 +207,4 @@ class NavigationBarColorController implements VrModeObserver { ...@@ -207,14 +207,4 @@ class NavigationBarColorController implements VrModeObserver {
: Color.BLACK); : Color.BLACK);
} }
} }
private void updateSystemUiVisibility(boolean useLightNavigation) {
int visibility = mRootView.getSystemUiVisibility();
if (useLightNavigation) {
visibility |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
} else {
visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
mRootView.setSystemUiVisibility(visibility);
}
} }
...@@ -490,4 +490,22 @@ public class UiUtils { ...@@ -490,4 +490,22 @@ public class UiUtils {
} }
return sSystemUiThemingDisabled; return sSystemUiThemingDisabled;
} }
/**
* Sets the navigation bar icons to dark or light. Note that this is only valid for Android
* O_MR1+.
* @param rootView The root view used to request updates to the system UI theme.
* @param useDarkIcons Whether the navigation bar icons should be dark.
*/
public static void setNavigationBarIconColor(View rootView, boolean useDarkIcons) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) return;
int systemUiVisibility = rootView.getSystemUiVisibility();
if (useDarkIcons) {
systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
} else {
systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
rootView.setSystemUiVisibility(systemUiVisibility);
}
} }
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