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

Commit 6d356b3c authored by Ryan Lin's avatar Ryan Lin Committed by Android (Google) Code Review
Browse files

Merge "Fix button is gone after dragging over 5 secs"

parents 25c8f639 d245501a
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -149,7 +149,7 @@ class MagnificationModeSwitch {
        }
        }
        switch (event.getAction()) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_DOWN:
                mImageView.animate().cancel();
                stopFadeOutAnimation();
                mLastDown.set(event.getRawX(), event.getRawY());
                mLastDown.set(event.getRawX(), event.getRawY());
                mLastDrag.set(event.getRawX(), event.getRawY());
                mLastDrag.set(event.getRawX(), event.getRawY());
                return true;
                return true;
@@ -217,13 +217,18 @@ class MagnificationModeSwitch {
                    AccessibilityManager.FLAG_CONTENT_ICONS
                    AccessibilityManager.FLAG_CONTENT_ICONS
                            | AccessibilityManager.FLAG_CONTENT_CONTROLS);
                            | 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) {
        if (mIsFadeOutAnimating) {
            mImageView.animate().cancel();
            mImageView.animate().cancel();
            mImageView.setAlpha(1f);
            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) {
    void onConfigurationChanged(int configDiff) {
+46 −12
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import static junit.framework.Assert.assertNotNull;


import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -91,6 +92,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
    private MagnificationModeSwitch mMagnificationModeSwitch;
    private MagnificationModeSwitch mMagnificationModeSwitch;
    private View.OnTouchListener mTouchListener;
    private View.OnTouchListener mTouchListener;
    private List<MotionEvent> mMotionEvents = new ArrayList<>();
    private List<MotionEvent> mMotionEvents = new ArrayList<>();
    private Runnable mFadeOutAnimation;


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -119,6 +121,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
            event.recycle();
            event.recycle();
        }
        }
        mMotionEvents.clear();
        mMotionEvents.clear();
        mFadeOutAnimation = null;
    }
    }


    @Test
    @Test
@@ -164,15 +167,9 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
    }
    }


    @Test
    @Test
    public void showMagnificationButton_windowMode_verifyAnimationEndAction() {
    public void showMagnificationButton_windowModeAndFadingOut_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());

        mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
        mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
        executeFadeOutAnimation();


        // Verify the end action after fade-out.
        // Verify the end action after fade-out.
        final ArgumentCaptor<Runnable> endActionCaptor = ArgumentCaptor.forClass(Runnable.class);
        final ArgumentCaptor<Runnable> endActionCaptor = ArgumentCaptor.forClass(Runnable.class);
@@ -207,9 +204,6 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        final long downTime = SystemClock.uptimeMillis();
        final long downTime = SystemClock.uptimeMillis();
        mTouchListener.onTouch(mSpyImageView,
        mTouchListener.onTouch(mSpyImageView,
                obtainMotionEvent(downTime, 0, ACTION_DOWN, 100, 100));
                obtainMotionEvent(downTime, 0, ACTION_DOWN, 100, 100));

        verify(mViewPropertyAnimator).cancel();

        resetAndStubMockImageViewAndAnimator();
        resetAndStubMockImageViewAndAnimator();
        mTouchListener.onTouch(mSpyImageView,
        mTouchListener.onTouch(mSpyImageView,
                obtainMotionEvent(downTime, downTime, ACTION_UP, 100, 100));
                obtainMotionEvent(downTime, downTime, ACTION_UP, 100, 100));
@@ -217,6 +211,31 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        verifyTapAction(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
        verifyTapAction(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
    }
    }


    @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
    @Test
    public void performDragging_showMagnificationButton_updateViewLayout() {
    public void performDragging_showMagnificationButton_updateViewLayout() {
        mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
        mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
@@ -229,7 +248,6 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        final long downTime = SystemClock.uptimeMillis();
        final long downTime = SystemClock.uptimeMillis();
        mTouchListener.onTouch(mSpyImageView, obtainMotionEvent(
        mTouchListener.onTouch(mSpyImageView, obtainMotionEvent(
                downTime, 0, ACTION_DOWN, 100, 100));
                downTime, 0, ACTION_DOWN, 100, 100));
        verify(mViewPropertyAnimator).cancel();


        mTouchListener.onTouch(mSpyImageView,
        mTouchListener.onTouch(mSpyImageView,
                obtainMotionEvent(downTime, downTime, ACTION_MOVE, 100 + offset,
                obtainMotionEvent(downTime, downTime, ACTION_MOVE, 100 + offset,
@@ -384,6 +402,16 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
            return null;
            return null;
        }).when(mSpyImageView).post(any(Runnable.class));
        }).when(mSpyImageView).post(any(Runnable.class));
        doReturn(mViewPropertyAnimator).when(mSpyImageView).animate();
        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() {
    private void resetAndStubMockAnimator() {
@@ -412,4 +440,10 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        mMotionEvents.add(event);
        mMotionEvents.add(event);
        return event;
        return event;
    }
    }

    private void executeFadeOutAnimation() {
        assertNotNull(mFadeOutAnimation);
        mFadeOutAnimation.run();
        mFadeOutAnimation = null;
    }
}
}