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

Unverified Commit 7529e539 authored by Michael Bestas's avatar Michael Bestas
Browse files

SystemUI: Clock AM/PM style customization



Co-authored-by: default avatarDhina17 <dhinalogu@gmail.com>
Change-Id: I7f27f135ae0d1e731c936792f655c115f107d20c
parent e4581380
Loading
Loading
Loading
Loading
+32 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.icu.lang.UCharacter;
import android.icu.text.DateTimePatternGenerator;
@@ -60,6 +61,8 @@ import com.android.systemui.statusbar.policy.ConfigurationController.Configurati
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

import lineageos.providers.LineageSettings;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -103,7 +106,8 @@ public class Clock extends TextView implements
    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 ContentObserver mContentObserver;
    private boolean mShowSeconds;
    private Handler mSecondsHandler;

@@ -135,7 +139,22 @@ public class Clock extends TextView implements
                R.styleable.Clock,
                0, 0);
        try {
            mAmPmStyle = a.getInt(R.styleable.Clock_amPmStyle, AM_PM_STYLE_GONE);
            mAmPmStyle = LineageSettings.System.getInt(mContext.getContentResolver(),
                    LineageSettings.System.STATUS_BAR_AM_PM, AM_PM_STYLE_GONE);
            mContentObserver = new ContentObserver(null) {
                @Override
                public void onChange(boolean selfChange) {
                    mAmPmStyle = LineageSettings.System.getInt(
                            mContext.getContentResolver(),
                            LineageSettings.System.STATUS_BAR_AM_PM, AM_PM_STYLE_GONE);
                    // Force refresh of dependent variables.
                    mContentDescriptionFormatString = "";
                    mDateTimePatternGenerator = null;
                    mContext.getMainExecutor().execute(() -> {
                        updateClock(true);
                    });
                }
            };
            mNonAdaptedColor = getCurrentTextColor();
        } finally {
            a.recycle();
@@ -199,6 +218,9 @@ public class Clock extends TextView implements
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
                    Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS);
            mContext.getContentResolver().registerContentObserver(
                    LineageSettings.System.getUriFor(LineageSettings.System.STATUS_BAR_AM_PM),
                    false, mContentObserver);
            mCommandQueue.addCallback(this);
            mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
            mCurrentUserId = mUserTracker.getUserId();
@@ -231,6 +253,7 @@ public class Clock extends TextView implements
        if (mAttached) {
            mBroadcastDispatcher.unregisterReceiver(mIntentReceiver);
            mAttached = false;
            mContext.getContentResolver().unregisterContentObserver(mContentObserver);
            Dependency.get(TunerService.class).removeTunable(this);
            mCommandQueue.removeCallback(this);
            mUserTracker.removeCallback(mUserChangedCallback);
@@ -310,19 +333,23 @@ public class Clock extends TextView implements
        super.setVisibility(visibility);
    }

    final void updateClock() {
        if (mDemoMode) return;
    final void updateClock(boolean forceTextUpdate) {
        if (mDemoMode || mCalendar == null) return;
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        CharSequence smallTime = getSmallTime();
        // 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
        // relayout if the text didn't actually change.
        if (!TextUtils.equals(smallTime, getText())) {
        if (forceTextUpdate || !TextUtils.equals(smallTime, getText())) {
            setText(smallTime);
        }
        setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
    }

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

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (CLOCK_SECONDS.equals(key)) {