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