From 9fe1ee7413d2d914cc24a1123a22dc5b16952b8f Mon Sep 17 00:00:00 2001 From: Anthony Chen Date: Fri, 7 Apr 2017 13:53:37 -0700 Subject: [PATCH] Allow clipping of notifications to be toggled. There are two clippings being changed. The first is the shrinking of the height when a notification is being scrolled offscreen. This effect is not noticeable on phones/tablet, where the background is a rectangle. However, for Android Auto, the background is a rounded rectangle. By allowing the clipping to be disabled, the notification now appears to scroll off-screen and not that its height is shrinking. The second modification is to allow the outline of the notification to have rounded corners. This allows the outline to clip its contents along the rounded edges. Test: booted up on phone and Android Auto headunit Bug: 33210494 Change-Id: Id41a57c9164cabe554b4c5b4d713e9d3cb805b09 --- .../res/layout/status_bar_expanded.xml | 1 + packages/SystemUI/res/values/config.xml | 9 ++++++++ packages/SystemUI/res/values/dimens.xml | 10 ++++++++ .../statusbar/ExpandableNotificationRow.java | 2 ++ .../statusbar/ExpandableOutlineView.java | 23 +++++++++++++++---- .../stack/NotificationStackScrollLayout.java | 21 +++++++++-------- .../statusbar/stack/StackScrollAlgorithm.java | 19 ++++++++------- 7 files changed, 63 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml index 22c25ab4583ee..e603c9f74d60c 100644 --- a/packages/SystemUI/res/layout/status_bar_expanded.xml +++ b/packages/SystemUI/res/layout/status_bar_expanded.xml @@ -50,6 +50,7 @@ false + + true + + + false + diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index d031fe84c591d..ae125b5738129 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -200,6 +200,13 @@ -1px 416dp + + + 0dp + + + 0dp + @dimen/match_parent @dimen/standard_notification_panel_width @@ -320,6 +327,9 @@ 0.5dp + + 0dp + 53dp diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 7277ff90a771f..0c74f4567bd88 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -798,7 +798,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView return mMenuRow; } + @Override public void onDensityOrFontScaleChanged() { + super.onDensityOrFontScaleChanged(); initDimens(); if (mIsSummaryWithChildren) { if (mChildrenContainer != null) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java index 553c478959815..f68770895e341 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java @@ -34,6 +34,7 @@ public abstract class ExpandableOutlineView extends ExpandableView { private final Rect mOutlineRect = new Rect(); private boolean mCustomOutline; private float mOutlineAlpha = -1f; + private float mOutlineRadius; /** * {@code true} if the children views of the {@link ExpandableOutlineView} are translated when @@ -46,12 +47,13 @@ public abstract class ExpandableOutlineView extends ExpandableView { public void getOutline(View view, Outline outline) { int translation = mShouldTranslateContents ? 0 : (int) getTranslation(); if (!mCustomOutline) { - outline.setRect(translation, + outline.setRoundRect(translation, mClipTopAmount, getWidth() + translation, - Math.max(getActualHeight() - mClipBottomAmount, mClipTopAmount)); + Math.max(getActualHeight() - mClipBottomAmount, mClipTopAmount), + mOutlineRadius); } else { - outline.setRect(mOutlineRect); + outline.setRoundRect(mOutlineRect, mOutlineRadius); } outline.setAlpha(mOutlineAlpha); } @@ -60,9 +62,20 @@ public abstract class ExpandableOutlineView extends ExpandableView { public ExpandableOutlineView(Context context, AttributeSet attrs) { super(context, attrs); setOutlineProvider(mProvider); + initDimens(); + } + + private void initDimens() { Resources res = getResources(); mShouldTranslateContents = res.getBoolean(R.bool.config_translateNotificationContentsOnSwipe); + mOutlineRadius = res.getDimension(R.dimen.notification_shadow_radius); + setClipToOutline(res.getBoolean(R.bool.config_clipNotificationsToOutline)); + } + + public void onDensityOrFontScaleChanged() { + initDimens(); + invalidateOutline(); } @Override @@ -119,8 +132,8 @@ public abstract class ExpandableOutlineView extends ExpandableView { } /** - * @return whether the view currently needs an outline. This is usually false in case it doesn't - * have a background. + * @return Whether the view currently needs an outline. This is usually {@code false} in case + * it doesn't have a background. */ protected boolean needsOutline() { if (isChildInGroup()) { 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 771e02a4c428c..859c4351c971b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -147,6 +147,7 @@ public class NotificationStackScrollLayout extends ViewGroup private int mPaddingBetweenElements; private int mIncreasedPaddingBetweenElements; private int mTopPadding; + private int mBottomMargin; private int mBottomInset = 0; /** @@ -510,17 +511,19 @@ public class NotificationStackScrollLayout extends ViewGroup mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mOverflingDistance = configuration.getScaledOverflingDistance(); - mCollapsedSize = context.getResources() - .getDimensionPixelSize(R.dimen.notification_min_height); + + Resources res = context.getResources(); + mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); mStackScrollAlgorithm.initView(context); mAmbientState.reload(context); - mPaddingBetweenElements = Math.max(1, context.getResources() - .getDimensionPixelSize(R.dimen.notification_divider_height)); - mIncreasedPaddingBetweenElements = context.getResources() - .getDimensionPixelSize(R.dimen.notification_divider_height_increased); - mMinTopOverScrollToEscape = getResources().getDimensionPixelSize( + 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 = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); + mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height); + mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); } public void setDrawBackgroundAsSrc(boolean asSrc) { @@ -1993,7 +1996,7 @@ public class NotificationStackScrollLayout extends ViewGroup } } } - mContentHeight = height + mTopPadding; + mContentHeight = height + mTopPadding + mBottomMargin; updateScrollability(); mAmbientState.setLayoutMaxHeight(mContentHeight); } 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 b5db78d128ff4..10a9644c4960d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java @@ -17,10 +17,10 @@ package com.android.systemui.statusbar.stack; import android.content.Context; +import android.content.res.Resources; import android.util.Log; import android.view.View; import android.view.ViewGroup; - import com.android.systemui.R; import com.android.systemui.statusbar.DismissView; import com.android.systemui.statusbar.EmptyShadeView; @@ -48,6 +48,7 @@ public class StackScrollAlgorithm { private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState(); private boolean mIsExpanded; + private boolean mClipNotificationScrollToTop; private int mStatusBarHeight; public StackScrollAlgorithm(Context context) { @@ -59,13 +60,14 @@ public class StackScrollAlgorithm { } private void initConstants(Context context) { - mPaddingBetweenElements = context.getResources().getDimensionPixelSize( + Resources res = context.getResources(); + mPaddingBetweenElements = res.getDimensionPixelSize( R.dimen.notification_divider_height); - mIncreasedPaddingBetweenElements = context.getResources() - .getDimensionPixelSize(R.dimen.notification_divider_height_increased); - mCollapsedSize = context.getResources() - .getDimensionPixelSize(R.dimen.notification_min_height); - mStatusBarHeight = context.getResources().getDimensionPixelSize(R.dimen.status_bar_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); } public void getStackScrollState(AmbientState ambientState, StackScrollState resultState) { @@ -142,7 +144,8 @@ public class StackScrollAlgorithm { float newNotificationEnd = newYTranslation + newHeight; boolean isHeadsUp = (child instanceof ExpandableNotificationRow) && ((ExpandableNotificationRow) child).isPinned(); - if (!state.inShelf && newYTranslation < previousNotificationEnd + if (mClipNotificationScrollToTop + && !state.inShelf && newYTranslation < previousNotificationEnd && (!isHeadsUp || ambientState.isShadeExpanded())) { // The previous view is overlapping on top, clip! float overlapAmount = previousNotificationEnd - newYTranslation;