Merge "Fix confusion related to EXPANSION_HIDDEN/VISIBLE and improve related test coverage." into tm-dev

This commit is contained in:
Xiaowen Lei
2022-03-21 22:49:23 +00:00
committed by Android (Google) Code Review
2 changed files with 123 additions and 35 deletions

View File

@@ -31,8 +31,8 @@ import android.view.MotionEvent;
import android.view.VelocityTracker; import android.view.VelocityTracker;
import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.KeyguardBouncer;
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.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.wm.shell.animation.FlingAnimationUtils; import com.android.wm.shell.animation.FlingAnimationUtils;
@@ -134,9 +134,9 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
NotificationShadeWindowController notificationShadeWindowController, NotificationShadeWindowController notificationShadeWindowController,
ValueAnimatorCreator valueAnimatorCreator, ValueAnimatorCreator valueAnimatorCreator,
VelocityTrackerFactory velocityTrackerFactory, VelocityTrackerFactory velocityTrackerFactory,
@Named(SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_CLOSING)
FlingAnimationUtils flingAnimationUtils,
@Named(SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_OPENING) @Named(SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_OPENING)
FlingAnimationUtils flingAnimationUtils,
@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) {
mDisplayMetrics = displayMetrics; mDisplayMetrics = displayMetrics;
@@ -154,11 +154,14 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
public void getTouchInitiationRegion(Region region) { public void getTouchInitiationRegion(Region region) {
if (mCentralSurfaces.isBouncerShowing()) { if (mCentralSurfaces.isBouncerShowing()) {
region.op(new Rect(0, 0, mDisplayMetrics.widthPixels, region.op(new Rect(0, 0, mDisplayMetrics.widthPixels,
Math.round(mDisplayMetrics.heightPixels * mBouncerZoneScreenPercentage)), Math.round(
mDisplayMetrics.heightPixels * mBouncerZoneScreenPercentage)),
Region.Op.UNION); Region.Op.UNION);
} else { } else {
region.op(new Rect(0, region.op(new Rect(0,
Math.round(mDisplayMetrics.heightPixels * (1 - mBouncerZoneScreenPercentage)), Math.round(
mDisplayMetrics.heightPixels
* (1 - mBouncerZoneScreenPercentage)),
mDisplayMetrics.widthPixels, mDisplayMetrics.widthPixels,
mDisplayMetrics.heightPixels), mDisplayMetrics.heightPixels),
Region.Op.UNION); Region.Op.UNION);
@@ -210,7 +213,6 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
final float velocityVector = final float velocityVector =
(float) Math.hypot(horizontalVelocity, verticalVelocity); (float) Math.hypot(horizontalVelocity, verticalVelocity);
final float expansion = flingRevealsOverlay(verticalVelocity, velocityVector) final float expansion = flingRevealsOverlay(verticalVelocity, velocityVector)
? KeyguardBouncer.EXPANSION_HIDDEN : KeyguardBouncer.EXPANSION_VISIBLE; ? KeyguardBouncer.EXPANSION_HIDDEN : KeyguardBouncer.EXPANSION_VISIBLE;
flingToExpansion(verticalVelocity, expansion); flingToExpansion(verticalVelocity, expansion);
@@ -236,8 +238,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
} }
protected boolean flingRevealsOverlay(float velocity, float velocityVector) { protected boolean flingRevealsOverlay(float velocity, float velocityVector) {
// Fully expand if the user has expanded the bouncer less than halfway or final velocity was // Fully expand the space above the bouncer, if the user has expanded the bouncer less
// positive, indicating an downward direction. // than halfway or final velocity was positive, indicating a downward direction.
if (Math.abs(velocityVector) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { if (Math.abs(velocityVector) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
return mCurrentExpansion > FLING_PERCENTAGE_THRESHOLD; return mCurrentExpansion > FLING_PERCENTAGE_THRESHOLD;
} else { } else {
@@ -246,17 +248,20 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
} }
protected void flingToExpansion(float velocity, float expansion) { protected void flingToExpansion(float velocity, float expansion) {
// The animation utils deal in pixel units, rather than expansion height.
final float viewHeight = mCentralSurfaces.getDisplayHeight(); final float viewHeight = mCentralSurfaces.getDisplayHeight();
final float currentHeight = viewHeight * mCurrentExpansion; final float currentHeight = viewHeight * mCurrentExpansion;
final float targetHeight = viewHeight * expansion; final float targetHeight = viewHeight * expansion;
final ValueAnimator animator = createExpansionAnimator(expansion); final ValueAnimator animator = createExpansionAnimator(expansion);
if (expansion == KeyguardBouncer.EXPANSION_HIDDEN) { if (expansion == KeyguardBouncer.EXPANSION_HIDDEN) {
// The animation utils deal in pixel units, rather than expansion height. // Hides the bouncer, i.e., fully expands the space above the bouncer.
mFlingAnimationUtils.apply(animator, currentHeight, targetHeight, velocity, viewHeight); mFlingAnimationUtilsClosing.apply(animator, currentHeight, targetHeight, velocity,
viewHeight);
} else { } else {
mFlingAnimationUtilsClosing.apply( // Shows the bouncer, i.e., fully collapses the space above the bouncer.
animator, mCurrentExpansion, currentHeight, targetHeight, viewHeight); mFlingAnimationUtils.apply(
animator, currentHeight, targetHeight, velocity, viewHeight);
} }
animator.start(); animator.start();

View File

@@ -39,8 +39,8 @@ import androidx.test.filters.SmallTest;
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;
import com.android.systemui.statusbar.phone.KeyguardBouncer;
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.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.wm.shell.animation.FlingAnimationUtils; import com.android.wm.shell.animation.FlingAnimationUtils;
@@ -112,8 +112,10 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
TOUCH_REGION); TOUCH_REGION);
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);
} }
/** /**
@@ -154,7 +156,7 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
* Makes sure expansion amount is proportional to scroll. * Makes sure expansion amount is proportional to scroll.
*/ */
@Test @Test
public void testExpansionAmount() { public void testExpansionAmount_whenBouncerHidden_setsCorrectValue() {
mTouchHandler.onSessionStart(mTouchSession); mTouchHandler.onSessionStart(mTouchSession);
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor = ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class); ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
@@ -180,6 +182,38 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
.onPanelExpansionChanged(eq(1 - scrollAmount), eq(false), eq(true)); .onPanelExpansionChanged(eq(1 - scrollAmount), 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, 0);
final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
0, SCREEN_HEIGHT_PX - distanceY, 0);
assertThat(gestureListenerCaptor.getValue().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(scrollAmount), eq(false), eq(true));
}
private void swipeToPosition(float position, float velocityY) { private void swipeToPosition(float position, float velocityY) {
mTouchHandler.onSessionStart(mTouchSession); mTouchHandler.onSessionStart(mTouchSession);
ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor = ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
@@ -212,14 +246,18 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
* down. * down.
*/ */
@Test @Test
public void testCollapseOnThreshold() { public void testSwipeBelowThreshold_collapsesBouncer() {
final float swipeUpPercentage = .3f; final float swipeUpPercentage = .3f;
swipeToPosition(swipeUpPercentage, -1); final float expansion = 1 - swipeUpPercentage;
// The upward velocity is ignored.
final float velocityY = -1;
swipeToPosition(swipeUpPercentage, velocityY);
verify(mValueAnimatorCreator).create(eq(1 - swipeUpPercentage), verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_HIDDEN));
eq(KeyguardBouncer.EXPANSION_VISIBLE)); verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator),
verify(mFlingAnimationUtilsClosing).apply(eq(mValueAnimator), anyFloat(), anyFloat(), eq(SCREEN_HEIGHT_PX * expansion),
anyFloat(), anyFloat()); eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_HIDDEN),
eq(velocityY), eq((float) SCREEN_HEIGHT_PX));
verify(mValueAnimator).start(); verify(mValueAnimator).start();
} }
@@ -227,14 +265,59 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
* Tests that ending a swipe above the set expansion threshold will continue the expansion. * Tests that ending a swipe above the set expansion threshold will continue the expansion.
*/ */
@Test @Test
public void testExpandOnThreshold() { public void testSwipeAboveThreshold_expandsBouncer() {
final float swipeUpPercentage = .7f; final float swipeUpPercentage = .7f;
swipeToPosition(swipeUpPercentage, 1); final float expansion = 1 - swipeUpPercentage;
// The downward velocity is ignored.
final float velocityY = 1;
swipeToPosition(swipeUpPercentage, velocityY);
verify(mValueAnimatorCreator).create(eq(1 - swipeUpPercentage), verify(mValueAnimatorCreator).create(eq(expansion), eq(KeyguardBouncer.EXPANSION_VISIBLE));
eq(KeyguardBouncer.EXPANSION_HIDDEN)); verify(mFlingAnimationUtils).apply(eq(mValueAnimator), eq(SCREEN_HEIGHT_PX * expansion),
verify(mFlingAnimationUtils).apply(eq(mValueAnimator), anyFloat(), anyFloat(), eq(SCREEN_HEIGHT_PX * KeyguardBouncer.EXPANSION_VISIBLE),
anyFloat(), anyFloat()); 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(); verify(mValueAnimator).start();
} }
} }