Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ac1e4d4 authored by Jason Chiu's avatar Jason Chiu
Browse files

Update icon tint color when the user toggles Dark theme

- Reload theme in slice provider when Dark theme mode changes for slices
- Reload theme in onCreate of Panel activity for its non-slice header
- Remove applyTheme from individual slices

Test: robotest
Fixes: 153700819
Change-Id: I40a7d2817c4b9100d7b2f2962a69c8a9ce6f7906
parent 7a31f2da
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -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);

+2 −10
Original line number Diff line number Diff line
@@ -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;
+0 −2
Original line number Diff line number Diff line
@@ -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
+0 −3
Original line number Diff line number Diff line
@@ -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()) {
Loading