Remove padding customization from stack scroller algorithm

Follow up to ag/13004818 - the normal divider height is now 0.5dp =>
4dp, which is not that different when compared to the divider
with increased height at 6dp.

This change simplifies padding math by removing the
- increased padding getter that ExpandableViews override
- padding map from stack scroll algorithm

Bug: 172289783
Test: visual, no regressions
Change-Id: I1183bdbcef81f0bb60bc07d71f9b5bb5f4dce50c
This commit is contained in:
Lyn Han
2020-11-08 01:11:01 -06:00
parent 012eb24033
commit ec72394775
6 changed files with 10 additions and 206 deletions

View File

@@ -632,9 +632,6 @@
<!-- The height of a notification header -->
<dimen name="notification_header_height">53dp</dimen>
<!-- The height of the divider between the individual notifications when the notification wants it to be increased. This is currently the case for notification groups -->
<dimen name="notification_divider_height_increased">6dp</dimen>
<!-- The height of the gap between adjacent notification sections. -->
<dimen name="notification_section_divider_height">@dimen/notification_side_paddings</dimen>

View File

@@ -331,7 +331,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
private OnUserInteractionCallback mOnUserInteractionCallback;
private NotificationGutsManager mNotificationGutsManager;
private boolean mIsLowPriority;
private boolean mIsColorized;
private boolean mUseIncreasedCollapsedHeight;
private boolean mUseIncreasedHeadsUpHeight;
private float mTranslationWhenRemoved;
@@ -541,7 +540,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
for (NotificationContentView l : mLayouts) {
l.onNotificationUpdated(mEntry);
}
mIsColorized = mEntry.getSbn().getNotification().isColorized();
mShowingPublicInitialized = false;
updateNotificationColor();
if (mMenuRow != null) {
@@ -1624,8 +1622,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
R.dimen.notification_max_heads_up_height_increased);
Resources res = getResources();
mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
R.dimen.notification_divider_height_increased);
mEnableNonGroupedNotificationExpand =
res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
mShowGroupBackgroundWhenExpanded =
@@ -2843,24 +2839,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
MetricsLogger.action(mContext, event, userExpanded);
}
@Override
public float getIncreasedPaddingAmount() {
if (mIsSummaryWithChildren) {
if (isGroupExpanded()) {
return 1.0f;
} else if (isUserLocked()) {
return mChildrenContainer.getIncreasedPaddingAmount();
}
} else if (isColorized() && (!mIsLowPriority || isExpanded())) {
return -1.0f;
}
return 0.0f;
}
private boolean isColorized() {
return mIsColorized && mBgTint != NO_COLOR;
}
@Override
protected boolean disallowSingleClick(MotionEvent event) {
if (areGutsExposed()) {

View File

@@ -499,15 +499,6 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable {
return super.hasOverlappingRendering() && getActualHeight() <= getHeight();
}
/**
* @return an amount between -1 and 1 of increased padding that this child needs. 1 means it
* needs a full increased padding while -1 means it needs no padding at all. For 0.0f the normal
* padding is applied.
*/
public float getIncreasedPaddingAmount() {
return 0.0f;
}
public boolean mustStayOnScreen() {
return false;
}

View File

@@ -1271,13 +1271,6 @@ public class NotificationChildrenContainer extends ViewGroup {
}
}
public float getIncreasedPaddingAmount() {
if (showingAsLowPriority()) {
return 0.0f;
}
return getGroupExpandFraction();
}
@VisibleForTesting
public boolean isUserLocked() {
return mUserLocked;

View File

@@ -198,7 +198,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
private int mIntrinsicContentHeight;
private int mCollapsedSize;
private int mPaddingBetweenElements;
private int mIncreasedPaddingBetweenElements;
private int mMaxTopPadding;
private int mTopPadding;
private int mBottomMargin;
@@ -883,8 +882,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
mAmbientState.reload(context);
mPaddingBetweenElements = Math.max(1,
res.getDimensionPixelSize(R.dimen.notification_divider_height));
mIncreasedPaddingBetweenElements =
res.getDimensionPixelSize(R.dimen.notification_divider_height_increased);
mMinTopOverScrollToEscape = res.getDimensionPixelSize(
R.dimen.min_top_overscroll_to_qs);
mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height);
@@ -1101,11 +1098,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
for (int i = 0; i < getChildCount(); i++) {
ExpandableView child = (ExpandableView) getChildAt(i);
if (mChildrenToAddAnimated.contains(child)) {
int startingPosition = getPositionInLinearLayout(child);
float increasedPaddingAmount = child.getIncreasedPaddingAmount();
int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements
: increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements;
int childHeight = getIntrinsicHeight(child) + padding;
final int startingPosition = getPositionInLinearLayout(child);
final int childHeight = getIntrinsicHeight(child) + mPaddingBetweenElements;
if (startingPosition < mOwnScrollY) {
// This child starts off screen, so let's keep it offscreen to keep the
// others visible
@@ -2299,7 +2293,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
private void updateContentHeight() {
int height = 0;
float previousPaddingRequest = mPaddingBetweenElements;
float previousPaddingAmount = 0.0f;
int numShownItems = 0;
boolean finish = false;
int maxDisplayedNotifications = mMaxDisplayedNotifications;
@@ -2318,37 +2311,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
} else {
viewHeight = expandableView.getIntrinsicHeight();
}
float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount();
float padding;
if (increasedPaddingAmount >= 0.0f) {
padding = (int) NotificationUtils.interpolate(
previousPaddingRequest,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
previousPaddingRequest = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
} else {
int ownPadding = (int) NotificationUtils.interpolate(
0,
mPaddingBetweenElements,
1.0f + increasedPaddingAmount);
if (previousPaddingAmount > 0.0f) {
padding = (int) NotificationUtils.interpolate(
ownPadding,
mIncreasedPaddingBetweenElements,
previousPaddingAmount);
} else {
padding = ownPadding;
}
previousPaddingRequest = ownPadding;
}
if (height != 0) {
height += padding;
height += mPaddingBetweenElements;
}
height += calculateGapHeight(previousView, expandableView, numShownItems);
previousPaddingAmount = increasedPaddingAmount;
height += viewHeight;
numShownItems++;
previousView = expandableView;
@@ -3056,22 +3022,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
}
updateOnScrollChange();
} else {
int startingPosition = getPositionInLinearLayout(removedChild);
float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount();
int padding;
if (increasedPaddingAmount >= 0) {
padding = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
} else {
padding = (int) NotificationUtils.interpolate(
0,
mPaddingBetweenElements,
1.0f + increasedPaddingAmount);
}
int childHeight = getIntrinsicHeight(removedChild) + padding;
int endPosition = startingPosition + childHeight;
final int startingPosition = getPositionInLinearLayout(removedChild);
final int childHeight = getIntrinsicHeight(removedChild) + mPaddingBetweenElements;
final int endPosition = startingPosition + childHeight;
if (endPosition <= mOwnScrollY) {
// This child is fully scrolled of the top, so we have to deduct its height from the
// scrollPosition
@@ -3104,42 +3057,13 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
requestedView = requestedRow = childInGroup.getNotificationParent();
}
int position = 0;
float previousPaddingRequest = mPaddingBetweenElements;
float previousPaddingAmount = 0.0f;
for (int i = 0; i < getChildCount(); i++) {
ExpandableView child = (ExpandableView) getChildAt(i);
boolean notGone = child.getVisibility() != View.GONE;
if (notGone && !child.hasNoContentHeight()) {
float increasedPaddingAmount = child.getIncreasedPaddingAmount();
float padding;
if (increasedPaddingAmount >= 0.0f) {
padding = (int) NotificationUtils.interpolate(
previousPaddingRequest,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
previousPaddingRequest = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
} else {
int ownPadding = (int) NotificationUtils.interpolate(
0,
mPaddingBetweenElements,
1.0f + increasedPaddingAmount);
if (previousPaddingAmount > 0.0f) {
padding = (int) NotificationUtils.interpolate(
ownPadding,
mIncreasedPaddingBetweenElements,
previousPaddingAmount);
} else {
padding = ownPadding;
}
previousPaddingRequest = ownPadding;
}
if (position != 0) {
position += padding;
position += mPaddingBetweenElements;
}
previousPaddingAmount = increasedPaddingAmount;
}
if (child == requestedView) {
if (requestedRow != null) {

View File

@@ -51,7 +51,6 @@ public class StackScrollAlgorithm {
private final ViewGroup mHostView;
private int mPaddingBetweenElements;
private int mIncreasedPaddingBetweenElements;
private int mGapHeight;
private int mCollapsedSize;
@@ -77,8 +76,6 @@ public class StackScrollAlgorithm {
Resources res = context.getResources();
mPaddingBetweenElements = res.getDimensionPixelSize(
R.dimen.notification_divider_height);
mIncreasedPaddingBetweenElements =
res.getDimensionPixelSize(R.dimen.notification_divider_height_increased);
mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height);
mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height);
mClipNotificationScrollToTop = res.getBoolean(R.bool.config_clipNotificationScrollToTop);
@@ -240,17 +237,8 @@ public class StackScrollAlgorithm {
int childCount = hostView.getChildCount();
state.visibleChildren.clear();
state.visibleChildren.ensureCapacity(childCount);
state.paddingMap.clear();
int notGoneIndex = 0;
ExpandableView lastView = null;
int firstHiddenIndex = ambientState.isDozing()
? (ambientState.hasPulsingNotifications() ? 1 : 0)
: childCount;
// The goal here is to fill the padding map, by iterating over how much padding each child
// needs. The map is thereby reused, by first filling it with the padding amount and when
// iterating over it again, it's filled with the actual resolved value.
for (int i = 0; i < childCount; i++) {
if (ANCHOR_SCROLLING) {
if (i == ambientState.getAnchorViewIndex()) {
@@ -262,39 +250,7 @@ public class StackScrollAlgorithm {
if (v == ambientState.getShelf()) {
continue;
}
if (i >= firstHiddenIndex) {
// we need normal padding now, to be in sync with what the stack calculates
lastView = null;
}
notGoneIndex = updateNotGoneIndex(state, notGoneIndex, v);
float increasedPadding = v.getIncreasedPaddingAmount();
if (increasedPadding != 0.0f) {
state.paddingMap.put(v, increasedPadding);
if (lastView != null) {
Float prevValue = state.paddingMap.get(lastView);
float newValue = getPaddingForValue(increasedPadding);
if (prevValue != null) {
float prevPadding = getPaddingForValue(prevValue);
if (increasedPadding > 0) {
newValue = NotificationUtils.interpolate(
prevPadding,
newValue,
increasedPadding);
} else if (prevValue > 0) {
newValue = NotificationUtils.interpolate(
newValue,
prevPadding,
prevValue);
}
}
state.paddingMap.put(lastView, newValue);
}
} else if (lastView != null) {
// Let's now resolve the value to an actual padding
float newValue = getPaddingForValue(state.paddingMap.get(lastView));
state.paddingMap.put(lastView, newValue);
}
if (v instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) v;
@@ -310,7 +266,6 @@ public class StackScrollAlgorithm {
}
}
}
lastView = v;
}
}
ExpandableNotificationRow expandingNotification = ambientState.getExpandingNotification();
@@ -321,22 +276,6 @@ public class StackScrollAlgorithm {
: -1;
}
private float getPaddingForValue(Float increasedPadding) {
if (increasedPadding == null) {
return mPaddingBetweenElements;
} else if (increasedPadding >= 0.0f) {
return NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
increasedPadding);
} else {
return NotificationUtils.interpolate(
0,
mPaddingBetweenElements,
1.0f + increasedPadding);
}
}
private int updateNotGoneIndex(StackScrollAlgorithmState state, int notGoneIndex,
ExpandableView v) {
ExpandableViewState viewState = v.getViewState();
@@ -413,10 +352,10 @@ public class StackScrollAlgorithm {
currentYPosition += mGapHeight;
}
int paddingAfterChild = getPaddingAfterChild(algorithmState, child);
int childHeight = getMaxAllowedChildHeight(child);
if (reverse) {
childViewState.yTranslation = currentYPosition - (childHeight + paddingAfterChild);
childViewState.yTranslation = currentYPosition
- (childHeight + mPaddingBetweenElements);
if (currentYPosition <= 0) {
childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP;
}
@@ -453,7 +392,7 @@ public class StackScrollAlgorithm {
currentYPosition -= mGapHeight;
}
} else {
currentYPosition = childViewState.yTranslation + childHeight + paddingAfterChild;
currentYPosition = childViewState.yTranslation + childHeight + mPaddingBetweenElements;
if (currentYPosition <= 0) {
childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP;
}
@@ -516,11 +455,6 @@ public class StackScrollAlgorithm {
return needsGapHeight;
}
protected int getPaddingAfterChild(StackScrollAlgorithmState algorithmState,
ExpandableView child) {
return algorithmState.getPaddingAfterChild(child);
}
private void updatePulsingStates(StackScrollAlgorithmState algorithmState,
AmbientState ambientState) {
int childCount = algorithmState.visibleChildren.size();
@@ -780,21 +714,8 @@ public class StackScrollAlgorithm {
*/
public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
/**
* The padding after each child measured in pixels.
*/
public final HashMap<ExpandableView, Float> paddingMap = new HashMap<>();
private int indexOfExpandingNotification;
public int getPaddingAfterChild(ExpandableView child) {
Float padding = paddingMap.get(child);
if (padding == null) {
// Should only happen for the last view
return mPaddingBetweenElements;
}
return (int) padding.floatValue();
}
public int getIndexOfExpandingNotification() {
return indexOfExpandingNotification;
}