diff options
| author | 2020-12-11 03:07:59 +0000 | |
|---|---|---|
| committer | 2020-12-11 03:07:59 +0000 | |
| commit | 6d356b3cfefeec2c6df025f8d6ef555ffd39b573 (patch) | |
| tree | 9994bd7dfac69b7d64cd6e908b40268b202035dc | |
| parent | 25c8f6395eea1424825dca0737d7f3b730c961a8 (diff) | |
| parent | d245501a5c9972b6ee948361aaa1eb743ed9e840 (diff) | |
Merge "Fix button is gone after dragging over 5 secs"
2 files changed, 55 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java index 267debc7dc2d..edc3216e0b81 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java @@ -149,7 +149,7 @@ class MagnificationModeSwitch { } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - mImageView.animate().cancel(); + stopFadeOutAnimation(); mLastDown.set(event.getRawX(), event.getRawY()); mLastDrag.set(event.getRawX(), event.getRawY()); return true; @@ -217,13 +217,18 @@ class MagnificationModeSwitch { AccessibilityManager.FLAG_CONTENT_ICONS | AccessibilityManager.FLAG_CONTENT_CONTROLS); } + // Refresh the time slot of the fade-out task whenever this method is called. + stopFadeOutAnimation(); + mImageView.postOnAnimationDelayed(mFadeOutAnimationTask, mUiTimeout); + } + + private void stopFadeOutAnimation() { + mImageView.removeCallbacks(mFadeOutAnimationTask); if (mIsFadeOutAnimating) { mImageView.animate().cancel(); mImageView.setAlpha(1f); + mIsFadeOutAnimating = false; } - // Refresh the time slot of the fade-out task whenever this method is called. - mImageView.removeCallbacks(mFadeOutAnimationTask); - mImageView.postOnAnimationDelayed(mFadeOutAnimationTask, mUiTimeout); } 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 0451d45a628b..96f3c156c978 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java @@ -33,6 +33,7 @@ import static junit.framework.Assert.assertNotNull; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; @@ -91,6 +92,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { private MagnificationModeSwitch mMagnificationModeSwitch; private View.OnTouchListener mTouchListener; private List<MotionEvent> mMotionEvents = new ArrayList<>(); + private Runnable mFadeOutAnimation; @Before public void setUp() throws Exception { @@ -119,6 +121,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { event.recycle(); } mMotionEvents.clear(); + mFadeOutAnimation = null; } @Test @@ -164,15 +167,9 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { } @Test - public void showMagnificationButton_windowMode_verifyAnimationEndAction() { - // Execute the runnable immediately to run the animation. - doAnswer((invocation) -> { - final Runnable action = invocation.getArgument(0); - action.run(); - return null; - }).when(mSpyImageView).postOnAnimationDelayed(any(Runnable.class), anyLong()); - + public void showMagnificationButton_windowModeAndFadingOut_verifyAnimationEndAction() { mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW); + executeFadeOutAnimation(); // Verify the end action after fade-out. final ArgumentCaptor<Runnable> endActionCaptor = ArgumentCaptor.forClass(Runnable.class); @@ -207,9 +204,6 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { final long downTime = SystemClock.uptimeMillis(); mTouchListener.onTouch(mSpyImageView, obtainMotionEvent(downTime, 0, ACTION_DOWN, 100, 100)); - - verify(mViewPropertyAnimator).cancel(); - resetAndStubMockImageViewAndAnimator(); mTouchListener.onTouch(mSpyImageView, obtainMotionEvent(downTime, downTime, ACTION_UP, 100, 100)); @@ -218,6 +212,31 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { } @Test + public void sendDownEvent_fullscreenMode_fadeOutAnimationIsNull() { + mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); + resetAndStubMockImageViewAndAnimator(); + + final long downTime = SystemClock.uptimeMillis(); + mTouchListener.onTouch(mSpyImageView, + obtainMotionEvent(downTime, 0, ACTION_DOWN, 100, 100)); + + assertNull(mFadeOutAnimation); + } + + @Test + public void sendDownEvent_fullscreenModeAndFadingOut_cancelAnimation() { + mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); + executeFadeOutAnimation(); + resetAndStubMockImageViewAndAnimator(); + + final long downTime = SystemClock.uptimeMillis(); + mTouchListener.onTouch(mSpyImageView, + obtainMotionEvent(downTime, 0, ACTION_DOWN, 100, 100)); + + verify(mViewPropertyAnimator).cancel(); + } + + @Test public void performDragging_showMagnificationButton_updateViewLayout() { mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); resetAndStubMockImageViewAndAnimator(); @@ -229,7 +248,6 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { final long downTime = SystemClock.uptimeMillis(); mTouchListener.onTouch(mSpyImageView, obtainMotionEvent( downTime, 0, ACTION_DOWN, 100, 100)); - verify(mViewPropertyAnimator).cancel(); mTouchListener.onTouch(mSpyImageView, obtainMotionEvent(downTime, downTime, ACTION_MOVE, 100 + offset, @@ -384,6 +402,16 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { return null; }).when(mSpyImageView).post(any(Runnable.class)); doReturn(mViewPropertyAnimator).when(mSpyImageView).animate(); + doAnswer((invocation) -> { + mFadeOutAnimation = invocation.getArgument(0); + return null; + }).when(mSpyImageView).postOnAnimationDelayed(any(Runnable.class), anyLong()); + doAnswer((invocation) -> { + if (mFadeOutAnimation == invocation.getArgument(0)) { + mFadeOutAnimation = null; + } + return null; + }).when(mSpyImageView).removeCallbacks(any(Runnable.class)); } private void resetAndStubMockAnimator() { @@ -412,4 +440,10 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { mMotionEvents.add(event); return event; } + + private void executeFadeOutAnimation() { + assertNotNull(mFadeOutAnimation); + mFadeOutAnimation.run(); + mFadeOutAnimation = null; + } } |