Merge "Update icon tint color when the user toggles Dark theme" into rvc-dev am: 8224a5ad3d
Change-Id: I50fc0c1cd70ad15388baa0f110955a2d9bee9573
This commit is contained in:
@@ -42,6 +42,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
@@ -1101,4 +1102,13 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
context.getString(R.string.config_settingsintelligence_package_name));
|
||||
return isSettingsIntelligence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the night mode is enabled.
|
||||
*/
|
||||
public static boolean isNightMode(Context context) {
|
||||
final int currentNightMode =
|
||||
context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
}
|
||||
|
@@ -105,9 +105,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
|
||||
|
@@ -24,7 +24,6 @@ import android.app.PendingIntent;
|
||||
import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
@@ -107,7 +106,7 @@ public class DarkThemeSlice implements CustomSliceable {
|
||||
final IconCompat icon =
|
||||
IconCompat.createWithResource(mContext, R.drawable.dark_theme);
|
||||
|
||||
final boolean isChecked = isDarkThemeMode(mContext);
|
||||
final boolean isChecked = Utils.isNightMode(mContext);
|
||||
if (sPreChecked != isChecked) {
|
||||
// Dark(Night) mode changed and reset the sSliceClicked.
|
||||
resetValue(isChecked, false);
|
||||
@@ -157,7 +156,7 @@ public class DarkThemeSlice implements CustomSliceable {
|
||||
@VisibleForTesting
|
||||
boolean isAvailable(Context context) {
|
||||
// check if dark theme mode is enabled or if dark theme scheduling is on.
|
||||
if (isDarkThemeMode(context) || isNightModeScheduled()) {
|
||||
if (Utils.isNightMode(context) || isNightModeScheduled()) {
|
||||
return false;
|
||||
}
|
||||
// checking the current battery level
|
||||
@@ -167,13 +166,6 @@ public class DarkThemeSlice implements CustomSliceable {
|
||||
return level <= BATTERY_LEVEL_THRESHOLD;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static boolean isDarkThemeMode(Context context) {
|
||||
final int currentNightMode =
|
||||
context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
|
||||
private void resetValue(boolean preChecked, boolean clicked) {
|
||||
sPreChecked = preChecked;
|
||||
sSliceClicked = clicked;
|
||||
|
@@ -75,8 +75,6 @@ public class MediaOutputGroupSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
// Add "Group" row
|
||||
|
@@ -81,9 +81,6 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
if (!isVisible()) {
|
||||
|
@@ -66,6 +66,7 @@ public class SettingsPanelActivity extends FragmentActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getApplicationContext().getTheme().rebase();
|
||||
createOrUpdatePanel(true /* shouldForceCreation */);
|
||||
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
|
||||
}
|
||||
|
@@ -140,8 +140,11 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
@VisibleForTesting
|
||||
Map<Uri, SliceData> mSliceWeakDataCache;
|
||||
|
||||
@VisibleForTesting
|
||||
final Map<Uri, SliceBackgroundWorker> mPinnedWorkers = new ArrayMap<>();
|
||||
|
||||
private boolean mNightMode;
|
||||
|
||||
public SettingsSliceProvider() {
|
||||
super(READ_SEARCH_INDEXABLES);
|
||||
}
|
||||
@@ -150,6 +153,8 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
public boolean onCreateSliceProvider() {
|
||||
mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(getContext());
|
||||
mSliceWeakDataCache = new WeakHashMap<>();
|
||||
mNightMode = Utils.isNightMode(getContext());
|
||||
getContext().setTheme(R.style.Theme_SettingsBase);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -201,6 +206,13 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean nightMode = Utils.isNightMode(getContext());
|
||||
if (mNightMode != nightMode) {
|
||||
Log.d(TAG, "Night mode changed, reload theme");
|
||||
mNightMode = nightMode;
|
||||
getContext().getTheme().rebase();
|
||||
}
|
||||
|
||||
// Before adding a slice to {@link CustomSliceManager}, please get approval
|
||||
// from the Settings team.
|
||||
if (CustomSliceRegistry.isValidUri(sliceUri)) {
|
||||
|
@@ -73,8 +73,6 @@ public class SliceBuilderUtils {
|
||||
* {@param sliceData} is an inline controller.
|
||||
*/
|
||||
public static Slice buildSlice(Context context, SliceData sliceData) {
|
||||
// Reload theme for switching dark mode on/off
|
||||
context.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
Log.d(TAG, "Creating slice for: " + sliceData.getPreferenceController());
|
||||
final BasePreferenceController controller = getPreferenceController(context, sliceData);
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
|
@@ -86,9 +86,6 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* accessPoint */);
|
||||
if (!isWifiEnabled) {
|
||||
|
Reference in New Issue
Block a user