Merge "Remove scroll-up effect from lockscreen swipe-up and unlock hint"

This commit is contained in:
Lyn Han
2022-02-04 21:46:21 +00:00
committed by Android (Google) Code Review
5 changed files with 82 additions and 19 deletions

View File

@@ -76,7 +76,10 @@ public class AmbientState {
private float mHideAmount;
private boolean mAppearing;
private float mPulseHeight = MAX_PULSE_HEIGHT;
/** How we much we are sleeping. 1f fully dozing (AOD), 0f fully awake (for all other states) */
private float mDozeAmount = 0.0f;
private Runnable mOnPulseHeightChangedListener;
private ExpandableNotificationRow mTrackedHeadsUpRow;
private float mAppearFraction;
@@ -96,6 +99,9 @@ public class AmbientState {
/** Height of the notifications panel without top padding when expansion completes. */
private float mStackEndHeight;
/** Whether we are swiping up. */
private boolean mIsSwipingUp;
/**
* @return Height of the notifications panel without top padding when expansion completes.
*/
@@ -132,6 +138,20 @@ public class AmbientState {
mExpansionFraction = expansionFraction;
}
/**
* @param isSwipingUp Whether we are swiping up.
*/
public void setSwipingUp(boolean isSwipingUp) {
mIsSwipingUp = isSwipingUp;
}
/**
* @return Whether we are swiping up.
*/
public boolean isSwipingUp() {
return mIsSwipingUp;
}
/**
* @return Fraction of shade expansion.
*/

View File

@@ -203,6 +203,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
private float mQsExpansionFraction;
private final int mSplitShadeMinContentHeight;
/** Whether we are flinging the shade open or closed. */
private boolean mIsFlinging;
/**
* The algorithm which calculates the properties for our children
*/
@@ -1269,6 +1272,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
updateStackPosition(false /* listenerNeedsAnimation */);
}
/**
* @return Whether we should skip stack height update for lockscreen swipe-up or unlock hint.
*/
private boolean shouldSkipHeightUpdate() {
// After the user swipes up on lockscreen and lets go,
// {@link PanelViewController) flings the shade back down.
return mAmbientState.isOnKeyguard() && (
mAmbientState.isUnlockHintRunning() || mAmbientState.isSwipingUp() || mIsFlinging);
}
/**
* Apply expansion fraction to the y position and height of the notifications panel.
* @param listenerNeedsAnimation does the listener need to animate?
@@ -1283,7 +1296,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
if (mOnStackYChanged != null) {
mOnStackYChanged.accept(listenerNeedsAnimation);
}
if (mQsExpansionFraction <= 0) {
if (mQsExpansionFraction <= 0 && !shouldSkipHeightUpdate()) {
final float endHeight = updateStackEndHeight(
getHeight(), getEmptyBottomMargin(), mTopPadding);
updateStackHeight(endHeight, fraction);
@@ -1325,22 +1338,27 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
@ShadeViewRefactor(RefactorComponent.COORDINATOR)
public void setExpandedHeight(float height) {
final float shadeBottom = getHeight() - getEmptyBottomMargin();
final float expansionFraction = MathUtils.saturate(height / shadeBottom);
mAmbientState.setExpansionFraction(expansionFraction);
final boolean skipHeightUpdate = shouldSkipHeightUpdate();
if (!skipHeightUpdate) {
final float expansionFraction = MathUtils.saturate(height / shadeBottom);
mAmbientState.setExpansionFraction(expansionFraction);
}
updateStackPosition();
mExpandedHeight = height;
setIsExpanded(height > 0);
int minExpansionHeight = getMinExpansionHeight();
if (height < minExpansionHeight) {
mClipRect.left = 0;
mClipRect.right = getWidth();
mClipRect.top = 0;
mClipRect.bottom = (int) height;
height = minExpansionHeight;
setRequestedClipBounds(mClipRect);
} else {
setRequestedClipBounds(null);
if (!skipHeightUpdate) {
mExpandedHeight = height;
setIsExpanded(height > 0);
int minExpansionHeight = getMinExpansionHeight();
if (height < minExpansionHeight) {
mClipRect.left = 0;
mClipRect.right = getWidth();
mClipRect.top = 0;
mClipRect.bottom = (int) height;
height = minExpansionHeight;
setRequestedClipBounds(mClipRect);
} else {
setRequestedClipBounds(null);
}
}
int stackHeight;
float translationY;
@@ -1368,7 +1386,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
}
}
} else {
stackHeight = (int) height;
stackHeight = (int) (skipHeightUpdate ? mExpandedHeight : height);
}
} else {
appearFraction = calculateAppearFraction(height);
@@ -1386,7 +1404,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
}
}
mAmbientState.setAppearFraction(appearFraction);
if (stackHeight != mCurrentStackHeight) {
if (stackHeight != mCurrentStackHeight && !skipHeightUpdate) {
mCurrentStackHeight = stackHeight;
updateAlgorithmHeightAndPadding();
requestChildrenUpdate();
@@ -5001,6 +5019,13 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
mAmbientState.setUnlockHintRunning(running);
}
/**
* @param isFlinging Whether we are flinging the shade open or closed.
*/
public void setIsFlinging(boolean isFlinging) {
mIsFlinging = isFlinging;
}
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) {
mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed;

View File

@@ -1195,6 +1195,13 @@ public class NotificationStackScrollLayoutController {
mView.setUnlockHintRunning(running);
}
/**
* @param isFlinging Whether we are flinging the shade open or close.
*/
public void setIsFlinging(boolean isFlinging) {
mView.setIsFlinging(isFlinging);
}
public boolean isFooterViewNotGone() {
return mView.isFooterViewNotGone();
}

View File

@@ -1885,9 +1885,16 @@ public class NotificationPanelViewController extends PanelViewController
mHeadsUpTouchHelper.notifyFling(!expand);
mKeyguardStateController.notifyPanelFlingStart(!expand /* flingingToDismiss */);
setClosingWithAlphaFadeout(!expand && !isOnKeyguard() && getFadeoutAlpha() == 1.0f);
mNotificationStackScrollLayoutController.setIsFlinging(true);
super.flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
}
@Override
protected void onFlingEnd(boolean cancelled) {
super.onFlingEnd(cancelled);
mNotificationStackScrollLayoutController.setIsFlinging(false);
}
private boolean onQsIntercept(MotionEvent event) {
int pointerIndex = event.findPointerIndex(mTrackingPointer);
if (pointerIndex < 0) {

View File

@@ -461,7 +461,7 @@ public abstract class PanelViewController {
boolean expands = onEmptySpaceClick(mInitialTouchX);
onTrackingStopped(expands);
}
mAmbientState.setSwipingUp(false);
mVelocityTracker.clear();
}
@@ -708,7 +708,7 @@ public abstract class PanelViewController {
animator.start();
}
private void onFlingEnd(boolean cancelled) {
void onFlingEnd(boolean cancelled) {
mIsFlinging = false;
// No overshoot when the animation ends
setOverExpansionInternal(0, false /* isFromGesture */);
@@ -1393,6 +1393,10 @@ public abstract class PanelViewController {
mUpwardsWhenThresholdReached = isDirectionUpwards(x, y);
}
if ((!mGestureWaitForTouchSlop || mTracking) && !isTrackingBlocked()) {
// Count h==0 as part of swipe-up,
// otherwise {@link NotificationStackScrollLayout}
// wrongly enables stack height updates at the start of lockscreen swipe-up
mAmbientState.setSwipingUp(h <= 0);
setExpandedHeightInternal(newHeight);
}
break;