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

Unverified Commit c8aeee84 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊 Committed by Michael Bestas
Browse files

SystemUI: support black theme for dark mode [1/4]



Co-authored-by: default avatarJesse Chan <jc@lineageos.org>
Change-Id: I57cd53de8f2c1e4d445441b514875b6af915b858
parent 5cec4924
Loading
Loading
Loading
Loading
+39 −4
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener;
import com.android.systemui.util.settings.SecureSettings;

import lineageos.providers.LineageSettings;

import org.json.JSONException;
import org.json.JSONObject;

@@ -102,6 +104,8 @@ import javax.inject.Inject;
@SysUISingleton
public class ThemeOverlayController extends CoreStartable implements Dumpable {
    protected static final String TAG = "ThemeOverlayController";
    protected static final String OVERLAY_BERRY_BLACK_THEME =
            "org.lineageos.overlay.customization.blacktheme";
    private static final boolean DEBUG = true;

    protected static final int NEUTRAL = 0;
@@ -240,6 +244,11 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
        return false;
    }

    private boolean isNightMode() {
        return (mResources.getConfiguration().uiMode
                & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
    }

    private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags, int userId) {
        final int currentUser = mUserTracker.getUserId();
        final boolean hadWallpaperColors = mCurrentColors.get(userId) != null;
@@ -403,6 +412,27 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
                },
                UserHandle.USER_ALL);

        mSecureSettings.registerContentObserverForUser(
                LineageSettings.Secure.getUriFor(LineageSettings.Secure.BERRY_BLACK_THEME),
                false,
                new ContentObserver(mBgHandler) {
                    @Override
                    public void onChange(boolean selfChange, Collection<Uri> collection, int flags,
                            int userId) {
                        if (DEBUG) Log.d(TAG, "Overlay changed for user: " + userId);
                        if (mUserTracker.getUserId() != userId) {
                            return;
                        }
                        if (!mDeviceProvisionedController.isUserSetup(userId)) {
                            Log.i(TAG, "Theme application deferred when setting changed.");
                            mDeferredThemeEvaluation = true;
                            return;
                        }
                        reevaluateSystemTheme(true /* forceReload */);
                    }
                },
                UserHandle.USER_ALL);

        if (!mIsMonetEnabled) {
            return;
        }
@@ -501,10 +531,7 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
     * Given a color candidate, return an overlay definition.
     */
    protected @Nullable FabricatedOverlay getOverlay(int color, int type, Style style) {
        boolean nightMode = (mResources.getConfiguration().uiMode
                & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;

        mColorScheme = new ColorScheme(color, nightMode, style);
        mColorScheme = new ColorScheme(color, isNightMode(), style);
        List<Integer> colorShades = type == ACCENT
                ? mColorScheme.getAllAccentColors() : mColorScheme.getAllNeutralColors();
        String name = type == ACCENT ? "accent" : "neutral";
@@ -623,6 +650,14 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
            categoryToPackage.put(OVERLAY_CATEGORY_ACCENT_COLOR, mSecondaryOverlay.getIdentifier());
        }

        boolean isBlackMode = (LineageSettings.Secure.getIntForUser(
                mContext.getContentResolver(), LineageSettings.Secure.BERRY_BLACK_THEME,
                0, currentUser) == 1) && isNightMode();
        if (categoryToPackage.containsKey(OVERLAY_CATEGORY_SYSTEM_PALETTE) && isBlackMode) {
            OverlayIdentifier blackTheme = new OverlayIdentifier(OVERLAY_BERRY_BLACK_THEME);
            categoryToPackage.put(OVERLAY_CATEGORY_SYSTEM_PALETTE, blackTheme);
        }

        Set<UserHandle> managedProfiles = new HashSet<>();
        for (UserInfo userInfo : mUserManager.getEnabledProfiles(currentUser)) {
            if (userInfo.isManagedProfile()) {