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

Commit eedbeab7 authored by Michael Bestas's avatar Michael Bestas Committed by Bruno Martins
Browse files

SystemUI: Add tunables for clock AM/PM style

Change-Id: I7f27f135ae0d1e731c936792f655c115f107d20c
parent 901d54cf
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ import com.android.systemui.tuner.TunerService.Tunable;

import libcore.icu.LocaleData;

import lineageos.providers.LineageSettings;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
@@ -66,6 +68,8 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        DarkReceiver, ConfigurationListener {

    public static final String CLOCK_SECONDS = "clock_seconds";
    private static final String CLOCK_STYLE =
            "lineagesystem:" + LineageSettings.System.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";
@@ -91,7 +95,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 +125,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 {
@@ -189,7 +193,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
            // The receiver will return immediately if the view does not have a Handler yet.
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
                    Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS);
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS, CLOCK_STYLE);
            mCommandQueue.addCallback(this);
            if (mShowDark) {
                Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
@@ -284,7 +288,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()));
@@ -295,6 +299,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 = TunerService.parseInteger(newValue, AM_PM_STYLE_GONE);
            mClockFormatString = ""; // force refresh
            updateClock();
        }
    }