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

Commit a28c120d authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

SysUI: Be smarter about theme changes

A theme config could change that does not require us to recreate
the status bar.  This patch looks for the cases where the theme
change requires recreating the status bar and only then do we
call recreateStatusbar().

Change-Id: I88a6e5aad9306adca6ace05418379698437bfbed
parent 6305a15b
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.ThemeChangeRequest.RequestType;
import android.content.res.ThemeConfig;
import android.content.res.Resources;
import android.database.ContentObserver;
@@ -880,7 +881,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                com.android.internal.R.integer.config_screenBrightnessDim);

        updateDisplaySize(); // populates mDisplayMetrics
        updateResources();
        updateResources(null);

        mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);

@@ -3678,7 +3679,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
        updateDisplaySize(); // populates mDisplayMetrics

        updateResources();
        updateResources(newConfig);
        updateClockSize();
        repositionNavigationBar();
        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
@@ -3854,14 +3855,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
     * should, but getting that smooth is tough.  Someday we'll fix that.  In the
     * meantime, just update the things that we know change.
     */
    void updateResources() {
    void updateResources(Configuration newConfig) {
        final Context context = mContext;
        final Resources res = context.getResources();

        // detect theme change.
        ThemeConfig newTheme = res.getConfiguration().themeConfig;
        if (newTheme != null &&
                (mCurrentTheme == null || !mCurrentTheme.equals(newTheme))) {
        ThemeConfig newTheme = newConfig != null ? newConfig.themeConfig : null;
        if (shouldUpdateStatusbar(mCurrentTheme, newTheme)) {
            mCurrentTheme = (ThemeConfig)newTheme.clone();
            recreateStatusBar();
        } else {
@@ -3893,6 +3892,25 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
    }

    /**
     * Determines if we need to recreate the status bar due to a theme change.  We currently
     * check if the overlay for the status bar, fonts, or icons, or forced update count have
     * changed.
     *
     * @param oldTheme
     * @param newTheme
     * @return True if we should recreate the status bar
     */
    private boolean shouldUpdateStatusbar(ThemeConfig oldTheme, ThemeConfig newTheme) {
        return newTheme != null && (oldTheme == null || !newTheme.getOverlayForStatusBar()
                .equals(oldTheme.getOverlayForStatusBar()) ||
                !newTheme.getFontPkgName()
                        .equals(oldTheme.getFontPkgName()) ||
                !newTheme.getIconPackPkgName()
                        .equals(oldTheme.getIconPackPkgName()) ||
                newTheme.getLastThemeChangeRequestType() == RequestType.THEME_UPDATED);
    }

    private void updateClockSize() {
        if (mStatusBarView == null) return;
        TextView clock = (TextView) mStatusBarView.findViewById(R.id.clock);