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

Commit b9652dfd authored by Michael Bestas's avatar Michael Bestas Committed by Luca Stefani
Browse files

SystemUI: Add tunables for clock AM/PM style

Change-Id: I7f27f135ae0d1e731c936792f655c115f107d20c
parent 691fd21e
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        DarkReceiver, ConfigurationListener {
        DarkReceiver, ConfigurationListener {


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


    private boolean mClockVisibleByPolicy = true;
    private boolean mClockVisibleByPolicy = true;
    private boolean mClockVisibleByUser = true;
    private boolean mClockVisibleByUser = true;
@@ -78,7 +79,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_SMALL   = 1;
    private static final int AM_PM_STYLE_GONE    = 2;
    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 final boolean mShowDark;
    private boolean mShowSeconds;
    private boolean mShowSeconds;
    private Handler mSecondsHandler;
    private Handler mSecondsHandler;
@@ -98,7 +99,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
                R.styleable.Clock,
                R.styleable.Clock,
                0, 0);
                0, 0);
        try {
        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);
            mShowDark = a.getBoolean(R.styleable.Clock_showDark, true);
        } finally {
        } finally {
            a.recycle();
            a.recycle();
@@ -121,7 +122,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C


            getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
            getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
                    null, Dependency.get(Dependency.TIME_TICK_HANDLER));
                    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).addCallbacks(this);
            SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
            if (mShowDark) {
            if (mShowDark) {
                Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
                Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
@@ -197,7 +198,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
    }
    }


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