blob: 7f1e9d0e1972004bd0e8208b0632f0920c0385aa [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;
Adrian Roos8d4e99f2017-05-25 18:03:58 -070032import android.view.View;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010033import android.view.ViewConfiguration;
Jorim Jaggi0a27be82014-06-11 03:22:39 +020034import android.view.ViewTreeObserver;
Jorim Jaggi90129582014-06-02 14:44:49 +020035import android.view.animation.Interpolator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040036import android.widget.FrameLayout;
37
Chris Wren27a52fa2017-02-01 14:21:43 -050038import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050039import com.android.internal.util.LatencyTracker;
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +020040import com.android.systemui.DejankUtils;
Matthew Nge2b4d792018-03-09 13:42:18 -080041import com.android.systemui.Dependency;
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +020042import com.android.systemui.Interpolators;
Daniel Sandler08d05e32012-08-08 16:39:54 -040043import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070044import com.android.systemui.classifier.FalsingManager;
John Spurlock813552c2014-09-19 08:30:21 -040045import com.android.systemui.doze.DozeLog;
Jorim Jaggi1d480692014-05-20 19:41:58 +020046import com.android.systemui.statusbar.FlingAnimationUtils;
Jorim Jaggi90129582014-06-02 14:44:49 +020047import com.android.systemui.statusbar.StatusBarState;
Matthew Ng5c0592e2018-03-08 14:51:36 -080048import com.android.systemui.statusbar.VibratorHelper;
Daniel Sandler08d05e32012-08-08 16:39:54 -040049
John Spurlockde84f0e2013-06-12 12:41:00 -040050import java.io.FileDescriptor;
51import java.io.PrintWriter;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080052import java.util.function.BiConsumer;
John Spurlockde84f0e2013-06-12 12:41:00 -040053
Selim Cinek4c6969a2014-05-26 19:22:17 +020054public abstract class PanelView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040055 public static final boolean DEBUG = PanelBar.DEBUG;
Daniel Sandler08d05e32012-08-08 16:39:54 -040056 public static final String TAG = PanelView.class.getSimpleName();
Selim Cinek48ff9b42016-11-09 19:31:51 -080057 private static final int INITIAL_OPENING_PEEK_DURATION = 200;
58 private static final int PEEK_ANIMATION_DURATION = 360;
Selim Cinek2627d722018-01-19 12:16:49 -080059 private static final int NO_FIXED_DURATION = -1;
Selim Cinek48ff9b42016-11-09 19:31:51 -080060 private long mDownTime;
61 private float mMinExpandHeight;
Chris Wren27a52fa2017-02-01 14:21:43 -050062 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinekbe2c4432017-05-30 12:11:09 -070063 private boolean mPanelUpdateWhenAnimatorEnds;
Selim Cinekf6559f82017-08-16 14:49:10 -070064 private boolean mVibrateOnOpening;
Selim Cinek2627d722018-01-19 12:16:49 -080065 protected boolean mLaunchingNotification;
66 private int mFixedDuration = NO_FIXED_DURATION;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080067 private BiConsumer<Float, Boolean> mExpansionListener;
Selim Cinek173f2d02015-04-29 15:36:56 -070068
John Spurlock97642182013-07-29 17:58:39 -040069 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040070 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040071 }
72
Jason Monk2a6ea9c2017-01-26 11:14:51 -050073 protected StatusBar mStatusBar;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090074 protected HeadsUpManagerPhone mHeadsUpManager;
Selim Cinek684a4422015-04-15 16:18:39 -070075
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040076 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020077 private float mHintDistance;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010078 private float mInitialOffsetOnTouch;
Selim Cinek79d79c42015-05-21 16:14:45 -070079 private boolean mCollapsedAndHeadsUpOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040080 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020081 protected float mExpandedHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +020082 private boolean mPanelClosedOnDown;
83 private boolean mHasLayoutedSinceDown;
84 private float mUpdateFlingVelocity;
85 private boolean mUpdateFlingOnLayout;
Jorim Jaggib7a33032014-08-20 16:21:36 +020086 private boolean mPeekTouching;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040087 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040088 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020089 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020090 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040091 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020092 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020093 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020094 private boolean mOverExpandedBeforeFling;
Selim Cinek19c8c702014-08-25 22:09:19 +020095 private boolean mTouchAboveFalsingThreshold;
96 private int mUnlockFalsingThreshold;
Selim Cinekab1dc952014-10-30 20:20:29 +010097 private boolean mTouchStartedInEmptyArea;
Selim Cinek547a06b2014-11-27 14:06:04 +010098 private boolean mMotionAborted;
Selim Cinek9db71052015-04-24 18:54:30 -070099 private boolean mUpwardsWhenTresholdReached;
Selim Cinek173f2d02015-04-29 15:36:56 -0700100 private boolean mAnimatingOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400101
Jorim Jaggi1d480692014-05-20 19:41:58 +0200102 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400103 private ObjectAnimator mPeekAnimator;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200104 private VelocityTrackerInterface mVelocityTracker;
Jorim Jaggi1d480692014-05-20 19:41:58 +0200105 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800106 private FlingAnimationUtils mFlingAnimationUtilsClosing;
Selim Cinek2411f762016-12-28 17:05:08 +0100107 private FlingAnimationUtils mFlingAnimationUtilsDismissing;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700108 private FalsingManager mFalsingManager;
Matthew Ng5c0592e2018-03-08 14:51:36 -0800109 private final VibratorHelper mVibratorHelper;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400110
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200111 /**
112 * Whether an instant expand request is currently pending and we are just waiting for layout.
113 */
114 private boolean mInstantExpanding;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700115 private boolean mAnimateAfterExpanding;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200116
Daniel Sandler08d05e32012-08-08 16:39:54 -0400117 PanelBar mBar;
118
Daniel Sandler50508132012-08-16 14:10:53 -0400119 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200120 private float mInitialTouchY;
121 private float mInitialTouchX;
Jorim Jaggid41083a2014-09-12 02:54:40 +0200122 private boolean mTouchDisabled;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400123
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800124 /**
125 * Whether or not the PanelView can be expanded or collapsed with a drag.
126 */
127 private boolean mNotificationsDragEnabled;
128
Jorim Jaggi90129582014-06-02 14:44:49 +0200129 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200130 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +0200131
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700132 /**
133 * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
134 */
135 private float mNextCollapseSpeedUpFactor = 1.0f;
136
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700137 protected boolean mExpanding;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200138 private boolean mGestureWaitForTouchSlop;
Selim Cinek9db71052015-04-24 18:54:30 -0700139 private boolean mIgnoreXTouchSlop;
Jorim Jaggie05256e2016-09-08 14:58:20 -0700140 private boolean mExpandLatencyTracking;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200141
Selim Cinek1685e632014-04-08 02:27:49 +0200142 protected void onExpandingFinished() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200143 mBar.onExpandingFinished();
Selim Cinek1685e632014-04-08 02:27:49 +0200144 }
145
146 protected void onExpandingStarted() {
147 }
148
Jorim Jaggib472b3472014-06-30 19:56:24 +0200149 private void notifyExpandingStarted() {
150 if (!mExpanding) {
151 mExpanding = true;
152 onExpandingStarted();
153 }
154 }
155
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700156 protected final void notifyExpandingFinished() {
Selim Cinekb0e4f9e2015-11-02 13:42:58 -0800157 endClosing();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200158 if (mExpanding) {
159 mExpanding = false;
160 onExpandingFinished();
161 }
162 }
163
Selim Cinek48ff9b42016-11-09 19:31:51 -0800164 private void runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished) {
165 mPeekHeight = peekHeight;
John Spurlock97642182013-07-29 17:58:39 -0400166 if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200167 if (mHeightAnimator != null) {
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400168 return;
169 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800170 if (mPeekAnimator != null) {
171 mPeekAnimator.cancel();
172 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200173 mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800174 .setDuration(duration);
Selim Cinekc18010f2016-01-20 13:41:30 -0800175 mPeekAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200176 mPeekAnimator.addListener(new AnimatorListenerAdapter() {
177 private boolean mCancelled;
178
179 @Override
180 public void onAnimationCancel(Animator animation) {
181 mCancelled = true;
182 }
183
184 @Override
185 public void onAnimationEnd(Animator animation) {
186 mPeekAnimator = null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800187 if (!mCancelled && collapseWhenFinished) {
Selim Cineka0f5c762015-06-22 14:44:46 -0400188 postOnAnimation(mPostCollapseRunnable);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200189 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800190
Jorim Jaggib472b3472014-06-30 19:56:24 +0200191 }
192 });
193 notifyExpandingStarted();
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400194 mPeekAnimator.start();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200195 mJustPeeked = true;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400196 }
197
Daniel Sandler08d05e32012-08-08 16:39:54 -0400198 public PanelView(Context context, AttributeSet attrs) {
199 super(context, attrs);
Selim Cinek593ee202016-12-28 15:01:16 +0100200 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f /* maxLengthSeconds */,
201 0.6f /* speedUpFactor */);
202 mFlingAnimationUtilsClosing = new FlingAnimationUtils(context, 0.5f /* maxLengthSeconds */,
203 0.6f /* speedUpFactor */);
Selim Cinek2411f762016-12-28 17:05:08 +0100204 mFlingAnimationUtilsDismissing = new FlingAnimationUtils(context,
205 0.5f /* maxLengthSeconds */, 0.2f /* speedUpFactor */, 0.6f /* x2 */,
206 0.84f /* y2 */);
Jorim Jaggi90129582014-06-02 14:44:49 +0200207 mBounceInterpolator = new BounceInterpolator();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700208 mFalsingManager = FalsingManager.getInstance(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800209 mNotificationsDragEnabled =
210 getResources().getBoolean(R.bool.config_enableNotificationShadeDrag);
Matthew Nge2b4d792018-03-09 13:42:18 -0800211 mVibratorHelper = Dependency.get(VibratorHelper.class);
Selim Cinekf6559f82017-08-16 14:49:10 -0700212 mVibrateOnOpening = mContext.getResources().getBoolean(
213 R.bool.config_vibrateOnIconAnimation);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400214 }
215
Jorim Jaggi069cd032014-05-15 03:09:01 +0200216 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400217 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100218 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
219 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200220 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200221 mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400222 }
223
224 private void trackMovement(MotionEvent event) {
225 // Add movement to velocity tracker using raw screen X and Y coordinates instead
226 // of window coordinates because the window frame may be moving at the same time.
227 float deltaX = event.getRawX() - event.getX();
228 float deltaY = event.getRawY() - event.getY();
229 event.offsetLocation(deltaX, deltaY);
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400230 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400231 event.offsetLocation(-deltaX, -deltaY);
232 }
233
Jorim Jaggid41083a2014-09-12 02:54:40 +0200234 public void setTouchDisabled(boolean disabled) {
235 mTouchDisabled = disabled;
Selim Cinek48a92a52017-05-02 20:02:30 -0700236 if (mTouchDisabled) {
237 cancelHeightAnimator();
238 if (mTracking) {
239 onTrackingStopped(true /* expanded */);
240 }
Selim Cinekeede5d72017-05-22 17:09:55 -0700241 notifyExpandingFinished();
Selim Cinek3127daf02016-07-22 18:04:23 -0700242 }
Jorim Jaggid41083a2014-09-12 02:54:40 +0200243 }
244
Jorim Jaggie05256e2016-09-08 14:58:20 -0700245 public void startExpandLatencyTracking() {
246 if (LatencyTracker.isEnabled(mContext)) {
247 LatencyTracker.getInstance(mContext).onActionStart(
248 LatencyTracker.ACTION_EXPAND_PANEL);
249 mExpandLatencyTracking = true;
250 }
251 }
252
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400253 @Override
254 public boolean onTouchEvent(MotionEvent event) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100255 if (mInstantExpanding || mTouchDisabled
256 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200257 return false;
258 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100259
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800260 // If dragging should not expand the notifications shade, then return false.
261 if (!mNotificationsDragEnabled) {
262 if (mTracking) {
263 // Turn off tracking if it's on or the shade can get stuck in the down position.
264 onTrackingStopped(true /* expand */);
265 }
266 return false;
267 }
268
Jun Mukaicf9933c2015-07-08 17:34:26 -0700269 // On expanding, single mouse click expands the panel instead of dragging.
Jun Mukaic99243a2015-10-15 02:59:57 -0700270 if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
Jun Mukaicf9933c2015-07-08 17:34:26 -0700271 if (event.getAction() == MotionEvent.ACTION_UP) {
272 expand(true);
273 }
274 return true;
275 }
276
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100277 /*
278 * We capture touch events here and update the expand height here in case according to
279 * the users fingers. This also handles multi-touch.
280 *
Chris Wren5d53df42015-06-26 11:26:03 -0400281 * If the user just clicks shortly, we show a quick peek of the shade.
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100282 *
283 * Flinging is also enabled in order to open or close the shade.
284 */
285
286 int pointerIndex = event.findPointerIndex(mTrackingPointer);
287 if (pointerIndex < 0) {
288 pointerIndex = 0;
289 mTrackingPointer = event.getPointerId(pointerIndex);
290 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200291 final float x = event.getX(pointerIndex);
Selim Cinek547a06b2014-11-27 14:06:04 +0100292 final float y = event.getY(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100293
Jorim Jaggib472b3472014-06-30 19:56:24 +0200294 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek684a4422015-04-15 16:18:39 -0700295 mGestureWaitForTouchSlop = isFullyCollapsed() || hasConflictingGestures();
296 mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200297 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200298
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100299 switch (event.getActionMasked()) {
300 case MotionEvent.ACTION_DOWN:
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700301 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200302 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800303 mMinExpandHeight = 0.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700304 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek31094df2014-08-14 19:28:15 +0200305 mHasLayoutedSinceDown = false;
306 mUpdateFlingOnLayout = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100307 mMotionAborted = false;
Jorim Jaggib7a33032014-08-20 16:21:36 +0200308 mPeekTouching = mPanelClosedOnDown;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800309 mDownTime = SystemClock.uptimeMillis();
Selim Cinek19c8c702014-08-25 22:09:19 +0200310 mTouchAboveFalsingThreshold = false;
Selim Cinek79d79c42015-05-21 16:14:45 -0700311 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
312 && mHeadsUpManager.hasPinnedHeadsUp();
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200313 if (mVelocityTracker == null) {
314 initVelocityTracker();
315 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100316 trackMovement(event);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800317 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
318 || mPeekAnimator != null) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200319 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800320 || mPeekAnimator != null;
Selim Cinekd18b86f2017-06-21 09:44:52 -0700321 cancelHeightAnimator();
322 cancelPeek();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200323 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200324 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800325 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()
326 && !mStatusBar.isBouncerShowing()) {
Evan Laird404a85c2018-02-28 15:31:29 -0500327 startOpening(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100328 }
329 break;
330
331 case MotionEvent.ACTION_POINTER_UP:
332 final int upPointer = event.getPointerId(event.getActionIndex());
333 if (mTrackingPointer == upPointer) {
334 // gesture is ongoing, find a new pointer to track
335 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
336 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200337 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100338 mTrackingPointer = event.getPointerId(newIndex);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700339 startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100340 }
341 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100342 case MotionEvent.ACTION_POINTER_DOWN:
343 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
344 mMotionAborted = true;
345 endMotionEvent(event, x, y, true /* forceCancel */);
346 return false;
347 }
348 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100349 case MotionEvent.ACTION_MOVE:
Selim Cinekd5ab6452016-12-08 16:34:00 -0800350 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200351 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200352
353 // If the panel was collapsed when touching, we only need to check for the
354 // y-component of the gesture, as we have no conflicting horizontal gesture.
355 if (Math.abs(h) > mTouchSlop
356 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800357 || mIgnoreXTouchSlop)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200358 mTouchSlopExceeded = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700359 if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
Jorim Jaggi0b1528a2014-10-28 22:47:46 +0100360 if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700361 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200362 h = 0;
363 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200364 cancelHeightAnimator();
Jorim Jaggi90129582014-06-02 14:44:49 +0200365 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200366 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200367 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800368 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200369 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200370 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100371 mPeekAnimator.cancel();
372 }
373 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800374 } else if (mPeekAnimator == null && mJustPeeked) {
375 // The initial peek has finished, but we haven't dragged as far yet, lets
376 // speed it up by starting at the peek height.
377 mInitialOffsetOnTouch = mExpandedHeight;
378 mInitialTouchY = y;
379 mMinExpandHeight = mExpandedHeight;
380 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100381 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800382 newHeight = Math.max(newHeight, mMinExpandHeight);
Selim Cinek29ed3c92014-09-23 20:44:35 +0200383 if (-h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200384 mTouchAboveFalsingThreshold = true;
Selim Cinek9db71052015-04-24 18:54:30 -0700385 mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
Selim Cinek19c8c702014-08-25 22:09:19 +0200386 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800387 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
388 !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000389 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100390 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100391 break;
392
393 case MotionEvent.ACTION_UP:
394 case MotionEvent.ACTION_CANCEL:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100395 trackMovement(event);
Selim Cinek547a06b2014-11-27 14:06:04 +0100396 endMotionEvent(event, x, y, false /* forceCancel */);
397 break;
398 }
Selim Cinek9db71052015-04-24 18:54:30 -0700399 return !mGestureWaitForTouchSlop || mTracking;
400 }
401
Evan Laird404a85c2018-02-28 15:31:29 -0500402 private void startOpening(MotionEvent event) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800403 runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
404 false /* collapseWhenFinished */);
405 notifyBarPanelExpansionChanged();
Matthew Ng5c0592e2018-03-08 14:51:36 -0800406 if (mVibrateOnOpening) {
407 mVibratorHelper.vibrate(VibrationEffect.EFFECT_TICK);
Selim Cinekf6559f82017-08-16 14:49:10 -0700408 }
Evan Laird404a85c2018-02-28 15:31:29 -0500409
410 //TODO: keyguard opens QS a different way; log that too?
411
412 // Log the position of the swipe that opened the panel
413 float width = mStatusBar.getDisplayWidth();
414 float height = mStatusBar.getDisplayHeight();
415 int rot = mStatusBar.getRotation();
416
417 mLockscreenGestureLogger.writeAtFractionalPosition(MetricsEvent.ACTION_PANEL_VIEW_EXPAND,
418 (int) (event.getX() / width * 100),
419 (int) (event.getY() / height * 100),
420 rot);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800421 }
422
423 protected abstract float getOpeningHeight();
424
Selim Cinek9db71052015-04-24 18:54:30 -0700425 /**
426 * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
427 * horizontal direction
428 */
429 private boolean isDirectionUpwards(float x, float y) {
430 float xDiff = x - mInitialTouchX;
431 float yDiff = y - mInitialTouchY;
432 if (yDiff >= 0) {
433 return false;
434 }
435 return Math.abs(yDiff) >= Math.abs(xDiff);
Selim Cinek547a06b2014-11-27 14:06:04 +0100436 }
437
Chris Wren621933f2017-06-14 15:59:03 -0400438 protected void startExpandingFromPeek() {
439 mStatusBar.handlePeekToExpandTransistion();
440 }
441
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700442 protected void startExpandMotion(float newX, float newY, boolean startTracking,
443 float expandedHeight) {
444 mInitialOffsetOnTouch = expandedHeight;
445 mInitialTouchY = newY;
446 mInitialTouchX = newX;
447 if (startTracking) {
448 mTouchSlopExceeded = true;
Selim Cinekdef35a82016-05-03 15:52:51 -0700449 setExpandedHeight(mInitialOffsetOnTouch);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700450 onTrackingStarted();
451 }
452 }
453
Selim Cinek547a06b2014-11-27 14:06:04 +0100454 private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
455 mTrackingPointer = -1;
456 if ((mTracking && mTouchSlopExceeded)
457 || Math.abs(x - mInitialTouchX) > mTouchSlop
458 || Math.abs(y - mInitialTouchY) > mTouchSlop
459 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
460 || forceCancel) {
461 float vel = 0f;
462 float vectorVel = 0f;
463 if (mVelocityTracker != null) {
464 mVelocityTracker.computeCurrentVelocity(1000);
465 vel = mVelocityTracker.getYVelocity();
466 vectorVel = (float) Math.hypot(
467 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
468 }
Selim Cinek9db71052015-04-24 18:54:30 -0700469 boolean expand = flingExpands(vel, vectorVel, x, y)
Selim Cinek547a06b2014-11-27 14:06:04 +0100470 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
471 || forceCancel;
Selim Cinek547a06b2014-11-27 14:06:04 +0100472 DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
473 mStatusBar.isFalsingThresholdNeeded(),
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700474 mStatusBar.isWakeUpComingFromTouch());
Christoph Studerb0183992014-12-22 21:02:26 +0100475 // Log collapse gesture if on lock screen.
476 if (!expand && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
477 float displayDensity = mStatusBar.getDisplayDensity();
478 int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
479 int velocityDp = (int) Math.abs(vel / displayDensity);
Chris Wren27a52fa2017-02-01 14:21:43 -0500480 mLockscreenGestureLogger.write(
481 MetricsEvent.ACTION_LS_UNLOCK,
Christoph Studerb0183992014-12-22 21:02:26 +0100482 heightDp, velocityDp);
483 }
Selim Cinek9db71052015-04-24 18:54:30 -0700484 fling(vel, expand, isFalseTouch(x, y));
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700485 onTrackingStopped(expand);
Selim Cinek547a06b2014-11-27 14:06:04 +0100486 mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
487 if (mUpdateFlingOnLayout) {
488 mUpdateFlingVelocity = vel;
489 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800490 } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking
491 && !mStatusBar.isBouncerShowing()) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800492 long timePassed = SystemClock.uptimeMillis() - mDownTime;
493 if (timePassed < ViewConfiguration.getLongPressTimeout()) {
494 // Lets show the user that he can actually expand the panel
495 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
496 } else {
497 // We need to collapse the panel since we peeked to the small height.
498 postOnAnimation(mPostCollapseRunnable);
499 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800500 } else if (!mStatusBar.isBouncerShowing()) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100501 boolean expands = onEmptySpaceClick(mInitialTouchX);
502 onTrackingStopped(expands);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100503 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100504
505 if (mVelocityTracker != null) {
506 mVelocityTracker.recycle();
507 mVelocityTracker = null;
508 }
509 mPeekTouching = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100510 }
511
Selim Cinekd5ab6452016-12-08 16:34:00 -0800512 protected float getCurrentExpandVelocity() {
513 if (mVelocityTracker == null) {
514 return 0;
515 }
516 mVelocityTracker.computeCurrentVelocity(1000);
517 return mVelocityTracker.getYVelocity();
518 }
519
Selim Cinek29ed3c92014-09-23 20:44:35 +0200520 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700521 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek29ed3c92014-09-23 20:44:35 +0200522 return (int) (mUnlockFalsingThreshold * factor);
523 }
524
Selim Cinek4c6969a2014-05-26 19:22:17 +0200525 protected abstract boolean hasConflictingGestures();
526
Selim Cinek9db71052015-04-24 18:54:30 -0700527 protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
528
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200529 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200530 mTracking = false;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800531 mBar.onTrackingStopped(expand);
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700532 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200533 }
534
535 protected void onTrackingStarted() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200536 endClosing();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200537 mTracking = true;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800538 mBar.onTrackingStarted();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200539 notifyExpandingStarted();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700540 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200541 }
542
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100543 @Override
544 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700545 if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled
Selim Cinek547a06b2014-11-27 14:06:04 +0100546 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200547 return false;
548 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100549
550 /*
Chris Wren5d53df42015-06-26 11:26:03 -0400551 * If the user drags anywhere inside the panel we intercept it if the movement is
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100552 * upwards. This allows closing the shade from anywhere inside the panel.
553 *
554 * We only do this if the current content is scrolled to the bottom,
555 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
556 * possible.
557 */
558 int pointerIndex = event.findPointerIndex(mTrackingPointer);
559 if (pointerIndex < 0) {
560 pointerIndex = 0;
561 mTrackingPointer = event.getPointerId(pointerIndex);
562 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200563 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100564 final float y = event.getY(pointerIndex);
565 boolean scrolledToBottom = isScrolledToBottom();
566
567 switch (event.getActionMasked()) {
568 case MotionEvent.ACTION_DOWN:
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200569 mStatusBar.userActivity();
Selim Cinek173f2d02015-04-29 15:36:56 -0700570 mAnimatingOnDown = mHeightAnimator != null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800571 mMinExpandHeight = 0.0f;
572 mDownTime = SystemClock.uptimeMillis();
573 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
574 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200575 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200576 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200577 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200578 return true;
579 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100580 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200581 mInitialTouchX = x;
Selim Cinekab1dc952014-10-30 20:20:29 +0100582 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
Jorim Jaggi90129582014-06-02 14:44:49 +0200583 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200584 mJustPeeked = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100585 mMotionAborted = false;
Selim Cinek684a4422015-04-15 16:18:39 -0700586 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700587 mCollapsedAndHeadsUpOnDown = false;
Selim Cinek31094df2014-08-14 19:28:15 +0200588 mHasLayoutedSinceDown = false;
589 mUpdateFlingOnLayout = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200590 mTouchAboveFalsingThreshold = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100591 initVelocityTracker();
592 trackMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100593 break;
594 case MotionEvent.ACTION_POINTER_UP:
595 final int upPointer = event.getPointerId(event.getActionIndex());
596 if (mTrackingPointer == upPointer) {
597 // gesture is ongoing, find a new pointer to track
598 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
599 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200600 mInitialTouchX = event.getX(newIndex);
601 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100602 }
603 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100604 case MotionEvent.ACTION_POINTER_DOWN:
605 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
606 mMotionAborted = true;
607 if (mVelocityTracker != null) {
608 mVelocityTracker.recycle();
609 mVelocityTracker = null;
610 }
611 }
612 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100613 case MotionEvent.ACTION_MOVE:
614 final float h = y - mInitialTouchY;
615 trackMovement(event);
Selim Cinek173f2d02015-04-29 15:36:56 -0700616 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
617 float hAbs = Math.abs(h);
618 if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
619 && hAbs > Math.abs(x - mInitialTouchX)) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200620 cancelHeightAnimator();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700621 startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100622 return true;
623 }
624 }
625 break;
Selim Cinek31094df2014-08-14 19:28:15 +0200626 case MotionEvent.ACTION_CANCEL:
627 case MotionEvent.ACTION_UP:
Selim Cinek547a06b2014-11-27 14:06:04 +0100628 if (mVelocityTracker != null) {
629 mVelocityTracker.recycle();
630 mVelocityTracker = null;
631 }
Selim Cinek31094df2014-08-14 19:28:15 +0200632 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100633 }
634 return false;
635 }
636
Selim Cinekab1dc952014-10-30 20:20:29 +0100637 /**
638 * @return Whether a pair of coordinates are inside the visible view content bounds.
639 */
640 protected abstract boolean isInContentBounds(float x, float y);
641
Selim Cinek831941f2015-06-17 15:09:30 -0700642 protected void cancelHeightAnimator() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200643 if (mHeightAnimator != null) {
Selim Cinekd18b86f2017-06-21 09:44:52 -0700644 if (mHeightAnimator.isRunning()) {
645 mPanelUpdateWhenAnimatorEnds = false;
646 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200647 mHeightAnimator.cancel();
648 }
649 endClosing();
650 }
651
652 private void endClosing() {
653 if (mClosing) {
654 mClosing = false;
655 onClosingFinished();
656 }
657 }
658
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100659 private void initVelocityTracker() {
660 if (mVelocityTracker != null) {
661 mVelocityTracker.recycle();
662 }
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200663 mVelocityTracker = VelocityTrackerFactory.obtain(getContext());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100664 }
665
666 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200667 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100668 }
669
670 protected float getContentHeight() {
671 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400672 }
673
Daniel Sandler08d05e32012-08-08 16:39:54 -0400674 @Override
675 protected void onFinishInflate() {
676 super.onFinishInflate();
677 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400678 }
679
Jorim Jaggi069cd032014-05-15 03:09:01 +0200680 @Override
681 protected void onConfigurationChanged(Configuration newConfig) {
682 super.onConfigurationChanged(newConfig);
683 loadDimens();
Jorim Jaggi069cd032014-05-15 03:09:01 +0200684 }
685
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200686 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200687 * @param vel the current vertical velocity of the motion
688 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200689 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200690 */
Selim Cinek9db71052015-04-24 18:54:30 -0700691 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
692 if (isFalseTouch(x, y)) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200693 return true;
694 }
Jorim Jaggib7240132014-06-30 01:39:07 +0200695 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200696 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200697 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200698 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400699 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200700 }
701
Selim Cinek9db71052015-04-24 18:54:30 -0700702 /**
703 * @param x the final x-coordinate when the finger was lifted
704 * @param y the final y-coordinate when the finger was lifted
705 * @return whether this motion should be regarded as a false touch
706 */
707 private boolean isFalseTouch(float x, float y) {
708 if (!mStatusBar.isFalsingThresholdNeeded()) {
709 return false;
710 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700711 if (mFalsingManager.isClassiferEnabled()) {
712 return mFalsingManager.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700713 }
Selim Cinek9db71052015-04-24 18:54:30 -0700714 if (!mTouchAboveFalsingThreshold) {
715 return true;
716 }
717 if (mUpwardsWhenTresholdReached) {
718 return false;
719 }
720 return !isDirectionUpwards(x, y);
Selim Cinek5386fb32014-09-03 16:37:36 +0200721 }
722
Jorim Jaggi1d480692014-05-20 19:41:58 +0200723 protected void fling(float vel, boolean expand) {
Selim Cinek9db71052015-04-24 18:54:30 -0700724 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700725 }
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200726
Selim Cinek9db71052015-04-24 18:54:30 -0700727 protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
728 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
729 }
730
731 protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
732 boolean expandBecauseOfFalsing) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700733 cancelPeek();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800734 float target = expand ? getMaxPanelHeight() : 0;
Jorim Jaggi3e02adb2015-05-13 17:50:26 -0700735 if (!expand) {
736 mClosing = true;
737 }
Selim Cinek9db71052015-04-24 18:54:30 -0700738 flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700739 }
740
741 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700742 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200743 // Hack to make the expand transition look nice when clear all button is visible - we make
744 // the animation only to the last notification, and then jump to the maximum panel height so
745 // clear all just fades in and the decelerating motion is towards the last notification.
746 final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
747 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
748 && !isClearAllVisible();
749 if (clearAllExpandHack) {
750 target = getMaxPanelHeight() - getClearAllHeight();
751 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200752 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200753 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200754 return;
755 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200756 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200757 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200758 if (expand) {
Selim Cinek61190fb2016-12-07 12:16:45 -0800759 if (expandBecauseOfFalsing && vel < 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200760 vel = 0;
761 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200762 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
Jorim Jaggi6626f542016-08-22 13:08:44 -0700763 if (vel == 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200764 animator.setDuration(350);
765 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200766 } else {
Selim Cinek2411f762016-12-28 17:05:08 +0100767 if (shouldUseDismissingAnimation()) {
Selim Cinekdf5501b2017-04-14 20:01:27 -0700768 if (vel == 0) {
769 animator.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
770 long duration = (long) (200 + mExpandedHeight / getHeight() * 100);
771 animator.setDuration(duration);
772 } else {
773 mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
774 getHeight());
775 }
Selim Cinek2411f762016-12-28 17:05:08 +0100776 } else {
777 mFlingAnimationUtilsClosing
778 .apply(animator, mExpandedHeight, target, vel, getHeight());
779 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200780
781 // Make it shorter if we run a canned animation
782 if (vel == 0) {
Selim Cinek593ee202016-12-28 15:01:16 +0100783 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200784 }
Selim Cinek2627d722018-01-19 12:16:49 -0800785 if (mFixedDuration != NO_FIXED_DURATION) {
786 animator.setDuration(mFixedDuration);
787 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200788 }
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() {
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800947 return mClosing || mLaunchingNotification;
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
Lucas Dupinbc9aac12018-03-04 20:18:15 -08001100 public boolean isUnlockHintRunning() {
1101 return mHintAnimationRunning;
1102 }
1103
Jorim Jaggi90129582014-06-02 14:44:49 +02001104 /**
1105 * Phase 1: Move everything upwards.
1106 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001107 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001108 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1109 ValueAnimator animator = createHeightAnimator(target);
1110 animator.setDuration(250);
Selim Cinekc18010f2016-01-20 13:41:30 -08001111 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi90129582014-06-02 14:44:49 +02001112 animator.addListener(new AnimatorListenerAdapter() {
1113 private boolean mCancelled;
1114
1115 @Override
1116 public void onAnimationCancel(Animator animation) {
1117 mCancelled = true;
1118 }
1119
1120 @Override
1121 public void onAnimationEnd(Animator animation) {
1122 if (mCancelled) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001123 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001124 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +02001125 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001126 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +02001127 }
1128 }
1129 });
1130 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001131 setAnimator(animator);
Adrian Roos8d4e99f2017-05-25 18:03:58 -07001132
1133 View[] viewsToAnimate = {
1134 mKeyguardBottomArea.getIndicationArea(),
1135 mStatusBar.getAmbientIndicationContainer()};
1136 for (View v : viewsToAnimate) {
1137 if (v == null) {
1138 continue;
1139 }
1140 v.animate()
1141 .translationY(-mHintDistance)
1142 .setDuration(250)
1143 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
1144 .withEndAction(() -> v.animate()
1145 .translationY(0)
1146 .setDuration(450)
1147 .setInterpolator(mBounceInterpolator)
1148 .start())
1149 .start();
1150 }
Jorim Jaggi90129582014-06-02 14:44:49 +02001151 }
1152
Selim Cinekbe2c4432017-05-30 12:11:09 -07001153 private void setAnimator(ValueAnimator animator) {
1154 mHeightAnimator = animator;
1155 if (animator == null && mPanelUpdateWhenAnimatorEnds) {
1156 mPanelUpdateWhenAnimatorEnds = false;
1157 requestPanelHeightUpdate();
1158 }
1159 }
1160
Jorim Jaggi90129582014-06-02 14:44:49 +02001161 /**
1162 * Phase 2: Bounce down.
1163 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001164 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001165 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1166 animator.setDuration(450);
1167 animator.setInterpolator(mBounceInterpolator);
1168 animator.addListener(new AnimatorListenerAdapter() {
1169 @Override
1170 public void onAnimationEnd(Animator animation) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001171 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001172 onAnimationFinished.run();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001173 notifyBarPanelExpansionChanged();
Jorim Jaggi90129582014-06-02 14:44:49 +02001174 }
1175 });
1176 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001177 setAnimator(animator);
Jorim Jaggi90129582014-06-02 14:44:49 +02001178 }
1179
1180 private ValueAnimator createHeightAnimator(float targetHeight) {
1181 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1182 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1183 @Override
1184 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001185 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +02001186 }
1187 });
1188 return animator;
1189 }
1190
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001191 protected void notifyBarPanelExpansionChanged() {
Selim Cinek48ff9b42016-11-09 19:31:51 -08001192 mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
Selim Cinek0fccc722015-07-29 17:04:36 -07001193 || mPeekAnimator != null || mInstantExpanding || isPanelVisibleBecauseOfHeadsUp()
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001194 || mTracking || mHeightAnimator != null);
Lucas Dupinbc9aac12018-03-04 20:18:15 -08001195 if (mExpansionListener != null) {
1196 mExpansionListener.accept(mExpandedFraction, mTracking);
1197 }
1198 }
1199
1200 public void setExpansionListener(BiConsumer<Float, Boolean> consumer) {
1201 mExpansionListener = consumer;
Jorim Jaggib472b3472014-06-30 19:56:24 +02001202 }
1203
Selim Cinek0fccc722015-07-29 17:04:36 -07001204 protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1205
Jorim Jaggi90129582014-06-02 14:44:49 +02001206 /**
1207 * Gets called when the user performs a click anywhere in the empty area of the panel.
1208 *
1209 * @return whether the panel will be expanded after the action performed by this method
1210 */
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001211 protected boolean onEmptySpaceClick(float x) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001212 if (mHintAnimationRunning) {
1213 return true;
1214 }
Selim Cinek6746c282015-04-21 19:58:31 -07001215 return onMiddleClicked();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001216 }
1217
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001218 protected final Runnable mPostCollapseRunnable = new Runnable() {
Jorim Jaggi488b7922014-08-05 21:12:02 +02001219 @Override
1220 public void run() {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -07001221 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
Jorim Jaggi488b7922014-08-05 21:12:02 +02001222 }
1223 };
Jorim Jaggi488b7922014-08-05 21:12:02 +02001224
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001225 protected abstract boolean onMiddleClicked();
Jorim Jaggi90129582014-06-02 14:44:49 +02001226
Jorim Jaggid7912d22014-09-30 17:38:19 +02001227 protected abstract boolean isDozing();
1228
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001229 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +02001230 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001231 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001232 + "]",
1233 this.getClass().getSimpleName(),
1234 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001235 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001236 mClosing?"T":"f",
1237 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001238 mJustPeeked?"T":"f",
1239 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001240 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1241 mTouchDisabled?"T":"f"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001242 ));
1243 }
Selim Cinek3c4635c2014-05-29 02:12:47 +02001244
1245 public abstract void resetViews();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001246
1247 protected abstract float getPeekHeight();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02001248 /**
1249 * @return whether "Clear all" button will be visible when the panel is fully expanded
1250 */
1251 protected abstract boolean fullyExpandedClearAllVisible();
1252
1253 protected abstract boolean isClearAllVisible();
1254
1255 /**
1256 * @return the height of the clear all button, in pixels
1257 */
1258 protected abstract int getClearAllHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001259
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001260 public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001261 mHeadsUpManager = headsUpManager;
1262 }
Selim Cinek2627d722018-01-19 12:16:49 -08001263
1264 public void setLaunchingNotification(boolean launchingNotification) {
1265 mLaunchingNotification = launchingNotification;
1266 }
1267
1268 public void collapseWithDuration(int animationDuration) {
1269 mFixedDuration = animationDuration;
1270 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
1271 mFixedDuration = NO_FIXED_DURATION;
1272 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001273}