diff options
3 files changed, 18 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index 6fd0c821bad1..3d4e896178f6 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -89,6 +89,7 @@ public class KeyguardClockSwitch extends RelativeLayout { private int mClockSwitchYAmount; @VisibleForTesting boolean mChildrenAreLaidOut = false; + private OnPreDrawListener mPreDrawListener; public KeyguardClockSwitch(Context context, AttributeSet attrs) { super(context, attrs); @@ -284,15 +285,14 @@ public class KeyguardClockSwitch extends RelativeLayout { if (mChildrenAreLaidOut) { animateClockChange(clockSize == LARGE); mDisplayedClockSize = clockSize; - } else { - getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { - @Override - public boolean onPreDraw() { - switchToClock(clockSize); - getViewTreeObserver().removeOnPreDrawListener(this); - return true; - } - }); + } else if (mPreDrawListener == null) { + mPreDrawListener = () -> { + switchToClock(clockSize); + getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener); + mPreDrawListener = null; + return true; + }; + getViewTreeObserver().addOnPreDrawListener(mPreDrawListener); } return true; } @@ -303,6 +303,13 @@ public class KeyguardClockSwitch extends RelativeLayout { mChildrenAreLaidOut = true; } + void onViewDetached() { + if (mPreDrawListener != null) { + getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener); + mPreDrawListener = null; + } + } + public Paint getPaint() { return mClockView.getPaint(); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 01976b41a4b2..1931c0a1645c 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -238,6 +238,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } mColorExtractor.removeOnColorsChangedListener(mColorsListener); mView.setClockPlugin(null, mStatusBarStateController.getState()); + mView.onViewDetached(); } /** diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java index fe0a2a4bbb14..5e0f427800fc 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java @@ -194,7 +194,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { verifyAttachment(times(1)); listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView); - + verify(mView).onViewDetached(); verify(mColorExtractor).removeOnColorsChangedListener( any(ColorExtractor.OnColorsChangedListener.class)); } |