From 34c0a8d72aee1867cf7b6d04531c7faec76ab473 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Mon, 12 May 2014 00:01:43 +0200 Subject: [PATCH] Improved the notification stack logic further The more card is now working correctly on the lock screen, as well as any other small cards. The slow down zone for the bottom stack was decreased to allow for more real estate in the scrolling area. Also improved the padding handling. Change-Id: I4816d8a96fc365083412e46af88e740a3fc735bc --- packages/SystemUI/res/values/dimens.xml | 10 +++- .../stack/NotificationStackScrollLayout.java | 7 ++- .../PiecewiseLinearIndentationFunctor.java | 19 ++++--- .../stack/StackIndentationFunctor.java | 36 ++++++++----- .../statusbar/stack/StackScrollAlgorithm.java | 50 +++++++++++++------ 5 files changed, 82 insertions(+), 40 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 4810575b1d923..ab3403057049a 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -243,7 +243,10 @@ 12dp - 18dp + 12dp + + + 12dp 8dp @@ -251,8 +254,11 @@ 2dp + + 0dp + - 3dp + 4dp 94dp diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java index afd5068445508..27f661992cb1d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -153,7 +153,10 @@ public class NotificationStackScrollLayout extends ViewGroup if (DEBUG) { int y = mCollapsedSize; canvas.drawLine(0, y, getWidth(), y, mDebugPaint); - y = (int) (getLayoutHeight() - mBottomStackPeekSize - mCollapsedSize); + y = (int) (getLayoutHeight() - mBottomStackPeekSize + - mStackScrollAlgorithm.getBottomStackSlowDownLength()); + canvas.drawLine(0, y, getWidth(), y, mDebugPaint); + y = (int) (getLayoutHeight() - mBottomStackPeekSize); canvas.drawLine(0, y, getWidth(), y, mDebugPaint); y = (int) getLayoutHeight(); canvas.drawLine(0, y, getWidth(), y, mDebugPaint); @@ -1226,6 +1229,7 @@ public class NotificationStackScrollLayout extends ViewGroup * See {@link AmbientState#setDimmed}. */ public void setDimmed(boolean dimmed, boolean animate) { + mStackScrollAlgorithm.setDimmed(dimmed); mAmbientState.setDimmed(dimmed); if (animate) { mDimmedNeedsAnimation = true; @@ -1311,6 +1315,7 @@ public class NotificationStackScrollLayout extends ViewGroup // ANIMATION_TYPE_DIMMED new AnimationFilter() + .animateY() .animateScale() .animateDimmed() }; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/PiecewiseLinearIndentationFunctor.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/PiecewiseLinearIndentationFunctor.java index 38b544f2cc019..1c37c35d49dce 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/PiecewiseLinearIndentationFunctor.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/PiecewiseLinearIndentationFunctor.java @@ -38,27 +38,26 @@ public class PiecewiseLinearIndentationFunctor extends StackIndentationFunctor { * the actual visual distance below the top card but is a maximum, * achieved when the next card just starts transitioning into the stack and * the stack is full. - * If totalTransitionDistance is equal to this, we directly start at the peek, - * otherwise the first element transitions between 0 and - * totalTransitionDistance - peekSize. + * If distanceToPeekStart is 0, we directly start at the peek, otherwise the + * first element transitions between 0 and distanceToPeekStart. * Visualization: * --------------------------------------------------- --- * | | | - * | FIRST ITEM | | <- totalTransitionDistance + * | FIRST ITEM | | <- distanceToPeekStart * | | | - * |---------------------------------------------------| | --- - * |__________________SECOND ITEM______________________| | | <- peekSize - * |===================================================| _|_ _|_ + * |---------------------------------------------------| --- --- + * |__________________SECOND ITEM______________________| | <- peekSize + * |===================================================| _|_ * - * @param totalTransitionDistance The total transition distance an element has to go through + * @param distanceToPeekStart The distance to the start of the peak. * @param linearPart The interpolation factor between the linear and the quadratic amount taken. * This factor must be somewhere in [0 , 1] */ PiecewiseLinearIndentationFunctor(int maxItemsInStack, int peekSize, - int totalTransitionDistance, + int distanceToPeekStart, float linearPart) { - super(maxItemsInStack, peekSize, totalTransitionDistance); + super(maxItemsInStack, peekSize, distanceToPeekStart); mBaseValues = new ArrayList(maxItemsInStack+1); initBaseValues(); mLinearPart = linearPart; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackIndentationFunctor.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackIndentationFunctor.java index f72947a6476ac..034eba6836ad9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackIndentationFunctor.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackIndentationFunctor.java @@ -21,8 +21,8 @@ package com.android.systemui.statusbar.stack; */ public abstract class StackIndentationFunctor { - protected final int mTotalTransitionDistance; - protected final int mDistanceToPeekStart; + protected int mTotalTransitionDistance; + protected int mDistanceToPeekStart; protected int mMaxItemsInStack; protected int mPeekSize; protected boolean mStackStartsAtPeek; @@ -37,31 +37,41 @@ public abstract class StackIndentationFunctor { * the actual visual distance below the top card but is a maximum, * achieved when the next card just starts transitioning into the stack and * the stack is full. - * If totalTransitionDistance is equal to this, we directly start at the peek, - * otherwise the first element transitions between 0 and - * totalTransitionDistance - peekSize. + * If distanceToPeekStart is 0, we directly start at the peek, otherwise the + * first element transitions between 0 and distanceToPeekStart. * Visualization: * --------------------------------------------------- --- * | | | - * | FIRST ITEM | | <- totalTransitionDistance + * | FIRST ITEM | | <- distanceToPeekStart * | | | - * |---------------------------------------------------| | --- - * |__________________SECOND ITEM______________________| | | <- peekSize - * |===================================================| _|_ _|_ + * |---------------------------------------------------| --- --- + * |__________________SECOND ITEM______________________| | <- peekSize + * |===================================================| _|_ * - * @param totalTransitionDistance The total transition distance an element has to go through + * @param distanceToPeekStart The distance to the start of the peak. */ - StackIndentationFunctor(int maxItemsInStack, int peekSize, int totalTransitionDistance) { - mTotalTransitionDistance = totalTransitionDistance; - mDistanceToPeekStart = mTotalTransitionDistance - peekSize; + StackIndentationFunctor(int maxItemsInStack, int peekSize, int distanceToPeekStart) { + mDistanceToPeekStart = distanceToPeekStart; mStackStartsAtPeek = mDistanceToPeekStart == 0; mMaxItemsInStack = maxItemsInStack; mPeekSize = peekSize; + updateTotalTransitionDistance(); } + private void updateTotalTransitionDistance() { + mTotalTransitionDistance = mDistanceToPeekStart + mPeekSize; + } + public void setPeekSize(int mPeekSize) { this.mPeekSize = mPeekSize; + updateTotalTransitionDistance(); + } + + public void setDistanceToPeekStart(int distanceToPeekStart) { + mDistanceToPeekStart = distanceToPeekStart; + mStackStartsAtPeek = mDistanceToPeekStart == 0; + updateTotalTransitionDistance(); } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java index 5e4d496ee00fb..7306c83e6abed 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java @@ -65,13 +65,40 @@ public class StackScrollAlgorithm { private ExpandableView mFirstChildWhileExpanding; private boolean mExpandedOnStart; private int mTopStackTotalSize; + private int mPaddingBetweenElementsDimmed; + private int mPaddingBetweenElementsNormal; + private int mBottomStackSlowDownLength; public StackScrollAlgorithm(Context context) { initConstants(context); + updatePadding(false); + } + + private void updatePadding(boolean dimmed) { + mPaddingBetweenElements = dimmed + ? mPaddingBetweenElementsDimmed + : mPaddingBetweenElementsNormal; + mTopStackTotalSize = mCollapsedSize + mPaddingBetweenElements; + mTopStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( + MAX_ITEMS_IN_TOP_STACK, + mTopStackPeekSize, + mTopStackTotalSize, + 0.5f); + mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( + MAX_ITEMS_IN_BOTTOM_STACK, + mBottomStackPeekSize, + getBottomStackSlowDownLength(), + 0.5f); + } + + public int getBottomStackSlowDownLength() { + return mBottomStackSlowDownLength + mPaddingBetweenElements; } private void initConstants(Context context) { - mPaddingBetweenElements = context.getResources() + mPaddingBetweenElementsDimmed = context.getResources() + .getDimensionPixelSize(R.dimen.notification_padding_dimmed); + mPaddingBetweenElementsNormal = context.getResources() .getDimensionPixelSize(R.dimen.notification_padding); mCollapsedSize = context.getResources() .getDimensionPixelSize(R.dimen.notification_min_height); @@ -82,17 +109,8 @@ public class StackScrollAlgorithm { mZDistanceBetweenElements = context.getResources() .getDimensionPixelSize(R.dimen.z_distance_between_notifications); mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements; - mTopStackTotalSize = mCollapsedSize + mPaddingBetweenElements; - mTopStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( - MAX_ITEMS_IN_TOP_STACK, - mTopStackPeekSize, - mTopStackTotalSize, - 0.5f); - mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( - MAX_ITEMS_IN_BOTTOM_STACK, - mBottomStackPeekSize, - mCollapsedSize + mBottomStackPeekSize + mPaddingBetweenElements, - 0.5f); + mBottomStackSlowDownLength = context.getResources() + .getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length); } @@ -206,7 +224,7 @@ public class StackScrollAlgorithm { float bottomPeekStart = mInnerHeight - mBottomStackPeekSize; // The position where the bottom stack starts. - float bottomStackStart = bottomPeekStart - mCollapsedSize; + float bottomStackStart = bottomPeekStart - mBottomStackSlowDownLength; // The y coordinate of the current child. float currentYPosition = 0.0f; @@ -352,7 +370,7 @@ public class StackScrollAlgorithm { algorithmState.itemsInBottomStack += algorithmState.partialInBottom; childViewState.yTranslation = transitioningPositionStart + offset - childHeight - mPaddingBetweenElements; - + // We want at least to be at the end of the top stack when collapsing clampPositionToTopStackEnd(childViewState, childHeight); childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA; @@ -621,6 +639,10 @@ public class StackScrollAlgorithm { } } + public void setDimmed(boolean dimmed) { + updatePadding(dimmed); + } + class StackScrollAlgorithmState { /**