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

Commit 13c9ec25 authored by Greg Ross's avatar Greg Ross Committed by Michael Bestas
Browse files

DeskClock: Fix display of AM/PM on screensaver

Fix regression introduced in I4bab4ce31630e6d2a5a1c857db9a76356f66e0ce
which caused the AM/PM indicator on the clock screensaver to be
displayed in bold text while the rest of the time is displayed in
regular text.

Change-Id: Id32a6587e28f99d99f6f546d92fad0f342b264bb
parent 8002d9cd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public final class Screensaver extends DreamService {

        setClockStyle();
        Utils.setClockIconTypeface(mContentView);
        Utils.setTimeFormat(mDigitalClock, false);
        Utils.setScreensaverTimeFormat(mDigitalClock, false);
        mAnalogClock.enableSeconds(false);

        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class ScreensaverActivity extends BaseActivity {
        final AnalogClock analogClock = mMainClockView.findViewById(R.id.analog_clock);

        Utils.setClockIconTypeface(mMainClockView);
        Utils.setTimeFormat((TextClock) digitalClock, false);
        Utils.setScreensaverTimeFormat((TextClock) digitalClock, false);
        Utils.setClockStyle(digitalClock, analogClock);
        Utils.dimClockView(true, mMainClockView);
        analogClock.enableSeconds(false);
+31 −3
Original line number Diff line number Diff line
@@ -326,7 +326,23 @@ public class Utils {
    public static void setTimeFormat(TextClock clock, boolean includeSeconds) {
        if (clock != null) {
            // Get the best format for 12 hours mode according to the locale
            clock.setFormat12Hour(get12ModeFormat(0.4f /* amPmRatio */, includeSeconds));
            clock.setFormat12Hour(get12ModeFormat(0.4f /* amPmRatio */, includeSeconds, true));
            // Get the best format for 24 hours mode according to the locale
            clock.setFormat24Hour(get24ModeFormat(includeSeconds));
        }
    }

    /***
     * Formats the time in the TextClock for the screensaver according to the Locale with a special
     * formatting treatment for the am/pm label.
     *
     * @param clock          TextClock to format
     * @param includeSeconds whether or not to include seconds in the clock's time
     */
    public static void setScreensaverTimeFormat(TextClock clock, boolean includeSeconds) {
        if (clock != null) {
            // Get the best format for 12 hours mode according to the locale
            clock.setFormat12Hour(get12ModeFormat(0.4f /* amPmRatio */, includeSeconds, false));
            // Get the best format for 24 hours mode according to the locale
            clock.setFormat24Hour(get24ModeFormat(includeSeconds));
        }
@@ -339,6 +355,18 @@ public class Utils {
     * @return format string for 12 hours mode time, not including seconds
     */
    public static CharSequence get12ModeFormat(float amPmRatio, boolean includeSeconds) {
        return get12ModeFormat(amPmRatio, includeSeconds, true);
    }

    /**
     * @param amPmRatio      a value between 0 and 1 that is the ratio of the relative size of the
     *                       am/pm string to the time string
     * @param includeSeconds whether or not to include seconds in the time string
     * @param amPmBolded     whether or not to bold the AM/PM
     * @return format string for 12 hours mode time, not including seconds
     */
    public static CharSequence get12ModeFormat(float amPmRatio, boolean includeSeconds,
            boolean amPmBolded) {
        String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(),
                includeSeconds ? "hmsa" : "hma");
        if (amPmRatio <= 0) {
@@ -356,8 +384,8 @@ public class Utils {
        final Spannable sp = new SpannableString(pattern);
        sp.setSpan(new RelativeSizeSpan(amPmRatio), amPmPos, amPmPos + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sp.setSpan(new StyleSpan(Typeface.BOLD), amPmPos, amPmPos + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sp.setSpan(new StyleSpan(amPmBolded ? Typeface.BOLD : Typeface.NORMAL), amPmPos,
                amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sp.setSpan(new TypefaceSpan("sans-serif"), amPmPos, amPmPos + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);