blob: 2495d2253abb88c3fd3681ebeacf60925fbf0a03 [file] [log] [blame]
Daniel Sandler50a53132012-10-24 15:02:27 -04001/*
2 * Copyright (C) 2012 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
Daniel Sandler08d05e32012-08-08 16:39:54 -040017package com.android.systemui.statusbar.phone;
18
Jorim Jaggi1d480692014-05-20 19:41:58 +020019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040021import android.animation.ObjectAnimator;
Jorim Jaggi1d480692014-05-20 19:41:58 +020022import android.animation.ValueAnimator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040023import android.content.Context;
Selim Cinekb84a1072014-05-15 19:10:18 +020024import android.content.res.Configuration;
Daniel Sandler08d05e32012-08-08 16:39:54 -040025import android.content.res.Resources;
Selim Cinek48ff9b42016-11-09 19:31:51 -080026import android.os.SystemClock;
Selim Cinekd95ca7c2017-07-26 12:20:38 -070027import android.os.VibrationEffect;
Daniel Sandler08d05e32012-08-08 16:39:54 -040028import android.util.AttributeSet;
John Spurlockcd686b52013-06-05 10:13:46 -040029import android.util.Log;
Jun Mukaide750b42015-10-01 18:35:33 +090030import android.view.InputDevice;
Daniel Sandler08d05e32012-08-08 16:39:54 -040031import android.view.MotionEvent;
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -070032import android.view.VelocityTracker;
Adrian Roos8d4e99f2017-05-25 18:03:58 -070033import android.view.View;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010034import android.view.ViewConfiguration;
Jorim Jaggi0a27be82014-06-11 03:22:39 +020035import android.view.ViewTreeObserver;
Jorim Jaggi90129582014-06-02 14:44:49 +020036import android.view.animation.Interpolator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040037import android.widget.FrameLayout;
38
Chris Wren27a52fa2017-02-01 14:21:43 -050039import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050040import com.android.internal.util.LatencyTracker;
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +020041import com.android.systemui.DejankUtils;
Matthew Nge2b4d792018-03-09 13:42:18 -080042import com.android.systemui.Dependency;
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +020043import com.android.systemui.Interpolators;
Daniel Sandler08d05e32012-08-08 16:39:54 -040044import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070045import com.android.systemui.classifier.FalsingManager;
John Spurlock813552c2014-09-19 08:30:21 -040046import com.android.systemui.doze.DozeLog;
Beverly8fdb5332019-02-04 14:29:49 -050047import com.android.systemui.plugins.statusbar.StatusBarStateController;
Jorim Jaggi1d480692014-05-20 19:41:58 +020048import com.android.systemui.statusbar.FlingAnimationUtils;
Jorim Jaggi90129582014-06-02 14:44:49 +020049import com.android.systemui.statusbar.StatusBarState;
Beverly8fdb5332019-02-04 14:29:49 -050050import com.android.systemui.statusbar.SysuiStatusBarStateController;
Matthew Ng5c0592e2018-03-08 14:51:36 -080051import com.android.systemui.statusbar.VibratorHelper;
Jason Monk1fd3fc32018-08-14 17:20:09 -040052import com.android.systemui.statusbar.policy.KeyguardMonitor;
Daniel Sandler08d05e32012-08-08 16:39:54 -040053
John Spurlockde84f0e2013-06-12 12:41:00 -040054import java.io.FileDescriptor;
55import java.io.PrintWriter;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080056import java.util.function.BiConsumer;
John Spurlockde84f0e2013-06-12 12:41:00 -040057
Selim Cinek4c6969a2014-05-26 19:22:17 +020058public abstract class PanelView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040059 public static final boolean DEBUG = PanelBar.DEBUG;
Daniel Sandler08d05e32012-08-08 16:39:54 -040060 public static final String TAG = PanelView.class.getSimpleName();
Selim Cinek48ff9b42016-11-09 19:31:51 -080061 private static final int INITIAL_OPENING_PEEK_DURATION = 200;
62 private static final int PEEK_ANIMATION_DURATION = 360;
Selim Cinek2627d722018-01-19 12:16:49 -080063 private static final int NO_FIXED_DURATION = -1;
Selim Cinek48ff9b42016-11-09 19:31:51 -080064 private long mDownTime;
65 private float mMinExpandHeight;
Chris Wren27a52fa2017-02-01 14:21:43 -050066 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinekbe2c4432017-05-30 12:11:09 -070067 private boolean mPanelUpdateWhenAnimatorEnds;
Selim Cinekf6559f82017-08-16 14:49:10 -070068 private boolean mVibrateOnOpening;
Selim Cinek2627d722018-01-19 12:16:49 -080069 protected boolean mLaunchingNotification;
70 private int mFixedDuration = NO_FIXED_DURATION;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080071 private BiConsumer<Float, Boolean> mExpansionListener;
Selim Cinek173f2d02015-04-29 15:36:56 -070072
John Spurlock97642182013-07-29 17:58:39 -040073 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040074 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040075 }
76
Jason Monk2a6ea9c2017-01-26 11:14:51 -050077 protected StatusBar mStatusBar;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090078 protected HeadsUpManagerPhone mHeadsUpManager;
Selim Cinek684a4422015-04-15 16:18:39 -070079
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040080 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020081 private float mHintDistance;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010082 private float mInitialOffsetOnTouch;
Selim Cinek79d79c42015-05-21 16:14:45 -070083 private boolean mCollapsedAndHeadsUpOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040084 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020085 protected float mExpandedHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +020086 private boolean mPanelClosedOnDown;
87 private boolean mHasLayoutedSinceDown;
88 private float mUpdateFlingVelocity;
89 private boolean mUpdateFlingOnLayout;
Jorim Jaggib7a33032014-08-20 16:21:36 +020090 private boolean mPeekTouching;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040091 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040092 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020093 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020094 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040095 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020096 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020097 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020098 private boolean mOverExpandedBeforeFling;
Selim Cinek19c8c702014-08-25 22:09:19 +020099 private boolean mTouchAboveFalsingThreshold;
100 private int mUnlockFalsingThreshold;
Selim Cinekab1dc952014-10-30 20:20:29 +0100101 private boolean mTouchStartedInEmptyArea;
Selim Cinek547a06b2014-11-27 14:06:04 +0100102 private boolean mMotionAborted;
Selim Cinek9db71052015-04-24 18:54:30 -0700103 private boolean mUpwardsWhenTresholdReached;
Selim Cinek173f2d02015-04-29 15:36:56 -0700104 private boolean mAnimatingOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400105
Jorim Jaggi1d480692014-05-20 19:41:58 +0200106 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400107 private ObjectAnimator mPeekAnimator;
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -0700108 private final VelocityTracker mVelocityTracker = VelocityTracker.obtain();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200109 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800110 private FlingAnimationUtils mFlingAnimationUtilsClosing;
Selim Cinek2411f762016-12-28 17:05:08 +0100111 private FlingAnimationUtils mFlingAnimationUtilsDismissing;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700112 private FalsingManager mFalsingManager;
Matthew Ng5c0592e2018-03-08 14:51:36 -0800113 private final VibratorHelper mVibratorHelper;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400114
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200115 /**
116 * Whether an instant expand request is currently pending and we are just waiting for layout.
117 */
118 private boolean mInstantExpanding;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700119 private boolean mAnimateAfterExpanding;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200120
Daniel Sandler08d05e32012-08-08 16:39:54 -0400121 PanelBar mBar;
122
Daniel Sandler50508132012-08-16 14:10:53 -0400123 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200124 private float mInitialTouchY;
125 private float mInitialTouchX;
Jorim Jaggid41083a2014-09-12 02:54:40 +0200126 private boolean mTouchDisabled;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400127
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800128 /**
129 * Whether or not the PanelView can be expanded or collapsed with a drag.
130 */
131 private boolean mNotificationsDragEnabled;
132
Jorim Jaggi90129582014-06-02 14:44:49 +0200133 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200134 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +0200135
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700136 /**
137 * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
138 */
139 private float mNextCollapseSpeedUpFactor = 1.0f;
140
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700141 protected boolean mExpanding;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200142 private boolean mGestureWaitForTouchSlop;
Selim Cinek9db71052015-04-24 18:54:30 -0700143 private boolean mIgnoreXTouchSlop;
Jorim Jaggie05256e2016-09-08 14:58:20 -0700144 private boolean mExpandLatencyTracking;
Jason Monk1fd3fc32018-08-14 17:20:09 -0400145 protected final KeyguardMonitor mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
Beverly8fdb5332019-02-04 14:29:49 -0500146 protected final SysuiStatusBarStateController mStatusBarStateController =
147 (SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200148
Selim Cinek1685e632014-04-08 02:27:49 +0200149 protected void onExpandingFinished() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200150 mBar.onExpandingFinished();
Selim Cinek1685e632014-04-08 02:27:49 +0200151 }
152
153 protected void onExpandingStarted() {
154 }
155
Jorim Jaggib472b3472014-06-30 19:56:24 +0200156 private void notifyExpandingStarted() {
157 if (!mExpanding) {
158 mExpanding = true;
159 onExpandingStarted();
160 }
161 }
162
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700163 protected final void notifyExpandingFinished() {
Selim Cinekb0e4f9e2015-11-02 13:42:58 -0800164 endClosing();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200165 if (mExpanding) {
166 mExpanding = false;
167 onExpandingFinished();
168 }
169 }
170
Selim Cinek48ff9b42016-11-09 19:31:51 -0800171 private void runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished) {
172 mPeekHeight = peekHeight;
John Spurlock97642182013-07-29 17:58:39 -0400173 if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200174 if (mHeightAnimator != null) {
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400175 return;
176 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800177 if (mPeekAnimator != null) {
178 mPeekAnimator.cancel();
179 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200180 mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800181 .setDuration(duration);
Selim Cinekc18010f2016-01-20 13:41:30 -0800182 mPeekAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200183 mPeekAnimator.addListener(new AnimatorListenerAdapter() {
184 private boolean mCancelled;
185
186 @Override
187 public void onAnimationCancel(Animator animation) {
188 mCancelled = true;
189 }
190
191 @Override
192 public void onAnimationEnd(Animator animation) {
193 mPeekAnimator = null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800194 if (!mCancelled && collapseWhenFinished) {
Selim Cineka0f5c762015-06-22 14:44:46 -0400195 postOnAnimation(mPostCollapseRunnable);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200196 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800197
Jorim Jaggib472b3472014-06-30 19:56:24 +0200198 }
199 });
200 notifyExpandingStarted();
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400201 mPeekAnimator.start();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200202 mJustPeeked = true;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400203 }
204
Daniel Sandler08d05e32012-08-08 16:39:54 -0400205 public PanelView(Context context, AttributeSet attrs) {
206 super(context, attrs);
Selim Cinek593ee202016-12-28 15:01:16 +0100207 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f /* maxLengthSeconds */,
208 0.6f /* speedUpFactor */);
209 mFlingAnimationUtilsClosing = new FlingAnimationUtils(context, 0.5f /* maxLengthSeconds */,
210 0.6f /* speedUpFactor */);
Selim Cinek2411f762016-12-28 17:05:08 +0100211 mFlingAnimationUtilsDismissing = new FlingAnimationUtils(context,
212 0.5f /* maxLengthSeconds */, 0.2f /* speedUpFactor */, 0.6f /* x2 */,
213 0.84f /* y2 */);
Jorim Jaggi90129582014-06-02 14:44:49 +0200214 mBounceInterpolator = new BounceInterpolator();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700215 mFalsingManager = FalsingManager.getInstance(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800216 mNotificationsDragEnabled =
217 getResources().getBoolean(R.bool.config_enableNotificationShadeDrag);
Matthew Nge2b4d792018-03-09 13:42:18 -0800218 mVibratorHelper = Dependency.get(VibratorHelper.class);
Selim Cinekf6559f82017-08-16 14:49:10 -0700219 mVibrateOnOpening = mContext.getResources().getBoolean(
220 R.bool.config_vibrateOnIconAnimation);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400221 }
222
Jorim Jaggi069cd032014-05-15 03:09:01 +0200223 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400224 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100225 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
226 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200227 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200228 mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400229 }
230
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700231 private void addMovement(MotionEvent event) {
232 // Add movement to velocity tracker using raw screen X and Y coordinates instead
233 // of window coordinates because the window frame may be moving at the same time.
234 float deltaX = event.getRawX() - event.getX();
235 float deltaY = event.getRawY() - event.getY();
236 event.offsetLocation(deltaX, deltaY);
237 mVelocityTracker.addMovement(event);
238 event.offsetLocation(-deltaX, -deltaY);
239 }
240
Jason Monke59dc402018-08-16 12:05:01 -0400241 public void setTouchAndAnimationDisabled(boolean disabled) {
Jorim Jaggid41083a2014-09-12 02:54:40 +0200242 mTouchDisabled = disabled;
Selim Cinek48a92a52017-05-02 20:02:30 -0700243 if (mTouchDisabled) {
244 cancelHeightAnimator();
245 if (mTracking) {
246 onTrackingStopped(true /* expanded */);
247 }
Selim Cinekeede5d72017-05-22 17:09:55 -0700248 notifyExpandingFinished();
Selim Cinek3127daf02016-07-22 18:04:23 -0700249 }
Jorim Jaggid41083a2014-09-12 02:54:40 +0200250 }
251
Jorim Jaggie05256e2016-09-08 14:58:20 -0700252 public void startExpandLatencyTracking() {
253 if (LatencyTracker.isEnabled(mContext)) {
254 LatencyTracker.getInstance(mContext).onActionStart(
255 LatencyTracker.ACTION_EXPAND_PANEL);
256 mExpandLatencyTracking = true;
257 }
258 }
259
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400260 @Override
261 public boolean onTouchEvent(MotionEvent event) {
lumark44f9e5a2018-05-07 21:49:35 +0800262 if (mInstantExpanding
263 || (mTouchDisabled && event.getActionMasked() != MotionEvent.ACTION_CANCEL)
Selim Cinek547a06b2014-11-27 14:06:04 +0100264 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200265 return false;
266 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100267
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800268 // If dragging should not expand the notifications shade, then return false.
269 if (!mNotificationsDragEnabled) {
270 if (mTracking) {
271 // Turn off tracking if it's on or the shade can get stuck in the down position.
272 onTrackingStopped(true /* expand */);
273 }
274 return false;
275 }
276
Jun Mukaicf9933c2015-07-08 17:34:26 -0700277 // On expanding, single mouse click expands the panel instead of dragging.
Jun Mukaic99243a2015-10-15 02:59:57 -0700278 if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
Jun Mukaicf9933c2015-07-08 17:34:26 -0700279 if (event.getAction() == MotionEvent.ACTION_UP) {
280 expand(true);
281 }
282 return true;
283 }
284
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100285 /*
286 * We capture touch events here and update the expand height here in case according to
287 * the users fingers. This also handles multi-touch.
288 *
Chris Wren5d53df42015-06-26 11:26:03 -0400289 * If the user just clicks shortly, we show a quick peek of the shade.
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100290 *
291 * Flinging is also enabled in order to open or close the shade.
292 */
293
294 int pointerIndex = event.findPointerIndex(mTrackingPointer);
295 if (pointerIndex < 0) {
296 pointerIndex = 0;
297 mTrackingPointer = event.getPointerId(pointerIndex);
298 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200299 final float x = event.getX(pointerIndex);
Selim Cinek547a06b2014-11-27 14:06:04 +0100300 final float y = event.getY(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100301
Jorim Jaggib472b3472014-06-30 19:56:24 +0200302 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek684a4422015-04-15 16:18:39 -0700303 mGestureWaitForTouchSlop = isFullyCollapsed() || hasConflictingGestures();
304 mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200305 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200306
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100307 switch (event.getActionMasked()) {
308 case MotionEvent.ACTION_DOWN:
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700309 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200310 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800311 mMinExpandHeight = 0.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700312 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek31094df2014-08-14 19:28:15 +0200313 mHasLayoutedSinceDown = false;
314 mUpdateFlingOnLayout = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100315 mMotionAborted = false;
Jorim Jaggib7a33032014-08-20 16:21:36 +0200316 mPeekTouching = mPanelClosedOnDown;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800317 mDownTime = SystemClock.uptimeMillis();
Selim Cinek19c8c702014-08-25 22:09:19 +0200318 mTouchAboveFalsingThreshold = false;
Selim Cinek79d79c42015-05-21 16:14:45 -0700319 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
320 && mHeadsUpManager.hasPinnedHeadsUp();
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700321 addMovement(event);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800322 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
323 || mPeekAnimator != null) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200324 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800325 || mPeekAnimator != null;
Selim Cinekd18b86f2017-06-21 09:44:52 -0700326 cancelHeightAnimator();
327 cancelPeek();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200328 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200329 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800330 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()
331 && !mStatusBar.isBouncerShowing()) {
Evan Laird404a85c2018-02-28 15:31:29 -0500332 startOpening(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100333 }
334 break;
335
336 case MotionEvent.ACTION_POINTER_UP:
337 final int upPointer = event.getPointerId(event.getActionIndex());
338 if (mTrackingPointer == upPointer) {
339 // gesture is ongoing, find a new pointer to track
340 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
341 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200342 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100343 mTrackingPointer = event.getPointerId(newIndex);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700344 startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100345 }
346 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100347 case MotionEvent.ACTION_POINTER_DOWN:
Jason Monk1fd3fc32018-08-14 17:20:09 -0400348 if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100349 mMotionAborted = true;
350 endMotionEvent(event, x, y, true /* forceCancel */);
351 return false;
352 }
353 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100354 case MotionEvent.ACTION_MOVE:
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700355 addMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200356 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200357
358 // If the panel was collapsed when touching, we only need to check for the
359 // y-component of the gesture, as we have no conflicting horizontal gesture.
360 if (Math.abs(h) > mTouchSlop
361 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800362 || mIgnoreXTouchSlop)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200363 mTouchSlopExceeded = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700364 if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
Jorim Jaggi0b1528a2014-10-28 22:47:46 +0100365 if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700366 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200367 h = 0;
368 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200369 cancelHeightAnimator();
Jorim Jaggi90129582014-06-02 14:44:49 +0200370 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200371 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200372 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800373 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200374 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200375 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100376 mPeekAnimator.cancel();
377 }
378 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800379 } else if (mPeekAnimator == null && mJustPeeked) {
380 // The initial peek has finished, but we haven't dragged as far yet, lets
381 // speed it up by starting at the peek height.
382 mInitialOffsetOnTouch = mExpandedHeight;
383 mInitialTouchY = y;
384 mMinExpandHeight = mExpandedHeight;
385 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100386 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800387 newHeight = Math.max(newHeight, mMinExpandHeight);
Selim Cinek29ed3c92014-09-23 20:44:35 +0200388 if (-h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200389 mTouchAboveFalsingThreshold = true;
Selim Cinek9db71052015-04-24 18:54:30 -0700390 mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
Selim Cinek19c8c702014-08-25 22:09:19 +0200391 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800392 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
393 !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000394 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100395 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100396 break;
397
398 case MotionEvent.ACTION_UP:
399 case MotionEvent.ACTION_CANCEL:
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700400 addMovement(event);
Selim Cinek547a06b2014-11-27 14:06:04 +0100401 endMotionEvent(event, x, y, false /* forceCancel */);
402 break;
403 }
Selim Cinek9db71052015-04-24 18:54:30 -0700404 return !mGestureWaitForTouchSlop || mTracking;
405 }
406
Evan Laird404a85c2018-02-28 15:31:29 -0500407 private void startOpening(MotionEvent event) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800408 runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
409 false /* collapseWhenFinished */);
410 notifyBarPanelExpansionChanged();
Matthew Ng5c0592e2018-03-08 14:51:36 -0800411 if (mVibrateOnOpening) {
412 mVibratorHelper.vibrate(VibrationEffect.EFFECT_TICK);
Selim Cinekf6559f82017-08-16 14:49:10 -0700413 }
Evan Laird404a85c2018-02-28 15:31:29 -0500414
415 //TODO: keyguard opens QS a different way; log that too?
416
417 // Log the position of the swipe that opened the panel
418 float width = mStatusBar.getDisplayWidth();
419 float height = mStatusBar.getDisplayHeight();
420 int rot = mStatusBar.getRotation();
421
422 mLockscreenGestureLogger.writeAtFractionalPosition(MetricsEvent.ACTION_PANEL_VIEW_EXPAND,
423 (int) (event.getX() / width * 100),
424 (int) (event.getY() / height * 100),
425 rot);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800426 }
427
428 protected abstract float getOpeningHeight();
429
Selim Cinek9db71052015-04-24 18:54:30 -0700430 /**
431 * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
432 * horizontal direction
433 */
434 private boolean isDirectionUpwards(float x, float y) {
435 float xDiff = x - mInitialTouchX;
436 float yDiff = y - mInitialTouchY;
437 if (yDiff >= 0) {
438 return false;
439 }
440 return Math.abs(yDiff) >= Math.abs(xDiff);
Selim Cinek547a06b2014-11-27 14:06:04 +0100441 }
442
Chris Wren621933f2017-06-14 15:59:03 -0400443 protected void startExpandingFromPeek() {
444 mStatusBar.handlePeekToExpandTransistion();
445 }
446
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700447 protected void startExpandMotion(float newX, float newY, boolean startTracking,
448 float expandedHeight) {
449 mInitialOffsetOnTouch = expandedHeight;
450 mInitialTouchY = newY;
451 mInitialTouchX = newX;
452 if (startTracking) {
453 mTouchSlopExceeded = true;
Selim Cinekdef35a82016-05-03 15:52:51 -0700454 setExpandedHeight(mInitialOffsetOnTouch);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700455 onTrackingStarted();
456 }
457 }
458
Selim Cinek547a06b2014-11-27 14:06:04 +0100459 private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
460 mTrackingPointer = -1;
461 if ((mTracking && mTouchSlopExceeded)
462 || Math.abs(x - mInitialTouchX) > mTouchSlop
463 || Math.abs(y - mInitialTouchY) > mTouchSlop
464 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
465 || forceCancel) {
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -0700466 mVelocityTracker.computeCurrentVelocity(1000);
467 float vel = mVelocityTracker.getYVelocity();
468 float vectorVel = (float) Math.hypot(
469 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
470
Selim Cinek9db71052015-04-24 18:54:30 -0700471 boolean expand = flingExpands(vel, vectorVel, x, y)
Selim Cinek547a06b2014-11-27 14:06:04 +0100472 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
473 || forceCancel;
Selim Cinek547a06b2014-11-27 14:06:04 +0100474 DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
475 mStatusBar.isFalsingThresholdNeeded(),
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700476 mStatusBar.isWakeUpComingFromTouch());
Christoph Studerb0183992014-12-22 21:02:26 +0100477 // Log collapse gesture if on lock screen.
Jason Monk1fd3fc32018-08-14 17:20:09 -0400478 if (!expand && mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
Christoph Studerb0183992014-12-22 21:02:26 +0100479 float displayDensity = mStatusBar.getDisplayDensity();
480 int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
481 int velocityDp = (int) Math.abs(vel / displayDensity);
Chris Wren27a52fa2017-02-01 14:21:43 -0500482 mLockscreenGestureLogger.write(
483 MetricsEvent.ACTION_LS_UNLOCK,
Christoph Studerb0183992014-12-22 21:02:26 +0100484 heightDp, velocityDp);
485 }
Selim Cinek9db71052015-04-24 18:54:30 -0700486 fling(vel, expand, isFalseTouch(x, y));
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700487 onTrackingStopped(expand);
Selim Cinek547a06b2014-11-27 14:06:04 +0100488 mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
489 if (mUpdateFlingOnLayout) {
490 mUpdateFlingVelocity = vel;
491 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800492 } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking
Jason Monk1fd3fc32018-08-14 17:20:09 -0400493 && !mStatusBar.isBouncerShowing() && !mKeyguardMonitor.isKeyguardFadingAway()) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800494 long timePassed = SystemClock.uptimeMillis() - mDownTime;
495 if (timePassed < ViewConfiguration.getLongPressTimeout()) {
496 // Lets show the user that he can actually expand the panel
497 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
498 } else {
499 // We need to collapse the panel since we peeked to the small height.
500 postOnAnimation(mPostCollapseRunnable);
501 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800502 } else if (!mStatusBar.isBouncerShowing()) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100503 boolean expands = onEmptySpaceClick(mInitialTouchX);
504 onTrackingStopped(expands);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100505 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100506
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -0700507 mVelocityTracker.clear();
Selim Cinek547a06b2014-11-27 14:06:04 +0100508 mPeekTouching = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100509 }
510
Selim Cinekd5ab6452016-12-08 16:34:00 -0800511 protected float getCurrentExpandVelocity() {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800512 mVelocityTracker.computeCurrentVelocity(1000);
513 return mVelocityTracker.getYVelocity();
514 }
515
Selim Cinek29ed3c92014-09-23 20:44:35 +0200516 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700517 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek29ed3c92014-09-23 20:44:35 +0200518 return (int) (mUnlockFalsingThreshold * factor);
519 }
520
Selim Cinek4c6969a2014-05-26 19:22:17 +0200521 protected abstract boolean hasConflictingGestures();
522
Selim Cinek9db71052015-04-24 18:54:30 -0700523 protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
524
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200525 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200526 mTracking = false;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800527 mBar.onTrackingStopped(expand);
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700528 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200529 }
530
531 protected void onTrackingStarted() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200532 endClosing();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200533 mTracking = true;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800534 mBar.onTrackingStarted();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200535 notifyExpandingStarted();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700536 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200537 }
538
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100539 @Override
540 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700541 if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled
Selim Cinek547a06b2014-11-27 14:06:04 +0100542 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200543 return false;
544 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100545
546 /*
Chris Wren5d53df42015-06-26 11:26:03 -0400547 * If the user drags anywhere inside the panel we intercept it if the movement is
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100548 * upwards. This allows closing the shade from anywhere inside the panel.
549 *
550 * We only do this if the current content is scrolled to the bottom,
551 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
552 * possible.
553 */
554 int pointerIndex = event.findPointerIndex(mTrackingPointer);
555 if (pointerIndex < 0) {
556 pointerIndex = 0;
557 mTrackingPointer = event.getPointerId(pointerIndex);
558 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200559 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100560 final float y = event.getY(pointerIndex);
561 boolean scrolledToBottom = isScrolledToBottom();
562
563 switch (event.getActionMasked()) {
564 case MotionEvent.ACTION_DOWN:
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200565 mStatusBar.userActivity();
Selim Cinek173f2d02015-04-29 15:36:56 -0700566 mAnimatingOnDown = mHeightAnimator != null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800567 mMinExpandHeight = 0.0f;
568 mDownTime = SystemClock.uptimeMillis();
569 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
570 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200571 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200572 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200573 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200574 return true;
575 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100576 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200577 mInitialTouchX = x;
Selim Cinekab1dc952014-10-30 20:20:29 +0100578 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
Jorim Jaggi90129582014-06-02 14:44:49 +0200579 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200580 mJustPeeked = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100581 mMotionAborted = false;
Selim Cinek684a4422015-04-15 16:18:39 -0700582 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700583 mCollapsedAndHeadsUpOnDown = false;
Selim Cinek31094df2014-08-14 19:28:15 +0200584 mHasLayoutedSinceDown = false;
585 mUpdateFlingOnLayout = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200586 mTouchAboveFalsingThreshold = false;
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700587 addMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100588 break;
589 case MotionEvent.ACTION_POINTER_UP:
590 final int upPointer = event.getPointerId(event.getActionIndex());
591 if (mTrackingPointer == upPointer) {
592 // gesture is ongoing, find a new pointer to track
593 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
594 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200595 mInitialTouchX = event.getX(newIndex);
596 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100597 }
598 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100599 case MotionEvent.ACTION_POINTER_DOWN:
Jason Monk1fd3fc32018-08-14 17:20:09 -0400600 if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100601 mMotionAborted = true;
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -0700602 mVelocityTracker.clear();
Selim Cinek547a06b2014-11-27 14:06:04 +0100603 }
604 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100605 case MotionEvent.ACTION_MOVE:
606 final float h = y - mInitialTouchY;
Siarhei Vishniakouc8548552018-10-24 23:14:55 -0700607 addMovement(event);
Selim Cinek173f2d02015-04-29 15:36:56 -0700608 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
609 float hAbs = Math.abs(h);
610 if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
611 && hAbs > Math.abs(x - mInitialTouchX)) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200612 cancelHeightAnimator();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700613 startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100614 return true;
615 }
616 }
617 break;
Selim Cinek31094df2014-08-14 19:28:15 +0200618 case MotionEvent.ACTION_CANCEL:
619 case MotionEvent.ACTION_UP:
Siarhei Vishniakoubf33d192018-08-28 14:42:23 -0700620 mVelocityTracker.clear();
Selim Cinek31094df2014-08-14 19:28:15 +0200621 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100622 }
623 return false;
624 }
625
Selim Cinekab1dc952014-10-30 20:20:29 +0100626 /**
627 * @return Whether a pair of coordinates are inside the visible view content bounds.
628 */
629 protected abstract boolean isInContentBounds(float x, float y);
630
Selim Cinek831941f2015-06-17 15:09:30 -0700631 protected void cancelHeightAnimator() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200632 if (mHeightAnimator != null) {
Selim Cinekd18b86f2017-06-21 09:44:52 -0700633 if (mHeightAnimator.isRunning()) {
634 mPanelUpdateWhenAnimatorEnds = false;
635 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200636 mHeightAnimator.cancel();
637 }
638 endClosing();
639 }
640
641 private void endClosing() {
642 if (mClosing) {
643 mClosing = false;
644 onClosingFinished();
645 }
646 }
647
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100648 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200649 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100650 }
651
652 protected float getContentHeight() {
653 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400654 }
655
Daniel Sandler08d05e32012-08-08 16:39:54 -0400656 @Override
657 protected void onFinishInflate() {
658 super.onFinishInflate();
659 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400660 }
661
Jorim Jaggi069cd032014-05-15 03:09:01 +0200662 @Override
663 protected void onConfigurationChanged(Configuration newConfig) {
664 super.onConfigurationChanged(newConfig);
665 loadDimens();
Jorim Jaggi069cd032014-05-15 03:09:01 +0200666 }
667
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200668 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200669 * @param vel the current vertical velocity of the motion
670 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200671 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200672 */
Selim Cinek9db71052015-04-24 18:54:30 -0700673 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
Dave Mankoffc88d6222018-10-25 15:31:20 -0400674 if (mFalsingManager.isUnlockingDisabled()) {
675 return true;
676 }
677
Selim Cinek9db71052015-04-24 18:54:30 -0700678 if (isFalseTouch(x, y)) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200679 return true;
680 }
Jorim Jaggib7240132014-06-30 01:39:07 +0200681 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200682 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200683 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200684 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400685 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200686 }
687
Selim Cinek9db71052015-04-24 18:54:30 -0700688 /**
689 * @param x the final x-coordinate when the finger was lifted
690 * @param y the final y-coordinate when the finger was lifted
691 * @return whether this motion should be regarded as a false touch
692 */
693 private boolean isFalseTouch(float x, float y) {
694 if (!mStatusBar.isFalsingThresholdNeeded()) {
695 return false;
696 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700697 if (mFalsingManager.isClassiferEnabled()) {
698 return mFalsingManager.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700699 }
Selim Cinek9db71052015-04-24 18:54:30 -0700700 if (!mTouchAboveFalsingThreshold) {
701 return true;
702 }
703 if (mUpwardsWhenTresholdReached) {
704 return false;
705 }
706 return !isDirectionUpwards(x, y);
Selim Cinek5386fb32014-09-03 16:37:36 +0200707 }
708
Jorim Jaggi1d480692014-05-20 19:41:58 +0200709 protected void fling(float vel, boolean expand) {
Selim Cinek9db71052015-04-24 18:54:30 -0700710 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700711 }
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200712
Selim Cinek9db71052015-04-24 18:54:30 -0700713 protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
714 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
715 }
716
717 protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
718 boolean expandBecauseOfFalsing) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700719 cancelPeek();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800720 float target = expand ? getMaxPanelHeight() : 0;
Jorim Jaggi3e02adb2015-05-13 17:50:26 -0700721 if (!expand) {
722 mClosing = true;
723 }
Selim Cinek9db71052015-04-24 18:54:30 -0700724 flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700725 }
726
727 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700728 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200729 // Hack to make the expand transition look nice when clear all button is visible - we make
730 // the animation only to the last notification, and then jump to the maximum panel height so
731 // clear all just fades in and the decelerating motion is towards the last notification.
732 final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
733 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
734 && !isClearAllVisible();
735 if (clearAllExpandHack) {
736 target = getMaxPanelHeight() - getClearAllHeight();
737 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200738 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200739 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200740 return;
741 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200742 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200743 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200744 if (expand) {
Selim Cinek61190fb2016-12-07 12:16:45 -0800745 if (expandBecauseOfFalsing && vel < 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200746 vel = 0;
747 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200748 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
Jorim Jaggi6626f542016-08-22 13:08:44 -0700749 if (vel == 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200750 animator.setDuration(350);
751 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200752 } else {
Selim Cinek2411f762016-12-28 17:05:08 +0100753 if (shouldUseDismissingAnimation()) {
Selim Cinekdf5501b2017-04-14 20:01:27 -0700754 if (vel == 0) {
755 animator.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
756 long duration = (long) (200 + mExpandedHeight / getHeight() * 100);
757 animator.setDuration(duration);
758 } else {
759 mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
760 getHeight());
761 }
Selim Cinek2411f762016-12-28 17:05:08 +0100762 } else {
763 mFlingAnimationUtilsClosing
764 .apply(animator, mExpandedHeight, target, vel, getHeight());
765 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200766
767 // Make it shorter if we run a canned animation
768 if (vel == 0) {
Selim Cinek593ee202016-12-28 15:01:16 +0100769 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200770 }
Selim Cinek2627d722018-01-19 12:16:49 -0800771 if (mFixedDuration != NO_FIXED_DURATION) {
772 animator.setDuration(mFixedDuration);
773 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200774 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200775 animator.addListener(new AnimatorListenerAdapter() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200776 private boolean mCancelled;
777
778 @Override
779 public void onAnimationCancel(Animator animation) {
780 mCancelled = true;
781 }
782
Jorim Jaggi1d480692014-05-20 19:41:58 +0200783 @Override
784 public void onAnimationEnd(Animator animation) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200785 if (clearAllExpandHack && !mCancelled) {
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200786 setExpandedHeightInternal(getMaxPanelHeight());
787 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700788 setAnimator(null);
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200789 if (!mCancelled) {
790 notifyExpandingFinished();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200791 }
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700792 notifyBarPanelExpansionChanged();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200793 }
794 });
Selim Cinekbe2c4432017-05-30 12:11:09 -0700795 setAnimator(animator);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200796 animator.start();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400797 }
798
Selim Cinek2411f762016-12-28 17:05:08 +0100799 protected abstract boolean shouldUseDismissingAnimation();
800
Daniel Sandler08d05e32012-08-08 16:39:54 -0400801 @Override
802 protected void onAttachedToWindow() {
803 super.onAttachedToWindow();
Daniel Sandler978f8532012-08-15 15:48:16 -0400804 mViewName = getResources().getResourceName(getId());
805 }
806
807 public String getName() {
808 return mViewName;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400809 }
810
Daniel Sandler08d05e32012-08-08 16:39:54 -0400811 public void setExpandedHeight(float height) {
John Spurlock97642182013-07-29 17:58:39 -0400812 if (DEBUG) logf("setExpandedHeight(%.1f)", height);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200813 setExpandedHeightInternal(height + getOverExpansionPixels());
Daniel Sandler08d05e32012-08-08 16:39:54 -0400814 }
815
Daniel Sandler50508132012-08-16 14:10:53 -0400816 @Override
Lucas Dupin60661a62018-04-12 10:50:13 -0700817 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Daniel Sandler50508132012-08-16 14:10:53 -0400818 super.onLayout(changed, left, top, right, bottom);
Selim Cinek5fbc6322016-01-15 17:17:58 -0800819 mStatusBar.onPanelLaidOut();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100820 requestPanelHeightUpdate();
Selim Cinek31094df2014-08-14 19:28:15 +0200821 mHasLayoutedSinceDown = true;
822 if (mUpdateFlingOnLayout) {
823 abortAnimations();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700824 fling(mUpdateFlingVelocity, true /* expands */);
Selim Cinek31094df2014-08-14 19:28:15 +0200825 mUpdateFlingOnLayout = false;
826 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100827 }
828
829 protected void requestPanelHeightUpdate() {
830 float currentMaxPanelHeight = getMaxPanelHeight();
831
Selim Cinekbe2c4432017-05-30 12:11:09 -0700832 if (isFullyCollapsed()) {
833 return;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100834 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700835
836 if (currentMaxPanelHeight == mExpandedHeight) {
837 return;
838 }
839
840 if (mPeekAnimator != null || mPeekTouching) {
841 return;
842 }
843
844 if (mTracking && !isTrackingBlocked()) {
845 return;
846 }
847
848 if (mHeightAnimator != null) {
849 mPanelUpdateWhenAnimatorEnds = true;
850 return;
851 }
852
853 setExpandedHeight(currentMaxPanelHeight);
Daniel Sandler50508132012-08-16 14:10:53 -0400854 }
855
Daniel Sandler08d05e32012-08-08 16:39:54 -0400856 public void setExpandedHeightInternal(float h) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700857 if (mExpandLatencyTracking && h != 0f) {
858 DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance(mContext).onActionEnd(
859 LatencyTracker.ACTION_EXPAND_PANEL));
860 mExpandLatencyTracking = false;
861 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200862 float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
863 if (mHeightAnimator == null) {
864 float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
865 if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
866 setOverExpansion(overExpansionPixels, true /* isPixels */);
867 }
868 mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
869 } else {
870 mExpandedHeight = h;
871 if (mOverExpandedBeforeFling) {
872 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
873 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100874 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400875
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +0200876 // If we are closing the panel and we are almost there due to a slow decelerating
877 // interpolator, abort the animation.
878 if (mExpandedHeight < 1f && mExpandedHeight != 0f && mClosing) {
879 mExpandedHeight = 0f;
880 if (mHeightAnimator != null) {
881 mHeightAnimator.end();
882 }
883 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800884 mExpandedFraction = Math.min(1f,
885 fhWithoutOverExpansion == 0 ? 0 : mExpandedHeight / fhWithoutOverExpansion);
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +0100886 onHeightUpdated(mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200887 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400888 }
889
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200890 /**
891 * @return true if the panel tracking should be temporarily blocked; this is used when a
892 * conflicting gesture (opening QS) is happening
893 */
894 protected abstract boolean isTrackingBlocked();
895
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200896 protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
Selim Cinek24120a52014-05-26 10:05:42 +0200897
Jorim Jaggi90129582014-06-02 14:44:49 +0200898 protected abstract void onHeightUpdated(float expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100899
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200900 protected abstract float getOverExpansionAmount();
901
902 protected abstract float getOverExpansionPixels();
903
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100904 /**
905 * This returns the maximum height of the panel. Children should override this if their
906 * desired height is not the full height.
907 *
908 * @return the default implementation simply returns the maximum height.
909 */
Selim Cinek31094df2014-08-14 19:28:15 +0200910 protected abstract int getMaxPanelHeight();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400911
912 public void setExpandedFraction(float frac) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100913 setExpandedHeight(getMaxPanelHeight() * frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400914 }
915
916 public float getExpandedHeight() {
917 return mExpandedHeight;
918 }
919
920 public float getExpandedFraction() {
921 return mExpandedFraction;
922 }
923
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700924 public boolean isFullyExpanded() {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100925 return mExpandedHeight >= getMaxPanelHeight();
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700926 }
927
928 public boolean isFullyCollapsed() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800929 return mExpandedFraction <= 0.0f;
Daniel Sandler67eab792012-10-02 17:08:23 -0400930 }
931
932 public boolean isCollapsing() {
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800933 return mClosing || mLaunchingNotification;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700934 }
935
John Spurlocka4b70af2013-08-17 14:05:49 -0400936 public boolean isTracking() {
937 return mTracking;
938 }
939
Daniel Sandler08d05e32012-08-08 16:39:54 -0400940 public void setBar(PanelBar panelBar) {
941 mBar = panelBar;
942 }
943
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700944 public void collapse(boolean delayed, float speedUpFactor) {
John Spurlock97642182013-07-29 17:58:39 -0400945 if (DEBUG) logf("collapse: " + this);
Selim Cinek9bb05632016-12-15 14:14:29 -0800946 if (canPanelBeCollapsed()) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200947 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200948 notifyExpandingStarted();
Jorim Jaggi3b866be2015-06-30 11:31:10 -0700949
950 // Set after notifyExpandingStarted, as notifyExpandingStarted resets the closing state.
951 mClosing = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200952 if (delayed) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700953 mNextCollapseSpeedUpFactor = speedUpFactor;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200954 postDelayed(mFlingCollapseRunnable, 120);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200955 } else {
Selim Cinek9db71052015-04-24 18:54:30 -0700956 fling(0, false /* expand */, speedUpFactor, false /* expandBecauseOfFalsing */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200957 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400958 }
959 }
960
Selim Cinek9bb05632016-12-15 14:14:29 -0800961 public boolean canPanelBeCollapsed() {
962 return !isFullyCollapsed() && !mTracking && !mClosing;
963 }
964
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200965 private final Runnable mFlingCollapseRunnable = new Runnable() {
966 @Override
967 public void run() {
Selim Cinek9db71052015-04-24 18:54:30 -0700968 fling(0, false /* expand */, mNextCollapseSpeedUpFactor,
969 false /* expandBecauseOfFalsing */);
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200970 }
971 };
972
John Spurlock97642182013-07-29 17:58:39 -0400973 public void cancelPeek() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800974 boolean cancelled = false;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200975 if (mPeekAnimator != null) {
Selim Cinek529c5322016-04-06 20:03:45 -0700976 cancelled = true;
John Spurlock97642182013-07-29 17:58:39 -0400977 mPeekAnimator.cancel();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400978 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200979
Selim Cinek529c5322016-04-06 20:03:45 -0700980 if (cancelled) {
981 // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
982 // notify mBar that we might have closed ourselves.
983 notifyBarPanelExpansionChanged();
984 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400985 }
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500986
Oren Blasberg8d3fea12015-07-10 14:21:44 -0700987 public void expand(final boolean animate) {
988 if (!isFullyCollapsed() && !isCollapsing()) {
989 return;
990 }
991
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200992 mInstantExpanding = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700993 mAnimateAfterExpanding = animate;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200994 mUpdateFlingOnLayout = false;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200995 abortAnimations();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200996 cancelPeek();
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200997 if (mTracking) {
998 onTrackingStopped(true /* expands */); // The panel is expanded after this call.
Jorim Jaggie62d5892014-09-02 16:31:19 +0200999 }
1000 if (mExpanding) {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001001 notifyExpandingFinished();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001002 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001003 notifyBarPanelExpansionChanged();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001004
1005 // Wait for window manager to pickup the change, so we know the maximum height of the panel
1006 // then.
1007 getViewTreeObserver().addOnGlobalLayoutListener(
1008 new ViewTreeObserver.OnGlobalLayoutListener() {
1009 @Override
1010 public void onGlobalLayout() {
Jorim Jaggic5804af2016-04-25 18:51:16 -07001011 if (!mInstantExpanding) {
1012 getViewTreeObserver().removeOnGlobalLayoutListener(this);
1013 return;
1014 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001015 if (mStatusBar.getStatusBarWindow().getHeight()
1016 != mStatusBar.getStatusBarHeight()) {
1017 getViewTreeObserver().removeOnGlobalLayoutListener(this);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001018 if (mAnimateAfterExpanding) {
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001019 notifyExpandingStarted();
1020 fling(0, true /* expand */);
1021 } else {
1022 setExpandedFraction(1f);
1023 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001024 mInstantExpanding = false;
1025 }
1026 }
1027 });
1028
1029 // Make sure a layout really happens.
1030 requestLayout();
1031 }
1032
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001033 public void instantCollapse() {
1034 abortAnimations();
1035 setExpandedFraction(0f);
1036 if (mExpanding) {
1037 notifyExpandingFinished();
1038 }
Jorim Jaggic5804af2016-04-25 18:51:16 -07001039 if (mInstantExpanding) {
1040 mInstantExpanding = false;
1041 notifyBarPanelExpansionChanged();
1042 }
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001043 }
1044
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001045 private void abortAnimations() {
1046 cancelPeek();
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001047 cancelHeightAnimator();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001048 removeCallbacks(mPostCollapseRunnable);
1049 removeCallbacks(mFlingCollapseRunnable);
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001050 }
1051
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001052 protected void onClosingFinished() {
1053 mBar.onClosingFinished();
1054 }
1055
1056
Jorim Jaggi90129582014-06-02 14:44:49 +02001057 protected void startUnlockHintAnimation() {
1058
1059 // We don't need to hint the user if an animation is already running or the user is changing
1060 // the expansion.
1061 if (mHeightAnimator != null || mTracking) {
1062 return;
1063 }
1064 cancelPeek();
Jorim Jaggib472b3472014-06-30 19:56:24 +02001065 notifyExpandingStarted();
Lucas Dupin60661a62018-04-12 10:50:13 -07001066 startUnlockHintAnimationPhase1(() -> {
1067 notifyExpandingFinished();
1068 onUnlockHintFinished();
1069 mHintAnimationRunning = false;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001070 });
Selim Cinekec29d342017-05-05 18:31:49 -07001071 onUnlockHintStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001072 mHintAnimationRunning = true;
Jorim Jaggi90129582014-06-02 14:44:49 +02001073 }
1074
Selim Cinekec29d342017-05-05 18:31:49 -07001075 protected void onUnlockHintFinished() {
1076 mStatusBar.onHintFinished();
1077 }
1078
1079 protected void onUnlockHintStarted() {
1080 mStatusBar.onUnlockHintStarted();
1081 }
1082
Lucas Dupinbc9aac12018-03-04 20:18:15 -08001083 public boolean isUnlockHintRunning() {
1084 return mHintAnimationRunning;
1085 }
1086
Jorim Jaggi90129582014-06-02 14:44:49 +02001087 /**
1088 * Phase 1: Move everything upwards.
1089 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001090 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001091 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1092 ValueAnimator animator = createHeightAnimator(target);
1093 animator.setDuration(250);
Selim Cinekc18010f2016-01-20 13:41:30 -08001094 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi90129582014-06-02 14:44:49 +02001095 animator.addListener(new AnimatorListenerAdapter() {
1096 private boolean mCancelled;
1097
1098 @Override
1099 public void onAnimationCancel(Animator animation) {
1100 mCancelled = true;
1101 }
1102
1103 @Override
1104 public void onAnimationEnd(Animator animation) {
1105 if (mCancelled) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001106 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001107 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +02001108 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001109 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +02001110 }
1111 }
1112 });
1113 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001114 setAnimator(animator);
Adrian Roos8d4e99f2017-05-25 18:03:58 -07001115
1116 View[] viewsToAnimate = {
1117 mKeyguardBottomArea.getIndicationArea(),
1118 mStatusBar.getAmbientIndicationContainer()};
1119 for (View v : viewsToAnimate) {
1120 if (v == null) {
1121 continue;
1122 }
1123 v.animate()
1124 .translationY(-mHintDistance)
1125 .setDuration(250)
1126 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
1127 .withEndAction(() -> v.animate()
1128 .translationY(0)
1129 .setDuration(450)
1130 .setInterpolator(mBounceInterpolator)
1131 .start())
1132 .start();
1133 }
Jorim Jaggi90129582014-06-02 14:44:49 +02001134 }
1135
Selim Cinekbe2c4432017-05-30 12:11:09 -07001136 private void setAnimator(ValueAnimator animator) {
1137 mHeightAnimator = animator;
1138 if (animator == null && mPanelUpdateWhenAnimatorEnds) {
1139 mPanelUpdateWhenAnimatorEnds = false;
1140 requestPanelHeightUpdate();
1141 }
1142 }
1143
Jorim Jaggi90129582014-06-02 14:44:49 +02001144 /**
1145 * Phase 2: Bounce down.
1146 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001147 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001148 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1149 animator.setDuration(450);
1150 animator.setInterpolator(mBounceInterpolator);
1151 animator.addListener(new AnimatorListenerAdapter() {
1152 @Override
1153 public void onAnimationEnd(Animator animation) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001154 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001155 onAnimationFinished.run();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001156 notifyBarPanelExpansionChanged();
Jorim Jaggi90129582014-06-02 14:44:49 +02001157 }
1158 });
1159 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001160 setAnimator(animator);
Jorim Jaggi90129582014-06-02 14:44:49 +02001161 }
1162
1163 private ValueAnimator createHeightAnimator(float targetHeight) {
1164 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1165 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1166 @Override
1167 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001168 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +02001169 }
1170 });
1171 return animator;
1172 }
1173
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001174 protected void notifyBarPanelExpansionChanged() {
Evan Laird0de26b02019-03-01 15:12:50 -05001175 if (mBar != null) {
1176 mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
1177 || mPeekAnimator != null || mInstantExpanding
1178 || isPanelVisibleBecauseOfHeadsUp() || mTracking || mHeightAnimator != null);
1179 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -08001180 if (mExpansionListener != null) {
1181 mExpansionListener.accept(mExpandedFraction, mTracking);
1182 }
1183 }
1184
1185 public void setExpansionListener(BiConsumer<Float, Boolean> consumer) {
1186 mExpansionListener = consumer;
Jorim Jaggib472b3472014-06-30 19:56:24 +02001187 }
1188
Selim Cinek0fccc722015-07-29 17:04:36 -07001189 protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1190
Jorim Jaggi90129582014-06-02 14:44:49 +02001191 /**
1192 * Gets called when the user performs a click anywhere in the empty area of the panel.
1193 *
1194 * @return whether the panel will be expanded after the action performed by this method
1195 */
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001196 protected boolean onEmptySpaceClick(float x) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001197 if (mHintAnimationRunning) {
1198 return true;
1199 }
Selim Cinek6746c282015-04-21 19:58:31 -07001200 return onMiddleClicked();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001201 }
1202
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001203 protected final Runnable mPostCollapseRunnable = new Runnable() {
Jorim Jaggi488b7922014-08-05 21:12:02 +02001204 @Override
1205 public void run() {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -07001206 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
Jorim Jaggi488b7922014-08-05 21:12:02 +02001207 }
1208 };
Jorim Jaggi488b7922014-08-05 21:12:02 +02001209
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001210 protected abstract boolean onMiddleClicked();
Jorim Jaggi90129582014-06-02 14:44:49 +02001211
Jorim Jaggid7912d22014-09-30 17:38:19 +02001212 protected abstract boolean isDozing();
1213
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001214 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +02001215 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001216 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001217 + "]",
1218 this.getClass().getSimpleName(),
1219 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001220 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001221 mClosing?"T":"f",
1222 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001223 mJustPeeked?"T":"f",
1224 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001225 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1226 mTouchDisabled?"T":"f"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001227 ));
1228 }
Selim Cinek3c4635c2014-05-29 02:12:47 +02001229
Lucas Dupinee63c372018-08-03 11:58:24 -07001230 public abstract void resetViews(boolean animate);
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001231
1232 protected abstract float getPeekHeight();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02001233 /**
1234 * @return whether "Clear all" button will be visible when the panel is fully expanded
1235 */
1236 protected abstract boolean fullyExpandedClearAllVisible();
1237
1238 protected abstract boolean isClearAllVisible();
1239
1240 /**
1241 * @return the height of the clear all button, in pixels
1242 */
1243 protected abstract int getClearAllHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001244
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001245 public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001246 mHeadsUpManager = headsUpManager;
1247 }
Selim Cinek2627d722018-01-19 12:16:49 -08001248
1249 public void setLaunchingNotification(boolean launchingNotification) {
1250 mLaunchingNotification = launchingNotification;
1251 }
1252
1253 public void collapseWithDuration(int animationDuration) {
1254 mFixedDuration = animationDuration;
1255 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
1256 mFixedDuration = NO_FIXED_DURATION;
1257 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001258}