From 388df6dd3d07376ecd7446cae36e1486cd313171 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 22 Oct 2015 13:25:11 -0700 Subject: [PATCH] Allow expanding notification groups by dragging down Bug: 24866646 Change-Id: Ie7c5ee6753c2f246df04189bb92e08baf0242797 --- .../com/android/systemui/ExpandHelper.java | 31 ++++++++++--------- .../statusbar/ExpandableNotificationRow.java | 24 ++++++++++++++ .../stack/NotificationChildrenContainer.java | 4 +++ .../stack/NotificationStackScrollLayout.java | 11 +++++-- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ExpandHelper.java b/packages/SystemUI/src/com/android/systemui/ExpandHelper.java index 5e1974ee2dfab..d9f7a46bb3c78 100644 --- a/packages/SystemUI/src/com/android/systemui/ExpandHelper.java +++ b/packages/SystemUI/src/com/android/systemui/ExpandHelper.java @@ -21,8 +21,6 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.content.Context; -import android.media.AudioAttributes; -import android.os.Vibrator; import android.util.Log; import android.view.Gravity; import android.view.HapticFeedbackConstants; @@ -144,8 +142,8 @@ public class ExpandHelper implements Gefingerpoken { public float getHeight() { return mView.getActualHeight(); } - public int getNaturalHeight(int maximum) { - return Math.min(maximum, mView.getMaxContentHeight()); + public int getNaturalHeight() { + return mView.getMaxContentHeight(); } } @@ -194,7 +192,7 @@ public class ExpandHelper implements Gefingerpoken { private float clamp(float target) { float out = target; - out = out < mSmallSize ? mSmallSize : (out > mLargeSize ? mLargeSize : out); + out = out < mSmallSize ? mSmallSize : out; out = out > mNaturalHeight ? mNaturalHeight : out; return out; } @@ -381,8 +379,8 @@ public class ExpandHelper implements Gefingerpoken { } private boolean isFullyExpanded(ExpandableView underFocus) { - return underFocus.areChildrenExpanded() || underFocus.getIntrinsicHeight() - - underFocus.getBottomDecorHeight() == underFocus.getMaxContentHeight(); + return underFocus.getIntrinsicHeight() == underFocus.getMaxContentHeight() + && (!underFocus.isSummaryWithChildren() || underFocus.areChildrenExpanded()); } @Override @@ -452,9 +450,7 @@ public class ExpandHelper implements Gefingerpoken { mScaler.setHeight(newHeight); mLastMotionY = ev.getRawY(); if (isFinished) { - mCallback.setUserExpandedChild(mResizedView, expanded); mCallback.expansionStateChanged(false); - return false; } else { mCallback.expansionStateChanged(true); } @@ -509,9 +505,11 @@ public class ExpandHelper implements Gefingerpoken { mScaler.setView(v); mOldHeight = mScaler.getHeight(); mCurrentHeight = mOldHeight; - if (mCallback.canChildBeExpanded(v)) { + boolean canBeExpanded = mCallback.canChildBeExpanded(v); + if (canBeExpanded) { if (DEBUG) Log.d(TAG, "working on an expandable child"); - mNaturalHeight = mScaler.getNaturalHeight(mLargeSize); + mNaturalHeight = mScaler.getNaturalHeight(); + mSmallSize = v.getMinHeight(); } else { if (DEBUG) Log.d(TAG, "working on a non-expandable child"); mNaturalHeight = mOldHeight; @@ -527,19 +525,22 @@ public class ExpandHelper implements Gefingerpoken { if (DEBUG) Log.d(TAG, "scale in finishing on view: " + mResizedView); float currentHeight = mScaler.getHeight(); - float targetHeight = mSmallSize; float h = mScaler.getHeight(); final boolean wasClosed = (mOldHeight == mSmallSize); + boolean nowExpanded; + int naturalHeight = mScaler.getNaturalHeight(); if (wasClosed) { - targetHeight = (force || currentHeight > mSmallSize) ? mNaturalHeight : mSmallSize; + nowExpanded = (force || currentHeight > mOldHeight); } else { - targetHeight = (force || currentHeight < mNaturalHeight) ? mSmallSize : mNaturalHeight; + nowExpanded = !force && currentHeight >= mOldHeight; } + nowExpanded |= mNaturalHeight == mSmallSize; if (mScaleAnimation.isRunning()) { mScaleAnimation.cancel(); } - mCallback.setUserExpandedChild(mResizedView, targetHeight == mNaturalHeight); + mCallback.setUserExpandedChild(mResizedView, nowExpanded); mCallback.expansionStateChanged(false); + float targetHeight = nowExpanded ? naturalHeight : mSmallSize; if (targetHeight != currentHeight) { mScaleAnimation.setFloatValues(targetHeight); mScaleAnimation.setupStartValues(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 7078f33b5af48..5f14bbfe895da 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -104,6 +104,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { private NotificationData.Entry mEntry; private boolean mShowNoBackground; private boolean mChildInGroup; + private ExpandableNotificationRow mNotificationParent; public NotificationContentView getPrivateLayout() { return mPrivateLayout; @@ -220,12 +221,17 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { return mChildInGroup; } + public ExpandableNotificationRow getNotificationParent() { + return mNotificationParent; + } + /** * @param isChildInGroup Is this notification now in a group * @param parent the new parent notification */ public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) { mChildInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup; + mNotificationParent = isChildInGroup ? parent : null; mShowNoBackground = mChildInGroup && hasSameBgColor(parent); mPrivateLayout.setIsChildInGroup(mShowNoBackground); updateBackground(); @@ -472,6 +478,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { @Override public void onInflate(ViewStub stub, View inflated) { mChildrenContainer = (NotificationChildrenContainer) inflated; + mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this); } }); mVetoButton = findViewById(R.id.veto); @@ -520,6 +527,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { } public boolean isExpandable() { + if (mIsSummaryWithChildren && !mShowingPublic) { + return !mChildrenExpanded; + } return mExpandable; } @@ -544,7 +554,21 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { * @param userExpanded whether the user wants this notification to be expanded */ public void setUserExpanded(boolean userExpanded) { + setUserExpanded(userExpanded, false /* allowChildExpansion */); + } + + /** + * Set this notification to be expanded by the user + * + * @param userExpanded whether the user wants this notification to be expanded + * @param allowChildExpansion whether a call to this method allows expanding children + */ + public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { mFalsingManager.setNotificationExpanded(); + if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) { + mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded); + return; + } if (userExpanded && !mExpandable) return; final boolean wasExpanded = isExpanded(); mHasUserChangedExpansion = true; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java index 539dace6cae10..c9ebc843768ff 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java @@ -452,6 +452,10 @@ public class NotificationChildrenContainer extends ViewGroup { mChildrenExpanded = childrenExpanded; } + public void setNotificationParent(ExpandableNotificationRow parent) { + mNotificationParent = parent; + } + public int getMaxContentHeight() { return getIntrinsicHeight(NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); } 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 573e45b1d87b4..aeca97c31376b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -747,7 +747,8 @@ public class NotificationStackScrollLayout extends ViewGroup public void setUserExpandedChild(View v, boolean userExpanded) { if (v instanceof ExpandableNotificationRow) { - ((ExpandableNotificationRow) v).setUserExpanded(userExpanded); + ((ExpandableNotificationRow) v).setUserExpanded(userExpanded, + true /* allowChildrenExpansion */); } } @@ -2344,7 +2345,13 @@ public class NotificationStackScrollLayout extends ViewGroup ExpandableNotificationRow row = (ExpandableNotificationRow) view; if (row.isUserLocked() && row != getFirstChildNotGone()) { // We are actually expanding this view - float endPosition = row.getTranslationY() + row.getActualHeight(); + float endPosition; + if (row.isChildInGroup()) { + ExpandableNotificationRow parent = row.getNotificationParent(); + endPosition = parent.getTranslationY() + parent.getActualHeight(); + } else { + endPosition = row.getTranslationY() + row.getActualHeight(); + } int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize - mBottomStackSlowDownHeight + (int) mStackTranslation; if (endPosition > stackEnd) {