diff options
| author | 2021-09-30 13:22:23 +0100 | |
|---|---|---|
| committer | 2021-10-01 11:51:49 +0100 | |
| commit | 731d0c41577a9386e1c62107f163ab031b7296d2 (patch) | |
| tree | 12aeb9a6f5a8eaafa8ff0c82b11da93ffef7bc2c | |
| parent | c4c480ab7e290a308827297606fb96cf7ada2f82 (diff) | |
Fixing smartspace position on lockscreen with big clock visible on large screens
Smartspace position when big clock appears should be updated by translating smartspace view. However, calculation sometimes was done before views were laid out and then using methods like getTop() would always return 0 and it would result in incorrect translation value. The solution is to check if views were laid out and if not, schedule repositioning only after that's done.
Fixes: 201548045
Test: manual
Change-Id: Id2494c1d6e4835765550d2abe58cc678dae641c1
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java | 26 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java | 1 |
2 files changed, 25 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index 8f14cd858f1e..f81f0b9ca2c3 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -11,6 +11,7 @@ import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver.OnPreDrawListener; import android.widget.FrameLayout; import android.widget.RelativeLayout; @@ -93,6 +94,7 @@ public class KeyguardClockSwitch extends RelativeLayout { private int[] mColorPalette; private int mClockSwitchYAmount; + @VisibleForTesting boolean mChildrenAreLaidOut = false; public KeyguardClockSwitch(Context context, AttributeSet attrs) { super(context, attrs); @@ -284,11 +286,31 @@ public class KeyguardClockSwitch extends RelativeLayout { if (mDisplayedClockSize != null && clockSize == mDisplayedClockSize) { return false; } - animateClockChange(clockSize == LARGE); - mDisplayedClockSize = clockSize; + + // let's make sure clock is changed only after all views were laid out so we can + // translate them properly + if (mChildrenAreLaidOut) { + animateClockChange(clockSize == LARGE); + mDisplayedClockSize = clockSize; + } else { + getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { + @Override + public boolean onPreDraw() { + switchToClock(clockSize); + getViewTreeObserver().removeOnPreDrawListener(this); + return true; + } + }); + } return true; } + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + super.onLayout(changed, l, t, r, b); + mChildrenAreLaidOut = true; + } + public Paint getPaint() { return mClockView.getPaint(); } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java index ce02b8339422..e4336fe07dbb 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java @@ -97,6 +97,7 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { mLargeClockFrame = mKeyguardClockSwitch.findViewById(R.id.lockscreen_clock_view_large); mLargeClockView = mKeyguardClockSwitch.findViewById(R.id.animatable_clock_view_large); mBigClock = new TextClock(getContext()); + mKeyguardClockSwitch.mChildrenAreLaidOut = true; MockitoAnnotations.initMocks(this); } |