From d5ab645f467255191c513adc0a5b2830b4e00cad Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 8 Dec 2016 16:34:00 -0800 Subject: [PATCH] Only doing the icon animations now when expanding slowly Previously the animation was too distrating when expanding fast. Test: add notification, expand fast, observe no animations Change-Id: I11658368b49094368886c64028c210a1dc95d938 Fixes: 33458094 --- .../systemui/statusbar/NotificationShelf.java | 24 ++++++++++---- .../phone/NotificationPanelView.java | 31 ++++++++++--------- .../systemui/statusbar/phone/PanelView.java | 11 +++++-- .../statusbar/stack/AmbientState.java | 27 ++++++++++++++++ .../stack/NotificationStackScrollLayout.java | 8 +++++ .../systemui/statusbar/stack/ViewState.java | 21 ++++++++++++- 6 files changed, 99 insertions(+), 23 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java index 324eb2df6e5e9..e054bbe672af4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java @@ -34,6 +34,7 @@ import com.android.systemui.statusbar.stack.AnimationProperties; import com.android.systemui.statusbar.stack.ExpandableViewState; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.stack.StackScrollState; +import com.android.systemui.statusbar.stack.ViewState; /** * A notification shelf view that is placed inside the notification scroller. It manages the @@ -200,7 +201,11 @@ public class NotificationShelf extends ActivatableNotificationView { int colorTwoBefore = NO_COLOR; int previousColor = NO_COLOR; float transitionAmount = 0.0f; - boolean scrollingFast = mAmbientState.getCurrentScrollVelocity() > mScrollFastThreshold; + boolean scrollingFast = mAmbientState.getCurrentScrollVelocity() > mScrollFastThreshold + || (mAmbientState.isExpansionChanging() + && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold); + boolean expandingAnimated = mAmbientState.isExpansionChanging() + && !mAmbientState.isPanelTracking(); int baseZHeight = mAmbientState.getBaseZHeight(); while (notificationIndex < mHostLayout.getChildCount()) { ExpandableView child = (ExpandableView) mHostLayout.getChildAt(notificationIndex); @@ -228,7 +233,7 @@ public class NotificationShelf extends ActivatableNotificationView { } updateNotificationClipHeight(row, notificationClipEnd); float inShelfAmount = updateIconAppearance(row, expandAmount, scrollingFast, - isLastChild); + expandingAnimated, isLastChild); numViewsInShelf += inShelfAmount; int ownColorUntinted = row.getBackgroundColorWithoutTint(); if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) { @@ -278,7 +283,7 @@ public class NotificationShelf extends ActivatableNotificationView { * @return the icon amount how much this notification is in the shelf; */ private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount, - boolean scrollingFast, boolean isLastChild) { + boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) { // Let calculate how much the view is in the shelf float viewStart = row.getTranslationY(); int fullHeight = row.getActualHeight() + mPaddingBetweenElements; @@ -316,12 +321,13 @@ public class NotificationShelf extends ActivatableNotificationView { iconTransitionAmount = 0.0f; } updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount, scrollingFast, - isLastChild); + expandingAnimated, isLastChild); return fullTransitionAmount; } private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount, - float fullTransitionAmount, boolean scrollingFast, boolean isLastChild) { + float fullTransitionAmount, boolean scrollingFast, boolean expandingAnimated, + boolean isLastChild) { StatusBarIconView icon = row.getEntry().expandedIcon; NotificationIconContainer.IconState iconState = getIconState(icon); if (iconState == null) { @@ -332,10 +338,16 @@ public class NotificationShelf extends ActivatableNotificationView { iconState.keepClampedPosition = false; } if (clampedAmount == fullTransitionAmount) { - iconState.useFullTransitionAmount = fullTransitionAmount == 0.0f || scrollingFast; + iconState.useFullTransitionAmount = fullTransitionAmount == 0.0f || scrollingFast + || expandingAnimated; iconState.translateContent = mMaxLayoutHeight - getTranslationY() - getIntrinsicHeight() > 0; } + if (scrollingFast || (expandingAnimated && iconState.useFullTransitionAmount + && !ViewState.isAnimatingY(icon))) { + iconState.cancelAnimations(icon); + iconState.useFullTransitionAmount = true; + } float transitionAmount; boolean needCannedAnimation = iconState.clampedAppearAmount == 1.0f && clampedAmount == 0.0f; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index b5865db5a2ea6..a239cb6fbef7c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -105,7 +105,7 @@ public class NotificationPanelView extends PanelView implements private boolean mAnimateNextTopPaddingChange; private int mTrackingPointer; - private VelocityTracker mVelocityTracker; + private VelocityTracker mQsVelocityTracker; private boolean mQsTracking; /** @@ -688,7 +688,7 @@ public class NotificationPanelView extends PanelView implements } private void flingQsWithCurrentVelocity(float y, boolean isCancelMotionEvent) { - float vel = getCurrentVelocity(); + float vel = getCurrentQSVelocity(); final boolean expandsQs = flingExpandsQs(vel); if (expandsQs) { logQsSwipeDown(y); @@ -697,7 +697,7 @@ public class NotificationPanelView extends PanelView implements } private void logQsSwipeDown(float y) { - float vel = getCurrentVelocity(); + float vel = getCurrentQSVelocity(); final int gesture = mStatusBarState == StatusBarState.KEYGUARD ? EventLogConstants.SYSUI_LOCKSCREEN_GESTURE_SWIPE_DOWN_QS : EventLogConstants.SYSUI_SHADE_GESTURE_SWIPE_DOWN_QS; @@ -926,9 +926,9 @@ public class NotificationPanelView extends PanelView implements flingQsWithCurrentVelocity(y, event.getActionMasked() == MotionEvent.ACTION_CANCEL); } - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; + if (mQsVelocityTracker != null) { + mQsVelocityTracker.recycle(); + mQsVelocityTracker = null; } break; } @@ -1290,24 +1290,24 @@ public class NotificationPanelView extends PanelView implements } private void trackMovement(MotionEvent event) { - if (mVelocityTracker != null) mVelocityTracker.addMovement(event); + if (mQsVelocityTracker != null) mQsVelocityTracker.addMovement(event); mLastTouchX = event.getX(); mLastTouchY = event.getY(); } private void initVelocityTracker() { - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); + if (mQsVelocityTracker != null) { + mQsVelocityTracker.recycle(); } - mVelocityTracker = VelocityTracker.obtain(); + mQsVelocityTracker = VelocityTracker.obtain(); } - private float getCurrentVelocity() { - if (mVelocityTracker == null) { + private float getCurrentQSVelocity() { + if (mQsVelocityTracker == null) { return 0; } - mVelocityTracker.computeCurrentVelocity(1000); - return mVelocityTracker.getYVelocity(); + mQsVelocityTracker.computeCurrentVelocity(1000); + return mQsVelocityTracker.getYVelocity(); } private void cancelQsAnimation() { @@ -2282,6 +2282,9 @@ public class NotificationPanelView extends PanelView implements } protected void updateExpandedHeight(float expandedHeight) { + if (mTracking) { + mNotificationStackScroller.setExpandingVelocity(getCurrentExpandVelocity()); + } mNotificationStackScroller.setExpandedHeight(expandedHeight); updateKeyguardBottomAreaAlpha(); setOpening(expandedHeight <= getOpeningHeight()); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java index 83bae11b70ffc..cf53e3fee6484 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java @@ -306,6 +306,7 @@ public abstract class PanelView extends FrameLayout { } break; case MotionEvent.ACTION_MOVE: + trackMovement(event); float h = y - mInitialTouchY; // If the panel was collapsed when touching, we only need to check for the @@ -346,8 +347,6 @@ public abstract class PanelView extends FrameLayout { !isTrackingBlocked()) { setExpandedHeightInternal(newHeight); } - - trackMovement(event); break; case MotionEvent.ACTION_UP: @@ -449,6 +448,14 @@ public abstract class PanelView extends FrameLayout { mPeekTouching = false; } + protected float getCurrentExpandVelocity() { + if (mVelocityTracker == null) { + return 0; + } + mVelocityTracker.computeCurrentVelocity(1000); + return mVelocityTracker.getYVelocity(); + } + private int getFalsingThreshold() { float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; return (int) (mUnlockFalsingThreshold * factor); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java index 94fc17a8b1d83..e1ff29703da78 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java @@ -55,6 +55,9 @@ public class AmbientState { private ActivatableNotificationView mLastVisibleBackgroundChild; private float mCurrentScrollVelocity; private int mStatusBarState; + private float mExpandingVelocity; + private boolean mPanelTracking; + private boolean mExpansionChanging; public AmbientState(Context context) { reload(context); @@ -260,4 +263,28 @@ public class AmbientState { public void setStatusBarState(int statusBarState) { mStatusBarState = statusBarState; } + + public void setExpandingVelocity(float expandingVelocity) { + mExpandingVelocity = expandingVelocity; + } + + public void setExpansionChanging(boolean expansionChanging) { + mExpansionChanging = expansionChanging; + } + + public boolean isExpansionChanging() { + return mExpansionChanging; + } + + public float getExpandingVelocity() { + return mExpandingVelocity; + } + + public void setPanelTracking(boolean panelTracking) { + mPanelTracking = panelTracking; + } + + public boolean isPanelTracking() { + return mPanelTracking; + } } 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 543550d6395d2..7d4927b9a5f7a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -3124,10 +3124,12 @@ public class NotificationStackScrollLayout extends ViewGroup public void onExpansionStarted() { mIsExpansionChanging = true; + mAmbientState.setExpansionChanging(true); } public void onExpansionStopped() { mIsExpansionChanging = false; + mAmbientState.setExpansionChanging(false); if (!mIsExpanded) { setOwnScrollY(0); mPhoneStatusBar.resetUserExpandedStates(); @@ -3155,9 +3157,11 @@ public class NotificationStackScrollLayout extends ViewGroup public void onPanelTrackingStarted() { mPanelTracking = true; + mAmbientState.setPanelTracking(true); } public void onPanelTrackingStopped() { mPanelTracking = false; + mAmbientState.setPanelTracking(false); } public void resetScrollPosition() { @@ -3987,6 +3991,10 @@ public class NotificationStackScrollLayout extends ViewGroup mAmbientState.setStatusBarState(statusBarState); } + public void setExpandingVelocity(float expandingVelocity) { + mAmbientState.setExpandingVelocity(expandingVelocity); + } + /** * A listener that is notified when some child locations might have changed. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/ViewState.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/ViewState.java index a8e5ac63392ed..b747592146691 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/ViewState.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/ViewState.java @@ -568,7 +568,26 @@ public class ViewState { } } - public static boolean isAnimatingY(ExpandableView child) { + public static boolean isAnimatingY(View child) { return getChildTag(child, TAG_ANIMATOR_TRANSLATION_Y) != null; } + + public void cancelAnimations(View view) { + Animator animator = getChildTag(view, TAG_ANIMATOR_TRANSLATION_X); + if (animator != null) { + animator.cancel(); + } + animator = getChildTag(view, TAG_ANIMATOR_TRANSLATION_Y); + if (animator != null) { + animator.cancel(); + } + animator = getChildTag(view, TAG_ANIMATOR_TRANSLATION_Z); + if (animator != null) { + animator.cancel(); + } + animator = getChildTag(view, TAG_ANIMATOR_ALPHA); + if (animator != null) { + animator.cancel(); + } + } }