Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.stack; |
| 18 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
| 23 | import android.animation.PropertyValuesHolder; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 24 | import android.animation.TimeAnimator; |
| 25 | import android.animation.ValueAnimator; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 26 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.res.Configuration; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 30 | import android.graphics.Canvas; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 31 | import android.graphics.Color; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 32 | import android.graphics.Paint; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 33 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 34 | import android.graphics.PorterDuff; |
| 35 | import android.graphics.PorterDuffXfermode; |
| 36 | import android.graphics.Rect; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 38 | import android.util.AttributeSet; |
| 39 | import android.util.Log; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 40 | import android.util.Pair; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 41 | import android.view.MotionEvent; |
| 42 | import android.view.VelocityTracker; |
| 43 | import android.view.View; |
| 44 | import android.view.ViewConfiguration; |
| 45 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 46 | import android.view.ViewTreeObserver; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 47 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 48 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 49 | import android.widget.OverScroller; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 50 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 51 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 52 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 53 | import com.android.systemui.R; |
| 54 | import com.android.systemui.SwipeHelper; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 55 | import com.android.systemui.classifier.FalsingManager; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 56 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.DismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 58 | import com.android.systemui.statusbar.EmptyShadeView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 59 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 60 | import com.android.systemui.statusbar.ExpandableView; |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.NotificationOverflowContainer; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 62 | import com.android.systemui.statusbar.NotificationSettingsIconRow; |
| 63 | import com.android.systemui.statusbar.NotificationSettingsIconRow.SettingsIconRowListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 64 | import com.android.systemui.statusbar.StackScrollerDecorView; |
Selim Cinek | cb2b673 | 2014-09-05 16:17:22 +0200 | [diff] [blame] | 65 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 68 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 69 | import com.android.systemui.statusbar.phone.ScrimController; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 71 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 72 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 73 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 74 | import java.util.Collections; |
| 75 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 76 | import java.util.HashSet; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 77 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 78 | /** |
| 79 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 80 | */ |
| 81 | public class NotificationStackScrollLayout extends ViewGroup |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 82 | implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter, |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 83 | ExpandableView.OnHeightChangedListener, NotificationGroupManager.OnGroupChangeListener, |
| 84 | SettingsIconRowListener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 85 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 86 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 87 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 88 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 89 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 90 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 91 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 95 | */ |
| 96 | private static final int INVALID_POINTER = -1; |
| 97 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 98 | private ExpandHelper mExpandHelper; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 99 | private NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 100 | private boolean mSwipingInProgress; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 101 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 102 | private final Paint mBackgroundPaint = new Paint(); |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * mCurrentStackHeight is the actual stack height, mLastSetStackHeight is the stack height set |
| 106 | * externally from {@link #setStackHeight} |
| 107 | */ |
| 108 | private float mLastSetStackHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 109 | private int mOwnScrollY; |
| 110 | private int mMaxLayoutHeight; |
| 111 | |
| 112 | private VelocityTracker mVelocityTracker; |
| 113 | private OverScroller mScroller; |
| 114 | private int mTouchSlop; |
| 115 | private int mMinimumVelocity; |
| 116 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 117 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 118 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 119 | private boolean mIsBeingDragged; |
| 120 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 121 | private int mDownX; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 122 | private int mActivePointerId; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 123 | private boolean mTouchIsClick; |
| 124 | private float mInitialTouchX; |
| 125 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 126 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 127 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 128 | private int mContentHeight; |
| 129 | private int mCollapsedSize; |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 130 | private int mBottomStackSlowDownHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 131 | private int mBottomStackPeekSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 132 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 133 | private int mIncreasedPaddingBetweenElements; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 134 | private int mTopPadding; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 135 | private int mCollapseSecondCardPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * The algorithm which calculates the properties for our children |
| 139 | */ |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 140 | private final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * The current State this Layout is in |
| 144 | */ |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 145 | private StackScrollState mCurrentStackScrollState = new StackScrollState(this); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 146 | private AmbientState mAmbientState = new AmbientState(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 147 | private NotificationGroupManager mGroupManager; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 148 | private HashSet<View> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 149 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
| 150 | private ArrayList<View> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 151 | private ArrayList<View> mSnappedBackChildren = new ArrayList<>(); |
| 152 | private ArrayList<View> mDragAnimPendingChildren = new ArrayList<>(); |
| 153 | private ArrayList<View> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 154 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 155 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 156 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 157 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 158 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 159 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 160 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 161 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 162 | /** |
| 163 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 164 | */ |
| 165 | private float mOverScrolledTopPixels; |
| 166 | |
| 167 | /** |
| 168 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 169 | */ |
| 170 | private float mOverScrolledBottomPixels; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 171 | private OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 172 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 173 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 174 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 175 | private boolean mNeedsAnimation; |
| 176 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 177 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 178 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 179 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 180 | private int mDarkAnimationOriginIndex; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 181 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 182 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 183 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 184 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 185 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 186 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 187 | private boolean mExpandingNotification; |
| 188 | private boolean mExpandedInThisMotion; |
| 189 | private boolean mScrollingEnabled; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 190 | private DismissView mDismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 191 | private EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 192 | private boolean mDismissAllInProgress; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Was the scroller scrolled to the top when the down motion was observed? |
| 196 | */ |
| 197 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 198 | /** |
| 199 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 200 | * when over scrolling on a expanded card. |
| 201 | */ |
| 202 | private float mMinTopOverScrollToEscape; |
| 203 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 204 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 205 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 206 | private boolean mDontReportNextOverScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 207 | private boolean mRequestViewResizeAnimationOnLayout; |
| 208 | private boolean mNeedViewResizeAnimation; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 209 | private View mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 210 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 211 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 212 | /** |
| 213 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 214 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 215 | * motion. |
| 216 | */ |
| 217 | private int mMaxScrollAfterExpand; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 218 | private SwipeHelper.LongPressListener mLongPressListener; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 219 | private GearDisplayedListener mGearDisplayedListener; |
| 220 | |
| 221 | private NotificationSettingsIconRow mCurrIconRow; |
| 222 | private View mTranslatingParentView; |
| 223 | private View mGearExposedView; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 227 | * animating. |
| 228 | */ |
| 229 | private boolean mOnlyScrollingInThisMotion; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 230 | private boolean mInterceptDelegateEnabled; |
| 231 | private boolean mDelegateToScrollView; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 232 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 233 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 234 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 235 | = new ViewTreeObserver.OnPreDrawListener() { |
| 236 | @Override |
| 237 | public boolean onPreDraw() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 238 | updateChildren(); |
| 239 | mChildrenUpdateRequested = false; |
| 240 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 241 | return true; |
| 242 | } |
| 243 | }; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 244 | private PhoneStatusBar mPhoneStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 245 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 246 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 247 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 248 | private HashSet<View> mClearOverlayViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 249 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 250 | = new HashSet<>(); |
| 251 | private HeadsUpManager mHeadsUpManager; |
| 252 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 253 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 254 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 255 | private NotificationOverflowContainer mOverflowContainer; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 256 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 257 | private FalsingManager mFalsingManager; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 258 | private boolean mAnimationRunning; |
| 259 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater |
| 260 | = new ViewTreeObserver.OnPreDrawListener() { |
| 261 | @Override |
| 262 | public boolean onPreDraw() { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 263 | // if it needs animation |
| 264 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 265 | updateBackground(); |
| 266 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 267 | return true; |
| 268 | } |
| 269 | }; |
| 270 | private Rect mBackgroundBounds = new Rect(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 271 | private Rect mStartAnimationRect = new Rect(); |
| 272 | private Rect mEndAnimationRect = new Rect(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 273 | private Rect mCurrentBounds = new Rect(-1, -1, -1, -1); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 274 | private boolean mAnimateNextBackgroundBottom; |
| 275 | private boolean mAnimateNextBackgroundTop; |
| 276 | private ObjectAnimator mBottomAnimator = null; |
| 277 | private ObjectAnimator mTopAnimator = null; |
| 278 | private ActivatableNotificationView mFirstVisibleBackgroundChild = null; |
| 279 | private ActivatableNotificationView mLastVisibleBackgroundChild = null; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 280 | private int mBgColor; |
| 281 | private float mDimAmount; |
| 282 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 283 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 284 | private Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
| 285 | @Override |
| 286 | public void onAnimationEnd(Animator animation) { |
| 287 | mDimAnimator = null; |
| 288 | } |
| 289 | }; |
| 290 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 291 | = new ValueAnimator.AnimatorUpdateListener() { |
| 292 | |
| 293 | @Override |
| 294 | public void onAnimationUpdate(ValueAnimator animation) { |
| 295 | setDimAmount((Float) animation.getAnimatedValue()); |
| 296 | } |
| 297 | }; |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 298 | private ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 299 | private boolean mContinuousShadowUpdate; |
| 300 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 301 | = new ViewTreeObserver.OnPreDrawListener() { |
| 302 | |
| 303 | @Override |
| 304 | public boolean onPreDraw() { |
| 305 | updateViewShadows(); |
| 306 | return true; |
| 307 | } |
| 308 | }; |
| 309 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 310 | @Override |
| 311 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 312 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 313 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 314 | if (endY < otherEndY) { |
| 315 | return -1; |
| 316 | } else if (endY > otherEndY) { |
| 317 | return 1; |
| 318 | } else { |
| 319 | // The two notifications end at the same location |
| 320 | return 0; |
| 321 | } |
| 322 | } |
| 323 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 324 | |
| 325 | public NotificationStackScrollLayout(Context context) { |
| 326 | this(context, null); |
| 327 | } |
| 328 | |
| 329 | public NotificationStackScrollLayout(Context context, AttributeSet attrs) { |
| 330 | this(context, attrs, 0); |
| 331 | } |
| 332 | |
| 333 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 334 | this(context, attrs, defStyleAttr, 0); |
| 335 | } |
| 336 | |
| 337 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 338 | int defStyleRes) { |
| 339 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 340 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 341 | int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); |
| 342 | int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height); |
| 343 | mExpandHelper = new ExpandHelper(getContext(), this, |
| 344 | minHeight, maxHeight); |
| 345 | mExpandHelper.setEventSource(this); |
| 346 | mExpandHelper.setScrollAdapter(this); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 347 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, this, getContext()); |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 348 | mSwipeHelper.setLongPressListener(mLongPressListener); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 349 | mStackScrollAlgorithm = new StackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 350 | initView(context); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 351 | setWillNotDraw(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 352 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 353 | mDebugPaint = new Paint(); |
| 354 | mDebugPaint.setColor(0xffff0000); |
| 355 | mDebugPaint.setStrokeWidth(2); |
| 356 | mDebugPaint.setStyle(Paint.Style.STROKE); |
| 357 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 358 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 359 | mBackgroundPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Override |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 363 | public void onGearTouched(ExpandableNotificationRow row) { |
| 364 | if (mLongPressListener != null) { |
| 365 | mLongPressListener.onLongPress(row, 0, 0); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 370 | protected void onDraw(Canvas canvas) { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 371 | canvas.drawRect(0, mCurrentBounds.top, getWidth(), mCurrentBounds.bottom, mBackgroundPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 372 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 373 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 374 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 375 | y = (int) (getLayoutHeight() - mBottomStackPeekSize |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 376 | - mBottomStackSlowDownHeight); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 377 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 378 | y = (int) (getLayoutHeight() - mBottomStackPeekSize); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 379 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 380 | y = (int) getLayoutHeight(); |
| 381 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 382 | y = getHeight() - getEmptyBottomMargin(); |
| 383 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 387 | private void updateBackgroundDimming() { |
| 388 | float alpha = BACKGROUND_ALPHA_DIMMED + (1 - BACKGROUND_ALPHA_DIMMED) * (1.0f - mDimAmount); |
| 389 | // We need to manually blend in the background color |
| 390 | int scrimColor = mScrimController.getScrimBehindColor(); |
| 391 | // SRC_OVER blending Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc |
| 392 | float alphaInv = 1 - alpha; |
| 393 | int color = Color.argb((int) (alpha * 255 + alphaInv * Color.alpha(scrimColor)), |
| 394 | (int) (Color.red(mBgColor) + alphaInv * Color.red(scrimColor)), |
| 395 | (int) (Color.green(mBgColor) + alphaInv * Color.green(scrimColor)), |
| 396 | (int) (Color.blue(mBgColor) + alphaInv * Color.blue(scrimColor))); |
| 397 | mBackgroundPaint.setColor(color); |
| 398 | invalidate(); |
| 399 | } |
| 400 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 401 | private void initView(Context context) { |
| 402 | mScroller = new OverScroller(getContext()); |
| 403 | setFocusable(true); |
| 404 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 405 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 406 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 407 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 408 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 409 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 410 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 411 | mCollapsedSize = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 412 | .getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 413 | mBottomStackPeekSize = context.getResources() |
| 414 | .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 415 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 416 | mPaddingBetweenElements = Math.max(1, context.getResources() |
Selim Cinek | cacc604 | 2016-01-21 16:16:41 -0800 | [diff] [blame] | 417 | .getDimensionPixelSize(R.dimen.notification_divider_height)); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 418 | mIncreasedPaddingBetweenElements = context.getResources() |
| 419 | .getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 420 | |
Selim Cinek | 587cbf3 | 2016-01-19 11:36:18 -0800 | [diff] [blame] | 421 | mBottomStackSlowDownHeight = mStackScrollAlgorithm.getBottomStackSlowDownLength(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 422 | mMinTopOverScrollToEscape = getResources().getDimensionPixelSize( |
| 423 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 424 | mCollapseSecondCardPadding = getResources().getDimensionPixelSize( |
| 425 | R.dimen.notification_collapse_second_card_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 428 | private void notifyHeightChangeListener(ExpandableView view) { |
| 429 | if (mOnHeightChangedListener != null) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 430 | mOnHeightChangedListener.onHeightChanged(view, false /* needsAnimation */); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 431 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Override |
| 435 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 436 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | 924c612 | 2016-01-15 18:24:05 -0800 | [diff] [blame] | 437 | measureChildren(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | @Override |
| 441 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 442 | |
| 443 | // we layout all our children centered on the top |
| 444 | float centerX = getWidth() / 2.0f; |
| 445 | for (int i = 0; i < getChildCount(); i++) { |
| 446 | View child = getChildAt(i); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 447 | if (child.getVisibility() == GONE) { |
| 448 | continue; |
| 449 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 450 | float width = child.getMeasuredWidth(); |
| 451 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 452 | child.layout((int) (centerX - width / 2.0f), |
| 453 | 0, |
| 454 | (int) (centerX + width / 2.0f), |
| 455 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 456 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 457 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 458 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 459 | clampScrollPosition(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 460 | if (mRequestViewResizeAnimationOnLayout) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 461 | requestAnimationOnViewResize(null); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 462 | mRequestViewResizeAnimationOnLayout = false; |
| 463 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 464 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 465 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 468 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 469 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 470 | mNeedViewResizeAnimation = true; |
| 471 | mNeedsAnimation = true; |
| 472 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 475 | public void updateSpeedBumpIndex(int newIndex) { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 476 | mAmbientState.setSpeedBumpIndex(newIndex); |
| 477 | } |
| 478 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 479 | public void setChildLocationsChangedListener(OnChildLocationsChangedListener listener) { |
| 480 | mListener = listener; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Returns the location the given child is currently rendered at. |
| 485 | * |
| 486 | * @param child the child to get the location for |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 487 | * @return one of {@link StackViewState}'s <code>LOCATION_*</code> constants |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 488 | */ |
| 489 | public int getChildLocation(View child) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 490 | StackViewState childViewState = mCurrentStackScrollState.getViewStateForView(child); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 491 | if (childViewState == null) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 492 | return StackViewState.LOCATION_UNKNOWN; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 493 | } |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 494 | if (childViewState.gone) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 495 | return StackViewState.LOCATION_GONE; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 496 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 497 | return childViewState.location; |
| 498 | } |
| 499 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 500 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 501 | mMaxLayoutHeight = maxLayoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 502 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 505 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 506 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
| 507 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 511 | * @return whether the height of the layout needs to be adapted, in order to ensure that the |
| 512 | * last child is not in the bottom stack. |
| 513 | */ |
| 514 | private boolean needsHeightAdaption() { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 515 | return getNotGoneChildCount() > 1; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 518 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 519 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 520 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 521 | */ |
| 522 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 523 | updateScrollStateForAddedChildren(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 524 | mAmbientState.setScrollY(mOwnScrollY); |
| 525 | mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 526 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 527 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 528 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 529 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 533 | private void updateScrollStateForAddedChildren() { |
| 534 | if (mChildrenToAddAnimated.isEmpty()) { |
| 535 | return; |
| 536 | } |
| 537 | for (int i = 0; i < getChildCount(); i++) { |
| 538 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 539 | if (mChildrenToAddAnimated.contains(child)) { |
| 540 | int startingPosition = getPositionInLinearLayout(child); |
| 541 | int padding = child.needsIncreasedPadding() |
| 542 | ? mIncreasedPaddingBetweenElements : |
| 543 | mPaddingBetweenElements; |
| 544 | int childHeight = getIntrinsicHeight(child) + padding; |
| 545 | if (startingPosition < mOwnScrollY) { |
| 546 | // This child starts off screen, so let's keep it offscreen to keep the others visible |
| 547 | |
| 548 | mOwnScrollY += childHeight; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | clampScrollPosition(); |
| 553 | } |
| 554 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 555 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 556 | if (!mChildrenUpdateRequested) { |
| 557 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 558 | mChildrenUpdateRequested = true; |
| 559 | invalidate(); |
| 560 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 563 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 564 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 565 | } |
| 566 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 567 | private void clampScrollPosition() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 568 | int scrollRange = getScrollRange(); |
| 569 | if (scrollRange < mOwnScrollY) { |
| 570 | mOwnScrollY = scrollRange; |
| 571 | } |
| 572 | } |
| 573 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 574 | public int getTopPadding() { |
| 575 | return mTopPadding; |
| 576 | } |
| 577 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 578 | private void setTopPadding(int topPadding, boolean animate) { |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 579 | if (mTopPadding != topPadding) { |
| 580 | mTopPadding = topPadding; |
| 581 | updateAlgorithmHeightAndPadding(); |
| 582 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 583 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 584 | mTopPaddingNeedsAnimation = true; |
| 585 | mNeedsAnimation = true; |
| 586 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 587 | requestChildrenUpdate(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 588 | notifyHeightChangeListener(null); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Update the height of the stack to a new height. |
| 594 | * |
| 595 | * @param height the new height of the stack |
| 596 | */ |
| 597 | public void setStackHeight(float height) { |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 598 | mLastSetStackHeight = height; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 599 | setIsExpanded(height > 0.0f); |
| 600 | int newStackHeight = (int) height; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 601 | int minStackHeight = getMinStackHeight(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 602 | int stackHeight; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 603 | float paddingOffset; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 604 | boolean trackingHeadsUp = mTrackingHeadsUp || mHeadsUpManager.hasPinnedHeadsUp(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 605 | int normalUnfoldPositionStart = trackingHeadsUp |
| 606 | ? mHeadsUpManager.getTopHeadsUpPinnedHeight() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 607 | : minStackHeight; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 608 | if (newStackHeight - mTopPadding - mTopPaddingOverflow >= normalUnfoldPositionStart |
Jorim Jaggi | 58bef33 | 2014-11-21 18:10:32 +0100 | [diff] [blame] | 609 | || getNotGoneChildCount() == 0) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 610 | paddingOffset = mTopPaddingOverflow; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 611 | stackHeight = newStackHeight; |
| 612 | } else { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 613 | int translationY; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 614 | if (!trackingHeadsUp) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 615 | // We did not reach the position yet where we actually start growing, |
| 616 | // so we translate the stack upwards. |
| 617 | translationY = (newStackHeight - minStackHeight); |
| 618 | // A slight parallax effect is introduced in order for the stack to catch up with |
| 619 | // the top card. |
| 620 | float partiallyThere = (newStackHeight - mTopPadding - mTopPaddingOverflow) |
| 621 | / minStackHeight; |
| 622 | partiallyThere = Math.max(0, partiallyThere); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 623 | translationY += (1 - partiallyThere) * (mBottomStackPeekSize + |
| 624 | mCollapseSecondCardPadding); |
| 625 | } else { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 626 | translationY = (int) (height - normalUnfoldPositionStart); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 627 | } |
| 628 | paddingOffset = translationY - mTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 629 | stackHeight = (int) (height - (translationY - mTopPadding)); |
| 630 | } |
| 631 | if (stackHeight != mCurrentStackHeight) { |
| 632 | mCurrentStackHeight = stackHeight; |
| 633 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 634 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 635 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 636 | setStackTranslation(paddingOffset); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 639 | public float getStackTranslation() { |
| 640 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 643 | private void setStackTranslation(float stackTranslation) { |
| 644 | if (stackTranslation != mStackTranslation) { |
| 645 | mStackTranslation = stackTranslation; |
| 646 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 647 | requestChildrenUpdate(); |
| 648 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 652 | * Get the current height of the view. This is at most the msize of the view given by a the |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 653 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 654 | * |
| 655 | * @return either the layout height or the externally defined height, whichever is smaller |
| 656 | */ |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 657 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 658 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 659 | } |
| 660 | |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 661 | public int getFirstItemMinHeight() { |
| 662 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 663 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | public int getBottomStackPeekSize() { |
| 667 | return mBottomStackPeekSize; |
| 668 | } |
| 669 | |
Jorim Jaggi | 5ad92c5 | 2014-07-28 21:07:32 +0200 | [diff] [blame] | 670 | public int getCollapseSecondCardPadding() { |
| 671 | return mCollapseSecondCardPadding; |
| 672 | } |
| 673 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 674 | public void setLongPressListener(SwipeHelper.LongPressListener listener) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 675 | mSwipeHelper.setLongPressListener(listener); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 676 | mLongPressListener = listener; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 679 | public void setGearDisplayedListener(GearDisplayedListener listener) { |
| 680 | mGearDisplayedListener = listener; |
| 681 | } |
| 682 | |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 683 | public void setQsContainer(ViewGroup qsContainer) { |
| 684 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 687 | public void onChildDismissed(View v) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 688 | if (mDismissAllInProgress) { |
| 689 | return; |
| 690 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 691 | setSwipingInProgress(false); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 692 | if (mDragAnimPendingChildren.contains(v)) { |
| 693 | // We start the swipe and finish it in the same frame, we don't want any animation |
| 694 | // for the drag |
| 695 | mDragAnimPendingChildren.remove(v); |
| 696 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 697 | mSwipedOutViews.add(v); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 698 | mAmbientState.onDragFinished(v); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 699 | updateContinuousShadowDrawing(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 700 | if (v instanceof ExpandableNotificationRow) { |
| 701 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 702 | if (row.isHeadsUp()) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 703 | mHeadsUpManager.addSwipedOutNotification(row.getStatusBarNotification().getKey()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | final View veto = v.findViewById(R.id.veto); |
| 707 | if (veto != null && veto.getVisibility() != View.GONE) { |
| 708 | veto.performClick(); |
| 709 | } |
| 710 | if (DEBUG) Log.v(TAG, "onChildDismissed: " + v); |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 711 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 712 | mFalsingManager.onNotificationDismissed(); |
| 713 | if (mFalsingManager.shouldEnforceBouncer()) { |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 714 | mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null /* cancelAction */, |
| 715 | false /* dismissShade */, true /* afterKeyguardGone */); |
| 716 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | @Override |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 720 | public void onChildSnappedBack(View animView, float targetLeft) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 721 | mAmbientState.onDragFinished(animView); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 722 | updateContinuousShadowDrawing(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 723 | if (!mDragAnimPendingChildren.contains(animView)) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 724 | if (mAnimationsEnabled) { |
| 725 | mSnappedBackChildren.add(animView); |
| 726 | mNeedsAnimation = true; |
| 727 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 728 | requestChildrenUpdate(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 729 | } else { |
| 730 | // We start the swipe and snap back in the same frame, we don't want any animation |
| 731 | mDragAnimPendingChildren.remove(animView); |
| 732 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 733 | |
| 734 | if (targetLeft == 0 && mCurrIconRow != null) { |
| 735 | mCurrIconRow.resetState(); |
| 736 | if (mGearExposedView != null && mGearExposedView == mTranslatingParentView) { |
| 737 | mGearExposedView = null; |
| 738 | } |
| 739 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 742 | @Override |
| 743 | public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 744 | if (!mIsExpanded && isPinnedHeadsUp(animView) && canChildBeDismissed(animView)) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 745 | mScrimController.setTopHeadsUpDragAmount(animView, |
| 746 | Math.min(Math.abs(swipeProgress - 1.0f), 1.0f)); |
| 747 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 748 | return true; // Don't fade out the notification |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 751 | public void onBeginDrag(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 752 | mFalsingManager.onNotificatonStartDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 753 | setSwipingInProgress(true); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 754 | mAmbientState.onBeginDrag(v); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 755 | updateContinuousShadowDrawing(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 756 | if (mAnimationsEnabled && (mIsExpanded || !isPinnedHeadsUp(v))) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 757 | mDragAnimPendingChildren.add(v); |
| 758 | mNeedsAnimation = true; |
| 759 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 760 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 761 | } |
| 762 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 763 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 764 | if (v instanceof ExpandableNotificationRow) { |
| 765 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 766 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 767 | } |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | private boolean isHeadsUp(View v) { |
| 772 | if (v instanceof ExpandableNotificationRow) { |
| 773 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 774 | return row.isHeadsUp(); |
| 775 | } |
| 776 | return false; |
| 777 | } |
| 778 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 779 | public void onDragCancelled(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 780 | mFalsingManager.onNotificatonStopDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 781 | setSwipingInProgress(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 784 | @Override |
| 785 | public float getFalsingThresholdFactor() { |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 786 | return mPhoneStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 789 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 790 | public View getChildAtPosition(MotionEvent ev) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 791 | View child = getChildAtPosition(ev.getX(), ev.getY()); |
| 792 | if (child instanceof ExpandableNotificationRow) { |
| 793 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 794 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 795 | if (mGearExposedView != null && parent != null |
| 796 | && parent.areChildrenExpanded() && mGearExposedView == parent) { |
| 797 | // In this case the group is expanded and showing the gear for the |
| 798 | // group, further interaction should apply to the group, not any |
| 799 | // child notifications so we use the parent of the child. |
| 800 | child = row.getNotificationParent(); |
| 801 | } |
| 802 | } |
| 803 | return child; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 804 | } |
| 805 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 806 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 807 | getLocationOnScreen(mTempInt2); |
| 808 | float localTouchY = touchY - mTempInt2[1]; |
| 809 | |
| 810 | ExpandableView closestChild = null; |
| 811 | float minDist = Float.MAX_VALUE; |
| 812 | |
| 813 | // find the view closest to the location, accounting for GONE views |
| 814 | final int count = getChildCount(); |
| 815 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 816 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 817 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 818 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 819 | continue; |
| 820 | } |
| 821 | float childTop = slidingChild.getTranslationY(); |
| 822 | float top = childTop + slidingChild.getClipTopAmount(); |
| 823 | float bottom = childTop + slidingChild.getActualHeight(); |
| 824 | |
| 825 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 826 | if (dist < minDist) { |
| 827 | closestChild = slidingChild; |
| 828 | minDist = dist; |
| 829 | } |
| 830 | } |
| 831 | return closestChild; |
| 832 | } |
| 833 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 834 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 835 | getLocationOnScreen(mTempInt2); |
| 836 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 839 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 840 | // find the view under the pointer, accounting for GONE views |
| 841 | final int count = getChildCount(); |
| 842 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 843 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 844 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 845 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 846 | continue; |
| 847 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 848 | float childTop = slidingChild.getTranslationY(); |
| 849 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 850 | float bottom = childTop + slidingChild.getActualHeight(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 851 | |
| 852 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 853 | // camera affordance). |
| 854 | int left = 0; |
| 855 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 856 | |
| 857 | if (touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 858 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 859 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 860 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 861 | && mHeadsUpManager.getTopEntry().entry.row != row |
| 862 | && mGroupManager.getGroupSummary( |
| 863 | mHeadsUpManager.getTopEntry().entry.row.getStatusBarNotification()) |
| 864 | != row) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 865 | continue; |
| 866 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 867 | return row.getViewAtPosition(touchY - childTop); |
| 868 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 869 | return slidingChild; |
| 870 | } |
| 871 | } |
| 872 | return null; |
| 873 | } |
| 874 | |
| 875 | public boolean canChildBeExpanded(View v) { |
| 876 | return v instanceof ExpandableNotificationRow |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 877 | && ((ExpandableNotificationRow) v).isExpandable() |
| 878 | && !((ExpandableNotificationRow) v).isHeadsUp(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 882 | if (v instanceof ExpandableNotificationRow) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 883 | ((ExpandableNotificationRow) v).setUserExpanded(userExpanded, |
| 884 | true /* allowChildrenExpansion */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | public void setUserLockedChild(View v, boolean userLocked) { |
| 889 | if (v instanceof ExpandableNotificationRow) { |
| 890 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 891 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 892 | removeLongPressCallback(); |
| 893 | requestDisallowInterceptTouchEvent(true); |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public void expansionStateChanged(boolean isExpanding) { |
| 898 | mExpandingNotification = isExpanding; |
| 899 | if (!mExpandedInThisMotion) { |
| 900 | mMaxScrollAfterExpand = mOwnScrollY; |
| 901 | mExpandedInThisMotion = true; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | public void setScrollingEnabled(boolean enable) { |
| 906 | mScrollingEnabled = enable; |
| 907 | } |
| 908 | |
| 909 | public void setExpandingEnabled(boolean enable) { |
| 910 | mExpandHelper.setEnabled(enable); |
| 911 | } |
| 912 | |
| 913 | private boolean isScrollingEnabled() { |
| 914 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 917 | public boolean canChildBeDismissed(View v) { |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 918 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 919 | } |
| 920 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 921 | @Override |
| 922 | public boolean isAntiFalsingNeeded() { |
Selim Cinek | cb2b673 | 2014-09-05 16:17:22 +0200 | [diff] [blame] | 923 | return mPhoneStatusBar.getBarState() == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 924 | } |
| 925 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 926 | private void setSwipingInProgress(boolean isSwiped) { |
| 927 | mSwipingInProgress = isSwiped; |
| 928 | if(isSwiped) { |
| 929 | requestDisallowInterceptTouchEvent(true); |
| 930 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | @Override |
| 934 | protected void onConfigurationChanged(Configuration newConfig) { |
| 935 | super.onConfigurationChanged(newConfig); |
| 936 | float densityScale = getResources().getDisplayMetrics().density; |
| 937 | mSwipeHelper.setDensityScale(densityScale); |
| 938 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 939 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 940 | initView(getContext()); |
| 941 | } |
| 942 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 943 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 944 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | @Override |
| 948 | public boolean onTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 949 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 950 | || ev.getActionMasked()== MotionEvent.ACTION_UP; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 951 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 952 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 953 | if (mIsExpanded && !mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 954 | if (isCancelOrUp) { |
| 955 | mExpandHelper.onlyObserveMovements(false); |
| 956 | } |
| 957 | boolean wasExpandingBefore = mExpandingNotification; |
| 958 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 959 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 960 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 961 | dispatchDownEventToScroller(ev); |
| 962 | } |
| 963 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 964 | boolean scrollerWantsIt = false; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 965 | if (mIsExpanded && !mSwipingInProgress && !mExpandingNotification |
| 966 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 967 | scrollerWantsIt = onScrollTouch(ev); |
| 968 | } |
| 969 | boolean horizontalSwipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 970 | if (!mIsBeingDragged |
| 971 | && !mExpandingNotification |
| 972 | && !mExpandedInThisMotion |
| 973 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 974 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 975 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 976 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 977 | } |
| 978 | |
| 979 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 980 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 981 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 982 | onScrollTouch(downEvent); |
| 983 | downEvent.recycle(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | private boolean onScrollTouch(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 987 | if (!isScrollingEnabled()) { |
| 988 | return false; |
| 989 | } |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 990 | if (ev.getY() < mQsContainer.getBottom()) { |
| 991 | return false; |
| 992 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 993 | initVelocityTrackerIfNotExists(); |
| 994 | mVelocityTracker.addMovement(ev); |
| 995 | |
| 996 | final int action = ev.getAction(); |
| 997 | |
| 998 | switch (action & MotionEvent.ACTION_MASK) { |
| 999 | case MotionEvent.ACTION_DOWN: { |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 1000 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1001 | return false; |
| 1002 | } |
| 1003 | boolean isBeingDragged = !mScroller.isFinished(); |
| 1004 | setIsBeingDragged(isBeingDragged); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1005 | |
| 1006 | /* |
| 1007 | * If being flinged and user touches, stop the fling. isFinished |
| 1008 | * will be false if being flinged. |
| 1009 | */ |
| 1010 | if (!mScroller.isFinished()) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1011 | mScroller.forceFinished(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | // Remember where the motion event started |
| 1015 | mLastMotionY = (int) ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1016 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1017 | mActivePointerId = ev.getPointerId(0); |
| 1018 | break; |
| 1019 | } |
| 1020 | case MotionEvent.ACTION_MOVE: |
| 1021 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 1022 | if (activePointerIndex == -1) { |
| 1023 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | final int y = (int) ev.getY(activePointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1028 | final int x = (int) ev.getX(activePointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1029 | int deltaY = mLastMotionY - y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1030 | final int xDiff = Math.abs(x - mDownX); |
| 1031 | final int yDiff = Math.abs(deltaY); |
| 1032 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1033 | setIsBeingDragged(true); |
| 1034 | if (deltaY > 0) { |
| 1035 | deltaY -= mTouchSlop; |
| 1036 | } else { |
| 1037 | deltaY += mTouchSlop; |
| 1038 | } |
| 1039 | } |
| 1040 | if (mIsBeingDragged) { |
| 1041 | // Scroll to follow the motion event |
| 1042 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1043 | int range = getScrollRange(); |
| 1044 | if (mExpandedInThisMotion) { |
| 1045 | range = Math.min(range, mMaxScrollAfterExpand); |
| 1046 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1047 | |
| 1048 | float scrollAmount; |
| 1049 | if (deltaY < 0) { |
| 1050 | scrollAmount = overScrollDown(deltaY); |
| 1051 | } else { |
| 1052 | scrollAmount = overScrollUp(deltaY, range); |
| 1053 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1054 | |
| 1055 | // Calling overScrollBy will call onOverScrolled, which |
| 1056 | // calls onScrollChanged if applicable. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1057 | if (scrollAmount != 0.0f) { |
| 1058 | // The scrolling motion could not be compensated with the |
| 1059 | // existing overScroll, we have to scroll the view |
| 1060 | overScrollBy(0, (int) scrollAmount, 0, mOwnScrollY, |
| 1061 | 0, range, 0, getHeight() / 2, true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1062 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1063 | } |
| 1064 | break; |
| 1065 | case MotionEvent.ACTION_UP: |
| 1066 | if (mIsBeingDragged) { |
| 1067 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 1068 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 1069 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 1070 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1071 | if (shouldOverScrollFling(initialVelocity)) { |
| 1072 | onOverScrollFling(true, initialVelocity); |
| 1073 | } else { |
| 1074 | if (getChildCount() > 0) { |
| 1075 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 1076 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 1077 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 1078 | fling(-initialVelocity); |
| 1079 | } else { |
| 1080 | onOverScrollFling(false, initialVelocity); |
| 1081 | } |
| 1082 | } else { |
| 1083 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 1084 | getScrollRange())) { |
| 1085 | postInvalidateOnAnimation(); |
| 1086 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1087 | } |
| 1088 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1089 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1090 | |
| 1091 | mActivePointerId = INVALID_POINTER; |
| 1092 | endDrag(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1093 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1094 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1095 | break; |
| 1096 | case MotionEvent.ACTION_CANCEL: |
| 1097 | if (mIsBeingDragged && getChildCount() > 0) { |
| 1098 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 1099 | postInvalidateOnAnimation(); |
| 1100 | } |
| 1101 | mActivePointerId = INVALID_POINTER; |
| 1102 | endDrag(); |
| 1103 | } |
| 1104 | break; |
| 1105 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 1106 | final int index = ev.getActionIndex(); |
| 1107 | mLastMotionY = (int) ev.getY(index); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1108 | mDownX = (int) ev.getX(index); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1109 | mActivePointerId = ev.getPointerId(index); |
| 1110 | break; |
| 1111 | } |
| 1112 | case MotionEvent.ACTION_POINTER_UP: |
| 1113 | onSecondaryPointerUp(ev); |
| 1114 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1115 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1121 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 1122 | if (mOverscrollTopChangedListener != null) { |
| 1123 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 1124 | } |
| 1125 | mDontReportNextOverScroll = true; |
| 1126 | setOverScrollAmount(0.0f, true, false); |
| 1127 | } |
| 1128 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1129 | /** |
| 1130 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1131 | * |
| 1132 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1133 | * @return The amount of scrolling to be performed by the scroller, |
| 1134 | * not handled by the overScroll amount. |
| 1135 | */ |
| 1136 | private float overScrollUp(int deltaY, int range) { |
| 1137 | deltaY = Math.max(deltaY, 0); |
| 1138 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1139 | float newTopAmount = currentTopAmount - deltaY; |
| 1140 | if (currentTopAmount > 0) { |
| 1141 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1142 | false /* animate */); |
| 1143 | } |
| 1144 | // Top overScroll might not grab all scrolling motion, |
| 1145 | // we have to scroll as well. |
| 1146 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1147 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1148 | if (newScrollY > range) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1149 | if (!mExpandedInThisMotion) { |
| 1150 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1151 | // We overScroll on the top |
| 1152 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1153 | false /* onTop */, |
| 1154 | false /* animate */); |
| 1155 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1156 | mOwnScrollY = range; |
| 1157 | scrollAmount = 0.0f; |
| 1158 | } |
| 1159 | return scrollAmount; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1164 | * |
| 1165 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1166 | * @return The amount of scrolling to be performed by the scroller, |
| 1167 | * not handled by the overScroll amount. |
| 1168 | */ |
| 1169 | private float overScrollDown(int deltaY) { |
| 1170 | deltaY = Math.min(deltaY, 0); |
| 1171 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1172 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1173 | if (currentBottomAmount > 0) { |
| 1174 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1175 | false /* animate */); |
| 1176 | } |
| 1177 | // Bottom overScroll might not grab all scrolling motion, |
| 1178 | // we have to scroll as well. |
| 1179 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1180 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1181 | if (newScrollY < 0) { |
| 1182 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1183 | // We overScroll on the top |
| 1184 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1185 | true /* onTop */, |
| 1186 | false /* animate */); |
| 1187 | mOwnScrollY = 0; |
| 1188 | scrollAmount = 0.0f; |
| 1189 | } |
| 1190 | return scrollAmount; |
| 1191 | } |
| 1192 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1193 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 1194 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 1195 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 1196 | final int pointerId = ev.getPointerId(pointerIndex); |
| 1197 | if (pointerId == mActivePointerId) { |
| 1198 | // This was our active pointer going up. Choose a new |
| 1199 | // active pointer and adjust accordingly. |
| 1200 | // TODO: Make this decision more intelligent. |
| 1201 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 1202 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 1203 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 1204 | if (mVelocityTracker != null) { |
| 1205 | mVelocityTracker.clear(); |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | private void initVelocityTrackerIfNotExists() { |
| 1211 | if (mVelocityTracker == null) { |
| 1212 | mVelocityTracker = VelocityTracker.obtain(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | private void recycleVelocityTracker() { |
| 1217 | if (mVelocityTracker != null) { |
| 1218 | mVelocityTracker.recycle(); |
| 1219 | mVelocityTracker = null; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | private void initOrResetVelocityTracker() { |
| 1224 | if (mVelocityTracker == null) { |
| 1225 | mVelocityTracker = VelocityTracker.obtain(); |
| 1226 | } else { |
| 1227 | mVelocityTracker.clear(); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | @Override |
| 1232 | public void computeScroll() { |
| 1233 | if (mScroller.computeScrollOffset()) { |
| 1234 | // This is called at drawing time by ViewGroup. |
| 1235 | int oldX = mScrollX; |
| 1236 | int oldY = mOwnScrollY; |
| 1237 | int x = mScroller.getCurrX(); |
| 1238 | int y = mScroller.getCurrY(); |
| 1239 | |
| 1240 | if (oldX != x || oldY != y) { |
| 1241 | final int range = getScrollRange(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1242 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
| 1243 | float currVelocity = mScroller.getCurrVelocity(); |
Selim Cinek | ba81962 | 2014-05-13 17:55:53 +0200 | [diff] [blame] | 1244 | if (currVelocity >= mMinimumVelocity) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1245 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
| 1246 | } |
| 1247 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1248 | |
| 1249 | overScrollBy(x - oldX, y - oldY, oldX, oldY, 0, range, |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1250 | 0, (int) (mMaxOverScroll), false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1251 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | // Keep on drawing until the animation has finished. |
| 1255 | postInvalidateOnAnimation(); |
| 1256 | } |
| 1257 | } |
| 1258 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1259 | @Override |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1260 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 1261 | int scrollX, int scrollY, |
| 1262 | int scrollRangeX, int scrollRangeY, |
| 1263 | int maxOverScrollX, int maxOverScrollY, |
| 1264 | boolean isTouchEvent) { |
| 1265 | |
| 1266 | int newScrollY = scrollY + deltaY; |
| 1267 | |
| 1268 | final int top = -maxOverScrollY; |
| 1269 | final int bottom = maxOverScrollY + scrollRangeY; |
| 1270 | |
| 1271 | boolean clampedY = false; |
| 1272 | if (newScrollY > bottom) { |
| 1273 | newScrollY = bottom; |
| 1274 | clampedY = true; |
| 1275 | } else if (newScrollY < top) { |
| 1276 | newScrollY = top; |
| 1277 | clampedY = true; |
| 1278 | } |
| 1279 | |
| 1280 | onOverScrolled(0, newScrollY, false, clampedY); |
| 1281 | |
| 1282 | return clampedY; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1287 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1288 | * same overScroll edge. |
| 1289 | * |
| 1290 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1291 | * the rubber-banding logic. |
| 1292 | * @param onTop Should the effect be applied on top of the scroller. |
| 1293 | * @param animate Should an animation be performed. |
| 1294 | */ |
| 1295 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1296 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1301 | * By default this will also cancel animations on the same overScroll edge. |
| 1302 | * |
| 1303 | * @param amount The amount to overScroll by. |
| 1304 | * @param onTop Should the effect be applied on top of the scroller. |
| 1305 | * @param animate Should an animation be performed. |
| 1306 | */ |
| 1307 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 1308 | setOverScrollAmount(amount, onTop, animate, true); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1313 | * |
| 1314 | * @param amount The amount to overScroll by. |
| 1315 | * @param onTop Should the effect be applied on top of the scroller. |
| 1316 | * @param animate Should an animation be performed. |
| 1317 | * @param cancelAnimators Should running animations be cancelled. |
| 1318 | */ |
| 1319 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1320 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1321 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1326 | * |
| 1327 | * @param amount The amount to overScroll by. |
| 1328 | * @param onTop Should the effect be applied on top of the scroller. |
| 1329 | * @param animate Should an animation be performed. |
| 1330 | * @param cancelAnimators Should running animations be cancelled. |
| 1331 | * @param isRubberbanded The value which will be passed to |
| 1332 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
| 1333 | */ |
| 1334 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1335 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1336 | if (cancelAnimators) { |
| 1337 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 1338 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1339 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1342 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 1343 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1344 | amount = Math.max(0, amount); |
| 1345 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1346 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1347 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1348 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1349 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1350 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1351 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1352 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1353 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1357 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1358 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 1359 | if (mDontReportNextOverScroll) { |
| 1360 | mDontReportNextOverScroll = false; |
| 1361 | return; |
| 1362 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1363 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1364 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | public void setOverscrollTopChangedListener( |
| 1369 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 1370 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 1371 | } |
| 1372 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1373 | public float getCurrentOverScrollAmount(boolean top) { |
| 1374 | return mAmbientState.getOverScrollAmount(top); |
| 1375 | } |
| 1376 | |
| 1377 | public float getCurrentOverScrolledPixels(boolean top) { |
| 1378 | return top? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
| 1379 | } |
| 1380 | |
| 1381 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 1382 | if (onTop) { |
| 1383 | mOverScrolledTopPixels = amount; |
| 1384 | } else { |
| 1385 | mOverScrolledBottomPixels = amount; |
| 1386 | } |
| 1387 | } |
| 1388 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1389 | private void customScrollTo(int y) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1390 | mOwnScrollY = y; |
Selim Cinek | 3af00cf | 2014-05-07 17:27:26 +0200 | [diff] [blame] | 1391 | updateChildren(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | @Override |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1395 | protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1396 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 1397 | if (!mScroller.isFinished()) { |
| 1398 | final int oldX = mScrollX; |
| 1399 | final int oldY = mOwnScrollY; |
| 1400 | mScrollX = scrollX; |
| 1401 | mOwnScrollY = scrollY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1402 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1403 | springBack(); |
| 1404 | } else { |
| 1405 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
| 1406 | invalidateParentIfNeeded(); |
| 1407 | updateChildren(); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1408 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 1409 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1410 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1411 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1412 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1413 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1414 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1415 | } else { |
| 1416 | customScrollTo(scrollY); |
| 1417 | scrollTo(scrollX, mScrollY); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1421 | private void springBack() { |
| 1422 | int scrollRange = getScrollRange(); |
| 1423 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 1424 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 1425 | if (overScrolledTop || overScrolledBottom) { |
| 1426 | boolean onTop; |
| 1427 | float newAmount; |
| 1428 | if (overScrolledTop) { |
| 1429 | onTop = true; |
| 1430 | newAmount = -mOwnScrollY; |
| 1431 | mOwnScrollY = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1432 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1433 | } else { |
| 1434 | onTop = false; |
| 1435 | newAmount = mOwnScrollY - scrollRange; |
| 1436 | mOwnScrollY = scrollRange; |
| 1437 | } |
| 1438 | setOverScrollAmount(newAmount, onTop, false); |
| 1439 | setOverScrollAmount(0.0f, onTop, true); |
| 1440 | mScroller.forceFinished(true); |
| 1441 | } |
| 1442 | } |
| 1443 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1444 | private int getScrollRange() { |
| 1445 | int scrollRange = 0; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1446 | ExpandableView firstChild = (ExpandableView) getFirstChildNotGone(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1447 | if (firstChild != null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1448 | int contentHeight = getContentHeight(); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 1449 | scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight + mBottomStackPeekSize |
| 1450 | + mBottomStackSlowDownHeight); |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1451 | if (scrollRange > 0) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1452 | int firstChildMaxExpandHeight = getMaxExpandHeight(firstChild); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1453 | // We want to at least be able collapse the first item and not ending in a weird |
| 1454 | // end state. |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1455 | scrollRange = Math.max(scrollRange, firstChildMaxExpandHeight |
| 1456 | - firstChild.getMinHeight()); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1457 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1458 | } |
| 1459 | return scrollRange; |
| 1460 | } |
| 1461 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1462 | /** |
| 1463 | * @return the first child which has visibility unequal to GONE |
| 1464 | */ |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1465 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1466 | int childCount = getChildCount(); |
| 1467 | for (int i = 0; i < childCount; i++) { |
| 1468 | View child = getChildAt(i); |
| 1469 | if (child.getVisibility() != View.GONE) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1470 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | return null; |
| 1474 | } |
| 1475 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1476 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1477 | * @return The first child which has visibility unequal to GONE which is currently below the |
| 1478 | * given translationY or equal to it. |
| 1479 | */ |
| 1480 | private View getFirstChildBelowTranlsationY(float translationY) { |
| 1481 | int childCount = getChildCount(); |
| 1482 | for (int i = 0; i < childCount; i++) { |
| 1483 | View child = getChildAt(i); |
| 1484 | if (child.getVisibility() != View.GONE && child.getTranslationY() >= translationY) { |
| 1485 | return child; |
| 1486 | } |
| 1487 | } |
| 1488 | return null; |
| 1489 | } |
| 1490 | |
| 1491 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1492 | * @return the last child which has visibility unequal to GONE |
| 1493 | */ |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1494 | public View getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1495 | int childCount = getChildCount(); |
| 1496 | for (int i = childCount - 1; i >= 0; i--) { |
| 1497 | View child = getChildAt(i); |
| 1498 | if (child.getVisibility() != View.GONE) { |
| 1499 | return child; |
| 1500 | } |
| 1501 | } |
| 1502 | return null; |
| 1503 | } |
| 1504 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1505 | /** |
| 1506 | * @return the number of children which have visibility unequal to GONE |
| 1507 | */ |
| 1508 | public int getNotGoneChildCount() { |
| 1509 | int childCount = getChildCount(); |
| 1510 | int count = 0; |
| 1511 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 1512 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1513 | if (child.getVisibility() != View.GONE && !child.willBeGone()) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1514 | count++; |
| 1515 | } |
| 1516 | } |
| 1517 | return count; |
| 1518 | } |
| 1519 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1520 | private int getMaxExpandHeight(View view) { |
| 1521 | if (view instanceof ExpandableNotificationRow) { |
| 1522 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 1523 | return row.getIntrinsicHeight(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1524 | } |
| 1525 | return view.getHeight(); |
| 1526 | } |
| 1527 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1528 | public int getContentHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1529 | return mContentHeight; |
| 1530 | } |
| 1531 | |
| 1532 | private void updateContentHeight() { |
| 1533 | int height = 0; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1534 | boolean previousNeedsIncreasedPaddings = false; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1535 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1536 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
| 1537 | if (expandableView.getVisibility() != View.GONE) { |
| 1538 | boolean needsIncreasedPaddings = expandableView.needsIncreasedPadding(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1539 | if (height != 0) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1540 | int padding = needsIncreasedPaddings || previousNeedsIncreasedPaddings |
| 1541 | ? mIncreasedPaddingBetweenElements |
| 1542 | : mPaddingBetweenElements; |
| 1543 | height += padding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1544 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1545 | previousNeedsIncreasedPaddings = needsIncreasedPaddings; |
| 1546 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1547 | } |
| 1548 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1549 | mContentHeight = height + mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1552 | private void updateBackground() { |
| 1553 | if (mAmbientState.isDark()) { |
| 1554 | return; |
| 1555 | } |
| 1556 | updateBackgroundBounds(); |
| 1557 | if (!mCurrentBounds.equals(mBackgroundBounds)) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1558 | if (mAnimateNextBackgroundTop || mAnimateNextBackgroundBottom || areBoundsAnimating()) { |
| 1559 | startBackgroundAnimation(); |
| 1560 | } else { |
| 1561 | mCurrentBounds.set(mBackgroundBounds); |
| 1562 | applyCurrentBackgroundBounds(); |
| 1563 | } |
| 1564 | } else { |
| 1565 | if (mBottomAnimator != null) { |
| 1566 | mBottomAnimator.cancel(); |
| 1567 | } |
| 1568 | if (mTopAnimator != null) { |
| 1569 | mTopAnimator.cancel(); |
| 1570 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1571 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1572 | mAnimateNextBackgroundBottom = false; |
| 1573 | mAnimateNextBackgroundTop = false; |
| 1574 | } |
| 1575 | |
| 1576 | private boolean areBoundsAnimating() { |
| 1577 | return mBottomAnimator != null || mTopAnimator != null; |
| 1578 | } |
| 1579 | |
| 1580 | private void startBackgroundAnimation() { |
| 1581 | startBottomAnimation(); |
| 1582 | startTopAnimation(); |
| 1583 | } |
| 1584 | |
| 1585 | private void startTopAnimation() { |
| 1586 | int previousEndValue = mEndAnimationRect.top; |
| 1587 | int newEndValue = mBackgroundBounds.top; |
| 1588 | ObjectAnimator previousAnimator = mTopAnimator; |
| 1589 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 1590 | return; |
| 1591 | } |
| 1592 | if (!mAnimateNextBackgroundTop) { |
| 1593 | // just a local update was performed |
| 1594 | if (previousAnimator != null) { |
| 1595 | // we need to increase all animation keyframes of the previous animator by the |
| 1596 | // relative change to the end value |
| 1597 | int previousStartValue = mStartAnimationRect.top; |
| 1598 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 1599 | values[0].setIntValues(previousStartValue, newEndValue); |
| 1600 | mStartAnimationRect.top = previousStartValue; |
| 1601 | mEndAnimationRect.top = newEndValue; |
| 1602 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 1603 | return; |
| 1604 | } else { |
| 1605 | // no new animation needed, let's just apply the value |
| 1606 | setBackgroundTop(newEndValue); |
| 1607 | return; |
| 1608 | } |
| 1609 | } |
| 1610 | if (previousAnimator != null) { |
| 1611 | previousAnimator.cancel(); |
| 1612 | } |
| 1613 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop", |
| 1614 | mCurrentBounds.top, newEndValue); |
| 1615 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 1616 | animator.setInterpolator(interpolator); |
| 1617 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 1618 | // remove the tag when the animation is finished |
| 1619 | animator.addListener(new AnimatorListenerAdapter() { |
| 1620 | @Override |
| 1621 | public void onAnimationEnd(Animator animation) { |
| 1622 | mStartAnimationRect.top = -1; |
| 1623 | mEndAnimationRect.top = -1; |
| 1624 | mTopAnimator = null; |
| 1625 | } |
| 1626 | }); |
| 1627 | animator.start(); |
| 1628 | mStartAnimationRect.top = mCurrentBounds.top; |
| 1629 | mEndAnimationRect.top = newEndValue; |
| 1630 | mTopAnimator = animator; |
| 1631 | } |
| 1632 | |
| 1633 | private void startBottomAnimation() { |
| 1634 | int previousStartValue = mStartAnimationRect.bottom; |
| 1635 | int previousEndValue = mEndAnimationRect.bottom; |
| 1636 | int newEndValue = mBackgroundBounds.bottom; |
| 1637 | ObjectAnimator previousAnimator = mBottomAnimator; |
| 1638 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 1639 | return; |
| 1640 | } |
| 1641 | if (!mAnimateNextBackgroundBottom) { |
| 1642 | // just a local update was performed |
| 1643 | if (previousAnimator != null) { |
| 1644 | // we need to increase all animation keyframes of the previous animator by the |
| 1645 | // relative change to the end value |
| 1646 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 1647 | values[0].setIntValues(previousStartValue, newEndValue); |
| 1648 | mStartAnimationRect.bottom = previousStartValue; |
| 1649 | mEndAnimationRect.bottom = newEndValue; |
| 1650 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 1651 | return; |
| 1652 | } else { |
| 1653 | // no new animation needed, let's just apply the value |
| 1654 | setBackgroundBottom(newEndValue); |
| 1655 | return; |
| 1656 | } |
| 1657 | } |
| 1658 | if (previousAnimator != null) { |
| 1659 | previousAnimator.cancel(); |
| 1660 | } |
| 1661 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", |
| 1662 | mCurrentBounds.bottom, newEndValue); |
| 1663 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 1664 | animator.setInterpolator(interpolator); |
| 1665 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 1666 | // remove the tag when the animation is finished |
| 1667 | animator.addListener(new AnimatorListenerAdapter() { |
| 1668 | @Override |
| 1669 | public void onAnimationEnd(Animator animation) { |
| 1670 | mStartAnimationRect.bottom = -1; |
| 1671 | mEndAnimationRect.bottom = -1; |
| 1672 | mBottomAnimator = null; |
| 1673 | } |
| 1674 | }); |
| 1675 | animator.start(); |
| 1676 | mStartAnimationRect.bottom = mCurrentBounds.bottom; |
| 1677 | mEndAnimationRect.bottom = newEndValue; |
| 1678 | mBottomAnimator = animator; |
| 1679 | } |
| 1680 | |
| 1681 | private void setBackgroundTop(int top) { |
| 1682 | mCurrentBounds.top = top; |
| 1683 | applyCurrentBackgroundBounds(); |
| 1684 | } |
| 1685 | |
| 1686 | public void setBackgroundBottom(int bottom) { |
| 1687 | mCurrentBounds.bottom = bottom; |
| 1688 | applyCurrentBackgroundBounds(); |
| 1689 | } |
| 1690 | |
| 1691 | private void applyCurrentBackgroundBounds() { |
| 1692 | mScrimController.setExcludedBackgroundArea(mCurrentBounds); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1693 | invalidate(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | /** |
| 1697 | * Update the background bounds to the new desired bounds |
| 1698 | */ |
| 1699 | private void updateBackgroundBounds() { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1700 | mBackgroundBounds.left = (int) getX(); |
| 1701 | mBackgroundBounds.right = (int) (getX() + getWidth()); |
| 1702 | if (!mIsExpanded) { |
| 1703 | mBackgroundBounds.top = 0; |
| 1704 | mBackgroundBounds.bottom = 0; |
| 1705 | } |
| 1706 | ActivatableNotificationView firstView = mFirstVisibleBackgroundChild; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1707 | int top = 0; |
| 1708 | if (firstView != null) { |
| 1709 | int finalTranslationY = (int) StackStateAnimator.getFinalTranslationY(firstView); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1710 | if (mAnimateNextBackgroundTop |
| 1711 | || mTopAnimator == null && mCurrentBounds.top == finalTranslationY |
| 1712 | || mTopAnimator != null && mEndAnimationRect.top == finalTranslationY) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1713 | // we're ending up at the same location as we are now, lets just skip the animation |
| 1714 | top = finalTranslationY; |
| 1715 | } else { |
| 1716 | top = (int) firstView.getTranslationY(); |
| 1717 | } |
| 1718 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1719 | ActivatableNotificationView lastView = mLastVisibleBackgroundChild; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1720 | int bottom = 0; |
| 1721 | if (lastView != null) { |
| 1722 | int finalTranslationY = (int) StackStateAnimator.getFinalTranslationY(lastView); |
| 1723 | int finalHeight = StackStateAnimator.getFinalActualHeight(lastView); |
| 1724 | int finalBottom = finalTranslationY + finalHeight; |
| 1725 | finalBottom = Math.min(finalBottom, getHeight()); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1726 | if (mAnimateNextBackgroundBottom |
| 1727 | || mBottomAnimator == null && mCurrentBounds.bottom == finalBottom |
| 1728 | || mBottomAnimator != null && mEndAnimationRect.bottom == finalBottom) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1729 | // we're ending up at the same location as we are now, lets just skip the animation |
| 1730 | bottom = finalBottom; |
| 1731 | } else { |
| 1732 | bottom = (int) (lastView.getTranslationY() + lastView.getActualHeight()); |
| 1733 | bottom = Math.min(bottom, getHeight()); |
| 1734 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1735 | } else { |
| 1736 | top = (int) (mTopPadding + mStackTranslation); |
Selim Cinek | 7db4298 | 2016-02-02 15:21:41 -0800 | [diff] [blame] | 1737 | bottom = top; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1738 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1739 | if (mPhoneStatusBar.getBarState() != StatusBarState.KEYGUARD) { |
| 1740 | mBackgroundBounds.top = (int) Math.max(mTopPadding + mStackTranslation, top); |
| 1741 | } else { |
| 1742 | // otherwise the animation from the shade to the keyguard will jump as it's maxed |
| 1743 | mBackgroundBounds.top = Math.max(0, top); |
| 1744 | } |
| 1745 | mBackgroundBounds.bottom = Math.min(getHeight(), Math.max(bottom, top)); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1746 | } |
| 1747 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1748 | private ActivatableNotificationView getFirstPinnedHeadsUp() { |
| 1749 | int childCount = getChildCount(); |
| 1750 | for (int i = 0; i < childCount; i++) { |
| 1751 | View child = getChildAt(i); |
| 1752 | if (child.getVisibility() != View.GONE |
| 1753 | && child instanceof ExpandableNotificationRow) { |
| 1754 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 1755 | if (row.isPinned()) { |
| 1756 | return row; |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | return null; |
| 1761 | } |
| 1762 | |
| 1763 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1764 | int childCount = getChildCount(); |
| 1765 | for (int i = childCount - 1; i >= 0; i--) { |
| 1766 | View child = getChildAt(i); |
| 1767 | if (child.getVisibility() != View.GONE |
| 1768 | && child instanceof ActivatableNotificationView) { |
| 1769 | return (ActivatableNotificationView) child; |
| 1770 | } |
| 1771 | } |
| 1772 | return null; |
| 1773 | } |
| 1774 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1775 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 1776 | int childCount = getChildCount(); |
| 1777 | for (int i = 0; i < childCount; i++) { |
| 1778 | View child = getChildAt(i); |
| 1779 | if (child.getVisibility() != View.GONE |
| 1780 | && child instanceof ActivatableNotificationView) { |
| 1781 | return (ActivatableNotificationView) child; |
| 1782 | } |
| 1783 | } |
| 1784 | return null; |
| 1785 | } |
| 1786 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1787 | /** |
| 1788 | * Fling the scroll view |
| 1789 | * |
| 1790 | * @param velocityY The initial velocity in the Y direction. Positive |
| 1791 | * numbers mean that the finger/cursor is moving down the screen, |
| 1792 | * which means we want to scroll towards the top. |
| 1793 | */ |
| 1794 | private void fling(int velocityY) { |
| 1795 | if (getChildCount() > 0) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1796 | int scrollRange = getScrollRange(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1797 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1798 | float topAmount = getCurrentOverScrollAmount(true); |
| 1799 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 1800 | if (velocityY < 0 && topAmount > 0) { |
| 1801 | mOwnScrollY -= (int) topAmount; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1802 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1803 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1804 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1805 | * mOverflingDistance + topAmount; |
| 1806 | } else if (velocityY > 0 && bottomAmount > 0) { |
| 1807 | mOwnScrollY += bottomAmount; |
| 1808 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1809 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 1810 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
| 1811 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1812 | } else { |
| 1813 | // it will be set once we reach the boundary |
| 1814 | mMaxOverScroll = 0.0f; |
| 1815 | } |
| 1816 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1817 | Math.max(0, scrollRange), 0, Integer.MAX_VALUE / 2); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1818 | |
| 1819 | postInvalidateOnAnimation(); |
| 1820 | } |
| 1821 | } |
| 1822 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1823 | /** |
| 1824 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 1825 | * overScroll view (i.e QS). |
| 1826 | */ |
| 1827 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 1828 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 1829 | return mScrolledToTopOnFirstDown |
| 1830 | && !mExpandedInThisMotion |
| 1831 | && topOverScroll > mMinTopOverScrollToEscape |
| 1832 | && initialVelocity > 0; |
| 1833 | } |
| 1834 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1835 | /** |
| 1836 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 1837 | * account. |
| 1838 | * |
| 1839 | * @param qsHeight the top padding imposed by the quick settings panel |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1840 | * @param animate whether to animate the change |
| 1841 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 1842 | * {@code qsHeight} is the final top padding |
| 1843 | */ |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1844 | public void updateTopPadding(float qsHeight, boolean animate, |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1845 | boolean ignoreIntrinsicPadding) { |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1846 | float start = qsHeight; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1847 | float stackHeight = getHeight() - start; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1848 | int minStackHeight = getMinStackHeight(); |
| 1849 | if (stackHeight <= minStackHeight) { |
| 1850 | float overflow = minStackHeight - stackHeight; |
| 1851 | stackHeight = minStackHeight; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1852 | start = getHeight() - stackHeight; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1853 | mTopPaddingOverflow = overflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1854 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1855 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1856 | } |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1857 | setTopPadding(ignoreIntrinsicPadding ? (int) start : clampPadding((int) start), |
| 1858 | animate); |
| 1859 | setStackHeight(mLastSetStackHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1862 | public int getMinStackHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1863 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1864 | final int firstChildMinHeight = firstChild != null ? firstChild.getMinHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1865 | : mCollapsedSize; |
| 1866 | return firstChildMinHeight + mBottomStackPeekSize + mCollapseSecondCardPadding; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | public float getTopPaddingOverflow() { |
| 1870 | return mTopPaddingOverflow; |
| 1871 | } |
| 1872 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1873 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1874 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1875 | final int firstChildMinHeight = firstChild != null ? (int) firstChild.getMinHeight() |
| 1876 | : mCollapsedSize; |
| 1877 | return mIntrinsicPadding + firstChildMinHeight + mBottomStackPeekSize |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1878 | + mCollapseSecondCardPadding; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1879 | } |
| 1880 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1881 | private int clampPadding(int desiredPadding) { |
| 1882 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 1883 | } |
| 1884 | |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1885 | private float getRubberBandFactor(boolean onTop) { |
| 1886 | if (!onTop) { |
| 1887 | return RUBBER_BAND_FACTOR_NORMAL; |
| 1888 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1889 | if (mExpandedInThisMotion) { |
| 1890 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 1891 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1892 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 1893 | } else if (mScrolledToTopOnFirstDown) { |
| 1894 | return 1.0f; |
| 1895 | } |
| 1896 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1897 | } |
| 1898 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1899 | /** |
| 1900 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 1901 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 1902 | * overscroll view (e.g. expand QS). |
| 1903 | */ |
| 1904 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 1905 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1906 | || !mScrolledToTopOnFirstDown; |
| 1907 | } |
| 1908 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1909 | private void endDrag() { |
| 1910 | setIsBeingDragged(false); |
| 1911 | |
| 1912 | recycleVelocityTracker(); |
| 1913 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1914 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 1915 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 1916 | } |
| 1917 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 1918 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 1919 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1920 | } |
| 1921 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1922 | private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) { |
| 1923 | ev.offsetLocation(sourceView.getX(), sourceView.getY()); |
| 1924 | ev.offsetLocation(-targetView.getX(), -targetView.getY()); |
| 1925 | } |
| 1926 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1927 | @Override |
| 1928 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1929 | initDownStates(ev); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1930 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1931 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 1932 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1933 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 1934 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1935 | boolean scrollWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1936 | if (!mSwipingInProgress && !mExpandingNotification) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1937 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 1938 | } |
| 1939 | boolean swipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1940 | if (!mIsBeingDragged |
| 1941 | && !mExpandingNotification |
| 1942 | && !mExpandedInThisMotion |
| 1943 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1944 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 1945 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1946 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 1947 | } |
| 1948 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1949 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 1950 | switch (ev.getActionMasked()) { |
| 1951 | case MotionEvent.ACTION_MOVE: |
| 1952 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 1953 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop )) { |
| 1954 | mTouchIsClick = false; |
| 1955 | } |
| 1956 | break; |
| 1957 | case MotionEvent.ACTION_UP: |
| 1958 | if (mPhoneStatusBar.getBarState() != StatusBarState.KEYGUARD && mTouchIsClick && |
| 1959 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 1960 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 1961 | } |
| 1962 | break; |
| 1963 | } |
| 1964 | } |
| 1965 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1966 | private void initDownStates(MotionEvent ev) { |
| 1967 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 1968 | mExpandedInThisMotion = false; |
| 1969 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1970 | mDisallowScrollingInThisMotion = false; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1971 | mTouchIsClick = true; |
| 1972 | mInitialTouchX = ev.getX(); |
| 1973 | mInitialTouchY = ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1974 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1977 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 1978 | mChildTransferInProgress = childTransferInProgress; |
| 1979 | } |
| 1980 | |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1981 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 1982 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1983 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1984 | // we only call our internal methods if this is actually a removal and not just a |
| 1985 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1986 | if (!mChildTransferInProgress) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1987 | onViewRemovedInternal(child); |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | private void onViewRemovedInternal(View child) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1992 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1993 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1994 | // This is only a position change, don't do anything special |
| 1995 | return; |
| 1996 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1997 | ((ExpandableView) child).setOnHeightChangedListener(null); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1998 | mCurrentStackScrollState.removeViewStateForView(child); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1999 | updateScrollStateForRemovedChild((ExpandableView) child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2000 | boolean animationGenerated = generateRemoveAnimation(child); |
| 2001 | if (animationGenerated && !mSwipedOutViews.contains(child)) { |
| 2002 | // Add this view to an overlay in order to ensure that it will still be temporary |
| 2003 | // drawn when removed |
| 2004 | getOverlay().add(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2005 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2006 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2007 | |
| 2008 | // Make sure the clipRect we might have set is removed |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 2009 | ((ExpandableView) child).setClipTopOptimization(0); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2012 | private boolean isChildInGroup(View child) { |
| 2013 | return child instanceof ExpandableNotificationRow |
| 2014 | && mGroupManager.isChildInGroupWithSummary( |
| 2015 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
| 2016 | } |
| 2017 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2018 | /** |
| 2019 | * Generate a remove animation for a child view. |
| 2020 | * |
| 2021 | * @param child The view to generate the remove animation for. |
| 2022 | * @return Whether an animation was generated. |
| 2023 | */ |
| 2024 | private boolean generateRemoveAnimation(View child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2025 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2026 | mAddedHeadsUpChildren.remove(child); |
| 2027 | return false; |
| 2028 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2029 | if (isClickedHeadsUp(child)) { |
| 2030 | // An animation is already running, add it to the Overlay |
| 2031 | mClearOverlayViewsWhenFinished.add(child); |
| 2032 | return true; |
| 2033 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2034 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2035 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2036 | // Generate Animations |
| 2037 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2038 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2039 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2040 | } else { |
| 2041 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2042 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2043 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2044 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2045 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2046 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2047 | } |
| 2048 | |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2049 | private boolean isClickedHeadsUp(View child) { |
| 2050 | return HeadsUpManager.isClickedHeadsUpNotification(child); |
| 2051 | } |
| 2052 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2053 | /** |
| 2054 | * Remove a removed child view from the heads up animations if it was just added there |
| 2055 | * |
| 2056 | * @return whether any child was removed from the list to animate |
| 2057 | */ |
| 2058 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2059 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2060 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2061 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2062 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2063 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2064 | mTmpList.add(eventPair); |
| 2065 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2066 | } |
| 2067 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2068 | if (hasAddEvent) { |
| 2069 | // This child was just added lets remove all events. |
| 2070 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
| 2071 | } |
| 2072 | mTmpList.clear(); |
| 2073 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2076 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2077 | * @param child the child to query |
| 2078 | * @return whether a view is not a top level child but a child notification and that group is |
| 2079 | * not expanded |
| 2080 | */ |
| 2081 | private boolean isChildInInvisibleGroup(View child) { |
| 2082 | if (child instanceof ExpandableNotificationRow) { |
| 2083 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2084 | ExpandableNotificationRow groupSummary = |
| 2085 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 2086 | if (groupSummary != null && groupSummary != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2087 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2094 | * Updates the scroll position when a child was removed |
| 2095 | * |
| 2096 | * @param removedChild the removed child |
| 2097 | */ |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2098 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2099 | int startingPosition = getPositionInLinearLayout(removedChild); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2100 | int padding = removedChild.needsIncreasedPadding() |
| 2101 | ? mIncreasedPaddingBetweenElements : |
| 2102 | mPaddingBetweenElements; |
| 2103 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2104 | int endPosition = startingPosition + childHeight; |
| 2105 | if (endPosition <= mOwnScrollY) { |
| 2106 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 2107 | // scrollPosition |
| 2108 | mOwnScrollY -= childHeight; |
| 2109 | } else if (startingPosition < mOwnScrollY) { |
| 2110 | // This child is currently being scrolled into, set the scroll position to the start of |
| 2111 | // this child |
| 2112 | mOwnScrollY = startingPosition; |
| 2113 | } |
| 2114 | } |
| 2115 | |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 2116 | private int getIntrinsicHeight(View view) { |
| 2117 | if (view instanceof ExpandableView) { |
| 2118 | ExpandableView expandableView = (ExpandableView) view; |
| 2119 | return expandableView.getIntrinsicHeight(); |
| 2120 | } |
| 2121 | return view.getHeight(); |
| 2122 | } |
| 2123 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2124 | private int getPositionInLinearLayout(View requestedChild) { |
| 2125 | int position = 0; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2126 | boolean previousNeedsIncreasedPaddings = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2127 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2128 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2129 | boolean notGone = child.getVisibility() != View.GONE; |
| 2130 | if (notGone) { |
| 2131 | boolean needsIncreasedPaddings = child.needsIncreasedPadding(); |
| 2132 | if (position != 0) { |
| 2133 | int padding = needsIncreasedPaddings || previousNeedsIncreasedPaddings |
| 2134 | ? mIncreasedPaddingBetweenElements : |
| 2135 | mPaddingBetweenElements; |
| 2136 | position += padding; |
| 2137 | } |
| 2138 | previousNeedsIncreasedPaddings = needsIncreasedPaddings; |
| 2139 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2140 | if (child == requestedChild) { |
| 2141 | return position; |
| 2142 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2143 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 2144 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2151 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2152 | super.onViewAdded(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2153 | onViewAddedInternal(child); |
| 2154 | } |
| 2155 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2156 | private void updateFirstAndLastBackgroundViews() { |
| 2157 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 2158 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
| 2159 | if (mAnimationsEnabled && mIsExpanded) { |
| 2160 | mAnimateNextBackgroundTop = firstChild != mFirstVisibleBackgroundChild; |
| 2161 | mAnimateNextBackgroundBottom = lastChild != mLastVisibleBackgroundChild; |
| 2162 | } else { |
| 2163 | mAnimateNextBackgroundTop = false; |
| 2164 | mAnimateNextBackgroundBottom = false; |
| 2165 | } |
| 2166 | mFirstVisibleBackgroundChild = firstChild; |
| 2167 | mLastVisibleBackgroundChild = lastChild; |
| 2168 | } |
| 2169 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2170 | private void onViewAddedInternal(View child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 2171 | updateHideSensitiveForChild(child); |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2172 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2173 | ((ExpandableView) child).setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2174 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2175 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 2176 | updateChronometerForChild(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2177 | } |
| 2178 | |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 2179 | private void updateHideSensitiveForChild(View child) { |
| 2180 | if (mAmbientState.isHideSensitive() && child instanceof ExpandableView) { |
| 2181 | ExpandableView expandableView = (ExpandableView) child; |
| 2182 | expandableView.setHideSensitiveForIntrinsicHeight(true); |
| 2183 | } |
| 2184 | } |
| 2185 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2186 | public void notifyGroupChildRemoved(View row) { |
| 2187 | onViewRemovedInternal(row); |
| 2188 | } |
| 2189 | |
| 2190 | public void notifyGroupChildAdded(View row) { |
| 2191 | onViewAddedInternal(row); |
| 2192 | } |
| 2193 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2194 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 2195 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2196 | updateNotificationAnimationStates(); |
| 2197 | } |
| 2198 | |
| 2199 | private void updateNotificationAnimationStates() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2200 | boolean running = mAnimationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2201 | int childCount = getChildCount(); |
| 2202 | for (int i = 0; i < childCount; i++) { |
| 2203 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2204 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2205 | updateAnimationState(running, child); |
| 2206 | } |
| 2207 | } |
| 2208 | |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2209 | private void updateAnimationState(View child) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 2210 | updateAnimationState(mAnimationsEnabled && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2214 | private void updateAnimationState(boolean running, View child) { |
| 2215 | if (child instanceof ExpandableNotificationRow) { |
| 2216 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2217 | row.setIconAnimationRunning(running); |
| 2218 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | public boolean isAddOrRemoveAnimationPending() { |
| 2222 | return mNeedsAnimation |
| 2223 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 2224 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2225 | /** |
| 2226 | * Generate an animation for an added child view. |
| 2227 | * |
| 2228 | * @param child The view to be added. |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2229 | * @param fromMoreCard Whether this add is coming from the "more" card on lockscreen. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2230 | */ |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2231 | public void generateAddAnimation(View child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2232 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2233 | // Generate Animations |
| 2234 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2235 | if (fromMoreCard) { |
| 2236 | mFromMoreCardAdditions.add(child); |
| 2237 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2238 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2239 | } |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 2240 | if (isHeadsUp(child) && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2241 | mAddedHeadsUpChildren.add(child); |
| 2242 | mChildrenToAddAnimated.remove(child); |
| 2243 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | /** |
| 2247 | * Change the position of child to a new location |
| 2248 | * |
| 2249 | * @param child the view to change the position for |
| 2250 | * @param newIndex the new index |
| 2251 | */ |
| 2252 | public void changeViewPosition(View child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2253 | int currentIndex = indexOfChild(child); |
| 2254 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2255 | mChangePositionInProgress = true; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2256 | removeView(child); |
| 2257 | addView(child, newIndex); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2258 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2259 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2260 | mChildrenChangingPositions.add(child); |
| 2261 | mNeedsAnimation = true; |
| 2262 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2263 | } |
| 2264 | } |
| 2265 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2266 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2267 | if (mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2268 | generateChildHierarchyEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2269 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2270 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2271 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2272 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState, |
| 2273 | mGoToFullShadeDelay); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2274 | setAnimationRunning(true); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2275 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2276 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 2277 | updateViewShadows(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2278 | } else { |
| 2279 | applyCurrentState(); |
| 2280 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2281 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | private void generateChildHierarchyEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2285 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2286 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2287 | generateChildAdditionEvents(); |
| 2288 | generatePositionChangeEvents(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 2289 | generateSnapBackEvents(); |
| 2290 | generateDragEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2291 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2292 | generateActivateEvent(); |
| 2293 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2294 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2295 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2296 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2297 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2298 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2299 | generateAnimateEverythingEvent(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2300 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2301 | } |
| 2302 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2303 | private void generateHeadsUpAnimationEvents() { |
| 2304 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2305 | ExpandableNotificationRow row = eventPair.first; |
| 2306 | boolean isHeadsUp = eventPair.second; |
| 2307 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 2308 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 2309 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 2310 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 2311 | type = row.wasJustClicked() |
| 2312 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 2313 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 2314 | } else { |
| 2315 | StackViewState viewState = mCurrentStackScrollState.getViewStateForView(row); |
| 2316 | if (viewState == null) { |
| 2317 | // A view state was never generated for this view, so we don't need to animate |
| 2318 | // this. This may happen with notification children. |
| 2319 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2320 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 2321 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 2322 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 2323 | // Our custom add animation |
| 2324 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 2325 | } else { |
| 2326 | // Normal add animation |
| 2327 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 2328 | } |
| 2329 | onBottom = !pinnedAndClosed; |
| 2330 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2331 | } |
| 2332 | AnimationEvent event = new AnimationEvent(row, type); |
| 2333 | event.headsUpFromBottom = onBottom; |
| 2334 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2335 | } |
| 2336 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2337 | mAddedHeadsUpChildren.clear(); |
| 2338 | } |
| 2339 | |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 2340 | private boolean shouldHunAppearFromBottom(StackViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2341 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 2342 | return false; |
| 2343 | } |
| 2344 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2347 | private void generateGroupExpansionEvent() { |
| 2348 | // Generate a group expansion/collapsing event if there is such a group at all |
| 2349 | if (mExpandedGroupView != null) { |
| 2350 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 2351 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 2352 | mExpandedGroupView = null; |
| 2353 | } |
| 2354 | } |
| 2355 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2356 | private void generateViewResizeEvent() { |
| 2357 | if (mNeedViewResizeAnimation) { |
| 2358 | mAnimationEvents.add( |
| 2359 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 2360 | } |
| 2361 | mNeedViewResizeAnimation = false; |
| 2362 | } |
| 2363 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 2364 | private void generateSnapBackEvents() { |
| 2365 | for (View child : mSnappedBackChildren) { |
| 2366 | mAnimationEvents.add(new AnimationEvent(child, |
| 2367 | AnimationEvent.ANIMATION_TYPE_SNAP_BACK)); |
| 2368 | } |
| 2369 | mSnappedBackChildren.clear(); |
| 2370 | } |
| 2371 | |
| 2372 | private void generateDragEvents() { |
| 2373 | for (View child : mDragAnimPendingChildren) { |
| 2374 | mAnimationEvents.add(new AnimationEvent(child, |
| 2375 | AnimationEvent.ANIMATION_TYPE_START_DRAG)); |
| 2376 | } |
| 2377 | mDragAnimPendingChildren.clear(); |
| 2378 | } |
| 2379 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2380 | private void generateChildRemovalEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 2381 | for (View child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2382 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
| 2383 | int animationType = childWasSwipedOut |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2384 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 2385 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2386 | AnimationEvent event = new AnimationEvent(child, animationType); |
| 2387 | |
| 2388 | // we need to know the view after this one |
| 2389 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(child.getTranslationY()); |
| 2390 | mAnimationEvents.add(event); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2391 | } |
| 2392 | mSwipedOutViews.clear(); |
| 2393 | mChildrenToRemoveAnimated.clear(); |
| 2394 | } |
| 2395 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2396 | private void generatePositionChangeEvents() { |
| 2397 | for (View child : mChildrenChangingPositions) { |
| 2398 | mAnimationEvents.add(new AnimationEvent(child, |
| 2399 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 2400 | } |
| 2401 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2402 | if (mGenerateChildOrderChangedEvent) { |
| 2403 | mAnimationEvents.add(new AnimationEvent(null, |
| 2404 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 2405 | mGenerateChildOrderChangedEvent = false; |
| 2406 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2407 | } |
| 2408 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2409 | private void generateChildAdditionEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 2410 | for (View child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2411 | if (mFromMoreCardAdditions.contains(child)) { |
| 2412 | mAnimationEvents.add(new AnimationEvent(child, |
| 2413 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 2414 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 2415 | } else { |
| 2416 | mAnimationEvents.add(new AnimationEvent(child, |
| 2417 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 2418 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2419 | } |
| 2420 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2421 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2422 | } |
| 2423 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2424 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 2425 | if (mTopPaddingNeedsAnimation) { |
| 2426 | mAnimationEvents.add( |
| 2427 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED)); |
| 2428 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2429 | mTopPaddingNeedsAnimation = false; |
| 2430 | } |
| 2431 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2432 | private void generateActivateEvent() { |
| 2433 | if (mActivateNeedsAnimation) { |
| 2434 | mAnimationEvents.add( |
| 2435 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 2436 | } |
| 2437 | mActivateNeedsAnimation = false; |
| 2438 | } |
| 2439 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2440 | private void generateAnimateEverythingEvent() { |
| 2441 | if (mEverythingNeedsAnimation) { |
| 2442 | mAnimationEvents.add( |
| 2443 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 2444 | } |
| 2445 | mEverythingNeedsAnimation = false; |
| 2446 | } |
| 2447 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2448 | private void generateDimmedEvent() { |
| 2449 | if (mDimmedNeedsAnimation) { |
| 2450 | mAnimationEvents.add( |
| 2451 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 2452 | } |
| 2453 | mDimmedNeedsAnimation = false; |
| 2454 | } |
| 2455 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2456 | private void generateHideSensitiveEvent() { |
| 2457 | if (mHideSensitiveNeedsAnimation) { |
| 2458 | mAnimationEvents.add( |
| 2459 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 2460 | } |
| 2461 | mHideSensitiveNeedsAnimation = false; |
| 2462 | } |
| 2463 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2464 | private void generateDarkEvent() { |
| 2465 | if (mDarkNeedsAnimation) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2466 | AnimationEvent ev = new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DARK); |
| 2467 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 2468 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2469 | } |
| 2470 | mDarkNeedsAnimation = false; |
| 2471 | } |
| 2472 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2473 | private void generateGoToFullShadeEvent() { |
| 2474 | if (mGoToFullShadeNeedsAnimation) { |
| 2475 | mAnimationEvents.add( |
| 2476 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 2477 | } |
| 2478 | mGoToFullShadeNeedsAnimation = false; |
| 2479 | } |
| 2480 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2481 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2482 | if (!isScrollingEnabled()) { |
| 2483 | return false; |
| 2484 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2485 | /* |
| 2486 | * This method JUST determines whether we want to intercept the motion. |
| 2487 | * If we return true, onMotionEvent will be called and we do the actual |
| 2488 | * scrolling there. |
| 2489 | */ |
| 2490 | |
| 2491 | /* |
| 2492 | * Shortcut the most recurring case: the user is in the dragging |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 2493 | * state and is moving their finger. We want to intercept this |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2494 | * motion. |
| 2495 | */ |
| 2496 | final int action = ev.getAction(); |
| 2497 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 2498 | return true; |
| 2499 | } |
| 2500 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2501 | switch (action & MotionEvent.ACTION_MASK) { |
| 2502 | case MotionEvent.ACTION_MOVE: { |
| 2503 | /* |
| 2504 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 2505 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2506 | */ |
| 2507 | |
| 2508 | /* |
| 2509 | * Locally do absolute value. mLastMotionY is set to the y value |
| 2510 | * of the down event. |
| 2511 | */ |
| 2512 | final int activePointerId = mActivePointerId; |
| 2513 | if (activePointerId == INVALID_POINTER) { |
| 2514 | // If we don't have a valid id, the touch down wasn't on content. |
| 2515 | break; |
| 2516 | } |
| 2517 | |
| 2518 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 2519 | if (pointerIndex == -1) { |
| 2520 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 2521 | + " in onInterceptTouchEvent"); |
| 2522 | break; |
| 2523 | } |
| 2524 | |
| 2525 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2526 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2527 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2528 | final int xDiff = Math.abs(x - mDownX); |
| 2529 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2530 | setIsBeingDragged(true); |
| 2531 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2532 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2533 | initVelocityTrackerIfNotExists(); |
| 2534 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2535 | } |
| 2536 | break; |
| 2537 | } |
| 2538 | |
| 2539 | case MotionEvent.ACTION_DOWN: { |
| 2540 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 2541 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2542 | if (getChildAtPosition(ev.getX(), y) == null) { |
| 2543 | setIsBeingDragged(false); |
| 2544 | recycleVelocityTracker(); |
| 2545 | break; |
| 2546 | } |
| 2547 | |
| 2548 | /* |
| 2549 | * Remember location of down touch. |
| 2550 | * ACTION_DOWN always refers to pointer index 0. |
| 2551 | */ |
| 2552 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2553 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2554 | mActivePointerId = ev.getPointerId(0); |
| 2555 | |
| 2556 | initOrResetVelocityTracker(); |
| 2557 | mVelocityTracker.addMovement(ev); |
| 2558 | /* |
| 2559 | * If being flinged and user touches the screen, initiate drag; |
| 2560 | * otherwise don't. mScroller.isFinished should be false when |
| 2561 | * being flinged. |
| 2562 | */ |
| 2563 | boolean isBeingDragged = !mScroller.isFinished(); |
| 2564 | setIsBeingDragged(isBeingDragged); |
| 2565 | break; |
| 2566 | } |
| 2567 | |
| 2568 | case MotionEvent.ACTION_CANCEL: |
| 2569 | case MotionEvent.ACTION_UP: |
| 2570 | /* Release the drag */ |
| 2571 | setIsBeingDragged(false); |
| 2572 | mActivePointerId = INVALID_POINTER; |
| 2573 | recycleVelocityTracker(); |
| 2574 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 2575 | postInvalidateOnAnimation(); |
| 2576 | } |
| 2577 | break; |
| 2578 | case MotionEvent.ACTION_POINTER_UP: |
| 2579 | onSecondaryPointerUp(ev); |
| 2580 | break; |
| 2581 | } |
| 2582 | |
| 2583 | /* |
| 2584 | * The only time we want to intercept motion events is if we are in the |
| 2585 | * drag mode. |
| 2586 | */ |
| 2587 | return mIsBeingDragged; |
| 2588 | } |
| 2589 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 2590 | /** |
| 2591 | * @return Whether the specified motion event is actually happening over the content. |
| 2592 | */ |
| 2593 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 2594 | return isInContentBounds(event.getY()); |
| 2595 | } |
| 2596 | |
| 2597 | /** |
| 2598 | * @return Whether a y coordinate is inside the content. |
| 2599 | */ |
| 2600 | public boolean isInContentBounds(float y) { |
| 2601 | return y < getHeight() - getEmptyBottomMargin(); |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 2602 | } |
| 2603 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2604 | private void setIsBeingDragged(boolean isDragged) { |
| 2605 | mIsBeingDragged = isDragged; |
| 2606 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2607 | requestDisallowInterceptTouchEvent(true); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2608 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | @Override |
| 2613 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 2614 | super.onWindowFocusChanged(hasWindowFocus); |
| 2615 | if (!hasWindowFocus) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2616 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2617 | } |
| 2618 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2619 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2620 | public void removeLongPressCallback() { |
| 2621 | mSwipeHelper.removeLongPressCallback(); |
| 2622 | } |
| 2623 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2624 | @Override |
| 2625 | public boolean isScrolledToTop() { |
| 2626 | return mOwnScrollY == 0; |
| 2627 | } |
| 2628 | |
| 2629 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2630 | public boolean isScrolledToBottom() { |
| 2631 | return mOwnScrollY >= getScrollRange(); |
| 2632 | } |
| 2633 | |
| 2634 | @Override |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2635 | public View getHostView() { |
| 2636 | return this; |
| 2637 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2638 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2639 | public int getEmptyBottomMargin() { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2640 | int emptyMargin = mMaxLayoutHeight - mContentHeight - mBottomStackPeekSize; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2641 | if (needsHeightAdaption()) { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2642 | emptyMargin -= mBottomStackSlowDownHeight; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 2643 | } else { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2644 | emptyMargin -= mCollapseSecondCardPadding; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2645 | } |
| 2646 | return Math.max(emptyMargin, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2647 | } |
| 2648 | |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 2649 | public float getKeyguardBottomStackSize() { |
| 2650 | return mBottomStackPeekSize + getResources().getDimensionPixelSize( |
| 2651 | R.dimen.bottom_stack_slow_down_length); |
| 2652 | } |
| 2653 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2654 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2655 | mIsExpansionChanging = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2656 | mStackScrollAlgorithm.onExpansionStarted(mCurrentStackScrollState); |
| 2657 | } |
| 2658 | |
| 2659 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2660 | mIsExpansionChanging = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2661 | mStackScrollAlgorithm.onExpansionStopped(); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 2662 | if (!mIsExpanded) { |
| 2663 | mOwnScrollY = 0; |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 2664 | |
| 2665 | // lets make sure nothing is in the overlay anymore |
| 2666 | getOverlay().clear(); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 2667 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2670 | public void onPanelTrackingStarted() { |
| 2671 | mPanelTracking = true; |
| 2672 | } |
| 2673 | public void onPanelTrackingStopped() { |
| 2674 | mPanelTracking = false; |
| 2675 | } |
| 2676 | |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 2677 | public void resetScrollPosition() { |
| 2678 | mScroller.abortAnimation(); |
| 2679 | mOwnScrollY = 0; |
| 2680 | } |
| 2681 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 2682 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2683 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2684 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2685 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2686 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 2687 | if (!mIsExpanded) { |
| 2688 | mGroupManager.collapseAllGroups(); |
| 2689 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2690 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 2691 | updateChronometers(); |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | private void updateChronometers() { |
| 2696 | int childCount = getChildCount(); |
| 2697 | for (int i = 0; i < childCount; i++) { |
| 2698 | updateChronometerForChild(getChildAt(i)); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | private void updateChronometerForChild(View child) { |
| 2703 | if (child instanceof ExpandableNotificationRow) { |
| 2704 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2705 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2706 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2707 | } |
| 2708 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2709 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2710 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2711 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2712 | updateScrollPositionOnExpandInBottom(view); |
| 2713 | clampScrollPosition(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 2714 | notifyHeightChangeListener(view); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2715 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 2716 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 2717 | ? (ExpandableNotificationRow) view |
| 2718 | : null; |
| 2719 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2720 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2721 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2722 | } |
| 2723 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2724 | @Override |
| 2725 | public void onReset(ExpandableView view) { |
Selim Cinek | 0e41dea | 2014-08-25 13:55:06 +0200 | [diff] [blame] | 2726 | if (mIsExpanded && mAnimationsEnabled) { |
| 2727 | mRequestViewResizeAnimationOnLayout = true; |
| 2728 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2729 | mStackScrollAlgorithm.onReset(view); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2730 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 2731 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2732 | } |
| 2733 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2734 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
| 2735 | if (view instanceof ExpandableNotificationRow) { |
| 2736 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2737 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2738 | // We are actually expanding this view |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 2739 | float endPosition; |
| 2740 | if (row.isChildInGroup()) { |
| 2741 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 2742 | endPosition = parent.getTranslationY() + parent.getActualHeight(); |
| 2743 | } else { |
| 2744 | endPosition = row.getTranslationY() + row.getActualHeight(); |
| 2745 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2746 | int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize - |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2747 | mBottomStackSlowDownHeight + (int) mStackTranslation; |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2748 | if (endPosition > stackEnd) { |
| 2749 | mOwnScrollY += endPosition - stackEnd; |
| 2750 | mDisallowScrollingInThisMotion = true; |
| 2751 | } |
| 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2756 | public void setOnHeightChangedListener( |
| 2757 | ExpandableView.OnHeightChangedListener mOnHeightChangedListener) { |
| 2758 | this.mOnHeightChangedListener = mOnHeightChangedListener; |
| 2759 | } |
| 2760 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2761 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 2762 | mOnEmptySpaceClickListener = listener; |
| 2763 | } |
| 2764 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2765 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2766 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 2767 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2768 | runAnimationFinishedRunnables(); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2769 | clearViewOverlays(); |
| 2770 | } |
| 2771 | |
| 2772 | private void clearViewOverlays() { |
| 2773 | for (View view : mClearOverlayViewsWhenFinished) { |
| 2774 | getOverlay().remove(view); |
| 2775 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2779 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 2780 | runnable.run(); |
| 2781 | } |
| 2782 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2783 | } |
| 2784 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2785 | /** |
| 2786 | * See {@link AmbientState#setDimmed}. |
| 2787 | */ |
| 2788 | public void setDimmed(boolean dimmed, boolean animate) { |
| 2789 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2790 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2791 | mDimmedNeedsAnimation = true; |
| 2792 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 2793 | animateDimmed(dimmed); |
| 2794 | } else { |
| 2795 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2796 | } |
| 2797 | requestChildrenUpdate(); |
| 2798 | } |
| 2799 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 2800 | private void setDimAmount(float dimAmount) { |
| 2801 | mDimAmount = dimAmount; |
| 2802 | updateBackgroundDimming(); |
| 2803 | } |
| 2804 | |
| 2805 | private void animateDimmed(boolean dimmed) { |
| 2806 | if (mDimAnimator != null) { |
| 2807 | mDimAnimator.cancel(); |
| 2808 | } |
| 2809 | float target = dimmed ? 1.0f : 0.0f; |
| 2810 | if (target == mDimAmount) { |
| 2811 | return; |
| 2812 | } |
| 2813 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 2814 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 2815 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 2816 | mDimAnimator.addListener(mDimEndListener); |
| 2817 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 2818 | mDimAnimator.start(); |
| 2819 | } |
| 2820 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2821 | public void setHideSensitive(boolean hideSensitive, boolean animate) { |
| 2822 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 2823 | int childCount = getChildCount(); |
| 2824 | for (int i = 0; i < childCount; i++) { |
| 2825 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 2826 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 2827 | } |
| 2828 | mAmbientState.setHideSensitive(hideSensitive); |
| 2829 | if (animate && mAnimationsEnabled) { |
| 2830 | mHideSensitiveNeedsAnimation = true; |
| 2831 | mNeedsAnimation = true; |
| 2832 | } |
| 2833 | requestChildrenUpdate(); |
| 2834 | } |
| 2835 | } |
| 2836 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2837 | /** |
| 2838 | * See {@link AmbientState#setActivatedChild}. |
| 2839 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 2840 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2841 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2842 | if (mAnimationsEnabled) { |
| 2843 | mActivateNeedsAnimation = true; |
| 2844 | mNeedsAnimation = true; |
| 2845 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2846 | requestChildrenUpdate(); |
| 2847 | } |
| 2848 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 2849 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2850 | return mAmbientState.getActivatedChild(); |
| 2851 | } |
| 2852 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2853 | private void applyCurrentState() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2854 | mCurrentStackScrollState.apply(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2855 | if (mListener != null) { |
| 2856 | mListener.onChildLocationsChanged(this); |
| 2857 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2858 | runAnimationFinishedRunnables(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2859 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 2860 | updateViewShadows(); |
| 2861 | } |
| 2862 | |
| 2863 | private void updateViewShadows() { |
| 2864 | // we need to work around an issue where the shadow would not cast between siblings when |
| 2865 | // their z difference is between 0 and 0.1 |
| 2866 | |
| 2867 | // Lefts first sort by Z difference |
| 2868 | for (int i = 0; i < getChildCount(); i++) { |
| 2869 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2870 | if (child.getVisibility() != GONE) { |
| 2871 | mTmpSortedChildren.add(child); |
| 2872 | } |
| 2873 | } |
| 2874 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 2875 | |
| 2876 | // Now lets update the shadow for the views |
| 2877 | ExpandableView previous = null; |
| 2878 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 2879 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 2880 | float translationZ = expandableView.getTranslationZ(); |
| 2881 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 2882 | float diff = otherZ - translationZ; |
| 2883 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 2884 | // There is no fake shadow to be drawn |
| 2885 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 2886 | } else { |
| 2887 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
| 2888 | expandableView.getTranslationY(); |
| 2889 | expandableView.setFakeShadowIntensity(diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
| 2890 | previous.getOutlineAlpha(), (int) yLocation, |
| 2891 | previous.getOutlineTranslation()); |
| 2892 | } |
| 2893 | previous = expandableView; |
| 2894 | } |
| 2895 | |
| 2896 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2897 | } |
| 2898 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2899 | public void goToFullShade(long delay) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2900 | mDismissView.setInvisible(); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2901 | mEmptyShadeView.setInvisible(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2902 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2903 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2904 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2905 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2906 | } |
| 2907 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2908 | public void cancelExpandHelper() { |
| 2909 | mExpandHelper.cancel(); |
| 2910 | } |
| 2911 | |
| 2912 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 2913 | mIntrinsicPadding = intrinsicPadding; |
| 2914 | } |
| 2915 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2916 | public int getIntrinsicPadding() { |
| 2917 | return mIntrinsicPadding; |
| 2918 | } |
| 2919 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2920 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2921 | * @return the y position of the first notification |
| 2922 | */ |
| 2923 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 2924 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2925 | } |
| 2926 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 2927 | @Override |
| 2928 | public boolean shouldDelayChildPressedState() { |
| 2929 | return true; |
| 2930 | } |
| 2931 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2932 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2933 | * See {@link AmbientState#setDark}. |
| 2934 | */ |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2935 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2936 | mAmbientState.setDark(dark); |
| 2937 | if (animate && mAnimationsEnabled) { |
| 2938 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2939 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2940 | mNeedsAnimation = true; |
| 2941 | } |
| 2942 | requestChildrenUpdate(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2943 | if (dark) { |
| 2944 | setWillNotDraw(!DEBUG); |
| 2945 | mScrimController.setExcludedBackgroundArea(null); |
| 2946 | } else { |
| 2947 | updateBackground(); |
| 2948 | setWillNotDraw(false); |
| 2949 | // TODO: fade in background |
| 2950 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2951 | } |
| 2952 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2953 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
| 2954 | if (screenLocation == null || screenLocation.y < mTopPadding + mTopPaddingOverflow) { |
| 2955 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 2956 | } |
| 2957 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 2958 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 2959 | } |
| 2960 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 2961 | if (child != null) { |
| 2962 | return getNotGoneIndex(child); |
| 2963 | } else { |
| 2964 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | private int getNotGoneIndex(View child) { |
| 2969 | int count = getChildCount(); |
| 2970 | int notGoneIndex = 0; |
| 2971 | for (int i = 0; i < count; i++) { |
| 2972 | View v = getChildAt(i); |
| 2973 | if (child == v) { |
| 2974 | return notGoneIndex; |
| 2975 | } |
| 2976 | if (v.getVisibility() != View.GONE) { |
| 2977 | notGoneIndex++; |
| 2978 | } |
| 2979 | } |
| 2980 | return -1; |
| 2981 | } |
| 2982 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2983 | public void setDismissView(DismissView dismissView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 2984 | int index = -1; |
| 2985 | if (mDismissView != null) { |
| 2986 | index = indexOfChild(mDismissView); |
| 2987 | removeView(mDismissView); |
| 2988 | } |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2989 | mDismissView = dismissView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 2990 | addView(mDismissView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2991 | } |
| 2992 | |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2993 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 2994 | int index = -1; |
| 2995 | if (mEmptyShadeView != null) { |
| 2996 | index = indexOfChild(mEmptyShadeView); |
| 2997 | removeView(mEmptyShadeView); |
| 2998 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2999 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 3000 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | public void updateEmptyShadeView(boolean visible) { |
| 3004 | int oldVisibility = mEmptyShadeView.willBeGone() ? GONE : mEmptyShadeView.getVisibility(); |
| 3005 | int newVisibility = visible ? VISIBLE : GONE; |
| 3006 | if (oldVisibility != newVisibility) { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3007 | if (newVisibility != GONE) { |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3008 | if (mEmptyShadeView.willBeGone()) { |
| 3009 | mEmptyShadeView.cancelAnimation(); |
| 3010 | } else { |
| 3011 | mEmptyShadeView.setInvisible(); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3012 | } |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3013 | mEmptyShadeView.setVisibility(newVisibility); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3014 | mEmptyShadeView.setWillBeGone(false); |
| 3015 | updateContentHeight(); |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 3016 | notifyHeightChangeListener(mEmptyShadeView); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3017 | } else { |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 3018 | Runnable onFinishedRunnable = new Runnable() { |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3019 | @Override |
| 3020 | public void run() { |
| 3021 | mEmptyShadeView.setVisibility(GONE); |
| 3022 | mEmptyShadeView.setWillBeGone(false); |
| 3023 | updateContentHeight(); |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 3024 | notifyHeightChangeListener(mEmptyShadeView); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3025 | } |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 3026 | }; |
| 3027 | if (mAnimationsEnabled) { |
| 3028 | mEmptyShadeView.setWillBeGone(true); |
| 3029 | mEmptyShadeView.performVisibilityAnimation(false, onFinishedRunnable); |
| 3030 | } else { |
| 3031 | mEmptyShadeView.setInvisible(); |
| 3032 | onFinishedRunnable.run(); |
| 3033 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 3038 | public void setOverflowContainer(NotificationOverflowContainer overFlowContainer) { |
| 3039 | mOverflowContainer = overFlowContainer; |
| 3040 | addView(mOverflowContainer); |
| 3041 | } |
| 3042 | |
| 3043 | public void updateOverflowContainerVisibility(boolean visible) { |
| 3044 | int oldVisibility = mOverflowContainer.willBeGone() ? GONE |
| 3045 | : mOverflowContainer.getVisibility(); |
| 3046 | final int newVisibility = visible ? VISIBLE : GONE; |
| 3047 | if (oldVisibility != newVisibility) { |
| 3048 | Runnable onFinishedRunnable = new Runnable() { |
| 3049 | @Override |
| 3050 | public void run() { |
| 3051 | mOverflowContainer.setVisibility(newVisibility); |
| 3052 | mOverflowContainer.setWillBeGone(false); |
| 3053 | updateContentHeight(); |
| 3054 | notifyHeightChangeListener(mOverflowContainer); |
| 3055 | } |
| 3056 | }; |
| 3057 | if (!mAnimationsEnabled || !mIsExpanded) { |
| 3058 | mOverflowContainer.cancelAppearDrawing(); |
| 3059 | onFinishedRunnable.run(); |
| 3060 | } else if (newVisibility != GONE) { |
| 3061 | mOverflowContainer.performAddAnimation(0, |
| 3062 | StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 3063 | mOverflowContainer.setVisibility(newVisibility); |
| 3064 | mOverflowContainer.setWillBeGone(false); |
| 3065 | updateContentHeight(); |
| 3066 | notifyHeightChangeListener(mOverflowContainer); |
| 3067 | } else { |
| 3068 | mOverflowContainer.performRemoveAnimation( |
| 3069 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3070 | 0.0f, |
| 3071 | onFinishedRunnable); |
| 3072 | mOverflowContainer.setWillBeGone(true); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3077 | public void updateDismissView(boolean visible) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3078 | int oldVisibility = mDismissView.willBeGone() ? GONE : mDismissView.getVisibility(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3079 | int newVisibility = visible ? VISIBLE : GONE; |
| 3080 | if (oldVisibility != newVisibility) { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3081 | if (newVisibility != GONE) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3082 | if (mDismissView.willBeGone()) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3083 | mDismissView.cancelAnimation(); |
| 3084 | } else { |
| 3085 | mDismissView.setInvisible(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3086 | } |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3087 | mDismissView.setVisibility(newVisibility); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3088 | mDismissView.setWillBeGone(false); |
| 3089 | updateContentHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3090 | notifyHeightChangeListener(mDismissView); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3091 | } else { |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 3092 | Runnable dimissHideFinishRunnable = new Runnable() { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3093 | @Override |
| 3094 | public void run() { |
| 3095 | mDismissView.setVisibility(GONE); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3096 | mDismissView.setWillBeGone(false); |
| 3097 | updateContentHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 3098 | notifyHeightChangeListener(mDismissView); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3099 | } |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 3100 | }; |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 3101 | if (mDismissView.isButtonVisible() && mIsExpanded && mAnimationsEnabled) { |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 3102 | mDismissView.setWillBeGone(true); |
| 3103 | mDismissView.performVisibilityAnimation(false, dimissHideFinishRunnable); |
| 3104 | } else { |
| 3105 | dimissHideFinishRunnable.run(); |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 3106 | } |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 3112 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 3113 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 3114 | if (dismissAllInProgress) { |
| 3115 | disableClipOptimization(); |
| 3116 | } |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 3117 | handleDismissAllClipping(); |
Mady Mellor | 3cb4024 | 2016-02-22 10:43:35 -0800 | [diff] [blame] | 3118 | if (mCurrIconRow != null && mCurrIconRow.isVisible()) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 3119 | mCurrIconRow.getNotificationParent().animateTranslateNotification(0 /* left target */); |
| 3120 | } |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | private void handleDismissAllClipping() { |
| 3124 | final int count = getChildCount(); |
| 3125 | boolean previousChildWillBeDismissed = false; |
| 3126 | for (int i = 0; i < count; i++) { |
| 3127 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3128 | if (child.getVisibility() == GONE) { |
| 3129 | continue; |
| 3130 | } |
| 3131 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 3132 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 3133 | } else { |
| 3134 | child.setMinClipTopAmount(0); |
| 3135 | } |
| 3136 | previousChildWillBeDismissed = canChildBeDismissed(child); |
| 3137 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | private void disableClipOptimization() { |
| 3141 | final int count = getChildCount(); |
| 3142 | for (int i = 0; i < count; i++) { |
| 3143 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3144 | if (child.getVisibility() == GONE) { |
| 3145 | continue; |
| 3146 | } |
| 3147 | child.setClipTopOptimization(0); |
| 3148 | } |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3149 | } |
| 3150 | |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3151 | public boolean isDismissViewNotGone() { |
| 3152 | return mDismissView.getVisibility() != View.GONE && !mDismissView.willBeGone(); |
| 3153 | } |
| 3154 | |
| 3155 | public boolean isDismissViewVisible() { |
| 3156 | return mDismissView.isVisible(); |
| 3157 | } |
| 3158 | |
| 3159 | public int getDismissViewHeight() { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3160 | int height = mDismissView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 1d49ec9 | 2014-08-25 18:44:01 +0200 | [diff] [blame] | 3161 | |
| 3162 | // Hack: Accommodate for additional distance when we only have one notification and the |
| 3163 | // dismiss all button. |
| 3164 | if (getNotGoneChildCount() == 2 && getLastChildNotGone() == mDismissView |
| 3165 | && getFirstChildNotGone() instanceof ActivatableNotificationView) { |
| 3166 | height += mCollapseSecondCardPadding; |
| 3167 | } |
| 3168 | return height; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 3169 | } |
| 3170 | |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 3171 | public int getEmptyShadeViewHeight() { |
| 3172 | return mEmptyShadeView.getHeight(); |
| 3173 | } |
| 3174 | |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 3175 | public float getBottomMostNotificationBottom() { |
| 3176 | final int count = getChildCount(); |
| 3177 | float max = 0; |
| 3178 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 3179 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 3180 | if (child.getVisibility() == GONE) { |
| 3181 | continue; |
| 3182 | } |
| 3183 | float bottom = child.getTranslationY() + child.getActualHeight(); |
| 3184 | if (bottom > max) { |
| 3185 | max = bottom; |
| 3186 | } |
| 3187 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 3188 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 3189 | } |
| 3190 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 3191 | public void setPhoneStatusBar(PhoneStatusBar phoneStatusBar) { |
| 3192 | this.mPhoneStatusBar = phoneStatusBar; |
| 3193 | } |
| 3194 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3195 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 3196 | this.mGroupManager = groupManager; |
| 3197 | } |
| 3198 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3199 | public void onGoToKeyguard() { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 3200 | requestAnimateEverything(); |
| 3201 | } |
| 3202 | |
| 3203 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3204 | if (mIsExpanded && mAnimationsEnabled) { |
| 3205 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 3206 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3207 | requestChildrenUpdate(); |
| 3208 | } |
| 3209 | } |
| 3210 | |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 3211 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 3212 | int childCount = getChildCount(); |
| 3213 | for (int i = childCount - 1; i >= 0; i--) { |
| 3214 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3215 | if (child.getVisibility() != View.GONE) { |
| 3216 | float childTop = child.getY(); |
| 3217 | if (childTop > touchY) { |
| 3218 | // we are above a notification entirely let's abort |
| 3219 | return false; |
| 3220 | } |
| 3221 | boolean belowChild = touchY > childTop + child.getActualHeight(); |
| 3222 | if (child == mDismissView) { |
| 3223 | if(!belowChild && !mDismissView.isOnEmptySpace(touchX - mDismissView.getX(), |
| 3224 | touchY - childTop)) { |
| 3225 | // We clicked on the dismiss button |
| 3226 | return false; |
| 3227 | } |
| 3228 | } else if (child == mEmptyShadeView) { |
| 3229 | // We arrived at the empty shade view, for which we accept all clicks |
| 3230 | return true; |
| 3231 | } else if (!belowChild){ |
| 3232 | // We are on a child |
| 3233 | return false; |
| 3234 | } |
| 3235 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 3236 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 3237 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 3238 | } |
| 3239 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3240 | @Override |
| 3241 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 3242 | boolean animated = mAnimationsEnabled && (mIsExpanded || changedRow.isPinned()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3243 | if (animated) { |
| 3244 | mExpandedGroupView = changedRow; |
| 3245 | mNeedsAnimation = true; |
| 3246 | } |
| 3247 | changedRow.setChildrenExpanded(expanded, animated); |
| 3248 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 3249 | } |
| 3250 | |
| 3251 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3252 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 3253 | mPhoneStatusBar.requestNotificationUpdate(); |
| 3254 | } |
| 3255 | |
| 3256 | @Override |
| 3257 | public void onChildIsolationChanged() { |
| 3258 | mPhoneStatusBar.requestNotificationUpdate(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | public void generateChildOrderChangedEvent() { |
| 3262 | if (mIsExpanded && mAnimationsEnabled) { |
| 3263 | mGenerateChildOrderChangedEvent = true; |
| 3264 | mNeedsAnimation = true; |
| 3265 | requestChildrenUpdate(); |
| 3266 | } |
| 3267 | } |
| 3268 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 3269 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3270 | mAnimationFinishedRunnables.add(runnable); |
| 3271 | } |
| 3272 | |
| 3273 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 3274 | mHeadsUpManager = headsUpManager; |
| 3275 | mAmbientState.setHeadsUpManager(headsUpManager); |
| 3276 | } |
| 3277 | |
| 3278 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
| 3279 | if (mAnimationsEnabled) { |
| 3280 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 3281 | mNeedsAnimation = true; |
| 3282 | requestChildrenUpdate(); |
| 3283 | } |
| 3284 | } |
| 3285 | |
| 3286 | public void setShadeExpanded(boolean shadeExpanded) { |
| 3287 | mAmbientState.setShadeExpanded(shadeExpanded); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3288 | mStateAnimator.setShadeExpanded(shadeExpanded); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3291 | /** |
| 3292 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 3293 | * position. |
| 3294 | * |
| 3295 | * @param height the height of the screen |
| 3296 | * @param bottomBarHeight the height of the bar on the bottom |
| 3297 | */ |
| 3298 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 3299 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 3300 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3301 | requestChildrenUpdate(); |
| 3302 | } |
| 3303 | |
| 3304 | public void setTrackingHeadsUp(boolean trackingHeadsUp) { |
| 3305 | mTrackingHeadsUp = trackingHeadsUp; |
| 3306 | } |
| 3307 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3308 | public void setScrimController(ScrimController scrimController) { |
| 3309 | mScrimController = scrimController; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 3310 | mScrimController.setScrimBehindChangeRunnable(new Runnable() { |
| 3311 | @Override |
| 3312 | public void run() { |
| 3313 | updateBackgroundDimming(); |
| 3314 | } |
| 3315 | }); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 3318 | public void forceNoOverlappingRendering(boolean force) { |
| 3319 | mForceNoOverlappingRendering = force; |
| 3320 | } |
| 3321 | |
| 3322 | @Override |
| 3323 | public boolean hasOverlappingRendering() { |
| 3324 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 3325 | } |
| 3326 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3327 | public void setAnimationRunning(boolean animationRunning) { |
| 3328 | if (animationRunning != mAnimationRunning) { |
| 3329 | if (animationRunning) { |
| 3330 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 3331 | } else { |
| 3332 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 3333 | } |
| 3334 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3335 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3336 | } |
| 3337 | } |
| 3338 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 3339 | public boolean isExpanded() { |
| 3340 | return mIsExpanded; |
| 3341 | } |
| 3342 | |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 3343 | /** |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 3344 | * A listener that is notified when some child locations might have changed. |
| 3345 | */ |
| 3346 | public interface OnChildLocationsChangedListener { |
| 3347 | public void onChildLocationsChanged(NotificationStackScrollLayout stackScrollLayout); |
| 3348 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3349 | |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 3350 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 3351 | * A listener that is notified when the empty space below the notifications is clicked on |
| 3352 | */ |
| 3353 | public interface OnEmptySpaceClickListener { |
| 3354 | public void onEmptySpaceClicked(float x, float y); |
| 3355 | } |
| 3356 | |
| 3357 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 3358 | * A listener that gets notified when the overscroll at the top has changed. |
| 3359 | */ |
| 3360 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 3361 | |
| 3362 | /** |
| 3363 | * Notifies a listener that the overscroll has changed. |
| 3364 | * |
| 3365 | * @param amount the amount of overscroll, in pixels |
| 3366 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 3367 | * unrubberbanded motion to directly expand overscroll view (e.g expand |
| 3368 | * QS) |
| 3369 | */ |
| 3370 | public void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3371 | |
| 3372 | /** |
| 3373 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 3374 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 3375 | * |
| 3376 | * @param velocity The velocity that the Scroller had when over flinging |
| 3377 | * @param open Should the fling open or close the overscroll view. |
| 3378 | */ |
| 3379 | public void flingTopOverscroll(float velocity, boolean open); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 3380 | } |
| 3381 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 3382 | /** |
| 3383 | * A listener that is notified when the gear is shown behind a notification. |
| 3384 | */ |
| 3385 | public interface GearDisplayedListener { |
| 3386 | void onGearDisplayed(ExpandableNotificationRow row); |
| 3387 | } |
| 3388 | |
| 3389 | private class NotificationSwipeHelper extends SwipeHelper { |
| 3390 | private static final int MOVE_STATE_LEFT = -1; |
| 3391 | private static final int MOVE_STATE_UNDEFINED = 0; |
| 3392 | private static final int MOVE_STATE_RIGHT = 1; |
| 3393 | |
| 3394 | private static final long GEAR_SHOW_DELAY = 60; |
| 3395 | |
| 3396 | private ArrayList<View> mTranslatingViews = new ArrayList<>(); |
| 3397 | private CheckForDrag mCheckForDrag; |
| 3398 | private Handler mHandler; |
| 3399 | private int mMoveState = MOVE_STATE_UNDEFINED; |
| 3400 | |
| 3401 | public NotificationSwipeHelper(int swipeDirection, Callback callback, Context context) { |
| 3402 | super(swipeDirection, callback, context); |
| 3403 | mHandler = new Handler(); |
| 3404 | } |
| 3405 | |
| 3406 | @Override |
| 3407 | public void onDownUpdate(View currView) { |
| 3408 | // Set the active view |
| 3409 | mTranslatingParentView = currView; |
| 3410 | |
| 3411 | // Reset check for drag gesture |
| 3412 | mCheckForDrag = null; |
| 3413 | |
| 3414 | // Slide back any notifications that might be showing a gear |
| 3415 | resetExposedGearView(); |
| 3416 | |
| 3417 | if (currView instanceof ExpandableNotificationRow) { |
| 3418 | // Set the listener for the current row's gear |
| 3419 | mCurrIconRow = ((ExpandableNotificationRow) currView).getSettingsRow(); |
| 3420 | mCurrIconRow.setGearListener(NotificationStackScrollLayout.this); |
| 3421 | |
| 3422 | // And the translating children |
| 3423 | mTranslatingViews = ((ExpandableNotificationRow) currView).getContentViews(); |
| 3424 | } |
| 3425 | mMoveState = MOVE_STATE_UNDEFINED; |
| 3426 | } |
| 3427 | |
| 3428 | @Override |
| 3429 | public void onMoveUpdate(View view, float translation, float delta) { |
| 3430 | final int newMoveState = (delta < 0) ? MOVE_STATE_RIGHT : MOVE_STATE_LEFT; |
| 3431 | if (mMoveState != MOVE_STATE_UNDEFINED && mMoveState != newMoveState) { |
| 3432 | // Changed directions, make sure we check for drag again. |
| 3433 | mCheckForDrag = null; |
| 3434 | } |
| 3435 | mMoveState = newMoveState; |
| 3436 | |
| 3437 | if (view instanceof ExpandableNotificationRow) { |
| 3438 | ((ExpandableNotificationRow) view).setTranslationForOutline(translation); |
| 3439 | if (!isPinnedHeadsUp(view)) { |
| 3440 | // Only show the gear if we're not a heads up view. |
| 3441 | checkForDrag(); |
| 3442 | if (mCurrIconRow != null) { |
| 3443 | mCurrIconRow.updateSettingsIcons(translation, getSize(view)); |
| 3444 | } |
| 3445 | } |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | @Override |
| 3450 | public void dismissChild(final View view, float velocity) { |
| 3451 | cancelCheckForDrag(); |
| 3452 | super.dismissChild(view, velocity); |
| 3453 | } |
| 3454 | |
| 3455 | @Override |
| 3456 | public void snapChild(final View animView, final float targetLeft, float velocity) { |
| 3457 | final float snapBackThreshold = getSpaceForGear(animView); |
| 3458 | final float translation = getTranslation(animView); |
| 3459 | final boolean fromLeft = translation > 0; |
| 3460 | final float absTrans = Math.abs(translation); |
| 3461 | final float notiThreshold = getSize(mTranslatingParentView) * 0.4f; |
| 3462 | |
| 3463 | boolean pastGear = (fromLeft && translation >= snapBackThreshold * 0.4f |
| 3464 | && translation <= notiThreshold) || |
| 3465 | (!fromLeft && absTrans >= snapBackThreshold * 0.4f |
| 3466 | && absTrans <= notiThreshold); |
| 3467 | |
| 3468 | if (pastGear && !isPinnedHeadsUp(animView)) { |
| 3469 | // bouncity |
| 3470 | final float target = fromLeft ? snapBackThreshold : -snapBackThreshold; |
| 3471 | mGearExposedView = mTranslatingParentView; |
| 3472 | if (mGearDisplayedListener != null |
| 3473 | && (animView instanceof ExpandableNotificationRow)) { |
| 3474 | mGearDisplayedListener.onGearDisplayed((ExpandableNotificationRow) animView); |
| 3475 | } |
| 3476 | super.snapChild(animView, target, velocity); |
| 3477 | } else { |
| 3478 | super.snapChild(animView, 0, velocity); |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | @Override |
| 3483 | public void onTranslationUpdate(View animView, float value, boolean canBeDismissed) { |
| 3484 | if (mDismissAllInProgress) { |
| 3485 | // When dismissing all, we translate the entire view instead. |
| 3486 | super.onTranslationUpdate(animView, value, canBeDismissed); |
| 3487 | return; |
| 3488 | } |
| 3489 | if (animView instanceof ExpandableNotificationRow) { |
| 3490 | ((ExpandableNotificationRow) animView).setTranslationForOutline(value); |
| 3491 | } |
| 3492 | if (mCurrIconRow != null) { |
| 3493 | mCurrIconRow.updateSettingsIcons(value, getSize(animView)); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | @Override |
| 3498 | public Animator getViewTranslationAnimator(View v, float target, |
| 3499 | AnimatorUpdateListener listener) { |
| 3500 | if (mDismissAllInProgress) { |
| 3501 | // When dismissing all, we translate the entire view instead. |
| 3502 | return super.getViewTranslationAnimator(v, target, listener); |
| 3503 | } |
| 3504 | ArrayList<Animator> animators = new ArrayList<Animator>(); |
| 3505 | for (int i = 0; i < mTranslatingViews.size(); i++) { |
| 3506 | ObjectAnimator anim = createTranslationAnimation(mTranslatingViews.get(i), target); |
| 3507 | animators.add(anim); |
| 3508 | if (i == 0 && listener != null) { |
| 3509 | anim.addUpdateListener(listener); |
| 3510 | } |
| 3511 | } |
| 3512 | AnimatorSet set = new AnimatorSet(); |
| 3513 | set.playTogether(animators); |
| 3514 | return set; |
| 3515 | } |
| 3516 | |
| 3517 | @Override |
| 3518 | public void setTranslation(View v, float translate) { |
| 3519 | if (mDismissAllInProgress) { |
| 3520 | // When dismissing all, we translate the entire view instead. |
| 3521 | super.setTranslation(v, translate); |
| 3522 | return; |
| 3523 | } |
| 3524 | // Translate the group of views |
| 3525 | for (int i = 0; i < mTranslatingViews.size(); i++) { |
| 3526 | if (mTranslatingViews.get(i) != null) { |
| 3527 | super.setTranslation(mTranslatingViews.get(i), translate); |
| 3528 | } |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | @Override |
| 3533 | public float getTranslation(View v) { |
| 3534 | if (mDismissAllInProgress) { |
| 3535 | // When dismissing all, we translate the entire view instead. |
| 3536 | return super.getTranslation(v); |
| 3537 | } |
| 3538 | // All of the views in the list should have same translation, just use first one. |
| 3539 | if (mTranslatingViews.size() > 0) { |
| 3540 | return super.getTranslation(mTranslatingViews.get(0)); |
| 3541 | } |
| 3542 | return 0; |
| 3543 | } |
| 3544 | |
| 3545 | |
| 3546 | /** |
| 3547 | * Returns the horizontal space in pixels required to display the gear behind a |
| 3548 | * notification. |
| 3549 | */ |
| 3550 | private float getSpaceForGear(View view) { |
| 3551 | if (view instanceof ExpandableNotificationRow) { |
| 3552 | return ((ExpandableNotificationRow) view).getSpaceForGear(); |
| 3553 | } |
| 3554 | return 0; |
| 3555 | } |
| 3556 | |
| 3557 | private void checkForDrag() { |
| 3558 | if (mCheckForDrag == null) { |
| 3559 | mCheckForDrag = new CheckForDrag(); |
| 3560 | mHandler.postDelayed(mCheckForDrag, GEAR_SHOW_DELAY); |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | private void cancelCheckForDrag() { |
| 3565 | if (mCurrIconRow != null) { |
| 3566 | mCurrIconRow.cancelFadeAnimator(); |
| 3567 | } |
| 3568 | mHandler.removeCallbacks(mCheckForDrag); |
| 3569 | mCheckForDrag = null; |
| 3570 | } |
| 3571 | |
| 3572 | private final class CheckForDrag implements Runnable { |
| 3573 | @Override |
| 3574 | public void run() { |
| 3575 | final float translation = getTranslation(mTranslatingParentView); |
| 3576 | final float absTransX = Math.abs(translation); |
| 3577 | final float bounceBackToGearWidth = getSpaceForGear(mTranslatingParentView); |
| 3578 | final float notiThreshold = getSize(mTranslatingParentView) * 0.4f; |
| 3579 | if (mCurrIconRow != null && absTransX >= bounceBackToGearWidth * 0.4 |
| 3580 | && absTransX < notiThreshold) { |
| 3581 | // Show icon |
| 3582 | mCurrIconRow.fadeInSettings(translation > 0 /* fromLeft */, translation, |
| 3583 | notiThreshold); |
| 3584 | } else { |
| 3585 | // Allow more to be posted if this wasn't a drag. |
| 3586 | mCheckForDrag = null; |
| 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | private void resetExposedGearView() { |
| 3592 | if (mGearExposedView == null || mGearExposedView == mTranslatingParentView) { |
| 3593 | // If no gear is showing or it's showing for this view we do nothing. |
| 3594 | return; |
| 3595 | } |
| 3596 | |
| 3597 | final View prevGearExposedView = mGearExposedView; |
| 3598 | mGearExposedView = null; |
| 3599 | |
| 3600 | AnimatorListenerAdapter listener = new AnimatorListenerAdapter() { |
| 3601 | public void onAnimationEnd(Animator animator) { |
| 3602 | if (prevGearExposedView instanceof ExpandableNotificationRow) { |
| 3603 | ((ExpandableNotificationRow) prevGearExposedView).getSettingsRow() |
| 3604 | .resetState(); |
| 3605 | } |
| 3606 | } |
| 3607 | }; |
| 3608 | AnimatorUpdateListener updateListener = new AnimatorUpdateListener() { |
| 3609 | @Override |
| 3610 | public void onAnimationUpdate(ValueAnimator animation) { |
| 3611 | if (prevGearExposedView instanceof ExpandableNotificationRow) { |
| 3612 | ((ExpandableNotificationRow) prevGearExposedView) |
| 3613 | .setTranslationForOutline((float) animation.getAnimatedValue()); |
| 3614 | } |
| 3615 | } |
| 3616 | }; |
| 3617 | Animator set = getViewTranslationAnimator(prevGearExposedView, 0, updateListener); |
| 3618 | set.addListener(listener); |
| 3619 | set.start(); |
| 3620 | } |
| 3621 | } |
| 3622 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3623 | private void updateContinuousShadowDrawing() { |
| 3624 | boolean continuousShadowUpdate = mAnimationRunning |
| 3625 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 3626 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 3627 | if (continuousShadowUpdate) { |
| 3628 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 3629 | } else { |
| 3630 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 3631 | } |
| 3632 | } |
| 3633 | } |
| 3634 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3635 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3636 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3637 | static AnimationFilter[] FILTERS = new AnimationFilter[] { |
| 3638 | |
| 3639 | // ANIMATION_TYPE_ADD |
| 3640 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3641 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3642 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 3643 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3644 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3645 | .animateZ() |
| 3646 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3647 | |
| 3648 | // ANIMATION_TYPE_REMOVE |
| 3649 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3650 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3651 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 3652 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3653 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3654 | .animateZ() |
| 3655 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3656 | |
| 3657 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3658 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3659 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3660 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 3661 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3662 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3663 | .animateZ() |
| 3664 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3665 | |
| 3666 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 3667 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3668 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3669 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 3670 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3671 | .animateY() |
| 3672 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3673 | .animateZ(), |
| 3674 | |
| 3675 | // ANIMATION_TYPE_START_DRAG |
| 3676 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3677 | .animateShadowAlpha(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3678 | |
| 3679 | // ANIMATION_TYPE_SNAP_BACK |
| 3680 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3681 | .animateShadowAlpha() |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3682 | .animateHeight(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3683 | |
| 3684 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 3685 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3686 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3687 | |
| 3688 | // ANIMATION_TYPE_DIMMED |
| 3689 | new AnimationFilter() |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 3690 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3691 | .animateDimmed(), |
| 3692 | |
| 3693 | // ANIMATION_TYPE_CHANGE_POSITION |
| 3694 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3695 | .animateAlpha() // maybe the children change positions |
| 3696 | .animateShadowAlpha() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3697 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 3698 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3699 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3700 | .animateZ(), |
| 3701 | |
| 3702 | // ANIMATION_TYPE_DARK |
| 3703 | new AnimationFilter() |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 3704 | .animateDark() |
| 3705 | .hasDelays(), |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3706 | |
| 3707 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 3708 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3709 | .animateShadowAlpha() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3710 | .animateHeight() |
| 3711 | .animateTopInset() |
| 3712 | .animateY() |
| 3713 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3714 | .animateZ() |
| 3715 | .hasDelays(), |
| 3716 | |
| 3717 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 3718 | new AnimationFilter() |
| 3719 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3720 | |
| 3721 | // ANIMATION_TYPE_VIEW_RESIZE |
| 3722 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3723 | .animateShadowAlpha() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3724 | .animateHeight() |
| 3725 | .animateTopInset() |
| 3726 | .animateY() |
| 3727 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3728 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3729 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 3730 | new AnimationFilter() |
| 3731 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3732 | .animateShadowAlpha() |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3733 | .animateHeight() |
| 3734 | .animateTopInset() |
| 3735 | .animateY() |
| 3736 | .animateZ(), |
| 3737 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3738 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 3739 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3740 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3741 | .animateHeight() |
| 3742 | .animateTopInset() |
| 3743 | .animateY() |
| 3744 | .animateZ(), |
| 3745 | |
| 3746 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 3747 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3748 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3749 | .animateHeight() |
| 3750 | .animateTopInset() |
| 3751 | .animateY() |
| 3752 | .animateZ(), |
| 3753 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3754 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3755 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3756 | .animateShadowAlpha() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3757 | .animateHeight() |
| 3758 | .animateTopInset() |
| 3759 | .animateY() |
| 3760 | .animateZ() |
| 3761 | .hasDelays(), |
| 3762 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3763 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 3764 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3765 | .animateShadowAlpha() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3766 | .animateHeight() |
| 3767 | .animateTopInset() |
| 3768 | .animateY() |
| 3769 | .animateZ(), |
| 3770 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3771 | // ANIMATION_TYPE_EVERYTHING |
| 3772 | new AnimationFilter() |
| 3773 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 3774 | .animateShadowAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3775 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3776 | .animateDimmed() |
| 3777 | .animateHideSensitive() |
| 3778 | .animateHeight() |
| 3779 | .animateTopInset() |
| 3780 | .animateY() |
| 3781 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3782 | }; |
| 3783 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3784 | static int[] LENGTHS = new int[] { |
| 3785 | |
| 3786 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3787 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3788 | |
| 3789 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3790 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3791 | |
| 3792 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3793 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3794 | |
| 3795 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 3796 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3797 | |
| 3798 | // ANIMATION_TYPE_START_DRAG |
| 3799 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3800 | |
| 3801 | // ANIMATION_TYPE_SNAP_BACK |
| 3802 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3803 | |
| 3804 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 3805 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 3806 | |
| 3807 | // ANIMATION_TYPE_DIMMED |
| 3808 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3809 | |
| 3810 | // ANIMATION_TYPE_CHANGE_POSITION |
| 3811 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3812 | |
| 3813 | // ANIMATION_TYPE_DARK |
| 3814 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3815 | |
| 3816 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 3817 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3818 | |
| 3819 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 3820 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3821 | |
| 3822 | // ANIMATION_TYPE_VIEW_RESIZE |
| 3823 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3824 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3825 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 3826 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3827 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3828 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 3829 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 3830 | |
| 3831 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 3832 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 3833 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3834 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3835 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 3836 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3837 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 3838 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3839 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3840 | // ANIMATION_TYPE_EVERYTHING |
| 3841 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3842 | }; |
| 3843 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3844 | static final int ANIMATION_TYPE_ADD = 0; |
| 3845 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 3846 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 3847 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
| 3848 | static final int ANIMATION_TYPE_START_DRAG = 4; |
| 3849 | static final int ANIMATION_TYPE_SNAP_BACK = 5; |
| 3850 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6; |
| 3851 | static final int ANIMATION_TYPE_DIMMED = 7; |
| 3852 | static final int ANIMATION_TYPE_CHANGE_POSITION = 8; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3853 | static final int ANIMATION_TYPE_DARK = 9; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3854 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3855 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3856 | static final int ANIMATION_TYPE_VIEW_RESIZE = 12; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3857 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 13; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3858 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 14; |
| 3859 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 15; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3860 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 16; |
| 3861 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 17; |
| 3862 | static final int ANIMATION_TYPE_EVERYTHING = 18; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3863 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3864 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 3865 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 3866 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3867 | final long eventStartTime; |
| 3868 | final View changingView; |
| 3869 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3870 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3871 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3872 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3873 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3874 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3875 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3876 | AnimationEvent(View view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3877 | this(view, type, LENGTHS[type]); |
| 3878 | } |
| 3879 | |
| 3880 | AnimationEvent(View view, int type, long length) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3881 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
| 3882 | changingView = view; |
| 3883 | animationType = type; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3884 | filter = FILTERS[type]; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3885 | this.length = length; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | /** |
| 3889 | * Combines the length of several animation events into a single value. |
| 3890 | * |
| 3891 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3892 | * @return The combined length. Depending on the event types, this might be the maximum of |
| 3893 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3894 | */ |
| 3895 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 3896 | long length = 0; |
| 3897 | int size = events.size(); |
| 3898 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3899 | AnimationEvent event = events.get(i); |
| 3900 | length = Math.max(length, event.length); |
| 3901 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 3902 | return event.length; |
| 3903 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3904 | } |
| 3905 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3909 | } |