Merge "Fix disappearing HUN when drag down from heads up" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-06-23 00:24:08 +00:00
committed by Android (Google) Code Review
3 changed files with 72 additions and 21 deletions

View File

@@ -83,6 +83,8 @@ public class AmbientState {
private float mDozeAmount = 0.0f;
private HeadsUpManager mHeadUpManager;
private Runnable mOnPulseHeightChangedListener;
private ExpandableNotificationRow mTrackedHeadsUpRow;
private float mAppearFraction;
public AmbientState(
Context context,
@@ -543,4 +545,27 @@ public class AmbientState {
public Runnable getOnPulseHeightChangedListener() {
return mOnPulseHeightChangedListener;
}
public void setTrackedHeadsUpRow(ExpandableNotificationRow row) {
mTrackedHeadsUpRow = row;
}
/**
* Returns the currently tracked heads up row, if there is one and it is currently above the
* shelf (still appearing).
*/
public ExpandableNotificationRow getTrackedHeadsUpRow() {
if (mTrackedHeadsUpRow == null || !mTrackedHeadsUpRow.isAboveShelf()) {
return null;
}
return mTrackedHeadsUpRow;
}
public void setAppearFraction(float appearFraction) {
mAppearFraction = appearFraction;
}
public float getAppearFraction() {
return mAppearFraction;
}
}

View File

@@ -1420,14 +1420,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
// start
translationY = height - appearStartPosition + getExpandTranslationStart();
}
stackHeight = (int) (height - translationY);
if (isHeadsUpTransition()) {
stackHeight =
getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight();
translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction);
} else {
stackHeight = (int) (height - translationY);
}
}
mAmbientState.setAppearFraction(appearFraction);
if (stackHeight != mCurrentStackHeight) {
mCurrentStackHeight = stackHeight;
updateAlgorithmHeightAndPadding();
@@ -1545,17 +1543,18 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
*/
@ShadeViewRefactor(RefactorComponent.COORDINATOR)
private float getAppearEndPosition() {
int appearPosition;
int notGoneChildCount = getNotGoneChildCount();
if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) {
int appearPosition = 0;
int visibleNotifCount = getVisibleNotificationCount();
if (mEmptyShadeView.getVisibility() == GONE && visibleNotifCount > 0) {
if (isHeadsUpTransition()
|| (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) {
appearPosition = getTopHeadsUpPinnedHeight();
} else {
appearPosition = 0;
if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) {
appearPosition += mShelf.getIntrinsicHeight();
if (mShelf.getVisibility() != GONE && visibleNotifCount > 1) {
appearPosition += mShelf.getIntrinsicHeight() + mPaddingBetweenElements;
}
appearPosition += getTopHeadsUpPinnedHeight()
+ getPositionInLinearLayout(mAmbientState.getTrackedHeadsUpRow());
} else if (mShelf.getVisibility() != GONE) {
appearPosition += mShelf.getIntrinsicHeight();
}
} else {
appearPosition = mEmptyShadeView.getHeight();
@@ -1565,9 +1564,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
private boolean isHeadsUpTransition() {
NotificationSection firstVisibleSection = getFirstVisibleSection();
return mTrackingHeadsUp && firstVisibleSection != null
&& firstVisibleSection.getFirstVisibleChild().isAboveShelf();
return mAmbientState.getTrackedHeadsUpRow() != null;
}
/**
@@ -2975,7 +2972,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
@ShadeViewRefactor(RefactorComponent.COORDINATOR)
public int getLayoutMinHeight() {
if (isHeadsUpTransition()) {
return getTopHeadsUpPinnedHeight();
ExpandableNotificationRow trackedHeadsUpRow = mAmbientState.getTrackedHeadsUpRow();
if (trackedHeadsUpRow.isAboveShelf()) {
int hunDistance = (int) MathUtils.lerp(
0,
getPositionInLinearLayout(trackedHeadsUpRow),
mAmbientState.getAppearFraction());
return getTopHeadsUpPinnedHeight() + hunDistance;
} else {
return getTopHeadsUpPinnedHeight();
}
}
return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight();
}
@@ -5295,6 +5301,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
public void setTrackingHeadsUp(ExpandableNotificationRow row) {
mAmbientState.setTrackedHeadsUpRow(row);
mTrackingHeadsUp = row != null;
mRoundnessManager.setTrackingHeadsUp(row);
}

View File

@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import android.util.MathUtils;
import android.view.View;
import android.view.ViewGroup;
@@ -441,7 +442,7 @@ public class StackScrollAlgorithm {
} else if (isEmptyShadeView) {
childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
+ ambientState.getStackTranslation() * 0.25f;
} else {
} else if (child != ambientState.getTrackedHeadsUpRow()) {
clampPositionToShelf(child, childViewState, ambientState);
}
@@ -539,6 +540,19 @@ public class StackScrollAlgorithm {
private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
AmbientState ambientState) {
int childCount = algorithmState.visibleChildren.size();
// Move the tracked heads up into position during the appear animation, by interpolating
// between the HUN inset (where it will appear as a HUN) and the end position in the shade
ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
if (trackedHeadsUpRow != null) {
ExpandableViewState childState = trackedHeadsUpRow.getViewState();
if (childState != null) {
float endPosition = childState.yTranslation - ambientState.getStackTranslation();
childState.yTranslation = MathUtils.lerp(
mHeadsUpInset, endPosition, ambientState.getAppearFraction());
}
}
ExpandableNotificationRow topHeadsUpEntry = null;
for (int i = 0; i < childCount; i++) {
View child = algorithmState.visibleChildren.get(i);
@@ -561,7 +575,7 @@ public class StackScrollAlgorithm {
&& !row.showingPulsing()) {
// Ensure that the heads up is always visible even when scrolled off
clampHunToTop(ambientState, row, childState);
if (i == 0 && row.isAboveShelf()) {
if (isTopEntry && row.isAboveShelf()) {
// the first hun can't get off screen.
clampHunToMaxTranslation(ambientState, row, childState);
childState.hidden = false;
@@ -636,9 +650,13 @@ public class StackScrollAlgorithm {
return;
}
ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
boolean isBeforeTrackedHeadsUp = trackedHeadsUpRow != null
&& mHostView.indexOfChild(child) < mHostView.indexOfChild(trackedHeadsUpRow);
int shelfStart = ambientState.getInnerHeight()
- ambientState.getShelf().getIntrinsicHeight();
if (ambientState.isAppearing() && !child.isAboveShelf()) {
if (ambientState.isAppearing() && !child.isAboveShelf() && !isBeforeTrackedHeadsUp) {
// Don't show none heads-up notifications while in appearing phase.
childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
}
@@ -695,7 +713,8 @@ public class StackScrollAlgorithm {
}
childViewState.zTranslation = baseZ
+ childrenOnTop * zDistanceBetweenElements;
} else if (i == 0 && (child.isAboveShelf() || child.showingPulsing())) {
} else if (child == ambientState.getTrackedHeadsUpRow()
|| (i == 0 && (child.isAboveShelf() || child.showingPulsing()))) {
// In case this is a new view that has never been measured before, we don't want to
// elevate if we are currently expanded more then the notification
int shelfHeight = ambientState.getShelf() == null ? 0 :
@@ -703,7 +722,7 @@ public class StackScrollAlgorithm {
float shelfStart = ambientState.getInnerHeight()
- shelfHeight + ambientState.getTopPadding()
+ ambientState.getStackTranslation();
float notificationEnd = childViewState.yTranslation + child.getPinnedHeadsUpHeight()
float notificationEnd = childViewState.yTranslation + child.getIntrinsicHeight()
+ mPaddingBetweenElements;
if (shelfStart > notificationEnd) {
childViewState.zTranslation = baseZ;