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 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.Configuration; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 21 | import android.graphics.Canvas; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 22 | import android.graphics.Paint; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.util.Log; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 25 | import android.view.MotionEvent; |
| 26 | import android.view.VelocityTracker; |
| 27 | import android.view.View; |
| 28 | import android.view.ViewConfiguration; |
| 29 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 30 | import android.view.ViewTreeObserver; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 31 | import android.view.animation.AnimationUtils; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 32 | import android.widget.OverScroller; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 33 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 34 | import com.android.systemui.ExpandHelper; |
| 35 | import com.android.systemui.R; |
| 36 | import com.android.systemui.SwipeHelper; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 37 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 38 | import com.android.systemui.statusbar.DismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 39 | import com.android.systemui.statusbar.EmptyShadeView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 40 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 41 | import com.android.systemui.statusbar.ExpandableView; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 42 | import com.android.systemui.statusbar.SpeedBumpView; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 44 | import com.android.systemui.statusbar.stack.StackScrollState.ViewState; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 45 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 46 | import java.util.ArrayList; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 47 | import java.util.HashSet; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 48 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 49 | /** |
| 50 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 51 | */ |
| 52 | public class NotificationStackScrollLayout extends ViewGroup |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 53 | implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter, |
| 54 | ExpandableView.OnHeightChangedListener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 55 | |
| 56 | private static final String TAG = "NotificationStackScrollLayout"; |
| 57 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 58 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 59 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 60 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 64 | */ |
| 65 | private static final int INVALID_POINTER = -1; |
| 66 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 67 | private ExpandHelper mExpandHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 68 | private SwipeHelper mSwipeHelper; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 69 | private boolean mSwipingInProgress; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 70 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
| 71 | private int mOwnScrollY; |
| 72 | private int mMaxLayoutHeight; |
| 73 | |
| 74 | private VelocityTracker mVelocityTracker; |
| 75 | private OverScroller mScroller; |
| 76 | private int mTouchSlop; |
| 77 | private int mMinimumVelocity; |
| 78 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 79 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 80 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 81 | private boolean mIsBeingDragged; |
| 82 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 83 | private int mDownX; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 84 | private int mActivePointerId; |
| 85 | |
| 86 | private int mSidePaddings; |
| 87 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 88 | private int mContentHeight; |
| 89 | private int mCollapsedSize; |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 90 | private int mBottomStackSlowDownHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 91 | private int mBottomStackPeekSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 92 | private int mPaddingBetweenElements; |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 93 | private int mPaddingBetweenElementsDimmed; |
| 94 | private int mPaddingBetweenElementsNormal; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 95 | private int mTopPadding; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 96 | private int mCollapseSecondCardPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * The algorithm which calculates the properties for our children |
| 100 | */ |
| 101 | private StackScrollAlgorithm mStackScrollAlgorithm; |
| 102 | |
| 103 | /** |
| 104 | * The current State this Layout is in |
| 105 | */ |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 106 | private StackScrollState mCurrentStackScrollState = new StackScrollState(this); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 107 | private AmbientState mAmbientState = new AmbientState(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 108 | private ArrayList<View> mChildrenToAddAnimated = new ArrayList<View>(); |
| 109 | private ArrayList<View> mChildrenToRemoveAnimated = new ArrayList<View>(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 110 | private ArrayList<View> mSnappedBackChildren = new ArrayList<View>(); |
| 111 | private ArrayList<View> mDragAnimPendingChildren = new ArrayList<View>(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 112 | private ArrayList<View> mChildrenChangingPositions = new ArrayList<View>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 113 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 114 | private ArrayList<AnimationEvent> mAnimationEvents |
| 115 | = new ArrayList<AnimationEvent>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 116 | private ArrayList<View> mSwipedOutViews = new ArrayList<View>(); |
| 117 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 118 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 119 | private boolean mChangePositionInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 120 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 121 | /** |
| 122 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 123 | */ |
| 124 | private float mOverScrolledTopPixels; |
| 125 | |
| 126 | /** |
| 127 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 128 | */ |
| 129 | private float mOverScrolledBottomPixels; |
| 130 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 131 | private OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 132 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 133 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 134 | private boolean mNeedsAnimation; |
| 135 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 136 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 137 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 138 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 139 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 140 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 141 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 142 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 143 | private SpeedBumpView mSpeedBumpView; |
| 144 | private boolean mIsExpansionChanging; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 145 | private boolean mExpandingNotification; |
| 146 | private boolean mExpandedInThisMotion; |
| 147 | private boolean mScrollingEnabled; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 148 | private DismissView mDismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 149 | private EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 150 | private boolean mDismissAllInProgress; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * Was the scroller scrolled to the top when the down motion was observed? |
| 154 | */ |
| 155 | private boolean mScrolledToTopOnFirstDown; |
| 156 | |
| 157 | /** |
| 158 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 159 | * when over scrolling on a expanded card. |
| 160 | */ |
| 161 | private float mMinTopOverScrollToEscape; |
| 162 | private int mIntrinsicPadding; |
| 163 | private int mNotificationTopPadding; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 164 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 165 | private boolean mDontReportNextOverScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 166 | private boolean mRequestViewResizeAnimationOnLayout; |
| 167 | private boolean mNeedViewResizeAnimation; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 171 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 172 | * motion. |
| 173 | */ |
| 174 | private int mMaxScrollAfterExpand; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 175 | private SwipeHelper.LongPressListener mLongPressListener; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 179 | * animating. |
| 180 | */ |
| 181 | private boolean mOnlyScrollingInThisMotion; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 182 | private ViewGroup mScrollView; |
| 183 | private boolean mInterceptDelegateEnabled; |
| 184 | private boolean mDelegateToScrollView; |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 185 | private boolean mDisallowScrollingInThisMotion; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 186 | private long mGoToFullShadeDelay; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 187 | |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 188 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 189 | = new ViewTreeObserver.OnPreDrawListener() { |
| 190 | @Override |
| 191 | public boolean onPreDraw() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 192 | updateChildren(); |
| 193 | mChildrenUpdateRequested = false; |
| 194 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 195 | return true; |
| 196 | } |
| 197 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 198 | |
| 199 | public NotificationStackScrollLayout(Context context) { |
| 200 | this(context, null); |
| 201 | } |
| 202 | |
| 203 | public NotificationStackScrollLayout(Context context, AttributeSet attrs) { |
| 204 | this(context, attrs, 0); |
| 205 | } |
| 206 | |
| 207 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 208 | this(context, attrs, defStyleAttr, 0); |
| 209 | } |
| 210 | |
| 211 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 212 | int defStyleRes) { |
| 213 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 214 | int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); |
| 215 | int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height); |
| 216 | mExpandHelper = new ExpandHelper(getContext(), this, |
| 217 | minHeight, maxHeight); |
| 218 | mExpandHelper.setEventSource(this); |
| 219 | mExpandHelper.setScrollAdapter(this); |
| 220 | |
| 221 | mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, getContext()); |
| 222 | mSwipeHelper.setLongPressListener(mLongPressListener); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 223 | initView(context); |
| 224 | if (DEBUG) { |
| 225 | setWillNotDraw(false); |
| 226 | mDebugPaint = new Paint(); |
| 227 | mDebugPaint.setColor(0xffff0000); |
| 228 | mDebugPaint.setStrokeWidth(2); |
| 229 | mDebugPaint.setStyle(Paint.Style.STROKE); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | protected void onDraw(Canvas canvas) { |
| 235 | if (DEBUG) { |
| 236 | int y = mCollapsedSize; |
| 237 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 238 | y = (int) (getLayoutHeight() - mBottomStackPeekSize |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 239 | - mBottomStackSlowDownHeight); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 240 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 241 | y = (int) (getLayoutHeight() - mBottomStackPeekSize); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 242 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 243 | y = (int) getLayoutHeight(); |
| 244 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 245 | y = getHeight() - getEmptyBottomMargin(); |
| 246 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | private void initView(Context context) { |
| 251 | mScroller = new OverScroller(getContext()); |
| 252 | setFocusable(true); |
| 253 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 254 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 255 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 256 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 257 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 258 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 259 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 260 | |
| 261 | mSidePaddings = context.getResources() |
| 262 | .getDimensionPixelSize(R.dimen.notification_side_padding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 263 | mCollapsedSize = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 264 | .getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 265 | mBottomStackPeekSize = context.getResources() |
| 266 | .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 267 | mStackScrollAlgorithm = new StackScrollAlgorithm(context); |
Jorim Jaggi | 220bf5c | 2014-06-14 22:43:12 +0200 | [diff] [blame] | 268 | mStackScrollAlgorithm.setDimmed(mAmbientState.isDimmed()); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 269 | mPaddingBetweenElementsDimmed = context.getResources() |
| 270 | .getDimensionPixelSize(R.dimen.notification_padding_dimmed); |
| 271 | mPaddingBetweenElementsNormal = context.getResources() |
| 272 | .getDimensionPixelSize(R.dimen.notification_padding); |
Jorim Jaggi | 220bf5c | 2014-06-14 22:43:12 +0200 | [diff] [blame] | 273 | updatePadding(mAmbientState.isDimmed()); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 274 | mMinTopOverScrollToEscape = getResources().getDimensionPixelSize( |
| 275 | R.dimen.min_top_overscroll_to_qs); |
| 276 | mNotificationTopPadding = getResources().getDimensionPixelSize( |
| 277 | R.dimen.notifications_top_padding); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 278 | mCollapseSecondCardPadding = getResources().getDimensionPixelSize( |
| 279 | R.dimen.notification_collapse_second_card_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | private void updatePadding(boolean dimmed) { |
| 283 | mPaddingBetweenElements = dimmed |
| 284 | ? mPaddingBetweenElementsDimmed |
| 285 | : mPaddingBetweenElementsNormal; |
| 286 | mBottomStackSlowDownHeight = mStackScrollAlgorithm.getBottomStackSlowDownLength(); |
| 287 | updateContentHeight(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 288 | notifyHeightChangeListener(null); |
| 289 | } |
| 290 | |
| 291 | private void notifyHeightChangeListener(ExpandableView view) { |
| 292 | if (mOnHeightChangedListener != null) { |
| 293 | mOnHeightChangedListener.onHeightChanged(view); |
| 294 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | @Override |
| 298 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 299 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 300 | int mode = MeasureSpec.getMode(widthMeasureSpec); |
| 301 | int size = MeasureSpec.getSize(widthMeasureSpec); |
| 302 | int childMeasureSpec = MeasureSpec.makeMeasureSpec(size - 2 * mSidePaddings, mode); |
| 303 | measureChildren(childMeasureSpec, heightMeasureSpec); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 308 | |
| 309 | // we layout all our children centered on the top |
| 310 | float centerX = getWidth() / 2.0f; |
| 311 | for (int i = 0; i < getChildCount(); i++) { |
| 312 | View child = getChildAt(i); |
| 313 | float width = child.getMeasuredWidth(); |
| 314 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 315 | child.layout((int) (centerX - width / 2.0f), |
| 316 | 0, |
| 317 | (int) (centerX + width / 2.0f), |
| 318 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 319 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 320 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 321 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 322 | clampScrollPosition(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 323 | requestAnimationOnViewResize(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 324 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 327 | private void requestAnimationOnViewResize() { |
| 328 | if (mRequestViewResizeAnimationOnLayout && mIsExpanded && mAnimationsEnabled) { |
| 329 | mNeedViewResizeAnimation = true; |
| 330 | mNeedsAnimation = true; |
| 331 | } |
| 332 | mRequestViewResizeAnimationOnLayout = false; |
| 333 | } |
| 334 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 335 | public void updateSpeedBumpIndex(int newIndex) { |
| 336 | int currentIndex = indexOfChild(mSpeedBumpView); |
| 337 | |
| 338 | // If we are currently layouted before the new speed bump index, we have to decrease it. |
| 339 | boolean validIndex = newIndex > 0; |
| 340 | if (newIndex > getChildCount() - 1) { |
| 341 | validIndex = false; |
| 342 | newIndex = -1; |
| 343 | } |
| 344 | if (validIndex && currentIndex != newIndex) { |
| 345 | changeViewPosition(mSpeedBumpView, newIndex); |
| 346 | } |
| 347 | updateSpeedBump(validIndex); |
| 348 | mAmbientState.setSpeedBumpIndex(newIndex); |
| 349 | } |
| 350 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 351 | public void setChildLocationsChangedListener(OnChildLocationsChangedListener listener) { |
| 352 | mListener = listener; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Returns the location the given child is currently rendered at. |
| 357 | * |
| 358 | * @param child the child to get the location for |
| 359 | * @return one of {@link ViewState}'s <code>LOCATION_*</code> constants |
| 360 | */ |
| 361 | public int getChildLocation(View child) { |
| 362 | ViewState childViewState = mCurrentStackScrollState.getViewStateForView(child); |
| 363 | if (childViewState == null) { |
| 364 | return ViewState.LOCATION_UNKNOWN; |
| 365 | } |
| 366 | return childViewState.location; |
| 367 | } |
| 368 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 369 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 370 | mMaxLayoutHeight = maxLayoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 371 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 374 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 375 | mStackScrollAlgorithm.setLayoutHeight(getLayoutHeight()); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 376 | mStackScrollAlgorithm.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 380 | * @return whether the height of the layout needs to be adapted, in order to ensure that the |
| 381 | * last child is not in the bottom stack. |
| 382 | */ |
| 383 | private boolean needsHeightAdaption() { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 384 | return getNotGoneChildCount() > 1; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 387 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 388 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 389 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 390 | */ |
| 391 | private void updateChildren() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 392 | mAmbientState.setScrollY(mOwnScrollY); |
| 393 | mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 394 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 395 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 396 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 397 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 401 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 402 | if (!mChildrenUpdateRequested) { |
| 403 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 404 | mChildrenUpdateRequested = true; |
| 405 | invalidate(); |
| 406 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 409 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 410 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 413 | private void clampScrollPosition() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 414 | int scrollRange = getScrollRange(); |
| 415 | if (scrollRange < mOwnScrollY) { |
| 416 | mOwnScrollY = scrollRange; |
| 417 | } |
| 418 | } |
| 419 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 420 | public int getTopPadding() { |
| 421 | return mTopPadding; |
| 422 | } |
| 423 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 424 | private void setTopPadding(int topPadding, boolean animate) { |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 425 | if (mTopPadding != topPadding) { |
| 426 | mTopPadding = topPadding; |
| 427 | updateAlgorithmHeightAndPadding(); |
| 428 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 429 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 430 | mTopPaddingNeedsAnimation = true; |
| 431 | mNeedsAnimation = true; |
| 432 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 433 | requestChildrenUpdate(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 434 | notifyHeightChangeListener(null); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Update the height of the stack to a new height. |
| 440 | * |
| 441 | * @param height the new height of the stack |
| 442 | */ |
| 443 | public void setStackHeight(float height) { |
| 444 | setIsExpanded(height > 0.0f); |
| 445 | int newStackHeight = (int) height; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 446 | int minStackHeight = getMinStackHeight(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 447 | int stackHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 448 | if (newStackHeight - mTopPadding >= minStackHeight || getNotGoneChildCount() == 0) { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 449 | setTranslationY(mTopPaddingOverflow); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 450 | stackHeight = newStackHeight; |
| 451 | } else { |
| 452 | |
| 453 | // We did not reach the position yet where we actually start growing, |
| 454 | // so we translate the stack upwards. |
| 455 | int translationY = (newStackHeight - minStackHeight); |
| 456 | // A slight parallax effect is introduced in order for the stack to catch up with |
| 457 | // the top card. |
| 458 | float partiallyThere = (float) (newStackHeight - mTopPadding) / minStackHeight; |
| 459 | partiallyThere = Math.max(0, partiallyThere); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 460 | translationY += (1 - partiallyThere) * (mBottomStackPeekSize + |
| 461 | mCollapseSecondCardPadding); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 462 | setTranslationY(translationY - mTopPadding); |
| 463 | stackHeight = (int) (height - (translationY - mTopPadding)); |
| 464 | } |
| 465 | if (stackHeight != mCurrentStackHeight) { |
| 466 | mCurrentStackHeight = stackHeight; |
| 467 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 468 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 469 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 473 | * 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] | 474 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 475 | * |
| 476 | * @return either the layout height or the externally defined height, whichever is smaller |
| 477 | */ |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 478 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 479 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 480 | } |
| 481 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 482 | public int getItemHeight() { |
| 483 | return mCollapsedSize; |
| 484 | } |
| 485 | |
| 486 | public int getBottomStackPeekSize() { |
| 487 | return mBottomStackPeekSize; |
| 488 | } |
| 489 | |
Jorim Jaggi | 5ad92c5 | 2014-07-28 21:07:32 +0200 | [diff] [blame] | 490 | public int getCollapseSecondCardPadding() { |
| 491 | return mCollapseSecondCardPadding; |
| 492 | } |
| 493 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 494 | public void setLongPressListener(SwipeHelper.LongPressListener listener) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 495 | mSwipeHelper.setLongPressListener(listener); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 496 | mLongPressListener = listener; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 499 | public void setScrollView(ViewGroup scrollView) { |
| 500 | mScrollView = scrollView; |
| 501 | } |
| 502 | |
| 503 | public void setInterceptDelegateEnabled(boolean interceptDelegateEnabled) { |
| 504 | mInterceptDelegateEnabled = interceptDelegateEnabled; |
| 505 | } |
| 506 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 507 | public void onChildDismissed(View v) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 508 | if (mDismissAllInProgress) { |
| 509 | return; |
| 510 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 511 | if (DEBUG) Log.v(TAG, "onChildDismissed: " + v); |
| 512 | final View veto = v.findViewById(R.id.veto); |
| 513 | if (veto != null && veto.getVisibility() != View.GONE) { |
| 514 | veto.performClick(); |
| 515 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 516 | setSwipingInProgress(false); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 517 | if (mDragAnimPendingChildren.contains(v)) { |
| 518 | // We start the swipe and finish it in the same frame, we don't want any animation |
| 519 | // for the drag |
| 520 | mDragAnimPendingChildren.remove(v); |
| 521 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 522 | mSwipedOutViews.add(v); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 523 | mAmbientState.onDragFinished(v); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public void onChildSnappedBack(View animView) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 528 | mAmbientState.onDragFinished(animView); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 529 | if (!mDragAnimPendingChildren.contains(animView)) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 530 | if (mAnimationsEnabled) { |
| 531 | mSnappedBackChildren.add(animView); |
| 532 | mNeedsAnimation = true; |
| 533 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 534 | requestChildrenUpdate(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 535 | } else { |
| 536 | // We start the swipe and snap back in the same frame, we don't want any animation |
| 537 | mDragAnimPendingChildren.remove(animView); |
| 538 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 541 | @Override |
| 542 | public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) { |
| 543 | return false; |
| 544 | } |
| 545 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 546 | public void onBeginDrag(View v) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 547 | setSwipingInProgress(true); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 548 | mAmbientState.onBeginDrag(v); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 549 | if (mAnimationsEnabled) { |
| 550 | mDragAnimPendingChildren.add(v); |
| 551 | mNeedsAnimation = true; |
| 552 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 553 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | public void onDragCancelled(View v) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 557 | setSwipingInProgress(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | public View getChildAtPosition(MotionEvent ev) { |
| 561 | return getChildAtPosition(ev.getX(), ev.getY()); |
| 562 | } |
| 563 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 564 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 565 | int[] location = new int[2]; |
| 566 | getLocationOnScreen(location); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 567 | return getChildAtPosition(touchX - location[0], touchY - location[1]); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 570 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 571 | // find the view under the pointer, accounting for GONE views |
| 572 | final int count = getChildCount(); |
| 573 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 574 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 575 | if (slidingChild.getVisibility() == GONE) { |
| 576 | continue; |
| 577 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 578 | float childTop = slidingChild.getTranslationY(); |
| 579 | float top = childTop + slidingChild.getClipTopAmount(); |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 580 | float bottom = top + slidingChild.getActualHeight(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 581 | |
| 582 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 583 | // camera affordance). |
| 584 | int left = 0; |
| 585 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 586 | |
| 587 | if (touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
| 588 | return slidingChild; |
| 589 | } |
| 590 | } |
| 591 | return null; |
| 592 | } |
| 593 | |
| 594 | public boolean canChildBeExpanded(View v) { |
| 595 | return v instanceof ExpandableNotificationRow |
| 596 | && ((ExpandableNotificationRow) v).isExpandable(); |
| 597 | } |
| 598 | |
| 599 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 600 | if (v instanceof ExpandableNotificationRow) { |
| 601 | ((ExpandableNotificationRow) v).setUserExpanded(userExpanded); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | public void setUserLockedChild(View v, boolean userLocked) { |
| 606 | if (v instanceof ExpandableNotificationRow) { |
| 607 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 608 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 609 | removeLongPressCallback(); |
| 610 | requestDisallowInterceptTouchEvent(true); |
| 611 | } |
| 612 | |
| 613 | @Override |
| 614 | public void expansionStateChanged(boolean isExpanding) { |
| 615 | mExpandingNotification = isExpanding; |
| 616 | if (!mExpandedInThisMotion) { |
| 617 | mMaxScrollAfterExpand = mOwnScrollY; |
| 618 | mExpandedInThisMotion = true; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | public void setScrollingEnabled(boolean enable) { |
| 623 | mScrollingEnabled = enable; |
| 624 | } |
| 625 | |
| 626 | public void setExpandingEnabled(boolean enable) { |
| 627 | mExpandHelper.setEnabled(enable); |
| 628 | } |
| 629 | |
| 630 | private boolean isScrollingEnabled() { |
| 631 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | public View getChildContentView(View v) { |
| 635 | return v; |
| 636 | } |
| 637 | |
| 638 | public boolean canChildBeDismissed(View v) { |
| 639 | final View veto = v.findViewById(R.id.veto); |
| 640 | return (veto != null && veto.getVisibility() != View.GONE); |
| 641 | } |
| 642 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 643 | private void setSwipingInProgress(boolean isSwiped) { |
| 644 | mSwipingInProgress = isSwiped; |
| 645 | if(isSwiped) { |
| 646 | requestDisallowInterceptTouchEvent(true); |
| 647 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | @Override |
| 651 | protected void onConfigurationChanged(Configuration newConfig) { |
| 652 | super.onConfigurationChanged(newConfig); |
| 653 | float densityScale = getResources().getDisplayMetrics().density; |
| 654 | mSwipeHelper.setDensityScale(densityScale); |
| 655 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 656 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 657 | initView(getContext()); |
| 658 | } |
| 659 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 660 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
| 661 | child.setClipBounds(null); |
| 662 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public boolean onTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 667 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 668 | || ev.getActionMasked()== MotionEvent.ACTION_UP; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 669 | if (mDelegateToScrollView) { |
| 670 | if (isCancelOrUp) { |
| 671 | mDelegateToScrollView = false; |
| 672 | } |
| 673 | transformTouchEvent(ev, this, mScrollView); |
| 674 | return mScrollView.onTouchEvent(ev); |
| 675 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 676 | boolean expandWantsIt = false; |
Jorim Jaggi | 341d182 | 2014-07-03 23:34:13 +0200 | [diff] [blame] | 677 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion && isScrollingEnabled()) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 678 | if (isCancelOrUp) { |
| 679 | mExpandHelper.onlyObserveMovements(false); |
| 680 | } |
| 681 | boolean wasExpandingBefore = mExpandingNotification; |
| 682 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 683 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 684 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 685 | dispatchDownEventToScroller(ev); |
| 686 | } |
| 687 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 688 | boolean scrollerWantsIt = false; |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 689 | if (!mSwipingInProgress && !mExpandingNotification && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 690 | scrollerWantsIt = onScrollTouch(ev); |
| 691 | } |
| 692 | boolean horizontalSwipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 693 | if (!mIsBeingDragged |
| 694 | && !mExpandingNotification |
| 695 | && !mExpandedInThisMotion |
| 696 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 697 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 698 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 699 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 700 | } |
| 701 | |
| 702 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 703 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 704 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 705 | onScrollTouch(downEvent); |
| 706 | downEvent.recycle(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | private boolean onScrollTouch(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 710 | if (!isScrollingEnabled()) { |
| 711 | return false; |
| 712 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 713 | initVelocityTrackerIfNotExists(); |
| 714 | mVelocityTracker.addMovement(ev); |
| 715 | |
| 716 | final int action = ev.getAction(); |
| 717 | |
| 718 | switch (action & MotionEvent.ACTION_MASK) { |
| 719 | case MotionEvent.ACTION_DOWN: { |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 720 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 721 | return false; |
| 722 | } |
| 723 | boolean isBeingDragged = !mScroller.isFinished(); |
| 724 | setIsBeingDragged(isBeingDragged); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * If being flinged and user touches, stop the fling. isFinished |
| 728 | * will be false if being flinged. |
| 729 | */ |
| 730 | if (!mScroller.isFinished()) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 731 | mScroller.forceFinished(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | // Remember where the motion event started |
| 735 | mLastMotionY = (int) ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 736 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 737 | mActivePointerId = ev.getPointerId(0); |
| 738 | break; |
| 739 | } |
| 740 | case MotionEvent.ACTION_MOVE: |
| 741 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 742 | if (activePointerIndex == -1) { |
| 743 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 744 | break; |
| 745 | } |
| 746 | |
| 747 | final int y = (int) ev.getY(activePointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 748 | final int x = (int) ev.getX(activePointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 749 | int deltaY = mLastMotionY - y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 750 | final int xDiff = Math.abs(x - mDownX); |
| 751 | final int yDiff = Math.abs(deltaY); |
| 752 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 753 | setIsBeingDragged(true); |
| 754 | if (deltaY > 0) { |
| 755 | deltaY -= mTouchSlop; |
| 756 | } else { |
| 757 | deltaY += mTouchSlop; |
| 758 | } |
| 759 | } |
| 760 | if (mIsBeingDragged) { |
| 761 | // Scroll to follow the motion event |
| 762 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 763 | int range = getScrollRange(); |
| 764 | if (mExpandedInThisMotion) { |
| 765 | range = Math.min(range, mMaxScrollAfterExpand); |
| 766 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 767 | |
| 768 | float scrollAmount; |
| 769 | if (deltaY < 0) { |
| 770 | scrollAmount = overScrollDown(deltaY); |
| 771 | } else { |
| 772 | scrollAmount = overScrollUp(deltaY, range); |
| 773 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 774 | |
| 775 | // Calling overScrollBy will call onOverScrolled, which |
| 776 | // calls onScrollChanged if applicable. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 777 | if (scrollAmount != 0.0f) { |
| 778 | // The scrolling motion could not be compensated with the |
| 779 | // existing overScroll, we have to scroll the view |
| 780 | overScrollBy(0, (int) scrollAmount, 0, mOwnScrollY, |
| 781 | 0, range, 0, getHeight() / 2, true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 782 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 783 | } |
| 784 | break; |
| 785 | case MotionEvent.ACTION_UP: |
| 786 | if (mIsBeingDragged) { |
| 787 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 788 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 789 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 790 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 791 | if (shouldOverScrollFling(initialVelocity)) { |
| 792 | onOverScrollFling(true, initialVelocity); |
| 793 | } else { |
| 794 | if (getChildCount() > 0) { |
| 795 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 796 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 797 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 798 | fling(-initialVelocity); |
| 799 | } else { |
| 800 | onOverScrollFling(false, initialVelocity); |
| 801 | } |
| 802 | } else { |
| 803 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 804 | getScrollRange())) { |
| 805 | postInvalidateOnAnimation(); |
| 806 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 807 | } |
| 808 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 809 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 810 | |
| 811 | mActivePointerId = INVALID_POINTER; |
| 812 | endDrag(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 813 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 814 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 815 | break; |
| 816 | case MotionEvent.ACTION_CANCEL: |
| 817 | if (mIsBeingDragged && getChildCount() > 0) { |
| 818 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 819 | postInvalidateOnAnimation(); |
| 820 | } |
| 821 | mActivePointerId = INVALID_POINTER; |
| 822 | endDrag(); |
| 823 | } |
| 824 | break; |
| 825 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 826 | final int index = ev.getActionIndex(); |
| 827 | mLastMotionY = (int) ev.getY(index); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 828 | mDownX = (int) ev.getX(index); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 829 | mActivePointerId = ev.getPointerId(index); |
| 830 | break; |
| 831 | } |
| 832 | case MotionEvent.ACTION_POINTER_UP: |
| 833 | onSecondaryPointerUp(ev); |
| 834 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 835 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 836 | break; |
| 837 | } |
| 838 | return true; |
| 839 | } |
| 840 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 841 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 842 | if (mOverscrollTopChangedListener != null) { |
| 843 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 844 | } |
| 845 | mDontReportNextOverScroll = true; |
| 846 | setOverScrollAmount(0.0f, true, false); |
| 847 | } |
| 848 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 849 | /** |
| 850 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 851 | * |
| 852 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 853 | * @return The amount of scrolling to be performed by the scroller, |
| 854 | * not handled by the overScroll amount. |
| 855 | */ |
| 856 | private float overScrollUp(int deltaY, int range) { |
| 857 | deltaY = Math.max(deltaY, 0); |
| 858 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 859 | float newTopAmount = currentTopAmount - deltaY; |
| 860 | if (currentTopAmount > 0) { |
| 861 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 862 | false /* animate */); |
| 863 | } |
| 864 | // Top overScroll might not grab all scrolling motion, |
| 865 | // we have to scroll as well. |
| 866 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 867 | float newScrollY = mOwnScrollY + scrollAmount; |
| 868 | if (newScrollY > range) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 869 | if (!mExpandedInThisMotion) { |
| 870 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 871 | // We overScroll on the top |
| 872 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 873 | false /* onTop */, |
| 874 | false /* animate */); |
| 875 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 876 | mOwnScrollY = range; |
| 877 | scrollAmount = 0.0f; |
| 878 | } |
| 879 | return scrollAmount; |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 884 | * |
| 885 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 886 | * @return The amount of scrolling to be performed by the scroller, |
| 887 | * not handled by the overScroll amount. |
| 888 | */ |
| 889 | private float overScrollDown(int deltaY) { |
| 890 | deltaY = Math.min(deltaY, 0); |
| 891 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 892 | float newBottomAmount = currentBottomAmount + deltaY; |
| 893 | if (currentBottomAmount > 0) { |
| 894 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 895 | false /* animate */); |
| 896 | } |
| 897 | // Bottom overScroll might not grab all scrolling motion, |
| 898 | // we have to scroll as well. |
| 899 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 900 | float newScrollY = mOwnScrollY + scrollAmount; |
| 901 | if (newScrollY < 0) { |
| 902 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 903 | // We overScroll on the top |
| 904 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 905 | true /* onTop */, |
| 906 | false /* animate */); |
| 907 | mOwnScrollY = 0; |
| 908 | scrollAmount = 0.0f; |
| 909 | } |
| 910 | return scrollAmount; |
| 911 | } |
| 912 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 913 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 914 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 915 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 916 | final int pointerId = ev.getPointerId(pointerIndex); |
| 917 | if (pointerId == mActivePointerId) { |
| 918 | // This was our active pointer going up. Choose a new |
| 919 | // active pointer and adjust accordingly. |
| 920 | // TODO: Make this decision more intelligent. |
| 921 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 922 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 923 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 924 | if (mVelocityTracker != null) { |
| 925 | mVelocityTracker.clear(); |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | private void initVelocityTrackerIfNotExists() { |
| 931 | if (mVelocityTracker == null) { |
| 932 | mVelocityTracker = VelocityTracker.obtain(); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | private void recycleVelocityTracker() { |
| 937 | if (mVelocityTracker != null) { |
| 938 | mVelocityTracker.recycle(); |
| 939 | mVelocityTracker = null; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | private void initOrResetVelocityTracker() { |
| 944 | if (mVelocityTracker == null) { |
| 945 | mVelocityTracker = VelocityTracker.obtain(); |
| 946 | } else { |
| 947 | mVelocityTracker.clear(); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public void computeScroll() { |
| 953 | if (mScroller.computeScrollOffset()) { |
| 954 | // This is called at drawing time by ViewGroup. |
| 955 | int oldX = mScrollX; |
| 956 | int oldY = mOwnScrollY; |
| 957 | int x = mScroller.getCurrX(); |
| 958 | int y = mScroller.getCurrY(); |
| 959 | |
| 960 | if (oldX != x || oldY != y) { |
| 961 | final int range = getScrollRange(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 962 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
| 963 | float currVelocity = mScroller.getCurrVelocity(); |
Selim Cinek | ba81962 | 2014-05-13 17:55:53 +0200 | [diff] [blame] | 964 | if (currVelocity >= mMinimumVelocity) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 965 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
| 966 | } |
| 967 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 968 | |
| 969 | overScrollBy(x - oldX, y - oldY, oldX, oldY, 0, range, |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 970 | 0, (int) (mMaxOverScroll), false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 971 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // Keep on drawing until the animation has finished. |
| 975 | postInvalidateOnAnimation(); |
| 976 | } |
| 977 | } |
| 978 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 979 | @Override |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 980 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 981 | int scrollX, int scrollY, |
| 982 | int scrollRangeX, int scrollRangeY, |
| 983 | int maxOverScrollX, int maxOverScrollY, |
| 984 | boolean isTouchEvent) { |
| 985 | |
| 986 | int newScrollY = scrollY + deltaY; |
| 987 | |
| 988 | final int top = -maxOverScrollY; |
| 989 | final int bottom = maxOverScrollY + scrollRangeY; |
| 990 | |
| 991 | boolean clampedY = false; |
| 992 | if (newScrollY > bottom) { |
| 993 | newScrollY = bottom; |
| 994 | clampedY = true; |
| 995 | } else if (newScrollY < top) { |
| 996 | newScrollY = top; |
| 997 | clampedY = true; |
| 998 | } |
| 999 | |
| 1000 | onOverScrolled(0, newScrollY, false, clampedY); |
| 1001 | |
| 1002 | return clampedY; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1007 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1008 | * same overScroll edge. |
| 1009 | * |
| 1010 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1011 | * the rubber-banding logic. |
| 1012 | * @param onTop Should the effect be applied on top of the scroller. |
| 1013 | * @param animate Should an animation be performed. |
| 1014 | */ |
| 1015 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1016 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1021 | * By default this will also cancel animations on the same overScroll edge. |
| 1022 | * |
| 1023 | * @param amount The amount to overScroll by. |
| 1024 | * @param onTop Should the effect be applied on top of the scroller. |
| 1025 | * @param animate Should an animation be performed. |
| 1026 | */ |
| 1027 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 1028 | setOverScrollAmount(amount, onTop, animate, true); |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1033 | * |
| 1034 | * @param amount The amount to overScroll by. |
| 1035 | * @param onTop Should the effect be applied on top of the scroller. |
| 1036 | * @param animate Should an animation be performed. |
| 1037 | * @param cancelAnimators Should running animations be cancelled. |
| 1038 | */ |
| 1039 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1040 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1041 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1046 | * |
| 1047 | * @param amount The amount to overScroll by. |
| 1048 | * @param onTop Should the effect be applied on top of the scroller. |
| 1049 | * @param animate Should an animation be performed. |
| 1050 | * @param cancelAnimators Should running animations be cancelled. |
| 1051 | * @param isRubberbanded The value which will be passed to |
| 1052 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
| 1053 | */ |
| 1054 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1055 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1056 | if (cancelAnimators) { |
| 1057 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 1058 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1059 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1062 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 1063 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1064 | amount = Math.max(0, amount); |
| 1065 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1066 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1067 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1068 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1069 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1070 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1071 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1072 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1073 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1077 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1078 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 1079 | if (mDontReportNextOverScroll) { |
| 1080 | mDontReportNextOverScroll = false; |
| 1081 | return; |
| 1082 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1083 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1084 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | public void setOverscrollTopChangedListener( |
| 1089 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 1090 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 1091 | } |
| 1092 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1093 | public float getCurrentOverScrollAmount(boolean top) { |
| 1094 | return mAmbientState.getOverScrollAmount(top); |
| 1095 | } |
| 1096 | |
| 1097 | public float getCurrentOverScrolledPixels(boolean top) { |
| 1098 | return top? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
| 1099 | } |
| 1100 | |
| 1101 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 1102 | if (onTop) { |
| 1103 | mOverScrolledTopPixels = amount; |
| 1104 | } else { |
| 1105 | mOverScrolledBottomPixels = amount; |
| 1106 | } |
| 1107 | } |
| 1108 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1109 | private void customScrollTo(int y) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1110 | mOwnScrollY = y; |
Selim Cinek | 3af00cf | 2014-05-07 17:27:26 +0200 | [diff] [blame] | 1111 | updateChildren(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | @Override |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1115 | protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1116 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 1117 | if (!mScroller.isFinished()) { |
| 1118 | final int oldX = mScrollX; |
| 1119 | final int oldY = mOwnScrollY; |
| 1120 | mScrollX = scrollX; |
| 1121 | mOwnScrollY = scrollY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1122 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1123 | springBack(); |
| 1124 | } else { |
| 1125 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
| 1126 | invalidateParentIfNeeded(); |
| 1127 | updateChildren(); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1128 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 1129 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1130 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1131 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1132 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1133 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1134 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1135 | } else { |
| 1136 | customScrollTo(scrollY); |
| 1137 | scrollTo(scrollX, mScrollY); |
| 1138 | } |
| 1139 | } |
| 1140 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1141 | private void springBack() { |
| 1142 | int scrollRange = getScrollRange(); |
| 1143 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 1144 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 1145 | if (overScrolledTop || overScrolledBottom) { |
| 1146 | boolean onTop; |
| 1147 | float newAmount; |
| 1148 | if (overScrolledTop) { |
| 1149 | onTop = true; |
| 1150 | newAmount = -mOwnScrollY; |
| 1151 | mOwnScrollY = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1152 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1153 | } else { |
| 1154 | onTop = false; |
| 1155 | newAmount = mOwnScrollY - scrollRange; |
| 1156 | mOwnScrollY = scrollRange; |
| 1157 | } |
| 1158 | setOverScrollAmount(newAmount, onTop, false); |
| 1159 | setOverScrollAmount(0.0f, onTop, true); |
| 1160 | mScroller.forceFinished(true); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1164 | private int getScrollRange() { |
| 1165 | int scrollRange = 0; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1166 | ExpandableView firstChild = (ExpandableView) getFirstChildNotGone(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1167 | if (firstChild != null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1168 | int contentHeight = getContentHeight(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1169 | int firstChildMaxExpandHeight = getMaxExpandHeight(firstChild); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 1170 | scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight + mBottomStackPeekSize |
| 1171 | + mBottomStackSlowDownHeight); |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1172 | if (scrollRange > 0) { |
| 1173 | View lastChild = getLastChildNotGone(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1174 | // We want to at least be able collapse the first item and not ending in a weird |
| 1175 | // end state. |
| 1176 | scrollRange = Math.max(scrollRange, firstChildMaxExpandHeight - mCollapsedSize); |
| 1177 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1178 | } |
| 1179 | return scrollRange; |
| 1180 | } |
| 1181 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1182 | /** |
| 1183 | * @return the first child which has visibility unequal to GONE |
| 1184 | */ |
| 1185 | private View getFirstChildNotGone() { |
| 1186 | int childCount = getChildCount(); |
| 1187 | for (int i = 0; i < childCount; i++) { |
| 1188 | View child = getChildAt(i); |
| 1189 | if (child.getVisibility() != View.GONE) { |
| 1190 | return child; |
| 1191 | } |
| 1192 | } |
| 1193 | return null; |
| 1194 | } |
| 1195 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1196 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1197 | * @return The first child which has visibility unequal to GONE which is currently below the |
| 1198 | * given translationY or equal to it. |
| 1199 | */ |
| 1200 | private View getFirstChildBelowTranlsationY(float translationY) { |
| 1201 | int childCount = getChildCount(); |
| 1202 | for (int i = 0; i < childCount; i++) { |
| 1203 | View child = getChildAt(i); |
| 1204 | if (child.getVisibility() != View.GONE && child.getTranslationY() >= translationY) { |
| 1205 | return child; |
| 1206 | } |
| 1207 | } |
| 1208 | return null; |
| 1209 | } |
| 1210 | |
| 1211 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1212 | * @return the last child which has visibility unequal to GONE |
| 1213 | */ |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1214 | public View getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1215 | int childCount = getChildCount(); |
| 1216 | for (int i = childCount - 1; i >= 0; i--) { |
| 1217 | View child = getChildAt(i); |
| 1218 | if (child.getVisibility() != View.GONE) { |
| 1219 | return child; |
| 1220 | } |
| 1221 | } |
| 1222 | return null; |
| 1223 | } |
| 1224 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1225 | /** |
| 1226 | * @return the number of children which have visibility unequal to GONE |
| 1227 | */ |
| 1228 | public int getNotGoneChildCount() { |
| 1229 | int childCount = getChildCount(); |
| 1230 | int count = 0; |
| 1231 | for (int i = 0; i < childCount; i++) { |
| 1232 | View child = getChildAt(i); |
| 1233 | if (child.getVisibility() != View.GONE) { |
| 1234 | count++; |
| 1235 | } |
| 1236 | } |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 1237 | if (mDismissView.willBeGone()) { |
| 1238 | count--; |
| 1239 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 1240 | if (mEmptyShadeView.willBeGone()) { |
| 1241 | count--; |
| 1242 | } |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1243 | return count; |
| 1244 | } |
| 1245 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1246 | private int getMaxExpandHeight(View view) { |
| 1247 | if (view instanceof ExpandableNotificationRow) { |
| 1248 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 1249 | return row.getIntrinsicHeight(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1250 | } |
| 1251 | return view.getHeight(); |
| 1252 | } |
| 1253 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1254 | public int getContentHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1255 | return mContentHeight; |
| 1256 | } |
| 1257 | |
| 1258 | private void updateContentHeight() { |
| 1259 | int height = 0; |
| 1260 | for (int i = 0; i < getChildCount(); i++) { |
| 1261 | View child = getChildAt(i); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1262 | if (child.getVisibility() != View.GONE) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1263 | if (height != 0) { |
| 1264 | // add the padding before this element |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1265 | height += mPaddingBetweenElements; |
| 1266 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1267 | if (child instanceof ExpandableNotificationRow) { |
| 1268 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 1269 | height += row.getIntrinsicHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1270 | } else if (child instanceof ExpandableView) { |
| 1271 | ExpandableView expandableView = (ExpandableView) child; |
| 1272 | height += expandableView.getActualHeight(); |
| 1273 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1274 | } |
| 1275 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1276 | mContentHeight = height + mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | /** |
| 1280 | * Fling the scroll view |
| 1281 | * |
| 1282 | * @param velocityY The initial velocity in the Y direction. Positive |
| 1283 | * numbers mean that the finger/cursor is moving down the screen, |
| 1284 | * which means we want to scroll towards the top. |
| 1285 | */ |
| 1286 | private void fling(int velocityY) { |
| 1287 | if (getChildCount() > 0) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1288 | int scrollRange = getScrollRange(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1289 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1290 | float topAmount = getCurrentOverScrollAmount(true); |
| 1291 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 1292 | if (velocityY < 0 && topAmount > 0) { |
| 1293 | mOwnScrollY -= (int) topAmount; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1294 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1295 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1296 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1297 | * mOverflingDistance + topAmount; |
| 1298 | } else if (velocityY > 0 && bottomAmount > 0) { |
| 1299 | mOwnScrollY += bottomAmount; |
| 1300 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1301 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 1302 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
| 1303 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1304 | } else { |
| 1305 | // it will be set once we reach the boundary |
| 1306 | mMaxOverScroll = 0.0f; |
| 1307 | } |
| 1308 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1309 | Math.max(0, scrollRange), 0, Integer.MAX_VALUE / 2); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1310 | |
| 1311 | postInvalidateOnAnimation(); |
| 1312 | } |
| 1313 | } |
| 1314 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1315 | /** |
| 1316 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 1317 | * overScroll view (i.e QS). |
| 1318 | */ |
| 1319 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 1320 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 1321 | return mScrolledToTopOnFirstDown |
| 1322 | && !mExpandedInThisMotion |
| 1323 | && topOverScroll > mMinTopOverScrollToEscape |
| 1324 | && initialVelocity > 0; |
| 1325 | } |
| 1326 | |
| 1327 | public void updateTopPadding(float qsHeight, int scrollY, boolean animate) { |
| 1328 | float start = qsHeight - scrollY + mNotificationTopPadding; |
| 1329 | float stackHeight = getHeight() - start; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1330 | int minStackHeight = getMinStackHeight(); |
| 1331 | if (stackHeight <= minStackHeight) { |
| 1332 | float overflow = minStackHeight - stackHeight; |
| 1333 | stackHeight = minStackHeight; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1334 | start = getHeight() - stackHeight; |
| 1335 | setTranslationY(overflow); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1336 | mTopPaddingOverflow = overflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1337 | } else { |
| 1338 | setTranslationY(0); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1339 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1340 | } |
| 1341 | setTopPadding(clampPadding((int) start), animate); |
| 1342 | } |
| 1343 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1344 | public int getNotificationTopPadding() { |
| 1345 | return mNotificationTopPadding; |
| 1346 | } |
| 1347 | |
| 1348 | public int getMinStackHeight() { |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 1349 | return mCollapsedSize + mBottomStackPeekSize + mCollapseSecondCardPadding; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | public float getTopPaddingOverflow() { |
| 1353 | return mTopPaddingOverflow; |
| 1354 | } |
| 1355 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1356 | public int getPeekHeight() { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1357 | return mIntrinsicPadding + mCollapsedSize + mBottomStackPeekSize |
| 1358 | + mCollapseSecondCardPadding; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1359 | } |
| 1360 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1361 | private int clampPadding(int desiredPadding) { |
| 1362 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 1363 | } |
| 1364 | |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1365 | private float getRubberBandFactor(boolean onTop) { |
| 1366 | if (!onTop) { |
| 1367 | return RUBBER_BAND_FACTOR_NORMAL; |
| 1368 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1369 | if (mExpandedInThisMotion) { |
| 1370 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
| 1371 | } else if (mIsExpansionChanging) { |
| 1372 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 1373 | } else if (mScrolledToTopOnFirstDown) { |
| 1374 | return 1.0f; |
| 1375 | } |
| 1376 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1377 | } |
| 1378 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1379 | /** |
| 1380 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 1381 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 1382 | * overscroll view (e.g. expand QS). |
| 1383 | */ |
| 1384 | private boolean isRubberbanded(boolean onTop) { |
| 1385 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging |
| 1386 | || !mScrolledToTopOnFirstDown; |
| 1387 | } |
| 1388 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1389 | private void endDrag() { |
| 1390 | setIsBeingDragged(false); |
| 1391 | |
| 1392 | recycleVelocityTracker(); |
| 1393 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1394 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 1395 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 1396 | } |
| 1397 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 1398 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 1399 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1402 | private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) { |
| 1403 | ev.offsetLocation(sourceView.getX(), sourceView.getY()); |
| 1404 | ev.offsetLocation(-targetView.getX(), -targetView.getY()); |
| 1405 | } |
| 1406 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1407 | @Override |
| 1408 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1409 | if (mInterceptDelegateEnabled) { |
| 1410 | transformTouchEvent(ev, this, mScrollView); |
| 1411 | if (mScrollView.onInterceptTouchEvent(ev)) { |
| 1412 | mDelegateToScrollView = true; |
| 1413 | removeLongPressCallback(); |
| 1414 | return true; |
| 1415 | } |
| 1416 | transformTouchEvent(ev, mScrollView, this); |
| 1417 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1418 | initDownStates(ev); |
| 1419 | boolean expandWantsIt = false; |
Jorim Jaggi | 341d182 | 2014-07-03 23:34:13 +0200 | [diff] [blame] | 1420 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion && isScrollingEnabled()) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1421 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 1422 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1423 | boolean scrollWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1424 | if (!mSwipingInProgress && !mExpandingNotification) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1425 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 1426 | } |
| 1427 | boolean swipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1428 | if (!mIsBeingDragged |
| 1429 | && !mExpandingNotification |
| 1430 | && !mExpandedInThisMotion |
| 1431 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1432 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 1433 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1434 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 1435 | } |
| 1436 | |
| 1437 | private void initDownStates(MotionEvent ev) { |
| 1438 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 1439 | mExpandedInThisMotion = false; |
| 1440 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1441 | mDisallowScrollingInThisMotion = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1442 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1443 | } |
| 1444 | |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1445 | @Override |
| 1446 | protected void onViewRemoved(View child) { |
| 1447 | super.onViewRemoved(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1448 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1449 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1450 | // This is only a position change, don't do anything special |
| 1451 | return; |
| 1452 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1453 | ((ExpandableView) child).setOnHeightChangedListener(null); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1454 | mCurrentStackScrollState.removeViewStateForView(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1455 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1456 | boolean animationGenerated = generateRemoveAnimation(child); |
| 1457 | if (animationGenerated && !mSwipedOutViews.contains(child)) { |
| 1458 | // Add this view to an overlay in order to ensure that it will still be temporary |
| 1459 | // drawn when removed |
| 1460 | getOverlay().add(child); |
| 1461 | } |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1462 | } |
| 1463 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1464 | /** |
| 1465 | * Generate a remove animation for a child view. |
| 1466 | * |
| 1467 | * @param child The view to generate the remove animation for. |
| 1468 | * @return Whether an animation was generated. |
| 1469 | */ |
| 1470 | private boolean generateRemoveAnimation(View child) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1471 | if (mIsExpanded && mAnimationsEnabled) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1472 | if (!mChildrenToAddAnimated.contains(child)) { |
| 1473 | // Generate Animations |
| 1474 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1475 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1476 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1477 | } else { |
| 1478 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 1479 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1480 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1481 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1482 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1483 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * Updates the scroll position when a child was removed |
| 1488 | * |
| 1489 | * @param removedChild the removed child |
| 1490 | */ |
| 1491 | private void updateScrollStateForRemovedChild(View removedChild) { |
| 1492 | int startingPosition = getPositionInLinearLayout(removedChild); |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 1493 | int childHeight = getIntrinsicHeight(removedChild) + mPaddingBetweenElements; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1494 | int endPosition = startingPosition + childHeight; |
| 1495 | if (endPosition <= mOwnScrollY) { |
| 1496 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 1497 | // scrollPosition |
| 1498 | mOwnScrollY -= childHeight; |
| 1499 | } else if (startingPosition < mOwnScrollY) { |
| 1500 | // This child is currently being scrolled into, set the scroll position to the start of |
| 1501 | // this child |
| 1502 | mOwnScrollY = startingPosition; |
| 1503 | } |
| 1504 | } |
| 1505 | |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 1506 | private int getIntrinsicHeight(View view) { |
| 1507 | if (view instanceof ExpandableView) { |
| 1508 | ExpandableView expandableView = (ExpandableView) view; |
| 1509 | return expandableView.getIntrinsicHeight(); |
| 1510 | } |
| 1511 | return view.getHeight(); |
| 1512 | } |
| 1513 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1514 | private int getPositionInLinearLayout(View requestedChild) { |
| 1515 | int position = 0; |
| 1516 | for (int i = 0; i < getChildCount(); i++) { |
| 1517 | View child = getChildAt(i); |
| 1518 | if (child == requestedChild) { |
| 1519 | return position; |
| 1520 | } |
| 1521 | if (child.getVisibility() != View.GONE) { |
| 1522 | position += child.getHeight(); |
| 1523 | if (i < getChildCount()-1) { |
| 1524 | position += mPaddingBetweenElements; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | @Override |
| 1532 | protected void onViewAdded(View child) { |
| 1533 | super.onViewAdded(child); |
| 1534 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1535 | ((ExpandableView) child).setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1536 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1539 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 1540 | mAnimationsEnabled = animationsEnabled; |
| 1541 | } |
| 1542 | |
| 1543 | public boolean isAddOrRemoveAnimationPending() { |
| 1544 | return mNeedsAnimation |
| 1545 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 1546 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1547 | /** |
| 1548 | * Generate an animation for an added child view. |
| 1549 | * |
| 1550 | * @param child The view to be added. |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1551 | * @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] | 1552 | */ |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1553 | public void generateAddAnimation(View child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1554 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1555 | // Generate Animations |
| 1556 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1557 | if (fromMoreCard) { |
| 1558 | mFromMoreCardAdditions.add(child); |
| 1559 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1560 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * Change the position of child to a new location |
| 1566 | * |
| 1567 | * @param child the view to change the position for |
| 1568 | * @param newIndex the new index |
| 1569 | */ |
| 1570 | public void changeViewPosition(View child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1571 | int currentIndex = indexOfChild(child); |
| 1572 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1573 | mChangePositionInProgress = true; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1574 | removeView(child); |
| 1575 | addView(child, newIndex); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1576 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1577 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1578 | mChildrenChangingPositions.add(child); |
| 1579 | mNeedsAnimation = true; |
| 1580 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1584 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1585 | if (mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1586 | generateChildHierarchyEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1587 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1588 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1589 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 1590 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState, |
| 1591 | mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1592 | mAnimationEvents.clear(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1593 | } else { |
| 1594 | applyCurrentState(); |
| 1595 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 1596 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | private void generateChildHierarchyEvents() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1600 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1601 | generateChildAdditionEvents(); |
| 1602 | generatePositionChangeEvents(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1603 | generateSnapBackEvents(); |
| 1604 | generateDragEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1605 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1606 | generateActivateEvent(); |
| 1607 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1608 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 1609 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 1610 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1611 | generateViewResizeEvent(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1612 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1615 | private void generateViewResizeEvent() { |
| 1616 | if (mNeedViewResizeAnimation) { |
| 1617 | mAnimationEvents.add( |
| 1618 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 1619 | } |
| 1620 | mNeedViewResizeAnimation = false; |
| 1621 | } |
| 1622 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1623 | private void generateSnapBackEvents() { |
| 1624 | for (View child : mSnappedBackChildren) { |
| 1625 | mAnimationEvents.add(new AnimationEvent(child, |
| 1626 | AnimationEvent.ANIMATION_TYPE_SNAP_BACK)); |
| 1627 | } |
| 1628 | mSnappedBackChildren.clear(); |
| 1629 | } |
| 1630 | |
| 1631 | private void generateDragEvents() { |
| 1632 | for (View child : mDragAnimPendingChildren) { |
| 1633 | mAnimationEvents.add(new AnimationEvent(child, |
| 1634 | AnimationEvent.ANIMATION_TYPE_START_DRAG)); |
| 1635 | } |
| 1636 | mDragAnimPendingChildren.clear(); |
| 1637 | } |
| 1638 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1639 | private void generateChildRemovalEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1640 | for (View child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1641 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
| 1642 | int animationType = childWasSwipedOut |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1643 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 1644 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1645 | AnimationEvent event = new AnimationEvent(child, animationType); |
| 1646 | |
| 1647 | // we need to know the view after this one |
| 1648 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(child.getTranslationY()); |
| 1649 | mAnimationEvents.add(event); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1650 | } |
| 1651 | mSwipedOutViews.clear(); |
| 1652 | mChildrenToRemoveAnimated.clear(); |
| 1653 | } |
| 1654 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1655 | private void generatePositionChangeEvents() { |
| 1656 | for (View child : mChildrenChangingPositions) { |
| 1657 | mAnimationEvents.add(new AnimationEvent(child, |
| 1658 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 1659 | } |
| 1660 | mChildrenChangingPositions.clear(); |
| 1661 | } |
| 1662 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1663 | private void generateChildAdditionEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1664 | for (View child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 1665 | if (mFromMoreCardAdditions.contains(child)) { |
| 1666 | mAnimationEvents.add(new AnimationEvent(child, |
| 1667 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 1668 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 1669 | } else { |
| 1670 | mAnimationEvents.add(new AnimationEvent(child, |
| 1671 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 1672 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1673 | } |
| 1674 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 1675 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1678 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 1679 | if (mTopPaddingNeedsAnimation) { |
| 1680 | mAnimationEvents.add( |
| 1681 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED)); |
| 1682 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1683 | mTopPaddingNeedsAnimation = false; |
| 1684 | } |
| 1685 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1686 | private void generateActivateEvent() { |
| 1687 | if (mActivateNeedsAnimation) { |
| 1688 | mAnimationEvents.add( |
| 1689 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 1690 | } |
| 1691 | mActivateNeedsAnimation = false; |
| 1692 | } |
| 1693 | |
| 1694 | private void generateDimmedEvent() { |
| 1695 | if (mDimmedNeedsAnimation) { |
| 1696 | mAnimationEvents.add( |
| 1697 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 1698 | } |
| 1699 | mDimmedNeedsAnimation = false; |
| 1700 | } |
| 1701 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1702 | private void generateHideSensitiveEvent() { |
| 1703 | if (mHideSensitiveNeedsAnimation) { |
| 1704 | mAnimationEvents.add( |
| 1705 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 1706 | } |
| 1707 | mHideSensitiveNeedsAnimation = false; |
| 1708 | } |
| 1709 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 1710 | private void generateDarkEvent() { |
| 1711 | if (mDarkNeedsAnimation) { |
| 1712 | mAnimationEvents.add( |
| 1713 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DARK)); |
| 1714 | } |
| 1715 | mDarkNeedsAnimation = false; |
| 1716 | } |
| 1717 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 1718 | private void generateGoToFullShadeEvent() { |
| 1719 | if (mGoToFullShadeNeedsAnimation) { |
| 1720 | mAnimationEvents.add( |
| 1721 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 1722 | } |
| 1723 | mGoToFullShadeNeedsAnimation = false; |
| 1724 | } |
| 1725 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1726 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1727 | if (!isScrollingEnabled()) { |
| 1728 | return false; |
| 1729 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1730 | /* |
| 1731 | * This method JUST determines whether we want to intercept the motion. |
| 1732 | * If we return true, onMotionEvent will be called and we do the actual |
| 1733 | * scrolling there. |
| 1734 | */ |
| 1735 | |
| 1736 | /* |
| 1737 | * Shortcut the most recurring case: the user is in the dragging |
| 1738 | * state and he is moving his finger. We want to intercept this |
| 1739 | * motion. |
| 1740 | */ |
| 1741 | final int action = ev.getAction(); |
| 1742 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 1743 | return true; |
| 1744 | } |
| 1745 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1746 | switch (action & MotionEvent.ACTION_MASK) { |
| 1747 | case MotionEvent.ACTION_MOVE: { |
| 1748 | /* |
| 1749 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
| 1750 | * whether the user has moved far enough from his original down touch. |
| 1751 | */ |
| 1752 | |
| 1753 | /* |
| 1754 | * Locally do absolute value. mLastMotionY is set to the y value |
| 1755 | * of the down event. |
| 1756 | */ |
| 1757 | final int activePointerId = mActivePointerId; |
| 1758 | if (activePointerId == INVALID_POINTER) { |
| 1759 | // If we don't have a valid id, the touch down wasn't on content. |
| 1760 | break; |
| 1761 | } |
| 1762 | |
| 1763 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 1764 | if (pointerIndex == -1) { |
| 1765 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 1766 | + " in onInterceptTouchEvent"); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
| 1770 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1771 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1772 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1773 | final int xDiff = Math.abs(x - mDownX); |
| 1774 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1775 | setIsBeingDragged(true); |
| 1776 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1777 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1778 | initVelocityTrackerIfNotExists(); |
| 1779 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1780 | } |
| 1781 | break; |
| 1782 | } |
| 1783 | |
| 1784 | case MotionEvent.ACTION_DOWN: { |
| 1785 | final int y = (int) ev.getY(); |
| 1786 | if (getChildAtPosition(ev.getX(), y) == null) { |
| 1787 | setIsBeingDragged(false); |
| 1788 | recycleVelocityTracker(); |
| 1789 | break; |
| 1790 | } |
| 1791 | |
| 1792 | /* |
| 1793 | * Remember location of down touch. |
| 1794 | * ACTION_DOWN always refers to pointer index 0. |
| 1795 | */ |
| 1796 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1797 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1798 | mActivePointerId = ev.getPointerId(0); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1799 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1800 | |
| 1801 | initOrResetVelocityTracker(); |
| 1802 | mVelocityTracker.addMovement(ev); |
| 1803 | /* |
| 1804 | * If being flinged and user touches the screen, initiate drag; |
| 1805 | * otherwise don't. mScroller.isFinished should be false when |
| 1806 | * being flinged. |
| 1807 | */ |
| 1808 | boolean isBeingDragged = !mScroller.isFinished(); |
| 1809 | setIsBeingDragged(isBeingDragged); |
| 1810 | break; |
| 1811 | } |
| 1812 | |
| 1813 | case MotionEvent.ACTION_CANCEL: |
| 1814 | case MotionEvent.ACTION_UP: |
| 1815 | /* Release the drag */ |
| 1816 | setIsBeingDragged(false); |
| 1817 | mActivePointerId = INVALID_POINTER; |
| 1818 | recycleVelocityTracker(); |
| 1819 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 1820 | postInvalidateOnAnimation(); |
| 1821 | } |
| 1822 | break; |
| 1823 | case MotionEvent.ACTION_POINTER_UP: |
| 1824 | onSecondaryPointerUp(ev); |
| 1825 | break; |
| 1826 | } |
| 1827 | |
| 1828 | /* |
| 1829 | * The only time we want to intercept motion events is if we are in the |
| 1830 | * drag mode. |
| 1831 | */ |
| 1832 | return mIsBeingDragged; |
| 1833 | } |
| 1834 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 1835 | /** |
| 1836 | * @return Whether the specified motion event is actually happening over the content. |
| 1837 | */ |
| 1838 | private boolean isInContentBounds(MotionEvent event) { |
| 1839 | return event.getY() < getHeight() - getEmptyBottomMargin(); |
| 1840 | } |
| 1841 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1842 | private void setIsBeingDragged(boolean isDragged) { |
| 1843 | mIsBeingDragged = isDragged; |
| 1844 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1845 | requestDisallowInterceptTouchEvent(true); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1846 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | @Override |
| 1851 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 1852 | super.onWindowFocusChanged(hasWindowFocus); |
| 1853 | if (!hasWindowFocus) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1854 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1855 | } |
| 1856 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 1857 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1858 | public void removeLongPressCallback() { |
| 1859 | mSwipeHelper.removeLongPressCallback(); |
| 1860 | } |
| 1861 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 1862 | @Override |
| 1863 | public boolean isScrolledToTop() { |
| 1864 | return mOwnScrollY == 0; |
| 1865 | } |
| 1866 | |
| 1867 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1868 | public boolean isScrolledToBottom() { |
| 1869 | return mOwnScrollY >= getScrollRange(); |
| 1870 | } |
| 1871 | |
| 1872 | @Override |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 1873 | public View getHostView() { |
| 1874 | return this; |
| 1875 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1876 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1877 | public int getEmptyBottomMargin() { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1878 | int emptyMargin = mMaxLayoutHeight - mContentHeight - mBottomStackPeekSize; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1879 | if (needsHeightAdaption()) { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1880 | emptyMargin -= mBottomStackSlowDownHeight; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1881 | } else { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1882 | emptyMargin -= mCollapseSecondCardPadding; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1883 | } |
| 1884 | return Math.max(emptyMargin, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1887 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1888 | mIsExpansionChanging = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1889 | mStackScrollAlgorithm.onExpansionStarted(mCurrentStackScrollState); |
| 1890 | } |
| 1891 | |
| 1892 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1893 | mIsExpansionChanging = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1894 | mStackScrollAlgorithm.onExpansionStopped(); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 1895 | if (!mIsExpanded) { |
| 1896 | mOwnScrollY = 0; |
| 1897 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1898 | } |
| 1899 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1900 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1901 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1902 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1903 | } |
| 1904 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1905 | @Override |
| 1906 | public void onHeightChanged(ExpandableView view) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1907 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1908 | updateScrollPositionOnExpandInBottom(view); |
| 1909 | clampScrollPosition(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1910 | notifyHeightChangeListener(view); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1911 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1914 | @Override |
| 1915 | public void onReset(ExpandableView view) { |
| 1916 | mRequestViewResizeAnimationOnLayout = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame^] | 1917 | mStackScrollAlgorithm.onReset(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1920 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
| 1921 | if (view instanceof ExpandableNotificationRow) { |
| 1922 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 1923 | if (row.isUserLocked()) { |
| 1924 | // We are actually expanding this view |
| 1925 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
| 1926 | int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize - |
| 1927 | mBottomStackSlowDownHeight; |
| 1928 | if (endPosition > stackEnd) { |
| 1929 | mOwnScrollY += endPosition - stackEnd; |
| 1930 | mDisallowScrollingInThisMotion = true; |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | } |
| 1935 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1936 | public void setOnHeightChangedListener( |
| 1937 | ExpandableView.OnHeightChangedListener mOnHeightChangedListener) { |
| 1938 | this.mOnHeightChangedListener = mOnHeightChangedListener; |
| 1939 | } |
| 1940 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1941 | public void onChildAnimationFinished() { |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1942 | requestChildrenUpdate(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1945 | /** |
| 1946 | * See {@link AmbientState#setDimmed}. |
| 1947 | */ |
| 1948 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 1949 | mStackScrollAlgorithm.setDimmed(dimmed); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1950 | mAmbientState.setDimmed(dimmed); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 1951 | updatePadding(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1952 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1953 | mDimmedNeedsAnimation = true; |
| 1954 | mNeedsAnimation = true; |
| 1955 | } |
| 1956 | requestChildrenUpdate(); |
| 1957 | } |
| 1958 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1959 | public void setHideSensitive(boolean hideSensitive, boolean animate) { |
| 1960 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 1961 | int childCount = getChildCount(); |
| 1962 | for (int i = 0; i < childCount; i++) { |
| 1963 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 1964 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 1965 | } |
| 1966 | mAmbientState.setHideSensitive(hideSensitive); |
| 1967 | if (animate && mAnimationsEnabled) { |
| 1968 | mHideSensitiveNeedsAnimation = true; |
| 1969 | mNeedsAnimation = true; |
| 1970 | } |
| 1971 | requestChildrenUpdate(); |
| 1972 | } |
| 1973 | } |
| 1974 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1975 | /** |
| 1976 | * See {@link AmbientState#setActivatedChild}. |
| 1977 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 1978 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1979 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1980 | if (mAnimationsEnabled) { |
| 1981 | mActivateNeedsAnimation = true; |
| 1982 | mNeedsAnimation = true; |
| 1983 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1984 | requestChildrenUpdate(); |
| 1985 | } |
| 1986 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 1987 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1988 | return mAmbientState.getActivatedChild(); |
| 1989 | } |
| 1990 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1991 | private void applyCurrentState() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1992 | mCurrentStackScrollState.apply(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1993 | if (mListener != null) { |
| 1994 | mListener.onChildLocationsChanged(this); |
| 1995 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1998 | public void setSpeedBumpView(SpeedBumpView speedBumpView) { |
| 1999 | mSpeedBumpView = speedBumpView; |
| 2000 | addView(speedBumpView); |
| 2001 | } |
| 2002 | |
| 2003 | private void updateSpeedBump(boolean visible) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2004 | boolean notGoneBefore = mSpeedBumpView.getVisibility() != GONE; |
| 2005 | if (visible != notGoneBefore) { |
| 2006 | int newVisibility = visible ? VISIBLE : GONE; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2007 | mSpeedBumpView.setVisibility(newVisibility); |
| 2008 | if (visible) { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2009 | // Make invisible to ensure that the appear animation is played. |
| 2010 | mSpeedBumpView.setInvisible(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2011 | } else { |
Jorim Jaggi | 8b73006 | 2014-07-31 22:19:52 +0200 | [diff] [blame] | 2012 | // TODO: This doesn't really work, because the view is already set to GONE above. |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2013 | generateRemoveAnimation(mSpeedBumpView); |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2018 | public void goToFullShade(long delay) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2019 | updateSpeedBump(true /* visibility */); |
| 2020 | mDismissView.setInvisible(); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2021 | mEmptyShadeView.setInvisible(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2022 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2023 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2024 | mNeedsAnimation = true; |
| 2025 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2026 | } |
| 2027 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2028 | public void cancelExpandHelper() { |
| 2029 | mExpandHelper.cancel(); |
| 2030 | } |
| 2031 | |
| 2032 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 2033 | mIntrinsicPadding = intrinsicPadding; |
| 2034 | } |
| 2035 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2036 | public int getIntrinsicPadding() { |
| 2037 | return mIntrinsicPadding; |
| 2038 | } |
| 2039 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2040 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2041 | * @return the y position of the first notification |
| 2042 | */ |
| 2043 | public float getNotificationsTopY() { |
| 2044 | return mTopPadding + getTranslationY(); |
| 2045 | } |
| 2046 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 2047 | @Override |
| 2048 | public boolean shouldDelayChildPressedState() { |
| 2049 | return true; |
| 2050 | } |
| 2051 | |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 2052 | public void setScrimAlpha(float progress) { |
Jorim Jaggi | 5ad92c5 | 2014-07-28 21:07:32 +0200 | [diff] [blame] | 2053 | if (progress != mAmbientState.getScrimAmount()) { |
| 2054 | mAmbientState.setScrimAmount(progress); |
| 2055 | requestChildrenUpdate(); |
| 2056 | } |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2059 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2060 | * See {@link AmbientState#setDark}. |
| 2061 | */ |
| 2062 | public void setDark(boolean dark, boolean animate) { |
| 2063 | mAmbientState.setDark(dark); |
| 2064 | if (animate && mAnimationsEnabled) { |
| 2065 | mDarkNeedsAnimation = true; |
| 2066 | mNeedsAnimation = true; |
| 2067 | } |
| 2068 | requestChildrenUpdate(); |
| 2069 | } |
| 2070 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2071 | public void setDismissView(DismissView dismissView) { |
| 2072 | mDismissView = dismissView; |
| 2073 | addView(mDismissView); |
| 2074 | } |
| 2075 | |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2076 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
| 2077 | mEmptyShadeView = emptyShadeView; |
| 2078 | addView(mEmptyShadeView); |
| 2079 | } |
| 2080 | |
| 2081 | public void updateEmptyShadeView(boolean visible) { |
| 2082 | int oldVisibility = mEmptyShadeView.willBeGone() ? GONE : mEmptyShadeView.getVisibility(); |
| 2083 | int newVisibility = visible ? VISIBLE : GONE; |
| 2084 | if (oldVisibility != newVisibility) { |
| 2085 | if (oldVisibility == GONE) { |
| 2086 | if (mEmptyShadeView.willBeGone()) { |
| 2087 | mEmptyShadeView.cancelAnimation(); |
| 2088 | } else { |
| 2089 | mEmptyShadeView.setInvisible(); |
| 2090 | mEmptyShadeView.setVisibility(newVisibility); |
| 2091 | } |
| 2092 | mEmptyShadeView.setWillBeGone(false); |
| 2093 | updateContentHeight(); |
| 2094 | } else { |
| 2095 | mEmptyShadeView.setWillBeGone(true); |
| 2096 | mEmptyShadeView.performVisibilityAnimation(false, new Runnable() { |
| 2097 | @Override |
| 2098 | public void run() { |
| 2099 | mEmptyShadeView.setVisibility(GONE); |
| 2100 | mEmptyShadeView.setWillBeGone(false); |
| 2101 | updateContentHeight(); |
| 2102 | } |
| 2103 | }); |
| 2104 | } |
| 2105 | } |
| 2106 | } |
| 2107 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2108 | public void updateDismissView(boolean visible) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2109 | int oldVisibility = mDismissView.willBeGone() ? GONE : mDismissView.getVisibility(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2110 | int newVisibility = visible ? VISIBLE : GONE; |
| 2111 | if (oldVisibility != newVisibility) { |
| 2112 | if (oldVisibility == GONE) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2113 | if (mDismissView.willBeGone()) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2114 | mDismissView.cancelAnimation(); |
| 2115 | } else { |
| 2116 | mDismissView.setInvisible(); |
| 2117 | mDismissView.setVisibility(newVisibility); |
| 2118 | } |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2119 | mDismissView.setWillBeGone(false); |
| 2120 | updateContentHeight(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2121 | } else { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2122 | mDismissView.setWillBeGone(true); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2123 | mDismissView.performVisibilityAnimation(false, new Runnable() { |
| 2124 | @Override |
| 2125 | public void run() { |
| 2126 | mDismissView.setVisibility(GONE); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2127 | mDismissView.setWillBeGone(false); |
| 2128 | updateContentHeight(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2129 | } |
| 2130 | }); |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 2136 | mDismissAllInProgress = dismissAllInProgress; |
| 2137 | } |
| 2138 | |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2139 | public boolean isDismissViewNotGone() { |
| 2140 | return mDismissView.getVisibility() != View.GONE && !mDismissView.willBeGone(); |
| 2141 | } |
| 2142 | |
| 2143 | public boolean isDismissViewVisible() { |
| 2144 | return mDismissView.isVisible(); |
| 2145 | } |
| 2146 | |
| 2147 | public int getDismissViewHeight() { |
| 2148 | return mDismissView.getHeight() + mPaddingBetweenElementsNormal; |
| 2149 | } |
| 2150 | |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 2151 | public float getBottomMostNotificationBottom() { |
| 2152 | final int count = getChildCount(); |
| 2153 | float max = 0; |
| 2154 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 2155 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 2156 | if (child.getVisibility() == GONE) { |
| 2157 | continue; |
| 2158 | } |
| 2159 | float bottom = child.getTranslationY() + child.getActualHeight(); |
| 2160 | if (bottom > max) { |
| 2161 | max = bottom; |
| 2162 | } |
| 2163 | } |
| 2164 | return max + getTranslationY(); |
| 2165 | } |
| 2166 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2167 | /** |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 2168 | * @param qsMinHeight The minimum height of the quick settings including padding |
| 2169 | * See {@link StackScrollAlgorithm#updateIsSmallScreen}. |
| 2170 | */ |
| 2171 | public void updateIsSmallScreen(int qsMinHeight) { |
| 2172 | mStackScrollAlgorithm.updateIsSmallScreen(mMaxLayoutHeight - qsMinHeight); |
| 2173 | } |
| 2174 | |
| 2175 | /** |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2176 | * A listener that is notified when some child locations might have changed. |
| 2177 | */ |
| 2178 | public interface OnChildLocationsChangedListener { |
| 2179 | public void onChildLocationsChanged(NotificationStackScrollLayout stackScrollLayout); |
| 2180 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2181 | |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2182 | /** |
| 2183 | * A listener that gets notified when the overscroll at the top has changed. |
| 2184 | */ |
| 2185 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2186 | |
| 2187 | /** |
| 2188 | * Notifies a listener that the overscroll has changed. |
| 2189 | * |
| 2190 | * @param amount the amount of overscroll, in pixels |
| 2191 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 2192 | * unrubberbanded motion to directly expand overscroll view (e.g expand |
| 2193 | * QS) |
| 2194 | */ |
| 2195 | public void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2196 | |
| 2197 | /** |
| 2198 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 2199 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 2200 | * |
| 2201 | * @param velocity The velocity that the Scroller had when over flinging |
| 2202 | * @param open Should the fling open or close the overscroll view. |
| 2203 | */ |
| 2204 | public void flingTopOverscroll(float velocity, boolean open); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2205 | } |
| 2206 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2207 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2208 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2209 | static AnimationFilter[] FILTERS = new AnimationFilter[] { |
| 2210 | |
| 2211 | // ANIMATION_TYPE_ADD |
| 2212 | new AnimationFilter() |
| 2213 | .animateAlpha() |
| 2214 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2215 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2216 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2217 | .animateZ() |
| 2218 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2219 | |
| 2220 | // ANIMATION_TYPE_REMOVE |
| 2221 | new AnimationFilter() |
| 2222 | .animateAlpha() |
| 2223 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2224 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2225 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2226 | .animateZ() |
| 2227 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2228 | |
| 2229 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 2230 | new AnimationFilter() |
| 2231 | .animateAlpha() |
| 2232 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2233 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2234 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2235 | .animateZ() |
| 2236 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2237 | |
| 2238 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 2239 | new AnimationFilter() |
| 2240 | .animateAlpha() |
| 2241 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2242 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2243 | .animateY() |
| 2244 | .animateDimmed() |
| 2245 | .animateScale() |
| 2246 | .animateZ(), |
| 2247 | |
| 2248 | // ANIMATION_TYPE_START_DRAG |
| 2249 | new AnimationFilter() |
| 2250 | .animateAlpha(), |
| 2251 | |
| 2252 | // ANIMATION_TYPE_SNAP_BACK |
| 2253 | new AnimationFilter() |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2254 | .animateAlpha() |
| 2255 | .animateHeight(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2256 | |
| 2257 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 2258 | new AnimationFilter() |
| 2259 | .animateScale() |
| 2260 | .animateAlpha(), |
| 2261 | |
| 2262 | // ANIMATION_TYPE_DIMMED |
| 2263 | new AnimationFilter() |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 2264 | .animateY() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2265 | .animateScale() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2266 | .animateDimmed(), |
| 2267 | |
| 2268 | // ANIMATION_TYPE_CHANGE_POSITION |
| 2269 | new AnimationFilter() |
| 2270 | .animateAlpha() |
| 2271 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2272 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2273 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2274 | .animateZ(), |
| 2275 | |
| 2276 | // ANIMATION_TYPE_DARK |
| 2277 | new AnimationFilter() |
| 2278 | .animateDark(), |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2279 | |
| 2280 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 2281 | new AnimationFilter() |
| 2282 | .animateAlpha() |
| 2283 | .animateHeight() |
| 2284 | .animateTopInset() |
| 2285 | .animateY() |
| 2286 | .animateDimmed() |
| 2287 | .animateScale() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2288 | .animateZ() |
| 2289 | .hasDelays(), |
| 2290 | |
| 2291 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 2292 | new AnimationFilter() |
| 2293 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2294 | |
| 2295 | // ANIMATION_TYPE_VIEW_RESIZE |
| 2296 | new AnimationFilter() |
| 2297 | .animateAlpha() |
| 2298 | .animateHeight() |
| 2299 | .animateTopInset() |
| 2300 | .animateY() |
| 2301 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2302 | }; |
| 2303 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2304 | static int[] LENGTHS = new int[] { |
| 2305 | |
| 2306 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2307 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2308 | |
| 2309 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2310 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2311 | |
| 2312 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 2313 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 2314 | |
| 2315 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 2316 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 2317 | |
| 2318 | // ANIMATION_TYPE_START_DRAG |
| 2319 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 2320 | |
| 2321 | // ANIMATION_TYPE_SNAP_BACK |
| 2322 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 2323 | |
| 2324 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 2325 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 2326 | |
| 2327 | // ANIMATION_TYPE_DIMMED |
| 2328 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2329 | |
| 2330 | // ANIMATION_TYPE_CHANGE_POSITION |
| 2331 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2332 | |
| 2333 | // ANIMATION_TYPE_DARK |
| 2334 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2335 | |
| 2336 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 2337 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2338 | |
| 2339 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 2340 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2341 | |
| 2342 | // ANIMATION_TYPE_VIEW_RESIZE |
| 2343 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2344 | }; |
| 2345 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2346 | static final int ANIMATION_TYPE_ADD = 0; |
| 2347 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 2348 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 2349 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
| 2350 | static final int ANIMATION_TYPE_START_DRAG = 4; |
| 2351 | static final int ANIMATION_TYPE_SNAP_BACK = 5; |
| 2352 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6; |
| 2353 | static final int ANIMATION_TYPE_DIMMED = 7; |
| 2354 | static final int ANIMATION_TYPE_CHANGE_POSITION = 8; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2355 | static final int ANIMATION_TYPE_DARK = 9; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2356 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2357 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2358 | static final int ANIMATION_TYPE_VIEW_RESIZE = 12; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2359 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2360 | final long eventStartTime; |
| 2361 | final View changingView; |
| 2362 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2363 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2364 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2365 | View viewAfterChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2366 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2367 | AnimationEvent(View view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2368 | this(view, type, LENGTHS[type]); |
| 2369 | } |
| 2370 | |
| 2371 | AnimationEvent(View view, int type, long length) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2372 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
| 2373 | changingView = view; |
| 2374 | animationType = type; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2375 | filter = FILTERS[type]; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2376 | this.length = length; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Combines the length of several animation events into a single value. |
| 2381 | * |
| 2382 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2383 | * @return The combined length. Depending on the event types, this might be the maximum of |
| 2384 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2385 | */ |
| 2386 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 2387 | long length = 0; |
| 2388 | int size = events.size(); |
| 2389 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2390 | AnimationEvent event = events.get(i); |
| 2391 | length = Math.max(length, event.length); |
| 2392 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 2393 | return event.length; |
| 2394 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 2395 | } |
| 2396 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2400 | } |