summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author mincheli <mincheli@google.com> 2020-09-01 18:59:07 +0800
committer mincheli <mincheli@google.com> 2020-09-01 20:14:59 +0800
commit47b120825662c043392b68d2c9585bf84dfcb877 (patch)
tree46ceb5bdc77c949f4913d7113b0a2d2513701a9c
parentbd3af96cb70a8e9ee2ecc1d9dccf31a91454daf8 (diff)
Keeps magnification button StartDelay for 3 secs even remove animations settings is on
When remove animations settings is on, all of the animation would be out of function and so as the start delay of magnification button animation. And this bug would make magnification mode unabled to be changed through magnification button when the settings is on because magnification button would be dismissed immediately when starting to show the button. To fix it, we use handler.postDelayed to handle the animation start delay. Bug: 167371292 Test: atest MagnificationModeSwitchTest Change-Id: Ib4e3afc8fb4dab28283afb7826b4656e113f4723
-rw-r--r--packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java18
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java7
2 files changed, 16 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java
index 128af3702c49..68e404e36bba 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java
@@ -43,6 +43,7 @@ class MagnificationModeSwitch {
private static final int DURATION_MS = 5000;
private static final int START_DELAY_MS = 3000;
+ private final Runnable mAnimationTask;
private final Context mContext;
private final WindowManager mWindowManager;
@@ -70,6 +71,14 @@ class MagnificationModeSwitch {
applyResourcesValues();
mImageView.setImageResource(getIconResId(mMagnificationMode));
mImageView.setOnTouchListener(this::onTouch);
+
+ mAnimationTask = () -> {
+ mImageView.animate()
+ .alpha(0f)
+ .setDuration(DURATION_MS)
+ .withEndAction(() -> removeButton())
+ .start();
+ };
}
private void applyResourcesValues() {
@@ -147,13 +156,8 @@ class MagnificationModeSwitch {
// Dismiss the magnification switch button after the button is displayed for a period of
// time.
mImageView.animate().cancel();
- mImageView.animate()
- .alpha(0f)
- .setStartDelay(START_DELAY_MS)
- .setDuration(DURATION_MS)
- .withEndAction(
- () -> removeButton())
- .start();
+ mImageView.removeCallbacks(mAnimationTask);
+ mImageView.postDelayed(mAnimationTask, START_DELAY_MS);
}
void onConfigurationChanged(int configDiff) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java
index cdbc647f152b..64e067396059 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java
@@ -231,7 +231,6 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
private void assertShowButtonAnimation() {
verify(mViewPropertyAnimator).cancel();
verify(mViewPropertyAnimator).setDuration(anyLong());
- verify(mViewPropertyAnimator).setStartDelay(anyLong());
verify(mViewPropertyAnimator).alpha(anyFloat());
verify(mViewPropertyAnimator).start();
}
@@ -239,11 +238,15 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
private void initMockImageViewAndAnimator() {
when(mViewPropertyAnimator.setDuration(anyLong())).thenReturn(mViewPropertyAnimator);
when(mViewPropertyAnimator.alpha(anyFloat())).thenReturn(mViewPropertyAnimator);
- when(mViewPropertyAnimator.setStartDelay(anyLong())).thenReturn(mViewPropertyAnimator);
when(mViewPropertyAnimator.withEndAction(any(Runnable.class))).thenReturn(
mViewPropertyAnimator);
when(mSpyImageView.animate()).thenReturn(mViewPropertyAnimator);
+ doAnswer(invocation -> {
+ Runnable run = invocation.getArgument(0);
+ run.run();
+ return null;
+ }).when(mSpyImageView).postDelayed(any(), anyLong());
}
private void resetMockImageViewAndAnimator() {