Merge "Add logging for Dream swipe up to show Bouncer." into tm-dev
This commit is contained in:
@@ -30,6 +30,10 @@ import android.view.InputEvent;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.VelocityTracker;
|
import android.view.VelocityTracker;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import com.android.internal.logging.UiEvent;
|
||||||
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
||||||
import com.android.systemui.statusbar.phone.CentralSurfaces;
|
import com.android.systemui.statusbar.phone.CentralSurfaces;
|
||||||
import com.android.systemui.statusbar.phone.KeyguardBouncer;
|
import com.android.systemui.statusbar.phone.KeyguardBouncer;
|
||||||
@@ -90,6 +94,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
|
|||||||
|
|
||||||
private VelocityTrackerFactory mVelocityTrackerFactory;
|
private VelocityTrackerFactory mVelocityTrackerFactory;
|
||||||
|
|
||||||
|
private final UiEventLogger mUiEventLogger;
|
||||||
|
|
||||||
private final GestureDetector.OnGestureListener mOnGestureListener =
|
private final GestureDetector.OnGestureListener mOnGestureListener =
|
||||||
new GestureDetector.SimpleOnGestureListener() {
|
new GestureDetector.SimpleOnGestureListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -131,6 +137,23 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
|
|||||||
mStatusBarKeyguardViewManager.onPanelExpansionChanged(mCurrentExpansion, false, true);
|
mStatusBarKeyguardViewManager.onPanelExpansionChanged(mCurrentExpansion, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public enum DreamEvent implements UiEventLogger.UiEventEnum {
|
||||||
|
@UiEvent(doc = "The screensaver has been swiped up.")
|
||||||
|
DREAM_SWIPED(988);
|
||||||
|
|
||||||
|
private final int mId;
|
||||||
|
|
||||||
|
DreamEvent(int id) {
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BouncerSwipeTouchHandler(
|
public BouncerSwipeTouchHandler(
|
||||||
DisplayMetrics displayMetrics,
|
DisplayMetrics displayMetrics,
|
||||||
@@ -143,7 +166,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
|
|||||||
FlingAnimationUtils flingAnimationUtils,
|
FlingAnimationUtils flingAnimationUtils,
|
||||||
@Named(SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_CLOSING)
|
@Named(SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_CLOSING)
|
||||||
FlingAnimationUtils flingAnimationUtilsClosing,
|
FlingAnimationUtils flingAnimationUtilsClosing,
|
||||||
@Named(SWIPE_TO_BOUNCER_START_REGION) float swipeRegionPercentage) {
|
@Named(SWIPE_TO_BOUNCER_START_REGION) float swipeRegionPercentage,
|
||||||
|
UiEventLogger uiEventLogger) {
|
||||||
mDisplayMetrics = displayMetrics;
|
mDisplayMetrics = displayMetrics;
|
||||||
mCentralSurfaces = centralSurfaces;
|
mCentralSurfaces = centralSurfaces;
|
||||||
mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
|
mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
|
||||||
@@ -153,6 +177,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
|
|||||||
mFlingAnimationUtilsClosing = flingAnimationUtilsClosing;
|
mFlingAnimationUtilsClosing = flingAnimationUtilsClosing;
|
||||||
mValueAnimatorCreator = valueAnimatorCreator;
|
mValueAnimatorCreator = valueAnimatorCreator;
|
||||||
mVelocityTrackerFactory = velocityTrackerFactory;
|
mVelocityTrackerFactory = velocityTrackerFactory;
|
||||||
|
mUiEventLogger = uiEventLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,6 +245,12 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
|
|||||||
|
|
||||||
final float expansion = flingRevealsOverlay(verticalVelocity, velocityVector)
|
final float expansion = flingRevealsOverlay(verticalVelocity, velocityVector)
|
||||||
? KeyguardBouncer.EXPANSION_HIDDEN : KeyguardBouncer.EXPANSION_VISIBLE;
|
? KeyguardBouncer.EXPANSION_HIDDEN : KeyguardBouncer.EXPANSION_VISIBLE;
|
||||||
|
|
||||||
|
// Log the swiping up to show Bouncer event.
|
||||||
|
if (!mBouncerInitiallyShowing && expansion == KeyguardBouncer.EXPANSION_VISIBLE) {
|
||||||
|
mUiEventLogger.log(DreamEvent.DREAM_SWIPED);
|
||||||
|
}
|
||||||
|
|
||||||
flingToExpansion(verticalVelocity, expansion);
|
flingToExpansion(verticalVelocity, expansion);
|
||||||
|
|
||||||
if (expansion == KeyguardBouncer.EXPANSION_HIDDEN) {
|
if (expansion == KeyguardBouncer.EXPANSION_HIDDEN) {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -37,6 +39,7 @@ import android.view.VelocityTracker;
|
|||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.systemui.shared.system.InputChannelCompat;
|
import com.android.systemui.shared.system.InputChannelCompat;
|
||||||
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
||||||
@@ -89,6 +92,9 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
VelocityTracker mVelocityTracker;
|
VelocityTracker mVelocityTracker;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
UiEventLogger mUiEventLogger;
|
||||||
|
|
||||||
final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
|
final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
|
||||||
|
|
||||||
private static final float TOUCH_REGION = .3f;
|
private static final float TOUCH_REGION = .3f;
|
||||||
@@ -110,11 +116,11 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
mVelocityTrackerFactory,
|
mVelocityTrackerFactory,
|
||||||
mFlingAnimationUtils,
|
mFlingAnimationUtils,
|
||||||
mFlingAnimationUtilsClosing,
|
mFlingAnimationUtilsClosing,
|
||||||
TOUCH_REGION);
|
TOUCH_REGION,
|
||||||
|
mUiEventLogger);
|
||||||
|
|
||||||
when(mCentralSurfaces.isBouncerShowing()).thenReturn(false);
|
when(mCentralSurfaces.isBouncerShowing()).thenReturn(false);
|
||||||
when(mCentralSurfaces.getDisplayHeight()).thenReturn((float) SCREEN_HEIGHT_PX);
|
when(mCentralSurfaces.getDisplayHeight()).thenReturn((float) SCREEN_HEIGHT_PX);
|
||||||
when(mCentralSurfaces.isBouncerShowing()).thenReturn(false);
|
|
||||||
when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator);
|
when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator);
|
||||||
when(mVelocityTrackerFactory.obtain()).thenReturn(mVelocityTracker);
|
when(mVelocityTrackerFactory.obtain()).thenReturn(mVelocityTracker);
|
||||||
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn(Float.MAX_VALUE);
|
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn(Float.MAX_VALUE);
|
||||||
@@ -154,18 +160,22 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
2)).isTrue();
|
2)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Direction {
|
||||||
|
DOWN,
|
||||||
|
UP,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes sure expansion amount is proportional to scroll.
|
* Makes sure the expansion amount is proportional to (1 - scroll).
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExpansionAmount_whenBouncerHidden_setsCorrectValue() {
|
public void testSwipeUp_setsCorrectExpansionAmount() {
|
||||||
mTouchHandler.onSessionStart(mTouchSession);
|
mTouchHandler.onSessionStart(mTouchSession);
|
||||||
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
||||||
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
||||||
verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());
|
verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());
|
||||||
|
|
||||||
final OnGestureListener gestureListener = gestureListenerCaptor.getValue();
|
final OnGestureListener gestureListener = gestureListenerCaptor.getValue();
|
||||||
when(mCentralSurfaces.isBouncerShowing()).thenReturn(false);
|
|
||||||
verifyScroll(.3f, Direction.UP, true, gestureListener);
|
verifyScroll(.3f, Direction.UP, true, gestureListener);
|
||||||
|
|
||||||
// Ensure that subsequent gestures are treated as expanding even if the bouncer state
|
// Ensure that subsequent gestures are treated as expanding even if the bouncer state
|
||||||
@@ -175,17 +185,18 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes sure collapse amount is proportional to scroll.
|
* Makes sure the expansion amount is proportional to scroll.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCollapseAmount() {
|
public void testSwipeDown_setsCorrectExpansionAmount() {
|
||||||
|
when(mCentralSurfaces.isBouncerShowing()).thenReturn(true);
|
||||||
|
|
||||||
mTouchHandler.onSessionStart(mTouchSession);
|
mTouchHandler.onSessionStart(mTouchSession);
|
||||||
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
||||||
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
||||||
verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());
|
verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());
|
||||||
|
|
||||||
final OnGestureListener gestureListener = gestureListenerCaptor.getValue();
|
final OnGestureListener gestureListener = gestureListenerCaptor.getValue();
|
||||||
when(mCentralSurfaces.isBouncerShowing()).thenReturn(true);
|
|
||||||
verifyScroll(.3f, Direction.DOWN, false, gestureListener);
|
verifyScroll(.3f, Direction.DOWN, false, gestureListener);
|
||||||
|
|
||||||
// Ensure that subsequent gestures are treated as collapsing even if the bouncer state
|
// Ensure that subsequent gestures are treated as collapsing even if the bouncer state
|
||||||
@@ -194,11 +205,6 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
verifyScroll(.7f, Direction.DOWN, false, gestureListener);
|
verifyScroll(.7f, Direction.DOWN, false, gestureListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Direction {
|
|
||||||
DOWN,
|
|
||||||
UP,
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyScroll(float percent, Direction direction, boolean expanding,
|
private void verifyScroll(float percent, Direction direction, boolean expanding,
|
||||||
android.view.GestureDetector.OnGestureListener gestureListener) {
|
android.view.GestureDetector.OnGestureListener gestureListener) {
|
||||||
|
|
||||||
@@ -209,48 +215,128 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
|
final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
|
||||||
0, direction == Direction.UP ? SCREEN_HEIGHT_PX - distanceY : distanceY, 0);
|
0, direction == Direction.UP ? SCREEN_HEIGHT_PX - distanceY : distanceY, 0);
|
||||||
|
|
||||||
|
reset(mStatusBarKeyguardViewManager);
|
||||||
assertThat(gestureListener.onScroll(event1, event2, 0, distanceY))
|
assertThat(gestureListener.onScroll(event1, event2, 0, distanceY))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
|
|
||||||
// Ensure correct expansion passed in.
|
|
||||||
verify(mStatusBarKeyguardViewManager)
|
|
||||||
.onPanelExpansionChanged(
|
|
||||||
eq(expanding ? 1 - percent : percent), eq(false), eq(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes sure expansion amount is proportional to scroll.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testExpansionAmount_whenBouncerShown_setsCorrectValue() {
|
|
||||||
when(mCentralSurfaces.isBouncerShowing()).thenReturn(true);
|
|
||||||
|
|
||||||
mTouchHandler.onSessionStart(mTouchSession);
|
|
||||||
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
|
||||||
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
|
||||||
verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());
|
|
||||||
|
|
||||||
final float scrollAmount = .3f;
|
|
||||||
final float distanceY = SCREEN_HEIGHT_PX * scrollAmount;
|
|
||||||
|
|
||||||
final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
|
|
||||||
0, SCREEN_HEIGHT_PX - distanceY, 0);
|
|
||||||
final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
|
|
||||||
0, SCREEN_HEIGHT_PX, 0);
|
|
||||||
|
|
||||||
assertThat(gestureListenerCaptor.getValue().onScroll(event1, event2, 0, distanceY))
|
|
||||||
.isTrue();
|
|
||||||
|
|
||||||
// Ensure only called once
|
// Ensure only called once
|
||||||
verify(mStatusBarKeyguardViewManager)
|
verify(mStatusBarKeyguardViewManager)
|
||||||
.onPanelExpansionChanged(anyFloat(), anyBoolean(), anyBoolean());
|
.onPanelExpansionChanged(anyFloat(), anyBoolean(), anyBoolean());
|
||||||
|
|
||||||
// Ensure correct expansion passed in.
|
// Ensure correct expansion passed in.
|
||||||
verify(mStatusBarKeyguardViewManager)
|
verify(mStatusBarKeyguardViewManager)
|
||||||
.onPanelExpansionChanged(eq(scrollAmount), eq(false), eq(true));
|
.onPanelExpansionChanged(
|
||||||
|
eq(expanding ? 1 - percent : percent), eq(false), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swipeToPosition(float position, float velocityY) {
|
/**
|
||||||
|
* Tests that ending an upward swipe before the set threshold leads to bouncer collapsing down.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSwipeUpPositionBelowThreshold_collapsesBouncer() {
|
||||||
|
final float swipeUpPercentage = .3f;
|
||||||
|
final float expansion = 1 - swipeUpPercentage;
|
||||||
|
// The upward velocity is ignored.
|
||||||
|
final float velocityY = -1;
|
||||||
|
swipeToPosition(swipeUpPercentage, Direction.UP, velocityY);
|
||||||
|
|
||||||
|
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_HIDDEN));
|
||||||
|
verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator),
|
||||||
|
eq(SCREEN_HEIGHT_PX * expansion),
|
||||||
|
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_HIDDEN),
|
||||||
|
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
||||||
|
verify(mValueAnimator).start();
|
||||||
|
verify(mUiEventLogger, never()).log(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that ending an upward swipe above the set threshold will continue the expansion.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSwipeUpPositionAboveThreshold_expandsBouncer() {
|
||||||
|
final float swipeUpPercentage = .7f;
|
||||||
|
final float expansion = 1 - swipeUpPercentage;
|
||||||
|
// The downward velocity is ignored.
|
||||||
|
final float velocityY = 1;
|
||||||
|
swipeToPosition(swipeUpPercentage, Direction.UP, velocityY);
|
||||||
|
|
||||||
|
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_VISIBLE));
|
||||||
|
verify(mFlingAnimationUtils).apply(eq(mValueAnimator), eq(SCREEN_HEIGHT_PX * expansion),
|
||||||
|
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
|
||||||
|
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
||||||
|
verify(mValueAnimator).start();
|
||||||
|
verify(mUiEventLogger).log(BouncerSwipeTouchHandler.DreamEvent.DREAM_SWIPED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that ending a downward swipe above the set threshold will continue the expansion,
|
||||||
|
* but will not trigger logging of the DREAM_SWIPED event.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSwipeDownPositionAboveThreshold_expandsBouncer_doesNotLog() {
|
||||||
|
when(mCentralSurfaces.isBouncerShowing()).thenReturn(true);
|
||||||
|
|
||||||
|
final float swipeDownPercentage = .3f;
|
||||||
|
// The downward velocity is ignored.
|
||||||
|
final float velocityY = 1;
|
||||||
|
swipeToPosition(swipeDownPercentage, Direction.DOWN, velocityY);
|
||||||
|
|
||||||
|
verify(mValueAnimatorCreator).create(eq(swipeDownPercentage),
|
||||||
|
eq(KeyguardBouncer.EXPANSION_VISIBLE));
|
||||||
|
verify(mFlingAnimationUtils).apply(eq(mValueAnimator),
|
||||||
|
eq(SCREEN_HEIGHT_PX * swipeDownPercentage),
|
||||||
|
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
|
||||||
|
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
||||||
|
verify(mValueAnimator).start();
|
||||||
|
verify(mUiEventLogger, never()).log(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that swiping down with a speed above the set threshold leads to bouncer collapsing
|
||||||
|
* down.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSwipeDownVelocityAboveMin_collapsesBouncer() {
|
||||||
|
when(mCentralSurfaces.isBouncerShowing()).thenReturn(true);
|
||||||
|
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn((float) 0);
|
||||||
|
|
||||||
|
// The ending position above the set threshold is ignored.
|
||||||
|
final float swipeDownPercentage = .3f;
|
||||||
|
final float velocityY = 1;
|
||||||
|
swipeToPosition(swipeDownPercentage, Direction.DOWN, velocityY);
|
||||||
|
|
||||||
|
verify(mValueAnimatorCreator).create(eq(swipeDownPercentage),
|
||||||
|
eq(KeyguardBouncer.EXPANSION_HIDDEN));
|
||||||
|
verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator),
|
||||||
|
eq(SCREEN_HEIGHT_PX * swipeDownPercentage),
|
||||||
|
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_HIDDEN),
|
||||||
|
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
||||||
|
verify(mValueAnimator).start();
|
||||||
|
verify(mUiEventLogger, never()).log(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that swiping up with a speed above the set threshold will continue the expansion.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSwipeUpVelocityAboveMin_expandsBouncer() {
|
||||||
|
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn((float) 0);
|
||||||
|
|
||||||
|
// The ending position below the set threshold is ignored.
|
||||||
|
final float swipeUpPercentage = .3f;
|
||||||
|
final float expansion = 1 - swipeUpPercentage;
|
||||||
|
final float velocityY = -1;
|
||||||
|
swipeToPosition(swipeUpPercentage, Direction.UP, velocityY);
|
||||||
|
|
||||||
|
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_VISIBLE));
|
||||||
|
verify(mFlingAnimationUtils).apply(eq(mValueAnimator), eq(SCREEN_HEIGHT_PX * expansion),
|
||||||
|
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
|
||||||
|
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
||||||
|
verify(mValueAnimator).start();
|
||||||
|
verify(mUiEventLogger).log(BouncerSwipeTouchHandler.DreamEvent.DREAM_SWIPED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void swipeToPosition(float percent, Direction direction, float velocityY) {
|
||||||
mTouchHandler.onSessionStart(mTouchSession);
|
mTouchHandler.onSessionStart(mTouchSession);
|
||||||
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
|
||||||
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
|
||||||
@@ -261,12 +347,12 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
when(mVelocityTracker.getYVelocity()).thenReturn(velocityY);
|
when(mVelocityTracker.getYVelocity()).thenReturn(velocityY);
|
||||||
|
|
||||||
final float distanceY = SCREEN_HEIGHT_PX * position;
|
final float distanceY = SCREEN_HEIGHT_PX * percent;
|
||||||
|
|
||||||
final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
|
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,
|
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(gestureListenerCaptor.getValue().onScroll(event1, event2, 0, distanceY))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
@@ -276,84 +362,4 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
inputEventListenerCaptor.getValue().onInputEvent(upEvent);
|
inputEventListenerCaptor.getValue().onInputEvent(upEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that ending a swipe before the set expansion threshold leads to bouncer collapsing
|
|
||||||
* down.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSwipeBelowThreshold_collapsesBouncer() {
|
|
||||||
final float swipeUpPercentage = .3f;
|
|
||||||
final float expansion = 1 - swipeUpPercentage;
|
|
||||||
// The upward velocity is ignored.
|
|
||||||
final float velocityY = -1;
|
|
||||||
swipeToPosition(swipeUpPercentage, velocityY);
|
|
||||||
|
|
||||||
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_HIDDEN));
|
|
||||||
verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator),
|
|
||||||
eq(SCREEN_HEIGHT_PX * expansion),
|
|
||||||
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_HIDDEN),
|
|
||||||
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
|
||||||
verify(mValueAnimator).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that ending a swipe above the set expansion threshold will continue the expansion.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSwipeAboveThreshold_expandsBouncer() {
|
|
||||||
final float swipeUpPercentage = .7f;
|
|
||||||
final float expansion = 1 - swipeUpPercentage;
|
|
||||||
// The downward velocity is ignored.
|
|
||||||
final float velocityY = 1;
|
|
||||||
swipeToPosition(swipeUpPercentage, velocityY);
|
|
||||||
|
|
||||||
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_VISIBLE));
|
|
||||||
verify(mFlingAnimationUtils).apply(eq(mValueAnimator), eq(SCREEN_HEIGHT_PX * expansion),
|
|
||||||
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
|
|
||||||
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
|
||||||
verify(mValueAnimator).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that swiping down with a speed above the set threshold leads to bouncer collapsing
|
|
||||||
* down.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSwipeDownVelocityAboveMin_collapsesBouncer() {
|
|
||||||
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn((float) 0);
|
|
||||||
|
|
||||||
// The swipe amount above the set expansion threshold is ignored.
|
|
||||||
final float swipeUpPercentage = .7f;
|
|
||||||
final float expansion = 1 - swipeUpPercentage;
|
|
||||||
final float velocityY = 1;
|
|
||||||
swipeToPosition(swipeUpPercentage, velocityY);
|
|
||||||
|
|
||||||
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_HIDDEN));
|
|
||||||
verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator),
|
|
||||||
eq(SCREEN_HEIGHT_PX * expansion),
|
|
||||||
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_HIDDEN),
|
|
||||||
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
|
||||||
verify(mValueAnimator).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that swiping up with a speed above the set threshold will continue the expansion.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSwipeUpVelocityAboveMin_expandsBouncer() {
|
|
||||||
when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn((float) 0);
|
|
||||||
|
|
||||||
// The swipe amount below the set expansion threshold is ignored.
|
|
||||||
final float swipeUpPercentage = .3f;
|
|
||||||
final float expansion = 1 - swipeUpPercentage;
|
|
||||||
final float velocityY = -1;
|
|
||||||
swipeToPosition(swipeUpPercentage, velocityY);
|
|
||||||
|
|
||||||
verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_VISIBLE));
|
|
||||||
verify(mFlingAnimationUtils).apply(eq(mValueAnimator), eq(SCREEN_HEIGHT_PX * expansion),
|
|
||||||
eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
|
|
||||||
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
|
|
||||||
verify(mValueAnimator).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user