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

Commit 0772b15a authored by Michael Bestas's avatar Michael Bestas
Browse files

SystemUI: Add tunables for clock AM/PM style

Squashed with the relevant fix of:

Author: dianlujitao <dianlujitao@lineageos.org>
Date:   Thu Nov 15 11:33:20 2018 +0800

    TunerServiceImpl: Blacklist Lineage settings from tuner reset

     * They use the tunable infrastructure but are real user settings and
       shouldn't be reset with tuner settings. Moreover, setting them to
       null would cause a IllegalArgumentException.

    Change-Id: Ie05910efaee867632a3bd2e84625d7735259130e

Change-Id: I7f27f135ae0d1e731c936792f655c115f107d20c
parent 5e0404f6
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        DarkReceiver, ConfigurationListener {

    public static final String CLOCK_SECONDS = "clock_seconds";
    public static final String CLOCK_STYLE = "lineagesystem:status_bar_am_pm";

    private static final String CLOCK_SUPER_PARCELABLE = "clock_super_parcelable";
    private static final String CURRENT_USER_ID = "current_user_id";
    private static final String VISIBLE_BY_POLICY = "visible_by_policy";
@@ -90,7 +92,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
    private static final int AM_PM_STYLE_SMALL   = 1;
    private static final int AM_PM_STYLE_GONE    = 2;

    private final int mAmPmStyle;
    private int mAmPmStyle = AM_PM_STYLE_GONE;
    private final boolean mShowDark;
    private boolean mShowSeconds;
    private Handler mSecondsHandler;
@@ -121,7 +123,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
                R.styleable.Clock,
                0, 0);
        try {
            mAmPmStyle = a.getInt(R.styleable.Clock_amPmStyle, AM_PM_STYLE_GONE);
            mAmPmStyle = a.getInt(R.styleable.Clock_amPmStyle, mAmPmStyle);
            mShowDark = a.getBoolean(R.styleable.Clock_showDark, true);
            mNonAdaptedColor = getCurrentTextColor();
        } finally {
@@ -185,7 +187,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C

            getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
                    null, Dependency.get(Dependency.TIME_TICK_HANDLER));
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS);
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS, CLOCK_STYLE);
            SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallback(this);
            if (mShowDark) {
                Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
@@ -277,7 +279,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
    }

    final void updateClock() {
        if (mDemoMode) return;
        if (mDemoMode || mCalendar == null) return;
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        setText(getSmallTime());
        setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
@@ -288,6 +290,10 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        if (CLOCK_SECONDS.equals(key)) {
            mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
            updateShowSeconds();
        } else if (CLOCK_STYLE.equals(key)) {
            mAmPmStyle = newValue == null ? AM_PM_STYLE_GONE : Integer.valueOf(newValue);
            mClockFormatString = ""; // force refresh
            updateClock();
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.qs.QSTileHost;
import com.android.systemui.settings.CurrentUserTracker;
import com.android.systemui.statusbar.phone.ClockController;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.util.leak.LeakDetector;

import lineageos.providers.LineageSettings;
@@ -65,6 +66,7 @@ public class TunerServiceImpl extends TunerService {
    // Things that use the tunable infrastructure but are now real user settings and
    // shouldn't be reset with tuner settings.
    private static final String[] RESET_BLACKLIST = new String[] {
            Clock.CLOCK_STYLE,
            ClockController.CLOCK_POSITION,
            QSTileHost.TILES_SETTING,
            Settings.Secure.DOZE_ALWAYS_ON