Loading packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java +11 −8 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { private Boolean mCapture; private boolean mBouncerInitiallyShowing; private TouchSession mTouchSession; private ValueAnimatorCreator mValueAnimatorCreator; Loading @@ -97,6 +99,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { // If the user scrolling favors a vertical direction, begin capturing // scrolls. mCapture = Math.abs(distanceY) > Math.abs(distanceX); mBouncerInitiallyShowing = mCentralSurfaces.isBouncerShowing(); if (mCapture) { // Since the user is dragging the bouncer up, set scrimmed to false. Loading @@ -115,7 +118,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { // (0). final float screenTravelPercentage = Math.abs((e1.getY() - e2.getY()) / mCentralSurfaces.getDisplayHeight()); setPanelExpansion(mCentralSurfaces.isBouncerShowing() setPanelExpansion(mBouncerInitiallyShowing ? screenTravelPercentage : 1 - screenTravelPercentage); return true; } Loading Loading @@ -174,16 +177,16 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { mTouchSession = session; mVelocityTracker.clear(); mNotificationShadeWindowController.setForcePluginOpen(true, this); session.registerGestureListener(mOnGestureListener); session.registerInputListener(ev -> onMotionEvent(ev)); } @Override public void onSessionEnd(TouchSession session) { session.registerCallback(() -> { mVelocityTracker.recycle(); mCapture = null; mNotificationShadeWindowController.setForcePluginOpen(false, this); }); session.registerGestureListener(mOnGestureListener); session.registerInputListener(ev -> onMotionEvent(ev)); } private void onMotionEvent(InputEvent event) { Loading packages/SystemUI/src/com/android/systemui/dreams/touch/DreamTouchHandler.java +0 −7 Original line number Diff line number Diff line Loading @@ -96,11 +96,4 @@ public interface DreamTouchHandler { * @param session */ void onSessionStart(TouchSession session); /** * Invoked when a session has ended. This will be invoked for every session completion, even * those that are removed through {@link TouchSession#pop()}. * @param session */ default void onSessionEnd(TouchSession session) { } } packages/SystemUI/src/com/android/systemui/dreams/touch/HideComplicationTouchHandler.java +0 −7 Original line number Diff line number Diff line Loading @@ -127,11 +127,4 @@ public class HideComplicationTouchHandler implements DreamTouchHandler { } }); } @Override public void onSessionEnd(TouchSession session) { if (DEBUG) { Log.d(TAG, "onSessionEnd"); } } } packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java +46 −10 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.graphics.Region; import android.testing.AndroidTestingRunner; import android.util.DisplayMetrics; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.VelocityTracker; Loading Loading @@ -111,6 +112,7 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase { mFlingAnimationUtilsClosing, TOUCH_REGION); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); when(mCentralSurfaces.getDisplayHeight()).thenReturn((float) SCREEN_HEIGHT_PX); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator); Loading Loading @@ -162,24 +164,58 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase { ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class); verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture()); final float scrollAmount = .3f; final float distanceY = SCREEN_HEIGHT_PX * scrollAmount; final OnGestureListener gestureListener = gestureListenerCaptor.getValue(); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); verifyScroll(.3f, Direction.UP, true, gestureListener); // Ensure that subsequent gestures are treated as expanding even if the bouncer state // changes. when(mCentralSurfaces.isBouncerShowing()).thenReturn(true); verifyScroll(.7f, Direction.UP, true, gestureListener); } /** * Makes sure collapse amount is proportional to scroll. */ @Test public void testCollapseAmount() { mTouchHandler.onSessionStart(mTouchSession); ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor = ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class); verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture()); final OnGestureListener gestureListener = gestureListenerCaptor.getValue(); when(mCentralSurfaces.isBouncerShowing()).thenReturn(true); verifyScroll(.3f, Direction.DOWN, false, gestureListener); // Ensure that subsequent gestures are treated as collapsing even if the bouncer state // changes. when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); verifyScroll(.7f, Direction.DOWN, false, gestureListener); } private enum Direction { DOWN, UP, } private void verifyScroll(float percent, Direction direction, boolean expanding, android.view.GestureDetector.OnGestureListener gestureListener) { final float distanceY = SCREEN_HEIGHT_PX * percent; final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, SCREEN_HEIGHT_PX, 0); 0, direction == Direction.UP ? SCREEN_HEIGHT_PX : 0, 0); final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, SCREEN_HEIGHT_PX - distanceY, 0); 0, direction == Direction.UP ? SCREEN_HEIGHT_PX - distanceY : distanceY, 0); assertThat(gestureListenerCaptor.getValue().onScroll(event1, event2, 0, distanceY)) assertThat(gestureListener.onScroll(event1, event2, 0, distanceY)) .isTrue(); // Ensure only called once verify(mStatusBarKeyguardViewManager) .onPanelExpansionChanged(anyFloat(), anyBoolean(), anyBoolean()); // Ensure correct expansion passed in. verify(mStatusBarKeyguardViewManager) .onPanelExpansionChanged(eq(1 - scrollAmount), eq(false), eq(true)); .onPanelExpansionChanged( eq(expanding ? 1 - percent : percent), eq(false), eq(true)); } /** Loading packages/SystemUI/tests/src/com/android/systemui/dreams/touch/DreamOverlayTouchMonitorTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -344,6 +344,26 @@ public class DreamOverlayTouchMonitorTest extends SysuiTestCase { verify(frontEventListener, never()).onInputEvent(any()); } @Test public void testPop() { final DreamTouchHandler touchHandler = Mockito.mock(DreamTouchHandler.class); final DreamTouchHandler.TouchSession.Callback callback = Mockito.mock(DreamTouchHandler.TouchSession.Callback.class); final Environment environment = new Environment(Stream.of(touchHandler) .collect(Collectors.toCollection(HashSet::new))); final InputEvent initialEvent = Mockito.mock(InputEvent.class); environment.publishInputEvent(initialEvent); final DreamTouchHandler.TouchSession session = captureSession(touchHandler); session.registerCallback(callback); session.pop(); environment.executeAll(); verify(callback).onRemoved(); } @Test public void testPause() { final DreamTouchHandler touchHandler = Mockito.mock(DreamTouchHandler.class); Loading Loading
packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java +11 −8 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { private Boolean mCapture; private boolean mBouncerInitiallyShowing; private TouchSession mTouchSession; private ValueAnimatorCreator mValueAnimatorCreator; Loading @@ -97,6 +99,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { // If the user scrolling favors a vertical direction, begin capturing // scrolls. mCapture = Math.abs(distanceY) > Math.abs(distanceX); mBouncerInitiallyShowing = mCentralSurfaces.isBouncerShowing(); if (mCapture) { // Since the user is dragging the bouncer up, set scrimmed to false. Loading @@ -115,7 +118,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { // (0). final float screenTravelPercentage = Math.abs((e1.getY() - e2.getY()) / mCentralSurfaces.getDisplayHeight()); setPanelExpansion(mCentralSurfaces.isBouncerShowing() setPanelExpansion(mBouncerInitiallyShowing ? screenTravelPercentage : 1 - screenTravelPercentage); return true; } Loading Loading @@ -174,16 +177,16 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { mTouchSession = session; mVelocityTracker.clear(); mNotificationShadeWindowController.setForcePluginOpen(true, this); session.registerGestureListener(mOnGestureListener); session.registerInputListener(ev -> onMotionEvent(ev)); } @Override public void onSessionEnd(TouchSession session) { session.registerCallback(() -> { mVelocityTracker.recycle(); mCapture = null; mNotificationShadeWindowController.setForcePluginOpen(false, this); }); session.registerGestureListener(mOnGestureListener); session.registerInputListener(ev -> onMotionEvent(ev)); } private void onMotionEvent(InputEvent event) { Loading
packages/SystemUI/src/com/android/systemui/dreams/touch/DreamTouchHandler.java +0 −7 Original line number Diff line number Diff line Loading @@ -96,11 +96,4 @@ public interface DreamTouchHandler { * @param session */ void onSessionStart(TouchSession session); /** * Invoked when a session has ended. This will be invoked for every session completion, even * those that are removed through {@link TouchSession#pop()}. * @param session */ default void onSessionEnd(TouchSession session) { } }
packages/SystemUI/src/com/android/systemui/dreams/touch/HideComplicationTouchHandler.java +0 −7 Original line number Diff line number Diff line Loading @@ -127,11 +127,4 @@ public class HideComplicationTouchHandler implements DreamTouchHandler { } }); } @Override public void onSessionEnd(TouchSession session) { if (DEBUG) { Log.d(TAG, "onSessionEnd"); } } }
packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java +46 −10 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.graphics.Region; import android.testing.AndroidTestingRunner; import android.util.DisplayMetrics; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.VelocityTracker; Loading Loading @@ -111,6 +112,7 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase { mFlingAnimationUtilsClosing, TOUCH_REGION); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); when(mCentralSurfaces.getDisplayHeight()).thenReturn((float) SCREEN_HEIGHT_PX); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator); Loading Loading @@ -162,24 +164,58 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase { ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class); verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture()); final float scrollAmount = .3f; final float distanceY = SCREEN_HEIGHT_PX * scrollAmount; final OnGestureListener gestureListener = gestureListenerCaptor.getValue(); when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); verifyScroll(.3f, Direction.UP, true, gestureListener); // Ensure that subsequent gestures are treated as expanding even if the bouncer state // changes. when(mCentralSurfaces.isBouncerShowing()).thenReturn(true); verifyScroll(.7f, Direction.UP, true, gestureListener); } /** * Makes sure collapse amount is proportional to scroll. */ @Test public void testCollapseAmount() { mTouchHandler.onSessionStart(mTouchSession); ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor = ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class); verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture()); final OnGestureListener gestureListener = gestureListenerCaptor.getValue(); when(mCentralSurfaces.isBouncerShowing()).thenReturn(true); verifyScroll(.3f, Direction.DOWN, false, gestureListener); // Ensure that subsequent gestures are treated as collapsing even if the bouncer state // changes. when(mCentralSurfaces.isBouncerShowing()).thenReturn(false); verifyScroll(.7f, Direction.DOWN, false, gestureListener); } private enum Direction { DOWN, UP, } private void verifyScroll(float percent, Direction direction, boolean expanding, android.view.GestureDetector.OnGestureListener gestureListener) { final float distanceY = SCREEN_HEIGHT_PX * percent; final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, SCREEN_HEIGHT_PX, 0); 0, direction == Direction.UP ? SCREEN_HEIGHT_PX : 0, 0); final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, SCREEN_HEIGHT_PX - distanceY, 0); 0, direction == Direction.UP ? SCREEN_HEIGHT_PX - distanceY : distanceY, 0); assertThat(gestureListenerCaptor.getValue().onScroll(event1, event2, 0, distanceY)) assertThat(gestureListener.onScroll(event1, event2, 0, distanceY)) .isTrue(); // Ensure only called once verify(mStatusBarKeyguardViewManager) .onPanelExpansionChanged(anyFloat(), anyBoolean(), anyBoolean()); // Ensure correct expansion passed in. verify(mStatusBarKeyguardViewManager) .onPanelExpansionChanged(eq(1 - scrollAmount), eq(false), eq(true)); .onPanelExpansionChanged( eq(expanding ? 1 - percent : percent), eq(false), eq(true)); } /** Loading
packages/SystemUI/tests/src/com/android/systemui/dreams/touch/DreamOverlayTouchMonitorTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -344,6 +344,26 @@ public class DreamOverlayTouchMonitorTest extends SysuiTestCase { verify(frontEventListener, never()).onInputEvent(any()); } @Test public void testPop() { final DreamTouchHandler touchHandler = Mockito.mock(DreamTouchHandler.class); final DreamTouchHandler.TouchSession.Callback callback = Mockito.mock(DreamTouchHandler.TouchSession.Callback.class); final Environment environment = new Environment(Stream.of(touchHandler) .collect(Collectors.toCollection(HashSet::new))); final InputEvent initialEvent = Mockito.mock(InputEvent.class); environment.publishInputEvent(initialEvent); final DreamTouchHandler.TouchSession session = captureSession(touchHandler); session.registerCallback(callback); session.pop(); environment.executeAll(); verify(callback).onRemoved(); } @Test public void testPause() { final DreamTouchHandler touchHandler = Mockito.mock(DreamTouchHandler.class); Loading