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

Commit e6284008 authored by Stefan Andonian's avatar Stefan Andonian
Browse files

Apply the clockIconDrawable's time in its constructor.

It is NOT guaranteed that drawInner will be called before a
ClockIconDrawable UX is shown on screen. To test this, I tinted the
ClockIconDrawable's foreground blue in its constructor, and red in its
drawInner method. If drawInner was always called before showing the
ClockIconDrawable on screen, it would be expected that all visible
ClockIconDrawables would have red tinted foregrounds. Instead, only 1
ClockIconDrawable is tinted red, and the rest are tinted blue. Here is
a screenshot: https://screenshot.googleplex.com/5saGse4nazp98QB.png.
Therefore, it can be concluded that drawInner is NOT guaranteed to run
before showing a ClockIconDrawable on screen. To failsafe against the
event that drawInner is not called before showing a ClockIconDrawable's
UX on screen, we set the time immediately in ClockIconDrawable's constructor. This method takes less than 1 ms to run and so there is no performance hit for putting this line of code here.

Bug: 188377749
Test: Verified that the time doesn't jump backwards to an incorrect time
when a user taps on the clock icon, then rapidly swipes back. It stays
at the same time as it was before the user tapped on the clock icon.

Change-Id: I67328c973d97974bcea340943f7ce02c55550d8e
parent 64644a3b
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -389,6 +389,10 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap

            mFullDrawable = (AdaptiveIconDrawable) mAnimInfo.baseDrawableState.newDrawable();
            mFG = (LayerDrawable) mFullDrawable.getForeground();

            // Time needs to be applied here since drawInternal is NOT guaranteed to be called
            // before this foreground drawable is shown on the screen.
            mAnimInfo.applyTime(mTime, mFG);
            mCanvasScale = 1 - 2 * mBoundsOffset;
        }

@@ -421,18 +425,6 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap
            reschedule();
        }

        @Override
        public boolean setState(int[] stateSet) {
            // If the user has just pressed the clock icon, and the clock app is launching,
            // we don't want to change the time shown. Doing so can result in jank.
            for (int state: stateSet) {
                if (state == android.R.attr.state_pressed) {
                    return false;
                }
            }
            return super.setState(stateSet);
        }

        @Override
        public boolean isThemed() {
            return mBgPaint.getColorFilter() != null;