Merge "Adjusted the behavior when expanding the notification panel" into nyc-dev

This commit is contained in:
Selim Cinek
2016-03-02 23:55:29 +00:00
committed by Android (Google) Code Review
5 changed files with 32 additions and 145 deletions

View File

@@ -326,9 +326,6 @@
<!-- The minimum amount of top overscroll to go to the quick settings. --> <!-- The minimum amount of top overscroll to go to the quick settings. -->
<dimen name="min_top_overscroll_to_qs">36dp</dimen> <dimen name="min_top_overscroll_to_qs">36dp</dimen>
<!-- The padding to the second card when the notifications collapse. -->
<dimen name="notification_collapse_second_card_padding">8dp</dimen>
<!-- The height of the speed bump view. --> <!-- The height of the speed bump view. -->
<dimen name="speed_bump_height">16dp</dimen> <dimen name="speed_bump_height">16dp</dimen>

View File

@@ -92,7 +92,14 @@ public class NotificationContentView extends FrameLayout {
= new ViewTreeObserver.OnPreDrawListener() { = new ViewTreeObserver.OnPreDrawListener() {
@Override @Override
public boolean onPreDraw() { public boolean onPreDraw() {
mAnimate = true; // We need to post since we don't want the notification to animate on the very first
// frame
post(new Runnable() {
@Override
public void run() {
mAnimate = true;
}
});
getViewTreeObserver().removeOnPreDrawListener(this); getViewTreeObserver().removeOnPreDrawListener(this);
return true; return true;
} }

View File

@@ -1397,7 +1397,7 @@ public class NotificationPanelView extends PanelView implements
// In Shade, interpolate linearly such that QS is closed whenever panel height is // In Shade, interpolate linearly such that QS is closed whenever panel height is
// minimum QS expansion + minStackHeight // minimum QS expansion + minStackHeight
float panelHeightQsCollapsed = mNotificationStackScroller.getIntrinsicPadding() float panelHeightQsCollapsed = mNotificationStackScroller.getIntrinsicPadding()
+ mNotificationStackScroller.getMinStackHeight(); + mNotificationStackScroller.getLayoutMinHeight();
float panelHeightQsExpanded = calculatePanelHeightQsExpanded(); float panelHeightQsExpanded = calculatePanelHeightQsExpanded();
t = (expandedHeight - panelHeightQsCollapsed) t = (expandedHeight - panelHeightQsCollapsed)
/ (panelHeightQsExpanded - panelHeightQsCollapsed); / (panelHeightQsExpanded - panelHeightQsCollapsed);
@@ -1453,7 +1453,7 @@ public class NotificationPanelView extends PanelView implements
&& mShadeEmpty) { && mShadeEmpty) {
notificationHeight = mNotificationStackScroller.getEmptyShadeViewHeight() notificationHeight = mNotificationStackScroller.getEmptyShadeViewHeight()
+ mNotificationStackScroller.getBottomStackPeekSize() + mNotificationStackScroller.getBottomStackPeekSize()
+ mNotificationStackScroller.getCollapseSecondCardPadding(); + mNotificationStackScroller.getBottomStackSlowDownHeight();
} }
int maxQsHeight = mQsMaxExpansionHeight; int maxQsHeight = mQsMaxExpansionHeight;
@@ -1468,7 +1468,7 @@ public class NotificationPanelView extends PanelView implements
+ notificationHeight; + notificationHeight;
if (totalHeight > mNotificationStackScroller.getHeight()) { if (totalHeight > mNotificationStackScroller.getHeight()) {
float fullyCollapsedHeight = maxQsHeight float fullyCollapsedHeight = maxQsHeight
+ mNotificationStackScroller.getMinStackHeight(); + mNotificationStackScroller.getLayoutMinHeight();
totalHeight = Math.max(fullyCollapsedHeight, mNotificationStackScroller.getHeight()); totalHeight = Math.max(fullyCollapsedHeight, mNotificationStackScroller.getHeight());
} }
return (int) totalHeight; return (int) totalHeight;
@@ -1485,7 +1485,7 @@ public class NotificationPanelView extends PanelView implements
private float getFadeoutAlpha() { private float getFadeoutAlpha() {
float alpha = (getNotificationsTopY() + mNotificationStackScroller.getFirstItemMinHeight()) float alpha = (getNotificationsTopY() + mNotificationStackScroller.getFirstItemMinHeight())
/ (mQsMinExpansionHeight + mNotificationStackScroller.getBottomStackPeekSize() / (mQsMinExpansionHeight + mNotificationStackScroller.getBottomStackPeekSize()
- mNotificationStackScroller.getCollapseSecondCardPadding()); - mNotificationStackScroller.getBottomStackSlowDownHeight());
alpha = Math.max(0, Math.min(alpha, 1)); alpha = Math.max(0, Math.min(alpha, 1));
alpha = (float) Math.pow(alpha, 0.75); alpha = (float) Math.pow(alpha, 0.75);
return alpha; return alpha;

View File

@@ -418,12 +418,9 @@ public class NotificationStackScrollLayout extends ViewGroup
.getDimensionPixelSize(R.dimen.notification_divider_height)); .getDimensionPixelSize(R.dimen.notification_divider_height));
mIncreasedPaddingBetweenElements = context.getResources() mIncreasedPaddingBetweenElements = context.getResources()
.getDimensionPixelSize(R.dimen.notification_divider_height_increased); .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
mBottomStackSlowDownHeight = mStackScrollAlgorithm.getBottomStackSlowDownLength(); mBottomStackSlowDownHeight = mStackScrollAlgorithm.getBottomStackSlowDownLength();
mMinTopOverScrollToEscape = getResources().getDimensionPixelSize( mMinTopOverScrollToEscape = getResources().getDimensionPixelSize(
R.dimen.min_top_overscroll_to_qs); R.dimen.min_top_overscroll_to_qs);
mCollapseSecondCardPadding = getResources().getDimensionPixelSize(
R.dimen.notification_collapse_second_card_padding);
} }
private void notifyHeightChangeListener(ExpandableView view) { private void notifyHeightChangeListener(ExpandableView view) {
@@ -508,14 +505,6 @@ public class NotificationStackScrollLayout extends ViewGroup
mAmbientState.setTopPadding(mTopPadding); mAmbientState.setTopPadding(mTopPadding);
} }
/**
* @return whether the height of the layout needs to be adapted, in order to ensure that the
* last child is not in the bottom stack.
*/
private boolean needsHeightAdaption() {
return getNotGoneChildCount() > 1;
}
/** /**
* Updates the children views according to the stack scroll algorithm. Call this whenever * Updates the children views according to the stack scroll algorithm. Call this whenever
* modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout.
@@ -599,7 +588,7 @@ public class NotificationStackScrollLayout extends ViewGroup
mLastSetStackHeight = height; mLastSetStackHeight = height;
setIsExpanded(height > 0.0f); setIsExpanded(height > 0.0f);
int newStackHeight = (int) height; int newStackHeight = (int) height;
int minStackHeight = getMinStackHeight(); int minStackHeight = getLayoutMinHeight();
int stackHeight; int stackHeight;
float paddingOffset; float paddingOffset;
boolean trackingHeadsUp = mTrackingHeadsUp || mHeadsUpManager.hasPinnedHeadsUp(); boolean trackingHeadsUp = mTrackingHeadsUp || mHeadsUpManager.hasPinnedHeadsUp();
@@ -612,20 +601,7 @@ public class NotificationStackScrollLayout extends ViewGroup
stackHeight = newStackHeight; stackHeight = newStackHeight;
} else { } else {
int translationY; int translationY;
if (!trackingHeadsUp) { translationY = newStackHeight - normalUnfoldPositionStart;
// We did not reach the position yet where we actually start growing,
// so we translate the stack upwards.
translationY = (newStackHeight - minStackHeight);
// A slight parallax effect is introduced in order for the stack to catch up with
// the top card.
float partiallyThere = (newStackHeight - mTopPadding - mTopPaddingOverflow)
/ minStackHeight;
partiallyThere = Math.max(0, partiallyThere);
translationY += (1 - partiallyThere) * (mBottomStackPeekSize +
mCollapseSecondCardPadding);
} else {
translationY = (int) (height - normalUnfoldPositionStart);
}
paddingOffset = translationY - mTopPadding; paddingOffset = translationY - mTopPadding;
stackHeight = (int) (height - (translationY - mTopPadding)); stackHeight = (int) (height - (translationY - mTopPadding));
} }
@@ -668,8 +644,8 @@ public class NotificationStackScrollLayout extends ViewGroup
return mBottomStackPeekSize; return mBottomStackPeekSize;
} }
public int getCollapseSecondCardPadding() { public int getBottomStackSlowDownHeight() {
return mCollapseSecondCardPadding; return mBottomStackSlowDownHeight;
} }
public void setLongPressListener(SwipeHelper.LongPressListener listener) { public void setLongPressListener(SwipeHelper.LongPressListener listener) {
@@ -1850,7 +1826,7 @@ public class NotificationStackScrollLayout extends ViewGroup
boolean ignoreIntrinsicPadding) { boolean ignoreIntrinsicPadding) {
float start = qsHeight; float start = qsHeight;
float stackHeight = getHeight() - start; float stackHeight = getHeight() - start;
int minStackHeight = getMinStackHeight(); int minStackHeight = getLayoutMinHeight();
if (stackHeight <= minStackHeight) { if (stackHeight <= minStackHeight) {
float overflow = minStackHeight - stackHeight; float overflow = minStackHeight - stackHeight;
stackHeight = minStackHeight; stackHeight = minStackHeight;
@@ -1864,11 +1840,16 @@ public class NotificationStackScrollLayout extends ViewGroup
setStackHeight(mLastSetStackHeight); setStackHeight(mLastSetStackHeight);
} }
public int getMinStackHeight() { public int getLayoutMinHeight() {
final ExpandableView firstChild = getFirstChildNotGone(); final ExpandableView firstChild = getFirstChildNotGone();
final int firstChildMinHeight = firstChild != null ? firstChild.getMinHeight() int firstChildMinHeight = firstChild != null
? firstChild.getIntrinsicHeight()
: mCollapsedSize; : mCollapsedSize;
return firstChildMinHeight + mBottomStackPeekSize + mCollapseSecondCardPadding; if (mOwnScrollY > 0) {
firstChildMinHeight = Math.max(firstChildMinHeight - mOwnScrollY, mCollapsedSize);
}
return Math.min(firstChildMinHeight + mBottomStackPeekSize + mBottomStackSlowDownHeight,
mMaxLayoutHeight - mTopPadding);
} }
public float getTopPaddingOverflow() { public float getTopPaddingOverflow() {
@@ -1880,7 +1861,7 @@ public class NotificationStackScrollLayout extends ViewGroup
final int firstChildMinHeight = firstChild != null ? (int) firstChild.getMinHeight() final int firstChildMinHeight = firstChild != null ? (int) firstChild.getMinHeight()
: mCollapsedSize; : mCollapsedSize;
return mIntrinsicPadding + firstChildMinHeight + mBottomStackPeekSize return mIntrinsicPadding + firstChildMinHeight + mBottomStackPeekSize
+ mCollapseSecondCardPadding; + mBottomStackSlowDownHeight;
} }
private int clampPadding(int desiredPadding) { private int clampPadding(int desiredPadding) {
@@ -1994,7 +1975,6 @@ public class NotificationStackScrollLayout extends ViewGroup
} }
private void onViewRemovedInternal(View child) { private void onViewRemovedInternal(View child) {
mStackScrollAlgorithm.notifyChildrenChanged(this);
if (mChangePositionInProgress) { if (mChangePositionInProgress) {
// This is only a position change, don't do anything special // This is only a position change, don't do anything special
return; return;
@@ -2175,7 +2155,6 @@ public class NotificationStackScrollLayout extends ViewGroup
private void onViewAddedInternal(View child) { private void onViewAddedInternal(View child) {
updateHideSensitiveForChild(child); updateHideSensitiveForChild(child);
mStackScrollAlgorithm.notifyChildrenChanged(this);
((ExpandableView) child).setOnHeightChangedListener(this); ((ExpandableView) child).setOnHeightChangedListener(this);
generateAddAnimation(child, false /* fromMoreCard */); generateAddAnimation(child, false /* fromMoreCard */);
updateAnimationState(child); updateAnimationState(child);
@@ -2643,12 +2622,8 @@ public class NotificationStackScrollLayout extends ViewGroup
} }
public int getEmptyBottomMargin() { public int getEmptyBottomMargin() {
int emptyMargin = mMaxLayoutHeight - mContentHeight - mBottomStackPeekSize; int emptyMargin = mMaxLayoutHeight - mContentHeight - mBottomStackPeekSize
if (needsHeightAdaption()) { - mBottomStackSlowDownHeight;
emptyMargin -= mBottomStackSlowDownHeight;
} else {
emptyMargin -= mCollapseSecondCardPadding;
}
return Math.max(emptyMargin, 0); return Math.max(emptyMargin, 0);
} }
@@ -2659,12 +2634,10 @@ public class NotificationStackScrollLayout extends ViewGroup
public void onExpansionStarted() { public void onExpansionStarted() {
mIsExpansionChanging = true; mIsExpansionChanging = true;
mStackScrollAlgorithm.onExpansionStarted(mCurrentStackScrollState);
} }
public void onExpansionStopped() { public void onExpansionStopped() {
mIsExpansionChanging = false; mIsExpansionChanging = false;
mStackScrollAlgorithm.onExpansionStopped();
if (!mIsExpanded) { if (!mIsExpanded) {
mOwnScrollY = 0; mOwnScrollY = 0;
@@ -2732,7 +2705,6 @@ public class NotificationStackScrollLayout extends ViewGroup
if (mIsExpanded && mAnimationsEnabled) { if (mIsExpanded && mAnimationsEnabled) {
mRequestViewResizeAnimationOnLayout = true; mRequestViewResizeAnimationOnLayout = true;
} }
mStackScrollAlgorithm.onReset(view);
updateAnimationState(view); updateAnimationState(view);
updateChronometerForChild(view); updateChronometerForChild(view);
} }
@@ -3163,15 +3135,7 @@ public class NotificationStackScrollLayout extends ViewGroup
} }
public int getDismissViewHeight() { public int getDismissViewHeight() {
int height = mDismissView.getHeight() + mPaddingBetweenElements; return mDismissView.getHeight() + mPaddingBetweenElements;
// Hack: Accommodate for additional distance when we only have one notification and the
// dismiss all button.
if (getNotGoneChildCount() == 2 && getLastChildNotGone() == mDismissView
&& getFirstChildNotGone() instanceof ActivatableNotificationView) {
height += mCollapseSecondCardPadding;
}
return height;
} }
public int getEmptyShadeViewHeight() { public int getEmptyShadeViewHeight() {

View File

@@ -52,13 +52,8 @@ public class StackScrollAlgorithm {
private StackIndentationFunctor mBottomStackIndentationFunctor; private StackIndentationFunctor mBottomStackIndentationFunctor;
private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState(); private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState();
private boolean mIsExpansionChanging;
private int mFirstChildMaxHeight;
private boolean mIsExpanded; private boolean mIsExpanded;
private ExpandableView mFirstChildWhileExpanding;
private boolean mExpandedOnStart;
private int mBottomStackSlowDownLength; private int mBottomStackSlowDownLength;
private int mCollapseSecondCardPadding;
public StackScrollAlgorithm(Context context) { public StackScrollAlgorithm(Context context) {
initView(context); initView(context);
@@ -86,8 +81,6 @@ public class StackScrollAlgorithm {
mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements; mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements;
mBottomStackSlowDownLength = context.getResources() mBottomStackSlowDownLength = context.getResources()
.getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length); .getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length);
mCollapseSecondCardPadding = context.getResources().getDimensionPixelSize(
R.dimen.notification_collapse_second_card_padding);
mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor(
MAX_ITEMS_IN_BOTTOM_STACK, MAX_ITEMS_IN_BOTTOM_STACK,
mBottomStackPeekSize, mBottomStackPeekSize,
@@ -508,7 +501,7 @@ public class StackScrollAlgorithm {
int childHeight, int minHeight, AmbientState ambientState) { int childHeight, int minHeight, AmbientState ambientState) {
int bottomStackStart = ambientState.getInnerHeight() int bottomStackStart = ambientState.getInnerHeight()
- mBottomStackPeekSize - mCollapseSecondCardPadding; - mBottomStackPeekSize - mBottomStackSlowDownLength;
int childStart = bottomStackStart - childHeight; int childStart = bottomStackStart - childHeight;
if (childStart < childViewState.yTranslation) { if (childStart < childViewState.yTranslation) {
float newHeight = bottomStackStart - childViewState.yTranslation; float newHeight = bottomStackStart - childViewState.yTranslation;
@@ -595,12 +588,9 @@ public class StackScrollAlgorithm {
// The starting position of the bottom stack peek // The starting position of the bottom stack peek
int bottomPeekStart = ambientState.getInnerHeight() - mBottomStackPeekSize - int bottomPeekStart = ambientState.getInnerHeight() - mBottomStackPeekSize -
mCollapseSecondCardPadding + ambientState.getScrollY(); mBottomStackSlowDownLength + ambientState.getScrollY();
// Collapse and expand the first child while the shade is being expanded // Collapse and expand the first child while the shade is being expanded
float maxHeight = mIsExpansionChanging && child == mFirstChildWhileExpanding childViewState.height = (int) Math.max(Math.min(bottomPeekStart, (float) childHeight),
? mFirstChildMaxHeight
: childHeight;
childViewState.height = (int) Math.max(Math.min(bottomPeekStart, maxHeight),
child.getMinHeight()); child.getMinHeight());
} }
@@ -656,55 +646,6 @@ public class StackScrollAlgorithm {
} }
} }
public void onExpansionStarted(StackScrollState currentState) {
mIsExpansionChanging = true;
mExpandedOnStart = mIsExpanded;
ViewGroup hostView = currentState.getHostView();
updateFirstChildHeightWhileExpanding(hostView);
}
private void updateFirstChildHeightWhileExpanding(ViewGroup hostView) {
mFirstChildWhileExpanding = (ExpandableView) findFirstVisibleChild(hostView);
if (mFirstChildWhileExpanding != null) {
if (mExpandedOnStart) {
// We are collapsing the shade, so the first child can get as most as high as the
// current height or the end value of the animation.
mFirstChildMaxHeight = StackStateAnimator.getFinalActualHeight(
mFirstChildWhileExpanding);
} else {
updateFirstChildMaxSizeToMaxHeight();
}
} else {
mFirstChildMaxHeight = 0;
}
}
private void updateFirstChildMaxSizeToMaxHeight() {
// We are expanding the shade, expand it to its full height.
if (!isMaxSizeInitialized(mFirstChildWhileExpanding)) {
// This child was not layouted yet, wait for a layout pass
mFirstChildWhileExpanding
.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
if (mFirstChildWhileExpanding != null) {
mFirstChildMaxHeight = getMaxAllowedChildHeight(
mFirstChildWhileExpanding);
} else {
mFirstChildMaxHeight = 0;
}
v.removeOnLayoutChangeListener(this);
}
});
} else {
mFirstChildMaxHeight = getMaxAllowedChildHeight(mFirstChildWhileExpanding);
}
}
private boolean isMaxSizeInitialized(ExpandableView child) { private boolean isMaxSizeInitialized(ExpandableView child) {
if (child instanceof ExpandableNotificationRow) { if (child instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) child; ExpandableNotificationRow row = (ExpandableNotificationRow) child;
@@ -724,32 +665,10 @@ public class StackScrollAlgorithm {
return null; return null;
} }
public void onExpansionStopped() {
mIsExpansionChanging = false;
mFirstChildWhileExpanding = null;
}
public void setIsExpanded(boolean isExpanded) { public void setIsExpanded(boolean isExpanded) {
this.mIsExpanded = isExpanded; this.mIsExpanded = isExpanded;
} }
public void notifyChildrenChanged(final NotificationStackScrollLayout hostView) {
if (mIsExpansionChanging) {
hostView.post(new Runnable() {
@Override
public void run() {
updateFirstChildHeightWhileExpanding(hostView);
}
});
}
}
public void onReset(ExpandableView view) {
if (view.equals(mFirstChildWhileExpanding)) {
updateFirstChildMaxSizeToMaxHeight();
}
}
class StackScrollAlgorithmState { class StackScrollAlgorithmState {
/** /**