Adapt the paddings of colored notifications

Colored notifications don't need spaces in between
them.

Test: existing tests pass
Bug: 34469375
Change-Id: Iebc374aa6349a542aee2fbc0998719174266fa21
This commit is contained in:
Selim Cinek
2017-01-23 20:47:24 -08:00
parent 7b9605b79c
commit a7ed2c1aaa
4 changed files with 130 additions and 36 deletions

View File

@@ -204,6 +204,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
private boolean mIsLastChild;
private Runnable mOnDismissRunnable;
private boolean mIsLowPriority;
private boolean mIsColorized;
public boolean isGroupExpansionChanging() {
if (isChildInGroup()) {
@@ -295,6 +296,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
for (NotificationContentView l : mLayouts) {
l.onNotificationUpdated(entry);
}
mIsColorized = mStatusBarNotification.getNotification().isColorized();
mShowingPublicInitialized = false;
updateNotificationColor();
if (mIsSummaryWithChildren) {
@@ -1853,10 +1855,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
} else if (isUserLocked()) {
return mChildrenContainer.getGroupExpandFraction();
}
} else if (isColorized()) {
return -1.0f;
}
return 0.0f;
}
private boolean isColorized() {
return mIsColorized;
}
@Override
protected boolean disallowSingleClick(MotionEvent event) {
float x = event.getX();

View File

@@ -404,7 +404,9 @@ public abstract class ExpandableView extends FrameLayout {
}
/**
* @return an amount between 0 and 1 of increased padding that this child needs
* @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;

View File

@@ -606,9 +606,9 @@ public class NotificationStackScrollLayout extends ViewGroup
ExpandableView child = (ExpandableView) getChildAt(i);
if (mChildrenToAddAnimated.contains(child)) {
int startingPosition = getPositionInLinearLayout(child);
int padding = child.getIncreasedPaddingAmount() == 1.0f
? mIncreasedPaddingBetweenElements :
mPaddingBetweenElements;
float increasedPaddingAmount = child.getIncreasedPaddingAmount();
int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements
: increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements;
int childHeight = getIntrinsicHeight(child) + padding;
if (startingPosition < mOwnScrollY) {
// This child starts off screen, so let's keep it offscreen to keep the others visible
@@ -1880,7 +1880,8 @@ public class NotificationStackScrollLayout extends ViewGroup
private void updateContentHeight() {
int height = 0;
float previousIncreasedAmount = 0.0f;
float previousPaddingRequest = mPaddingBetweenElements;
float previousPaddingAmount = 0.0f;
int numShownItems = 0;
boolean finish = false;
int maxDisplayedNotifications = mAmbientState.isDark()
@@ -1897,13 +1898,35 @@ public class NotificationStackScrollLayout extends ViewGroup
finish = true;
}
float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount();
if (height != 0) {
height += (int) NotificationUtils.interpolate(
float padding;
if (increasedPaddingAmount >= 0.0f) {
padding = (int) NotificationUtils.interpolate(
previousPaddingRequest,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
previousPaddingRequest = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
Math.max(previousIncreasedAmount, increasedPaddingAmount));
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;
}
previousIncreasedAmount = increasedPaddingAmount;
if (height != 0) {
height += padding;
}
previousPaddingAmount = increasedPaddingAmount;
height += expandableView.getIntrinsicHeight();
numShownItems++;
if (finish) {
@@ -2566,10 +2589,19 @@ public class NotificationStackScrollLayout extends ViewGroup
*/
private void updateScrollStateForRemovedChild(ExpandableView removedChild) {
int startingPosition = getPositionInLinearLayout(removedChild);
int padding = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
removedChild.getIncreasedPaddingAmount());
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;
if (endPosition <= mOwnScrollY) {
@@ -2601,19 +2633,42 @@ public class NotificationStackScrollLayout extends ViewGroup
requestedView = requestedRow = childInGroup.getNotificationParent();
}
int position = 0;
float previousIncreasedAmount = 0.0f;
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();
if (position != 0) {
position += (int) NotificationUtils.interpolate(
float padding;
if (increasedPaddingAmount >= 0.0f) {
padding = (int) NotificationUtils.interpolate(
previousPaddingRequest,
mIncreasedPaddingBetweenElements,
increasedPaddingAmount);
previousPaddingRequest = (int) NotificationUtils.interpolate(
mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
Math.max(previousIncreasedAmount, increasedPaddingAmount));
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;
}
previousIncreasedAmount = increasedPaddingAmount;
if (position != 0) {
position += padding;
}
previousPaddingAmount = increasedPaddingAmount;
}
if (child == requestedView) {
if (requestedRow != null) {

View File

@@ -27,7 +27,6 @@ import com.android.systemui.statusbar.EmptyShadeView;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.ExpandableView;
import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.StackScrollerDecorView;
import com.android.systemui.statusbar.notification.NotificationUtils;
import java.util.ArrayList;
@@ -244,7 +243,7 @@ public class StackScrollAlgorithm {
int childCount = hostView.getChildCount();
state.visibleChildren.clear();
state.visibleChildren.ensureCapacity(childCount);
state.increasedPaddingMap.clear();
state.paddingMap.clear();
int notGoneIndex = 0;
ExpandableView lastView = null;
for (int i = 0; i < childCount; i++) {
@@ -254,16 +253,31 @@ public class StackScrollAlgorithm {
continue;
}
notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v);
float increasedPadding = v.getIncreasedPaddingAmount();
float increasedPadding = v.getIncreasedPaddingAmount();;
if (increasedPadding != 0.0f) {
state.increasedPaddingMap.put(v, increasedPadding);
state.paddingMap.put(v, increasedPadding);
if (lastView != null) {
Float prevValue = state.increasedPaddingMap.get(lastView);
float newValue = prevValue != null
? Math.max(prevValue, increasedPadding)
: increasedPadding;
state.increasedPaddingMap.put(lastView, newValue);
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) {
float newValue = getPaddingForValue(state.paddingMap.get(lastView));
state.paddingMap.put(lastView, newValue);
}
if (v instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) v;
@@ -287,6 +301,22 @@ public class StackScrollAlgorithm {
}
}
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(StackScrollState resultState,
StackScrollAlgorithmState state, int notGoneIndex,
ExpandableView v) {
@@ -527,18 +557,17 @@ public class StackScrollAlgorithm {
public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
/**
* The children from the host that need an increased padding after them. A value of 0 means
* no increased padding, a value of 1 means full padding.
* The padding after each child measured in pixels.
*/
public final HashMap<ExpandableView, Float> increasedPaddingMap = new HashMap<>();
public final HashMap<ExpandableView, Float> paddingMap = new HashMap<>();
public int getPaddingAfterChild(ExpandableView child) {
Float paddingValue = increasedPaddingMap.get(child);
return paddingValue == null
? mPaddingBetweenElements
: (int) NotificationUtils.interpolate(mPaddingBetweenElements,
mIncreasedPaddingBetweenElements,
paddingValue);
Float padding = paddingMap.get(child);
if (padding == null) {
// Should only happen for the last view
return mPaddingBetweenElements;
}
return (int) padding.floatValue();
}
}