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

Unverified Commit ea5ed91e authored by Michael Bestas's avatar Michael Bestas
Browse files

SystemUI: Add tunables for clock AM/PM style

Change-Id: I7f27f135ae0d1e731c936792f655c115f107d20c
parent 481742f4
Loading
Loading
Loading
Loading
+20 −6
Original line number Original line Diff line number Diff line
@@ -55,6 +55,8 @@ import com.android.systemui.statusbar.policy.ConfigurationController.Configurati
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.tuner.TunerService.Tunable;


import lineageos.providers.LineageSettings;

import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Calendar;
@@ -71,6 +73,8 @@ public class Clock extends TextView implements
        DarkReceiver, ConfigurationListener {
        DarkReceiver, ConfigurationListener {


    public static final String CLOCK_SECONDS = "clock_seconds";
    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 CLOCK_SUPER_PARCELABLE = "clock_super_parcelable";
    private static final String CURRENT_USER_ID = "current_user_id";
    private static final String CURRENT_USER_ID = "current_user_id";
    private static final String VISIBLE_BY_POLICY = "visible_by_policy";
    private static final String VISIBLE_BY_POLICY = "visible_by_policy";
@@ -98,7 +102,7 @@ public class Clock extends TextView implements
    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 boolean mShowSeconds;
    private boolean mShowSeconds;
    private Handler mSecondsHandler;
    private Handler mSecondsHandler;


@@ -125,7 +129,7 @@ public class Clock extends TextView implements
                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);
            mNonAdaptedColor = getCurrentTextColor();
            mNonAdaptedColor = getCurrentTextColor();
        } finally {
        } finally {
            a.recycle();
            a.recycle();
@@ -192,7 +196,7 @@ public class Clock extends TextView implements
            // The receiver will return immediately if the view does not have a Handler yet.
            // The receiver will return immediately if the view does not have a Handler yet.
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
                    Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
                    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);
            mCommandQueue.addCallback(this);
            mCurrentUserTracker.startTracking();
            mCurrentUserTracker.startTracking();
            mCurrentUserId = mCurrentUserTracker.getCurrentUserId();
            mCurrentUserId = mCurrentUserTracker.getCurrentUserId();
@@ -291,19 +295,23 @@ public class Clock extends TextView implements
        super.setVisibility(visibility);
        super.setVisibility(visibility);
    }
    }


    final void updateClock() {
    final void updateClock(boolean forceTextUpdate) {
        if (mDemoMode) return;
        if (mDemoMode || mCalendar == null) return;
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        CharSequence smallTime = getSmallTime();
        CharSequence smallTime = getSmallTime();
        // Setting text actually triggers a layout pass (because the text view is set to
        // Setting text actually triggers a layout pass (because the text view is set to
        // wrap_content width and TextView always relayouts for this). Avoid needless
        // wrap_content width and TextView always relayouts for this). Avoid needless
        // relayout if the text didn't actually change.
        // relayout if the text didn't actually change.
        if (!TextUtils.equals(smallTime, getText())) {
        if (forceTextUpdate || !TextUtils.equals(smallTime, getText())) {
            setText(smallTime);
            setText(smallTime);
        }
        }
        setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
        setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
    }
    }


    final void updateClock() {
        updateClock(false);
    }

    /**
    /**
     * In order to avoid the clock growing and shrinking due to proportional fonts, we want to
     * In order to avoid the clock growing and shrinking due to proportional fonts, we want to
     * cache the drawn width at a given number of characters (removing the cache when it changes),
     * cache the drawn width at a given number of characters (removing the cache when it changes),
@@ -335,6 +343,12 @@ public class Clock extends TextView implements
        if (CLOCK_SECONDS.equals(key)) {
        if (CLOCK_SECONDS.equals(key)) {
            mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
            mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
            updateShowSeconds();
            updateShowSeconds();
        } else if (CLOCK_STYLE.equals(key)) {
            mAmPmStyle = TunerService.parseInteger(newValue, AM_PM_STYLE_GONE);
            // Force refresh of dependent variables.
            mContentDescriptionFormatString = "";
            mDateTimePatternGenerator = null;
            updateClock(true);
        }
        }
    }
    }