blob: 2fc22caa6c0541c5cec4303845387d7c2984d84f [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 Cinek4f6c85f2017-12-04 16:42:33 +010026import android.database.ContentObserver;
Selim Cinekf6559f82017-08-16 14:49:10 -070027import android.os.AsyncTask;
Selim Cinek4f6c85f2017-12-04 16:42:33 +010028import android.os.Handler;
Selim Cinek48ff9b42016-11-09 19:31:51 -080029import android.os.SystemClock;
Selim Cinek4f6c85f2017-12-04 16:42:33 +010030import android.os.UserHandle;
Selim Cinekd95ca7c2017-07-26 12:20:38 -070031import android.os.VibrationEffect;
32import android.os.Vibrator;
Selim Cinek4f6c85f2017-12-04 16:42:33 +010033import android.provider.Settings;
Daniel Sandler08d05e32012-08-08 16:39:54 -040034import android.util.AttributeSet;
John Spurlockcd686b52013-06-05 10:13:46 -040035import android.util.Log;
Jun Mukaide750b42015-10-01 18:35:33 +090036import android.view.InputDevice;
Daniel Sandler08d05e32012-08-08 16:39:54 -040037import android.view.MotionEvent;
Adrian Roos8d4e99f2017-05-25 18:03:58 -070038import android.view.View;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010039import android.view.ViewConfiguration;
Jorim Jaggi0a27be82014-06-11 03:22:39 +020040import android.view.ViewTreeObserver;
Jorim Jaggi90129582014-06-02 14:44:49 +020041import android.view.animation.Interpolator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040042import android.widget.FrameLayout;
43
Chris Wren27a52fa2017-02-01 14:21:43 -050044import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050045import com.android.internal.util.LatencyTracker;
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +020046import com.android.systemui.DejankUtils;
47import com.android.systemui.Interpolators;
Daniel Sandler08d05e32012-08-08 16:39:54 -040048import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070049import com.android.systemui.classifier.FalsingManager;
John Spurlock813552c2014-09-19 08:30:21 -040050import com.android.systemui.doze.DozeLog;
Jorim Jaggi1d480692014-05-20 19:41:58 +020051import com.android.systemui.statusbar.FlingAnimationUtils;
Jorim Jaggi90129582014-06-02 14:44:49 +020052import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070053import com.android.systemui.statusbar.policy.HeadsUpManager;
Daniel Sandler08d05e32012-08-08 16:39:54 -040054
John Spurlockde84f0e2013-06-12 12:41:00 -040055import java.io.FileDescriptor;
56import java.io.PrintWriter;
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;
63 private long mDownTime;
64 private float mMinExpandHeight;
Chris Wren27a52fa2017-02-01 14:21:43 -050065 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinekbe2c4432017-05-30 12:11:09 -070066 private boolean mPanelUpdateWhenAnimatorEnds;
Selim Cinekf6559f82017-08-16 14:49:10 -070067 private boolean mVibrateOnOpening;
Selim Cinek4f6c85f2017-12-04 16:42:33 +010068 private boolean mVibrationEnabled;
Selim Cinek173f2d02015-04-29 15:36:56 -070069
John Spurlock97642182013-07-29 17:58:39 -040070 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040071 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040072 }
73
Jason Monk2a6ea9c2017-01-26 11:14:51 -050074 protected StatusBar mStatusBar;
Selim Cinek684a4422015-04-15 16:18:39 -070075 protected HeadsUpManager mHeadsUpManager;
76
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040077 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020078 private float mHintDistance;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010079 private float mInitialOffsetOnTouch;
Selim Cinek79d79c42015-05-21 16:14:45 -070080 private boolean mCollapsedAndHeadsUpOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040081 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020082 protected float mExpandedHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +020083 private boolean mPanelClosedOnDown;
84 private boolean mHasLayoutedSinceDown;
85 private float mUpdateFlingVelocity;
86 private boolean mUpdateFlingOnLayout;
Jorim Jaggib7a33032014-08-20 16:21:36 +020087 private boolean mPeekTouching;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040088 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040089 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020090 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020091 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040092 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020093 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020094 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020095 private boolean mOverExpandedBeforeFling;
Selim Cinek19c8c702014-08-25 22:09:19 +020096 private boolean mTouchAboveFalsingThreshold;
97 private int mUnlockFalsingThreshold;
Selim Cinekab1dc952014-10-30 20:20:29 +010098 private boolean mTouchStartedInEmptyArea;
Selim Cinek547a06b2014-11-27 14:06:04 +010099 private boolean mMotionAborted;
Selim Cinek9db71052015-04-24 18:54:30 -0700100 private boolean mUpwardsWhenTresholdReached;
Selim Cinek173f2d02015-04-29 15:36:56 -0700101 private boolean mAnimatingOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400102
Jorim Jaggi1d480692014-05-20 19:41:58 +0200103 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400104 private ObjectAnimator mPeekAnimator;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200105 private VelocityTrackerInterface mVelocityTracker;
Jorim Jaggi1d480692014-05-20 19:41:58 +0200106 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800107 private FlingAnimationUtils mFlingAnimationUtilsClosing;
Selim Cinek2411f762016-12-28 17:05:08 +0100108 private FlingAnimationUtils mFlingAnimationUtilsDismissing;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700109 private FalsingManager mFalsingManager;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700110 private final Vibrator mVibrator;
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100111 final private ContentObserver mVibrationObserver = new ContentObserver(Handler.getMain()) {
112 @Override
113 public void onChange(boolean selfChange) {
114 updateHapticFeedBackEnabled();
115 }
116 };
Daniel Sandler08d05e32012-08-08 16:39:54 -0400117
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200118 /**
119 * Whether an instant expand request is currently pending and we are just waiting for layout.
120 */
121 private boolean mInstantExpanding;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700122 private boolean mAnimateAfterExpanding;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200123
Daniel Sandler08d05e32012-08-08 16:39:54 -0400124 PanelBar mBar;
125
Daniel Sandler50508132012-08-16 14:10:53 -0400126 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200127 private float mInitialTouchY;
128 private float mInitialTouchX;
Jorim Jaggid41083a2014-09-12 02:54:40 +0200129 private boolean mTouchDisabled;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400130
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800131 /**
132 * Whether or not the PanelView can be expanded or collapsed with a drag.
133 */
134 private boolean mNotificationsDragEnabled;
135
Jorim Jaggi90129582014-06-02 14:44:49 +0200136 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200137 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +0200138
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700139 /**
140 * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
141 */
142 private float mNextCollapseSpeedUpFactor = 1.0f;
143
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700144 protected boolean mExpanding;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200145 private boolean mGestureWaitForTouchSlop;
Selim Cinek9db71052015-04-24 18:54:30 -0700146 private boolean mIgnoreXTouchSlop;
Jorim Jaggie05256e2016-09-08 14:58:20 -0700147 private boolean mExpandLatencyTracking;
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);
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700218 mVibrator = mContext.getSystemService(Vibrator.class);
Selim Cinekf6559f82017-08-16 14:49:10 -0700219 mVibrateOnOpening = mContext.getResources().getBoolean(
220 R.bool.config_vibrateOnIconAnimation);
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100221 mContext.getContentResolver().registerContentObserver(
222 Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED), true,
223 mVibrationObserver);
224 mVibrationObserver.onChange(false /* selfChange */);
225 }
226
227 public void updateHapticFeedBackEnabled() {
228 mVibrationEnabled = Settings.System.getIntForUser(mContext.getContentResolver(),
229 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400230 }
231
Jorim Jaggi069cd032014-05-15 03:09:01 +0200232 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400233 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100234 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
235 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200236 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200237 mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400238 }
239
240 private void trackMovement(MotionEvent event) {
241 // Add movement to velocity tracker using raw screen X and Y coordinates instead
242 // of window coordinates because the window frame may be moving at the same time.
243 float deltaX = event.getRawX() - event.getX();
244 float deltaY = event.getRawY() - event.getY();
245 event.offsetLocation(deltaX, deltaY);
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400246 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400247 event.offsetLocation(-deltaX, -deltaY);
248 }
249
Jorim Jaggid41083a2014-09-12 02:54:40 +0200250 public void setTouchDisabled(boolean disabled) {
251 mTouchDisabled = disabled;
Selim Cinek48a92a52017-05-02 20:02:30 -0700252 if (mTouchDisabled) {
253 cancelHeightAnimator();
254 if (mTracking) {
255 onTrackingStopped(true /* expanded */);
256 }
Selim Cinekeede5d72017-05-22 17:09:55 -0700257 notifyExpandingFinished();
Selim Cinek3127daf02016-07-22 18:04:23 -0700258 }
Jorim Jaggid41083a2014-09-12 02:54:40 +0200259 }
260
Jorim Jaggie05256e2016-09-08 14:58:20 -0700261 public void startExpandLatencyTracking() {
262 if (LatencyTracker.isEnabled(mContext)) {
263 LatencyTracker.getInstance(mContext).onActionStart(
264 LatencyTracker.ACTION_EXPAND_PANEL);
265 mExpandLatencyTracking = true;
266 }
267 }
268
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400269 @Override
270 public boolean onTouchEvent(MotionEvent event) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100271 if (mInstantExpanding || mTouchDisabled
272 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200273 return false;
274 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100275
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800276 // If dragging should not expand the notifications shade, then return false.
277 if (!mNotificationsDragEnabled) {
278 if (mTracking) {
279 // Turn off tracking if it's on or the shade can get stuck in the down position.
280 onTrackingStopped(true /* expand */);
281 }
282 return false;
283 }
284
Jun Mukaicf9933c2015-07-08 17:34:26 -0700285 // On expanding, single mouse click expands the panel instead of dragging.
Jun Mukaic99243a2015-10-15 02:59:57 -0700286 if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
Jun Mukaicf9933c2015-07-08 17:34:26 -0700287 if (event.getAction() == MotionEvent.ACTION_UP) {
288 expand(true);
289 }
290 return true;
291 }
292
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100293 /*
294 * We capture touch events here and update the expand height here in case according to
295 * the users fingers. This also handles multi-touch.
296 *
Chris Wren5d53df42015-06-26 11:26:03 -0400297 * If the user just clicks shortly, we show a quick peek of the shade.
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100298 *
299 * Flinging is also enabled in order to open or close the shade.
300 */
301
302 int pointerIndex = event.findPointerIndex(mTrackingPointer);
303 if (pointerIndex < 0) {
304 pointerIndex = 0;
305 mTrackingPointer = event.getPointerId(pointerIndex);
306 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200307 final float x = event.getX(pointerIndex);
Selim Cinek547a06b2014-11-27 14:06:04 +0100308 final float y = event.getY(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100309
Jorim Jaggib472b3472014-06-30 19:56:24 +0200310 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek684a4422015-04-15 16:18:39 -0700311 mGestureWaitForTouchSlop = isFullyCollapsed() || hasConflictingGestures();
312 mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200313 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200314
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100315 switch (event.getActionMasked()) {
316 case MotionEvent.ACTION_DOWN:
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700317 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200318 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800319 mMinExpandHeight = 0.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700320 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek31094df2014-08-14 19:28:15 +0200321 mHasLayoutedSinceDown = false;
322 mUpdateFlingOnLayout = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100323 mMotionAborted = false;
Jorim Jaggib7a33032014-08-20 16:21:36 +0200324 mPeekTouching = mPanelClosedOnDown;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800325 mDownTime = SystemClock.uptimeMillis();
Selim Cinek19c8c702014-08-25 22:09:19 +0200326 mTouchAboveFalsingThreshold = false;
Selim Cinek79d79c42015-05-21 16:14:45 -0700327 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
328 && mHeadsUpManager.hasPinnedHeadsUp();
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200329 if (mVelocityTracker == null) {
330 initVelocityTracker();
331 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100332 trackMovement(event);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800333 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
334 || mPeekAnimator != null) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200335 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800336 || mPeekAnimator != null;
Selim Cinekd18b86f2017-06-21 09:44:52 -0700337 cancelHeightAnimator();
338 cancelPeek();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200339 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200340 }
Selim Cinek79d79c42015-05-21 16:14:45 -0700341 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800342 startOpening();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100343 }
344 break;
345
346 case MotionEvent.ACTION_POINTER_UP:
347 final int upPointer = event.getPointerId(event.getActionIndex());
348 if (mTrackingPointer == upPointer) {
349 // gesture is ongoing, find a new pointer to track
350 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
351 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200352 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100353 mTrackingPointer = event.getPointerId(newIndex);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700354 startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100355 }
356 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100357 case MotionEvent.ACTION_POINTER_DOWN:
358 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
359 mMotionAborted = true;
360 endMotionEvent(event, x, y, true /* forceCancel */);
361 return false;
362 }
363 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100364 case MotionEvent.ACTION_MOVE:
Selim Cinekd5ab6452016-12-08 16:34:00 -0800365 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200366 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200367
368 // If the panel was collapsed when touching, we only need to check for the
369 // y-component of the gesture, as we have no conflicting horizontal gesture.
370 if (Math.abs(h) > mTouchSlop
371 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800372 || mIgnoreXTouchSlop)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200373 mTouchSlopExceeded = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700374 if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
Jorim Jaggi0b1528a2014-10-28 22:47:46 +0100375 if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700376 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200377 h = 0;
378 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200379 cancelHeightAnimator();
Jorim Jaggi90129582014-06-02 14:44:49 +0200380 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200381 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200382 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800383 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200384 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200385 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100386 mPeekAnimator.cancel();
387 }
388 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800389 } else if (mPeekAnimator == null && mJustPeeked) {
390 // The initial peek has finished, but we haven't dragged as far yet, lets
391 // speed it up by starting at the peek height.
392 mInitialOffsetOnTouch = mExpandedHeight;
393 mInitialTouchY = y;
394 mMinExpandHeight = mExpandedHeight;
395 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100396 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800397 newHeight = Math.max(newHeight, mMinExpandHeight);
Selim Cinek29ed3c92014-09-23 20:44:35 +0200398 if (-h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200399 mTouchAboveFalsingThreshold = true;
Selim Cinek9db71052015-04-24 18:54:30 -0700400 mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
Selim Cinek19c8c702014-08-25 22:09:19 +0200401 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800402 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
403 !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000404 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100405 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100406 break;
407
408 case MotionEvent.ACTION_UP:
409 case MotionEvent.ACTION_CANCEL:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100410 trackMovement(event);
Selim Cinek547a06b2014-11-27 14:06:04 +0100411 endMotionEvent(event, x, y, false /* forceCancel */);
412 break;
413 }
Selim Cinek9db71052015-04-24 18:54:30 -0700414 return !mGestureWaitForTouchSlop || mTracking;
415 }
416
Selim Cinek48ff9b42016-11-09 19:31:51 -0800417 private void startOpening() {;
418 runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
419 false /* collapseWhenFinished */);
420 notifyBarPanelExpansionChanged();
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100421 if (mVibrateOnOpening && mVibrationEnabled) {
Michael Wrightc330f7a2017-08-31 14:54:04 -0700422 AsyncTask.execute(() ->
423 mVibrator.vibrate(VibrationEffect.get(VibrationEffect.EFFECT_TICK, false)));
Selim Cinekf6559f82017-08-16 14:49:10 -0700424 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800425 }
426
427 protected abstract float getOpeningHeight();
428
Selim Cinek9db71052015-04-24 18:54:30 -0700429 /**
430 * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
431 * horizontal direction
432 */
433 private boolean isDirectionUpwards(float x, float y) {
434 float xDiff = x - mInitialTouchX;
435 float yDiff = y - mInitialTouchY;
436 if (yDiff >= 0) {
437 return false;
438 }
439 return Math.abs(yDiff) >= Math.abs(xDiff);
Selim Cinek547a06b2014-11-27 14:06:04 +0100440 }
441
Chris Wren621933f2017-06-14 15:59:03 -0400442 protected void startExpandingFromPeek() {
443 mStatusBar.handlePeekToExpandTransistion();
444 }
445
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700446 protected void startExpandMotion(float newX, float newY, boolean startTracking,
447 float expandedHeight) {
448 mInitialOffsetOnTouch = expandedHeight;
449 mInitialTouchY = newY;
450 mInitialTouchX = newX;
451 if (startTracking) {
452 mTouchSlopExceeded = true;
Selim Cinekdef35a82016-05-03 15:52:51 -0700453 setExpandedHeight(mInitialOffsetOnTouch);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700454 onTrackingStarted();
455 }
456 }
457
Selim Cinek547a06b2014-11-27 14:06:04 +0100458 private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
459 mTrackingPointer = -1;
460 if ((mTracking && mTouchSlopExceeded)
461 || Math.abs(x - mInitialTouchX) > mTouchSlop
462 || Math.abs(y - mInitialTouchY) > mTouchSlop
463 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
464 || forceCancel) {
465 float vel = 0f;
466 float vectorVel = 0f;
467 if (mVelocityTracker != null) {
468 mVelocityTracker.computeCurrentVelocity(1000);
469 vel = mVelocityTracker.getYVelocity();
470 vectorVel = (float) Math.hypot(
471 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
472 }
Selim Cinek9db71052015-04-24 18:54:30 -0700473 boolean expand = flingExpands(vel, vectorVel, x, y)
Selim Cinek547a06b2014-11-27 14:06:04 +0100474 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
475 || forceCancel;
Selim Cinek547a06b2014-11-27 14:06:04 +0100476 DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
477 mStatusBar.isFalsingThresholdNeeded(),
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700478 mStatusBar.isWakeUpComingFromTouch());
Christoph Studerb0183992014-12-22 21:02:26 +0100479 // Log collapse gesture if on lock screen.
480 if (!expand && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
481 float displayDensity = mStatusBar.getDisplayDensity();
482 int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
483 int velocityDp = (int) Math.abs(vel / displayDensity);
Chris Wren27a52fa2017-02-01 14:21:43 -0500484 mLockscreenGestureLogger.write(
485 MetricsEvent.ACTION_LS_UNLOCK,
Christoph Studerb0183992014-12-22 21:02:26 +0100486 heightDp, velocityDp);
487 }
Selim Cinek9db71052015-04-24 18:54:30 -0700488 fling(vel, expand, isFalseTouch(x, y));
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700489 onTrackingStopped(expand);
Selim Cinek547a06b2014-11-27 14:06:04 +0100490 mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
491 if (mUpdateFlingOnLayout) {
492 mUpdateFlingVelocity = vel;
493 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800494 } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking) {
495 long timePassed = SystemClock.uptimeMillis() - mDownTime;
496 if (timePassed < ViewConfiguration.getLongPressTimeout()) {
497 // Lets show the user that he can actually expand the panel
498 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
499 } else {
500 // We need to collapse the panel since we peeked to the small height.
501 postOnAnimation(mPostCollapseRunnable);
502 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100503 } else {
504 boolean expands = onEmptySpaceClick(mInitialTouchX);
505 onTrackingStopped(expands);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100506 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100507
508 if (mVelocityTracker != null) {
509 mVelocityTracker.recycle();
510 mVelocityTracker = null;
511 }
512 mPeekTouching = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100513 }
514
Selim Cinekd5ab6452016-12-08 16:34:00 -0800515 protected float getCurrentExpandVelocity() {
516 if (mVelocityTracker == null) {
517 return 0;
518 }
519 mVelocityTracker.computeCurrentVelocity(1000);
520 return mVelocityTracker.getYVelocity();
521 }
522
Selim Cinek29ed3c92014-09-23 20:44:35 +0200523 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700524 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek29ed3c92014-09-23 20:44:35 +0200525 return (int) (mUnlockFalsingThreshold * factor);
526 }
527
Selim Cinek4c6969a2014-05-26 19:22:17 +0200528 protected abstract boolean hasConflictingGestures();
529
Selim Cinek9db71052015-04-24 18:54:30 -0700530 protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
531
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200532 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200533 mTracking = false;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800534 mBar.onTrackingStopped(expand);
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700535 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200536 }
537
538 protected void onTrackingStarted() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200539 endClosing();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200540 mTracking = true;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800541 mBar.onTrackingStarted();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200542 notifyExpandingStarted();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700543 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200544 }
545
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100546 @Override
547 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700548 if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled
Selim Cinek547a06b2014-11-27 14:06:04 +0100549 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200550 return false;
551 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100552
553 /*
Chris Wren5d53df42015-06-26 11:26:03 -0400554 * If the user drags anywhere inside the panel we intercept it if the movement is
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100555 * upwards. This allows closing the shade from anywhere inside the panel.
556 *
557 * We only do this if the current content is scrolled to the bottom,
558 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
559 * possible.
560 */
561 int pointerIndex = event.findPointerIndex(mTrackingPointer);
562 if (pointerIndex < 0) {
563 pointerIndex = 0;
564 mTrackingPointer = event.getPointerId(pointerIndex);
565 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200566 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100567 final float y = event.getY(pointerIndex);
568 boolean scrolledToBottom = isScrolledToBottom();
569
570 switch (event.getActionMasked()) {
571 case MotionEvent.ACTION_DOWN:
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200572 mStatusBar.userActivity();
Selim Cinek173f2d02015-04-29 15:36:56 -0700573 mAnimatingOnDown = mHeightAnimator != null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800574 mMinExpandHeight = 0.0f;
575 mDownTime = SystemClock.uptimeMillis();
576 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
577 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200578 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200579 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200580 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200581 return true;
582 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100583 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200584 mInitialTouchX = x;
Selim Cinekab1dc952014-10-30 20:20:29 +0100585 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
Jorim Jaggi90129582014-06-02 14:44:49 +0200586 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200587 mJustPeeked = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100588 mMotionAborted = false;
Selim Cinek684a4422015-04-15 16:18:39 -0700589 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700590 mCollapsedAndHeadsUpOnDown = false;
Selim Cinek31094df2014-08-14 19:28:15 +0200591 mHasLayoutedSinceDown = false;
592 mUpdateFlingOnLayout = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200593 mTouchAboveFalsingThreshold = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100594 initVelocityTracker();
595 trackMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100596 break;
597 case MotionEvent.ACTION_POINTER_UP:
598 final int upPointer = event.getPointerId(event.getActionIndex());
599 if (mTrackingPointer == upPointer) {
600 // gesture is ongoing, find a new pointer to track
601 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
602 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200603 mInitialTouchX = event.getX(newIndex);
604 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100605 }
606 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100607 case MotionEvent.ACTION_POINTER_DOWN:
608 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
609 mMotionAborted = true;
610 if (mVelocityTracker != null) {
611 mVelocityTracker.recycle();
612 mVelocityTracker = null;
613 }
614 }
615 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100616 case MotionEvent.ACTION_MOVE:
617 final float h = y - mInitialTouchY;
618 trackMovement(event);
Selim Cinek173f2d02015-04-29 15:36:56 -0700619 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
620 float hAbs = Math.abs(h);
621 if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
622 && hAbs > Math.abs(x - mInitialTouchX)) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200623 cancelHeightAnimator();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700624 startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100625 return true;
626 }
627 }
628 break;
Selim Cinek31094df2014-08-14 19:28:15 +0200629 case MotionEvent.ACTION_CANCEL:
630 case MotionEvent.ACTION_UP:
Selim Cinek547a06b2014-11-27 14:06:04 +0100631 if (mVelocityTracker != null) {
632 mVelocityTracker.recycle();
633 mVelocityTracker = null;
634 }
Selim Cinek31094df2014-08-14 19:28:15 +0200635 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100636 }
637 return false;
638 }
639
Selim Cinekab1dc952014-10-30 20:20:29 +0100640 /**
641 * @return Whether a pair of coordinates are inside the visible view content bounds.
642 */
643 protected abstract boolean isInContentBounds(float x, float y);
644
Selim Cinek831941f2015-06-17 15:09:30 -0700645 protected void cancelHeightAnimator() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200646 if (mHeightAnimator != null) {
Selim Cinekd18b86f2017-06-21 09:44:52 -0700647 if (mHeightAnimator.isRunning()) {
648 mPanelUpdateWhenAnimatorEnds = false;
649 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200650 mHeightAnimator.cancel();
651 }
652 endClosing();
653 }
654
655 private void endClosing() {
656 if (mClosing) {
657 mClosing = false;
658 onClosingFinished();
659 }
660 }
661
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100662 private void initVelocityTracker() {
663 if (mVelocityTracker != null) {
664 mVelocityTracker.recycle();
665 }
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200666 mVelocityTracker = VelocityTrackerFactory.obtain(getContext());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100667 }
668
669 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200670 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100671 }
672
673 protected float getContentHeight() {
674 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400675 }
676
Daniel Sandler08d05e32012-08-08 16:39:54 -0400677 @Override
678 protected void onFinishInflate() {
679 super.onFinishInflate();
680 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400681 }
682
Jorim Jaggi069cd032014-05-15 03:09:01 +0200683 @Override
684 protected void onConfigurationChanged(Configuration newConfig) {
685 super.onConfigurationChanged(newConfig);
686 loadDimens();
Jorim Jaggi069cd032014-05-15 03:09:01 +0200687 }
688
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200689 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200690 * @param vel the current vertical velocity of the motion
691 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200692 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200693 */
Selim Cinek9db71052015-04-24 18:54:30 -0700694 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
695 if (isFalseTouch(x, y)) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200696 return true;
697 }
Jorim Jaggib7240132014-06-30 01:39:07 +0200698 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200699 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200700 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200701 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400702 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200703 }
704
Selim Cinek9db71052015-04-24 18:54:30 -0700705 /**
706 * @param x the final x-coordinate when the finger was lifted
707 * @param y the final y-coordinate when the finger was lifted
708 * @return whether this motion should be regarded as a false touch
709 */
710 private boolean isFalseTouch(float x, float y) {
711 if (!mStatusBar.isFalsingThresholdNeeded()) {
712 return false;
713 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700714 if (mFalsingManager.isClassiferEnabled()) {
715 return mFalsingManager.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700716 }
Selim Cinek9db71052015-04-24 18:54:30 -0700717 if (!mTouchAboveFalsingThreshold) {
718 return true;
719 }
720 if (mUpwardsWhenTresholdReached) {
721 return false;
722 }
723 return !isDirectionUpwards(x, y);
Selim Cinek5386fb32014-09-03 16:37:36 +0200724 }
725
Jorim Jaggi1d480692014-05-20 19:41:58 +0200726 protected void fling(float vel, boolean expand) {
Selim Cinek9db71052015-04-24 18:54:30 -0700727 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700728 }
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200729
Selim Cinek9db71052015-04-24 18:54:30 -0700730 protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
731 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
732 }
733
734 protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
735 boolean expandBecauseOfFalsing) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700736 cancelPeek();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800737 float target = expand ? getMaxPanelHeight() : 0;
Jorim Jaggi3e02adb2015-05-13 17:50:26 -0700738 if (!expand) {
739 mClosing = true;
740 }
Selim Cinek9db71052015-04-24 18:54:30 -0700741 flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700742 }
743
744 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700745 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200746 // Hack to make the expand transition look nice when clear all button is visible - we make
747 // the animation only to the last notification, and then jump to the maximum panel height so
748 // clear all just fades in and the decelerating motion is towards the last notification.
749 final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
750 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
751 && !isClearAllVisible();
752 if (clearAllExpandHack) {
753 target = getMaxPanelHeight() - getClearAllHeight();
754 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200755 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200756 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200757 return;
758 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200759 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200760 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200761 if (expand) {
Selim Cinek61190fb2016-12-07 12:16:45 -0800762 if (expandBecauseOfFalsing && vel < 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200763 vel = 0;
764 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200765 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
Jorim Jaggi6626f542016-08-22 13:08:44 -0700766 if (vel == 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200767 animator.setDuration(350);
768 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200769 } else {
Selim Cinek2411f762016-12-28 17:05:08 +0100770 if (shouldUseDismissingAnimation()) {
Selim Cinekdf5501b2017-04-14 20:01:27 -0700771 if (vel == 0) {
772 animator.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
773 long duration = (long) (200 + mExpandedHeight / getHeight() * 100);
774 animator.setDuration(duration);
775 } else {
776 mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
777 getHeight());
778 }
Selim Cinek2411f762016-12-28 17:05:08 +0100779 } else {
780 mFlingAnimationUtilsClosing
781 .apply(animator, mExpandedHeight, target, vel, getHeight());
782 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200783
784 // Make it shorter if we run a canned animation
785 if (vel == 0) {
Selim Cinek593ee202016-12-28 15:01:16 +0100786 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200787 }
788 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200789 animator.addListener(new AnimatorListenerAdapter() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200790 private boolean mCancelled;
791
792 @Override
793 public void onAnimationCancel(Animator animation) {
794 mCancelled = true;
795 }
796
Jorim Jaggi1d480692014-05-20 19:41:58 +0200797 @Override
798 public void onAnimationEnd(Animator animation) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200799 if (clearAllExpandHack && !mCancelled) {
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200800 setExpandedHeightInternal(getMaxPanelHeight());
801 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700802 setAnimator(null);
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200803 if (!mCancelled) {
804 notifyExpandingFinished();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200805 }
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700806 notifyBarPanelExpansionChanged();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200807 }
808 });
Selim Cinekbe2c4432017-05-30 12:11:09 -0700809 setAnimator(animator);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200810 animator.start();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400811 }
812
Selim Cinek2411f762016-12-28 17:05:08 +0100813 protected abstract boolean shouldUseDismissingAnimation();
814
Daniel Sandler08d05e32012-08-08 16:39:54 -0400815 @Override
816 protected void onAttachedToWindow() {
817 super.onAttachedToWindow();
Daniel Sandler978f8532012-08-15 15:48:16 -0400818 mViewName = getResources().getResourceName(getId());
819 }
820
821 public String getName() {
822 return mViewName;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400823 }
824
Daniel Sandler08d05e32012-08-08 16:39:54 -0400825 public void setExpandedHeight(float height) {
John Spurlock97642182013-07-29 17:58:39 -0400826 if (DEBUG) logf("setExpandedHeight(%.1f)", height);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200827 setExpandedHeightInternal(height + getOverExpansionPixels());
Daniel Sandler08d05e32012-08-08 16:39:54 -0400828 }
829
Daniel Sandler50508132012-08-16 14:10:53 -0400830 @Override
831 protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
Daniel Sandler50508132012-08-16 14:10:53 -0400832 super.onLayout(changed, left, top, right, bottom);
Selim Cinek5fbc6322016-01-15 17:17:58 -0800833 mStatusBar.onPanelLaidOut();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100834 requestPanelHeightUpdate();
Selim Cinek31094df2014-08-14 19:28:15 +0200835 mHasLayoutedSinceDown = true;
836 if (mUpdateFlingOnLayout) {
837 abortAnimations();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700838 fling(mUpdateFlingVelocity, true /* expands */);
Selim Cinek31094df2014-08-14 19:28:15 +0200839 mUpdateFlingOnLayout = false;
840 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100841 }
842
843 protected void requestPanelHeightUpdate() {
844 float currentMaxPanelHeight = getMaxPanelHeight();
845
Selim Cinekbe2c4432017-05-30 12:11:09 -0700846 if (isFullyCollapsed()) {
847 return;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100848 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700849
850 if (currentMaxPanelHeight == mExpandedHeight) {
851 return;
852 }
853
854 if (mPeekAnimator != null || mPeekTouching) {
855 return;
856 }
857
858 if (mTracking && !isTrackingBlocked()) {
859 return;
860 }
861
862 if (mHeightAnimator != null) {
863 mPanelUpdateWhenAnimatorEnds = true;
864 return;
865 }
866
867 setExpandedHeight(currentMaxPanelHeight);
Daniel Sandler50508132012-08-16 14:10:53 -0400868 }
869
Daniel Sandler08d05e32012-08-08 16:39:54 -0400870 public void setExpandedHeightInternal(float h) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700871 if (mExpandLatencyTracking && h != 0f) {
872 DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance(mContext).onActionEnd(
873 LatencyTracker.ACTION_EXPAND_PANEL));
874 mExpandLatencyTracking = false;
875 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200876 float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
877 if (mHeightAnimator == null) {
878 float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
879 if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
880 setOverExpansion(overExpansionPixels, true /* isPixels */);
881 }
882 mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
883 } else {
884 mExpandedHeight = h;
885 if (mOverExpandedBeforeFling) {
886 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
887 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100888 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400889
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +0200890 // If we are closing the panel and we are almost there due to a slow decelerating
891 // interpolator, abort the animation.
892 if (mExpandedHeight < 1f && mExpandedHeight != 0f && mClosing) {
893 mExpandedHeight = 0f;
894 if (mHeightAnimator != null) {
895 mHeightAnimator.end();
896 }
897 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800898 mExpandedFraction = Math.min(1f,
899 fhWithoutOverExpansion == 0 ? 0 : mExpandedHeight / fhWithoutOverExpansion);
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +0100900 onHeightUpdated(mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200901 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400902 }
903
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200904 /**
905 * @return true if the panel tracking should be temporarily blocked; this is used when a
906 * conflicting gesture (opening QS) is happening
907 */
908 protected abstract boolean isTrackingBlocked();
909
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200910 protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
Selim Cinek24120a52014-05-26 10:05:42 +0200911
Jorim Jaggi90129582014-06-02 14:44:49 +0200912 protected abstract void onHeightUpdated(float expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100913
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200914 protected abstract float getOverExpansionAmount();
915
916 protected abstract float getOverExpansionPixels();
917
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100918 /**
919 * This returns the maximum height of the panel. Children should override this if their
920 * desired height is not the full height.
921 *
922 * @return the default implementation simply returns the maximum height.
923 */
Selim Cinek31094df2014-08-14 19:28:15 +0200924 protected abstract int getMaxPanelHeight();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400925
926 public void setExpandedFraction(float frac) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100927 setExpandedHeight(getMaxPanelHeight() * frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400928 }
929
930 public float getExpandedHeight() {
931 return mExpandedHeight;
932 }
933
934 public float getExpandedFraction() {
935 return mExpandedFraction;
936 }
937
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700938 public boolean isFullyExpanded() {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100939 return mExpandedHeight >= getMaxPanelHeight();
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700940 }
941
942 public boolean isFullyCollapsed() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800943 return mExpandedFraction <= 0.0f;
Daniel Sandler67eab792012-10-02 17:08:23 -0400944 }
945
946 public boolean isCollapsing() {
947 return mClosing;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700948 }
949
John Spurlocka4b70af2013-08-17 14:05:49 -0400950 public boolean isTracking() {
951 return mTracking;
952 }
953
Daniel Sandler08d05e32012-08-08 16:39:54 -0400954 public void setBar(PanelBar panelBar) {
955 mBar = panelBar;
956 }
957
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700958 public void collapse(boolean delayed, float speedUpFactor) {
John Spurlock97642182013-07-29 17:58:39 -0400959 if (DEBUG) logf("collapse: " + this);
Selim Cinek9bb05632016-12-15 14:14:29 -0800960 if (canPanelBeCollapsed()) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200961 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200962 notifyExpandingStarted();
Jorim Jaggi3b866be2015-06-30 11:31:10 -0700963
964 // Set after notifyExpandingStarted, as notifyExpandingStarted resets the closing state.
965 mClosing = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200966 if (delayed) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700967 mNextCollapseSpeedUpFactor = speedUpFactor;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200968 postDelayed(mFlingCollapseRunnable, 120);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200969 } else {
Selim Cinek9db71052015-04-24 18:54:30 -0700970 fling(0, false /* expand */, speedUpFactor, false /* expandBecauseOfFalsing */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200971 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400972 }
973 }
974
Selim Cinek9bb05632016-12-15 14:14:29 -0800975 public boolean canPanelBeCollapsed() {
976 return !isFullyCollapsed() && !mTracking && !mClosing;
977 }
978
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200979 private final Runnable mFlingCollapseRunnable = new Runnable() {
980 @Override
981 public void run() {
Selim Cinek9db71052015-04-24 18:54:30 -0700982 fling(0, false /* expand */, mNextCollapseSpeedUpFactor,
983 false /* expandBecauseOfFalsing */);
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200984 }
985 };
986
John Spurlock97642182013-07-29 17:58:39 -0400987 public void cancelPeek() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800988 boolean cancelled = false;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200989 if (mPeekAnimator != null) {
Selim Cinek529c5322016-04-06 20:03:45 -0700990 cancelled = true;
John Spurlock97642182013-07-29 17:58:39 -0400991 mPeekAnimator.cancel();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400992 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200993
Selim Cinek529c5322016-04-06 20:03:45 -0700994 if (cancelled) {
995 // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
996 // notify mBar that we might have closed ourselves.
997 notifyBarPanelExpansionChanged();
998 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400999 }
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001000
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001001 public void expand(final boolean animate) {
1002 if (!isFullyCollapsed() && !isCollapsing()) {
1003 return;
1004 }
1005
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001006 mInstantExpanding = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07001007 mAnimateAfterExpanding = animate;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001008 mUpdateFlingOnLayout = false;
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001009 abortAnimations();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001010 cancelPeek();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001011 if (mTracking) {
1012 onTrackingStopped(true /* expands */); // The panel is expanded after this call.
Jorim Jaggie62d5892014-09-02 16:31:19 +02001013 }
1014 if (mExpanding) {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001015 notifyExpandingFinished();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001016 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001017 notifyBarPanelExpansionChanged();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001018
1019 // Wait for window manager to pickup the change, so we know the maximum height of the panel
1020 // then.
1021 getViewTreeObserver().addOnGlobalLayoutListener(
1022 new ViewTreeObserver.OnGlobalLayoutListener() {
1023 @Override
1024 public void onGlobalLayout() {
Jorim Jaggic5804af2016-04-25 18:51:16 -07001025 if (!mInstantExpanding) {
1026 getViewTreeObserver().removeOnGlobalLayoutListener(this);
1027 return;
1028 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001029 if (mStatusBar.getStatusBarWindow().getHeight()
1030 != mStatusBar.getStatusBarHeight()) {
1031 getViewTreeObserver().removeOnGlobalLayoutListener(this);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001032 if (mAnimateAfterExpanding) {
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001033 notifyExpandingStarted();
1034 fling(0, true /* expand */);
1035 } else {
1036 setExpandedFraction(1f);
1037 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001038 mInstantExpanding = false;
1039 }
1040 }
1041 });
1042
1043 // Make sure a layout really happens.
1044 requestLayout();
1045 }
1046
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001047 public void instantCollapse() {
1048 abortAnimations();
1049 setExpandedFraction(0f);
1050 if (mExpanding) {
1051 notifyExpandingFinished();
1052 }
Jorim Jaggic5804af2016-04-25 18:51:16 -07001053 if (mInstantExpanding) {
1054 mInstantExpanding = false;
1055 notifyBarPanelExpansionChanged();
1056 }
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001057 }
1058
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001059 private void abortAnimations() {
1060 cancelPeek();
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001061 cancelHeightAnimator();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001062 removeCallbacks(mPostCollapseRunnable);
1063 removeCallbacks(mFlingCollapseRunnable);
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001064 }
1065
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001066 protected void onClosingFinished() {
1067 mBar.onClosingFinished();
1068 }
1069
1070
Jorim Jaggi90129582014-06-02 14:44:49 +02001071 protected void startUnlockHintAnimation() {
1072
1073 // We don't need to hint the user if an animation is already running or the user is changing
1074 // the expansion.
1075 if (mHeightAnimator != null || mTracking) {
1076 return;
1077 }
1078 cancelPeek();
Jorim Jaggib472b3472014-06-30 19:56:24 +02001079 notifyExpandingStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001080 startUnlockHintAnimationPhase1(new Runnable() {
1081 @Override
1082 public void run() {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001083 notifyExpandingFinished();
Selim Cinekec29d342017-05-05 18:31:49 -07001084 onUnlockHintFinished();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001085 mHintAnimationRunning = false;
1086 }
1087 });
Selim Cinekec29d342017-05-05 18:31:49 -07001088 onUnlockHintStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001089 mHintAnimationRunning = true;
Jorim Jaggi90129582014-06-02 14:44:49 +02001090 }
1091
Selim Cinekec29d342017-05-05 18:31:49 -07001092 protected void onUnlockHintFinished() {
1093 mStatusBar.onHintFinished();
1094 }
1095
1096 protected void onUnlockHintStarted() {
1097 mStatusBar.onUnlockHintStarted();
1098 }
1099
Jorim Jaggi90129582014-06-02 14:44:49 +02001100 /**
1101 * Phase 1: Move everything upwards.
1102 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001103 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001104 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1105 ValueAnimator animator = createHeightAnimator(target);
1106 animator.setDuration(250);
Selim Cinekc18010f2016-01-20 13:41:30 -08001107 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi90129582014-06-02 14:44:49 +02001108 animator.addListener(new AnimatorListenerAdapter() {
1109 private boolean mCancelled;
1110
1111 @Override
1112 public void onAnimationCancel(Animator animation) {
1113 mCancelled = true;
1114 }
1115
1116 @Override
1117 public void onAnimationEnd(Animator animation) {
1118 if (mCancelled) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001119 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001120 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +02001121 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001122 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +02001123 }
1124 }
1125 });
1126 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001127 setAnimator(animator);
Adrian Roos8d4e99f2017-05-25 18:03:58 -07001128
1129 View[] viewsToAnimate = {
1130 mKeyguardBottomArea.getIndicationArea(),
1131 mStatusBar.getAmbientIndicationContainer()};
1132 for (View v : viewsToAnimate) {
1133 if (v == null) {
1134 continue;
1135 }
1136 v.animate()
1137 .translationY(-mHintDistance)
1138 .setDuration(250)
1139 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
1140 .withEndAction(() -> v.animate()
1141 .translationY(0)
1142 .setDuration(450)
1143 .setInterpolator(mBounceInterpolator)
1144 .start())
1145 .start();
1146 }
Jorim Jaggi90129582014-06-02 14:44:49 +02001147 }
1148
Selim Cinekbe2c4432017-05-30 12:11:09 -07001149 private void setAnimator(ValueAnimator animator) {
1150 mHeightAnimator = animator;
1151 if (animator == null && mPanelUpdateWhenAnimatorEnds) {
1152 mPanelUpdateWhenAnimatorEnds = false;
1153 requestPanelHeightUpdate();
1154 }
1155 }
1156
Jorim Jaggi90129582014-06-02 14:44:49 +02001157 /**
1158 * Phase 2: Bounce down.
1159 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001160 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001161 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1162 animator.setDuration(450);
1163 animator.setInterpolator(mBounceInterpolator);
1164 animator.addListener(new AnimatorListenerAdapter() {
1165 @Override
1166 public void onAnimationEnd(Animator animation) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001167 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001168 onAnimationFinished.run();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001169 notifyBarPanelExpansionChanged();
Jorim Jaggi90129582014-06-02 14:44:49 +02001170 }
1171 });
1172 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001173 setAnimator(animator);
Jorim Jaggi90129582014-06-02 14:44:49 +02001174 }
1175
1176 private ValueAnimator createHeightAnimator(float targetHeight) {
1177 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1178 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1179 @Override
1180 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001181 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +02001182 }
1183 });
1184 return animator;
1185 }
1186
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001187 protected void notifyBarPanelExpansionChanged() {
Selim Cinek48ff9b42016-11-09 19:31:51 -08001188 mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
Selim Cinek0fccc722015-07-29 17:04:36 -07001189 || mPeekAnimator != null || mInstantExpanding || isPanelVisibleBecauseOfHeadsUp()
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001190 || mTracking || mHeightAnimator != null);
Jorim Jaggib472b3472014-06-30 19:56:24 +02001191 }
1192
Selim Cinek0fccc722015-07-29 17:04:36 -07001193 protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1194
Jorim Jaggi90129582014-06-02 14:44:49 +02001195 /**
1196 * Gets called when the user performs a click anywhere in the empty area of the panel.
1197 *
1198 * @return whether the panel will be expanded after the action performed by this method
1199 */
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001200 protected boolean onEmptySpaceClick(float x) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001201 if (mHintAnimationRunning) {
1202 return true;
1203 }
Selim Cinek6746c282015-04-21 19:58:31 -07001204 return onMiddleClicked();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001205 }
1206
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001207 protected final Runnable mPostCollapseRunnable = new Runnable() {
Jorim Jaggi488b7922014-08-05 21:12:02 +02001208 @Override
1209 public void run() {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -07001210 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
Jorim Jaggi488b7922014-08-05 21:12:02 +02001211 }
1212 };
Jorim Jaggi488b7922014-08-05 21:12:02 +02001213
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001214 protected abstract boolean onMiddleClicked();
Jorim Jaggi90129582014-06-02 14:44:49 +02001215
Jorim Jaggid7912d22014-09-30 17:38:19 +02001216 protected abstract boolean isDozing();
1217
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001218 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +02001219 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001220 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001221 + "]",
1222 this.getClass().getSimpleName(),
1223 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001224 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001225 mClosing?"T":"f",
1226 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001227 mJustPeeked?"T":"f",
1228 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001229 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1230 mTouchDisabled?"T":"f"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001231 ));
1232 }
Selim Cinek3c4635c2014-05-29 02:12:47 +02001233
1234 public abstract void resetViews();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001235
1236 protected abstract float getPeekHeight();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02001237 /**
1238 * @return whether "Clear all" button will be visible when the panel is fully expanded
1239 */
1240 protected abstract boolean fullyExpandedClearAllVisible();
1241
1242 protected abstract boolean isClearAllVisible();
1243
1244 /**
1245 * @return the height of the clear all button, in pixels
1246 */
1247 protected abstract int getClearAllHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001248
1249 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
1250 mHeadsUpManager = headsUpManager;
1251 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001252}