blob: a62a424caaf5e2239b15efe58cbe987e6be3ddad [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;
Selim Cinek2627d722018-01-19 12:16:49 -080063 private static final int NO_FIXED_DURATION = -1;
Selim Cinek48ff9b42016-11-09 19:31:51 -080064 private long mDownTime;
65 private float mMinExpandHeight;
Chris Wren27a52fa2017-02-01 14:21:43 -050066 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinekbe2c4432017-05-30 12:11:09 -070067 private boolean mPanelUpdateWhenAnimatorEnds;
Selim Cinekf6559f82017-08-16 14:49:10 -070068 private boolean mVibrateOnOpening;
Selim Cinek4f6c85f2017-12-04 16:42:33 +010069 private boolean mVibrationEnabled;
Selim Cinek2627d722018-01-19 12:16:49 -080070 protected boolean mLaunchingNotification;
71 private int mFixedDuration = NO_FIXED_DURATION;
Selim Cinek173f2d02015-04-29 15:36:56 -070072
John Spurlock97642182013-07-29 17:58:39 -040073 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040074 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040075 }
76
Jason Monk2a6ea9c2017-01-26 11:14:51 -050077 protected StatusBar mStatusBar;
Selim Cinek684a4422015-04-15 16:18:39 -070078 protected HeadsUpManager mHeadsUpManager;
79
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040080 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020081 private float mHintDistance;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010082 private float mInitialOffsetOnTouch;
Selim Cinek79d79c42015-05-21 16:14:45 -070083 private boolean mCollapsedAndHeadsUpOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040084 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020085 protected float mExpandedHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +020086 private boolean mPanelClosedOnDown;
87 private boolean mHasLayoutedSinceDown;
88 private float mUpdateFlingVelocity;
89 private boolean mUpdateFlingOnLayout;
Jorim Jaggib7a33032014-08-20 16:21:36 +020090 private boolean mPeekTouching;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040091 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040092 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020093 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020094 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040095 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020096 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020097 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020098 private boolean mOverExpandedBeforeFling;
Selim Cinek19c8c702014-08-25 22:09:19 +020099 private boolean mTouchAboveFalsingThreshold;
100 private int mUnlockFalsingThreshold;
Selim Cinekab1dc952014-10-30 20:20:29 +0100101 private boolean mTouchStartedInEmptyArea;
Selim Cinek547a06b2014-11-27 14:06:04 +0100102 private boolean mMotionAborted;
Selim Cinek9db71052015-04-24 18:54:30 -0700103 private boolean mUpwardsWhenTresholdReached;
Selim Cinek173f2d02015-04-29 15:36:56 -0700104 private boolean mAnimatingOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400105
Jorim Jaggi1d480692014-05-20 19:41:58 +0200106 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400107 private ObjectAnimator mPeekAnimator;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200108 private VelocityTrackerInterface mVelocityTracker;
Jorim Jaggi1d480692014-05-20 19:41:58 +0200109 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800110 private FlingAnimationUtils mFlingAnimationUtilsClosing;
Selim Cinek2411f762016-12-28 17:05:08 +0100111 private FlingAnimationUtils mFlingAnimationUtilsDismissing;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700112 private FalsingManager mFalsingManager;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700113 private final Vibrator mVibrator;
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100114 final private ContentObserver mVibrationObserver = new ContentObserver(Handler.getMain()) {
115 @Override
116 public void onChange(boolean selfChange) {
117 updateHapticFeedBackEnabled();
118 }
119 };
Daniel Sandler08d05e32012-08-08 16:39:54 -0400120
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200121 /**
122 * Whether an instant expand request is currently pending and we are just waiting for layout.
123 */
124 private boolean mInstantExpanding;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700125 private boolean mAnimateAfterExpanding;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200126
Daniel Sandler08d05e32012-08-08 16:39:54 -0400127 PanelBar mBar;
128
Daniel Sandler50508132012-08-16 14:10:53 -0400129 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200130 private float mInitialTouchY;
131 private float mInitialTouchX;
Jorim Jaggid41083a2014-09-12 02:54:40 +0200132 private boolean mTouchDisabled;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400133
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800134 /**
135 * Whether or not the PanelView can be expanded or collapsed with a drag.
136 */
137 private boolean mNotificationsDragEnabled;
138
Jorim Jaggi90129582014-06-02 14:44:49 +0200139 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200140 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +0200141
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700142 /**
143 * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
144 */
145 private float mNextCollapseSpeedUpFactor = 1.0f;
146
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700147 protected boolean mExpanding;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200148 private boolean mGestureWaitForTouchSlop;
Selim Cinek9db71052015-04-24 18:54:30 -0700149 private boolean mIgnoreXTouchSlop;
Jorim Jaggie05256e2016-09-08 14:58:20 -0700150 private boolean mExpandLatencyTracking;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200151
Selim Cinek1685e632014-04-08 02:27:49 +0200152 protected void onExpandingFinished() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200153 mBar.onExpandingFinished();
Selim Cinek1685e632014-04-08 02:27:49 +0200154 }
155
156 protected void onExpandingStarted() {
157 }
158
Jorim Jaggib472b3472014-06-30 19:56:24 +0200159 private void notifyExpandingStarted() {
160 if (!mExpanding) {
161 mExpanding = true;
162 onExpandingStarted();
163 }
164 }
165
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700166 protected final void notifyExpandingFinished() {
Selim Cinekb0e4f9e2015-11-02 13:42:58 -0800167 endClosing();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200168 if (mExpanding) {
169 mExpanding = false;
170 onExpandingFinished();
171 }
172 }
173
Selim Cinek48ff9b42016-11-09 19:31:51 -0800174 private void runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished) {
175 mPeekHeight = peekHeight;
John Spurlock97642182013-07-29 17:58:39 -0400176 if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200177 if (mHeightAnimator != null) {
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400178 return;
179 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800180 if (mPeekAnimator != null) {
181 mPeekAnimator.cancel();
182 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200183 mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800184 .setDuration(duration);
Selim Cinekc18010f2016-01-20 13:41:30 -0800185 mPeekAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200186 mPeekAnimator.addListener(new AnimatorListenerAdapter() {
187 private boolean mCancelled;
188
189 @Override
190 public void onAnimationCancel(Animator animation) {
191 mCancelled = true;
192 }
193
194 @Override
195 public void onAnimationEnd(Animator animation) {
196 mPeekAnimator = null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800197 if (!mCancelled && collapseWhenFinished) {
Selim Cineka0f5c762015-06-22 14:44:46 -0400198 postOnAnimation(mPostCollapseRunnable);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200199 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800200
Jorim Jaggib472b3472014-06-30 19:56:24 +0200201 }
202 });
203 notifyExpandingStarted();
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400204 mPeekAnimator.start();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200205 mJustPeeked = true;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400206 }
207
Daniel Sandler08d05e32012-08-08 16:39:54 -0400208 public PanelView(Context context, AttributeSet attrs) {
209 super(context, attrs);
Selim Cinek593ee202016-12-28 15:01:16 +0100210 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f /* maxLengthSeconds */,
211 0.6f /* speedUpFactor */);
212 mFlingAnimationUtilsClosing = new FlingAnimationUtils(context, 0.5f /* maxLengthSeconds */,
213 0.6f /* speedUpFactor */);
Selim Cinek2411f762016-12-28 17:05:08 +0100214 mFlingAnimationUtilsDismissing = new FlingAnimationUtils(context,
215 0.5f /* maxLengthSeconds */, 0.2f /* speedUpFactor */, 0.6f /* x2 */,
216 0.84f /* y2 */);
Jorim Jaggi90129582014-06-02 14:44:49 +0200217 mBounceInterpolator = new BounceInterpolator();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700218 mFalsingManager = FalsingManager.getInstance(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800219 mNotificationsDragEnabled =
220 getResources().getBoolean(R.bool.config_enableNotificationShadeDrag);
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700221 mVibrator = mContext.getSystemService(Vibrator.class);
Selim Cinekf6559f82017-08-16 14:49:10 -0700222 mVibrateOnOpening = mContext.getResources().getBoolean(
223 R.bool.config_vibrateOnIconAnimation);
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100224 mContext.getContentResolver().registerContentObserver(
225 Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED), true,
226 mVibrationObserver);
227 mVibrationObserver.onChange(false /* selfChange */);
228 }
229
230 public void updateHapticFeedBackEnabled() {
231 mVibrationEnabled = Settings.System.getIntForUser(mContext.getContentResolver(),
232 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400233 }
234
Jorim Jaggi069cd032014-05-15 03:09:01 +0200235 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400236 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100237 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
238 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200239 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200240 mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400241 }
242
243 private void trackMovement(MotionEvent event) {
244 // Add movement to velocity tracker using raw screen X and Y coordinates instead
245 // of window coordinates because the window frame may be moving at the same time.
246 float deltaX = event.getRawX() - event.getX();
247 float deltaY = event.getRawY() - event.getY();
248 event.offsetLocation(deltaX, deltaY);
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400249 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400250 event.offsetLocation(-deltaX, -deltaY);
251 }
252
Jorim Jaggid41083a2014-09-12 02:54:40 +0200253 public void setTouchDisabled(boolean disabled) {
254 mTouchDisabled = disabled;
Selim Cinek48a92a52017-05-02 20:02:30 -0700255 if (mTouchDisabled) {
256 cancelHeightAnimator();
257 if (mTracking) {
258 onTrackingStopped(true /* expanded */);
259 }
Selim Cinekeede5d72017-05-22 17:09:55 -0700260 notifyExpandingFinished();
Selim Cinek3127daf02016-07-22 18:04:23 -0700261 }
Jorim Jaggid41083a2014-09-12 02:54:40 +0200262 }
263
Jorim Jaggie05256e2016-09-08 14:58:20 -0700264 public void startExpandLatencyTracking() {
265 if (LatencyTracker.isEnabled(mContext)) {
266 LatencyTracker.getInstance(mContext).onActionStart(
267 LatencyTracker.ACTION_EXPAND_PANEL);
268 mExpandLatencyTracking = true;
269 }
270 }
271
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400272 @Override
273 public boolean onTouchEvent(MotionEvent event) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100274 if (mInstantExpanding || mTouchDisabled
275 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200276 return false;
277 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100278
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800279 // If dragging should not expand the notifications shade, then return false.
280 if (!mNotificationsDragEnabled) {
281 if (mTracking) {
282 // Turn off tracking if it's on or the shade can get stuck in the down position.
283 onTrackingStopped(true /* expand */);
284 }
285 return false;
286 }
287
Jun Mukaicf9933c2015-07-08 17:34:26 -0700288 // On expanding, single mouse click expands the panel instead of dragging.
Jun Mukaic99243a2015-10-15 02:59:57 -0700289 if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
Jun Mukaicf9933c2015-07-08 17:34:26 -0700290 if (event.getAction() == MotionEvent.ACTION_UP) {
291 expand(true);
292 }
293 return true;
294 }
295
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100296 /*
297 * We capture touch events here and update the expand height here in case according to
298 * the users fingers. This also handles multi-touch.
299 *
Chris Wren5d53df42015-06-26 11:26:03 -0400300 * If the user just clicks shortly, we show a quick peek of the shade.
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100301 *
302 * Flinging is also enabled in order to open or close the shade.
303 */
304
305 int pointerIndex = event.findPointerIndex(mTrackingPointer);
306 if (pointerIndex < 0) {
307 pointerIndex = 0;
308 mTrackingPointer = event.getPointerId(pointerIndex);
309 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200310 final float x = event.getX(pointerIndex);
Selim Cinek547a06b2014-11-27 14:06:04 +0100311 final float y = event.getY(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100312
Jorim Jaggib472b3472014-06-30 19:56:24 +0200313 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek684a4422015-04-15 16:18:39 -0700314 mGestureWaitForTouchSlop = isFullyCollapsed() || hasConflictingGestures();
315 mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200316 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200317
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100318 switch (event.getActionMasked()) {
319 case MotionEvent.ACTION_DOWN:
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700320 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200321 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800322 mMinExpandHeight = 0.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700323 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek31094df2014-08-14 19:28:15 +0200324 mHasLayoutedSinceDown = false;
325 mUpdateFlingOnLayout = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100326 mMotionAborted = false;
Jorim Jaggib7a33032014-08-20 16:21:36 +0200327 mPeekTouching = mPanelClosedOnDown;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800328 mDownTime = SystemClock.uptimeMillis();
Selim Cinek19c8c702014-08-25 22:09:19 +0200329 mTouchAboveFalsingThreshold = false;
Selim Cinek79d79c42015-05-21 16:14:45 -0700330 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
331 && mHeadsUpManager.hasPinnedHeadsUp();
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200332 if (mVelocityTracker == null) {
333 initVelocityTracker();
334 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100335 trackMovement(event);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800336 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
337 || mPeekAnimator != null) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200338 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800339 || mPeekAnimator != null;
Selim Cinekd18b86f2017-06-21 09:44:52 -0700340 cancelHeightAnimator();
341 cancelPeek();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200342 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200343 }
Selim Cinek79d79c42015-05-21 16:14:45 -0700344 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800345 startOpening();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100346 }
347 break;
348
349 case MotionEvent.ACTION_POINTER_UP:
350 final int upPointer = event.getPointerId(event.getActionIndex());
351 if (mTrackingPointer == upPointer) {
352 // gesture is ongoing, find a new pointer to track
353 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
354 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200355 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100356 mTrackingPointer = event.getPointerId(newIndex);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700357 startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100358 }
359 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100360 case MotionEvent.ACTION_POINTER_DOWN:
361 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
362 mMotionAborted = true;
363 endMotionEvent(event, x, y, true /* forceCancel */);
364 return false;
365 }
366 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100367 case MotionEvent.ACTION_MOVE:
Selim Cinekd5ab6452016-12-08 16:34:00 -0800368 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200369 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200370
371 // If the panel was collapsed when touching, we only need to check for the
372 // y-component of the gesture, as we have no conflicting horizontal gesture.
373 if (Math.abs(h) > mTouchSlop
374 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800375 || mIgnoreXTouchSlop)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200376 mTouchSlopExceeded = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700377 if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
Jorim Jaggi0b1528a2014-10-28 22:47:46 +0100378 if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700379 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200380 h = 0;
381 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200382 cancelHeightAnimator();
Jorim Jaggi90129582014-06-02 14:44:49 +0200383 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200384 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200385 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800386 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200387 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200388 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100389 mPeekAnimator.cancel();
390 }
391 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800392 } else if (mPeekAnimator == null && mJustPeeked) {
393 // The initial peek has finished, but we haven't dragged as far yet, lets
394 // speed it up by starting at the peek height.
395 mInitialOffsetOnTouch = mExpandedHeight;
396 mInitialTouchY = y;
397 mMinExpandHeight = mExpandedHeight;
398 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100399 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800400 newHeight = Math.max(newHeight, mMinExpandHeight);
Selim Cinek29ed3c92014-09-23 20:44:35 +0200401 if (-h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200402 mTouchAboveFalsingThreshold = true;
Selim Cinek9db71052015-04-24 18:54:30 -0700403 mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
Selim Cinek19c8c702014-08-25 22:09:19 +0200404 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800405 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
406 !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000407 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100408 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100409 break;
410
411 case MotionEvent.ACTION_UP:
412 case MotionEvent.ACTION_CANCEL:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100413 trackMovement(event);
Selim Cinek547a06b2014-11-27 14:06:04 +0100414 endMotionEvent(event, x, y, false /* forceCancel */);
415 break;
416 }
Selim Cinek9db71052015-04-24 18:54:30 -0700417 return !mGestureWaitForTouchSlop || mTracking;
418 }
419
Selim Cinek48ff9b42016-11-09 19:31:51 -0800420 private void startOpening() {;
421 runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
422 false /* collapseWhenFinished */);
423 notifyBarPanelExpansionChanged();
Selim Cinek4f6c85f2017-12-04 16:42:33 +0100424 if (mVibrateOnOpening && mVibrationEnabled) {
Michael Wrightc330f7a2017-08-31 14:54:04 -0700425 AsyncTask.execute(() ->
426 mVibrator.vibrate(VibrationEffect.get(VibrationEffect.EFFECT_TICK, false)));
Selim Cinekf6559f82017-08-16 14:49:10 -0700427 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800428 }
429
430 protected abstract float getOpeningHeight();
431
Selim Cinek9db71052015-04-24 18:54:30 -0700432 /**
433 * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
434 * horizontal direction
435 */
436 private boolean isDirectionUpwards(float x, float y) {
437 float xDiff = x - mInitialTouchX;
438 float yDiff = y - mInitialTouchY;
439 if (yDiff >= 0) {
440 return false;
441 }
442 return Math.abs(yDiff) >= Math.abs(xDiff);
Selim Cinek547a06b2014-11-27 14:06:04 +0100443 }
444
Chris Wren621933f2017-06-14 15:59:03 -0400445 protected void startExpandingFromPeek() {
446 mStatusBar.handlePeekToExpandTransistion();
447 }
448
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700449 protected void startExpandMotion(float newX, float newY, boolean startTracking,
450 float expandedHeight) {
451 mInitialOffsetOnTouch = expandedHeight;
452 mInitialTouchY = newY;
453 mInitialTouchX = newX;
454 if (startTracking) {
455 mTouchSlopExceeded = true;
Selim Cinekdef35a82016-05-03 15:52:51 -0700456 setExpandedHeight(mInitialOffsetOnTouch);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700457 onTrackingStarted();
458 }
459 }
460
Selim Cinek547a06b2014-11-27 14:06:04 +0100461 private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
462 mTrackingPointer = -1;
463 if ((mTracking && mTouchSlopExceeded)
464 || Math.abs(x - mInitialTouchX) > mTouchSlop
465 || Math.abs(y - mInitialTouchY) > mTouchSlop
466 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
467 || forceCancel) {
468 float vel = 0f;
469 float vectorVel = 0f;
470 if (mVelocityTracker != null) {
471 mVelocityTracker.computeCurrentVelocity(1000);
472 vel = mVelocityTracker.getYVelocity();
473 vectorVel = (float) Math.hypot(
474 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
475 }
Selim Cinek9db71052015-04-24 18:54:30 -0700476 boolean expand = flingExpands(vel, vectorVel, x, y)
Selim Cinek547a06b2014-11-27 14:06:04 +0100477 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
478 || forceCancel;
Selim Cinek547a06b2014-11-27 14:06:04 +0100479 DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
480 mStatusBar.isFalsingThresholdNeeded(),
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700481 mStatusBar.isWakeUpComingFromTouch());
Christoph Studerb0183992014-12-22 21:02:26 +0100482 // Log collapse gesture if on lock screen.
483 if (!expand && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
484 float displayDensity = mStatusBar.getDisplayDensity();
485 int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
486 int velocityDp = (int) Math.abs(vel / displayDensity);
Chris Wren27a52fa2017-02-01 14:21:43 -0500487 mLockscreenGestureLogger.write(
488 MetricsEvent.ACTION_LS_UNLOCK,
Christoph Studerb0183992014-12-22 21:02:26 +0100489 heightDp, velocityDp);
490 }
Selim Cinek9db71052015-04-24 18:54:30 -0700491 fling(vel, expand, isFalseTouch(x, y));
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700492 onTrackingStopped(expand);
Selim Cinek547a06b2014-11-27 14:06:04 +0100493 mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
494 if (mUpdateFlingOnLayout) {
495 mUpdateFlingVelocity = vel;
496 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800497 } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking) {
498 long timePassed = SystemClock.uptimeMillis() - mDownTime;
499 if (timePassed < ViewConfiguration.getLongPressTimeout()) {
500 // Lets show the user that he can actually expand the panel
501 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
502 } else {
503 // We need to collapse the panel since we peeked to the small height.
504 postOnAnimation(mPostCollapseRunnable);
505 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100506 } else {
507 boolean expands = onEmptySpaceClick(mInitialTouchX);
508 onTrackingStopped(expands);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100509 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100510
511 if (mVelocityTracker != null) {
512 mVelocityTracker.recycle();
513 mVelocityTracker = null;
514 }
515 mPeekTouching = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100516 }
517
Selim Cinekd5ab6452016-12-08 16:34:00 -0800518 protected float getCurrentExpandVelocity() {
519 if (mVelocityTracker == null) {
520 return 0;
521 }
522 mVelocityTracker.computeCurrentVelocity(1000);
523 return mVelocityTracker.getYVelocity();
524 }
525
Selim Cinek29ed3c92014-09-23 20:44:35 +0200526 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700527 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek29ed3c92014-09-23 20:44:35 +0200528 return (int) (mUnlockFalsingThreshold * factor);
529 }
530
Selim Cinek4c6969a2014-05-26 19:22:17 +0200531 protected abstract boolean hasConflictingGestures();
532
Selim Cinek9db71052015-04-24 18:54:30 -0700533 protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
534
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200535 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200536 mTracking = false;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800537 mBar.onTrackingStopped(expand);
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700538 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200539 }
540
541 protected void onTrackingStarted() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200542 endClosing();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200543 mTracking = true;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800544 mBar.onTrackingStarted();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200545 notifyExpandingStarted();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700546 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200547 }
548
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100549 @Override
550 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700551 if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled
Selim Cinek547a06b2014-11-27 14:06:04 +0100552 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200553 return false;
554 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100555
556 /*
Chris Wren5d53df42015-06-26 11:26:03 -0400557 * If the user drags anywhere inside the panel we intercept it if the movement is
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100558 * upwards. This allows closing the shade from anywhere inside the panel.
559 *
560 * We only do this if the current content is scrolled to the bottom,
561 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
562 * possible.
563 */
564 int pointerIndex = event.findPointerIndex(mTrackingPointer);
565 if (pointerIndex < 0) {
566 pointerIndex = 0;
567 mTrackingPointer = event.getPointerId(pointerIndex);
568 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200569 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100570 final float y = event.getY(pointerIndex);
571 boolean scrolledToBottom = isScrolledToBottom();
572
573 switch (event.getActionMasked()) {
574 case MotionEvent.ACTION_DOWN:
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200575 mStatusBar.userActivity();
Selim Cinek173f2d02015-04-29 15:36:56 -0700576 mAnimatingOnDown = mHeightAnimator != null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800577 mMinExpandHeight = 0.0f;
578 mDownTime = SystemClock.uptimeMillis();
579 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
580 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200581 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200582 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200583 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200584 return true;
585 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100586 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200587 mInitialTouchX = x;
Selim Cinekab1dc952014-10-30 20:20:29 +0100588 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
Jorim Jaggi90129582014-06-02 14:44:49 +0200589 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200590 mJustPeeked = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100591 mMotionAborted = false;
Selim Cinek684a4422015-04-15 16:18:39 -0700592 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700593 mCollapsedAndHeadsUpOnDown = false;
Selim Cinek31094df2014-08-14 19:28:15 +0200594 mHasLayoutedSinceDown = false;
595 mUpdateFlingOnLayout = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200596 mTouchAboveFalsingThreshold = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100597 initVelocityTracker();
598 trackMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100599 break;
600 case MotionEvent.ACTION_POINTER_UP:
601 final int upPointer = event.getPointerId(event.getActionIndex());
602 if (mTrackingPointer == upPointer) {
603 // gesture is ongoing, find a new pointer to track
604 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
605 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200606 mInitialTouchX = event.getX(newIndex);
607 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100608 }
609 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100610 case MotionEvent.ACTION_POINTER_DOWN:
611 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
612 mMotionAborted = true;
613 if (mVelocityTracker != null) {
614 mVelocityTracker.recycle();
615 mVelocityTracker = null;
616 }
617 }
618 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100619 case MotionEvent.ACTION_MOVE:
620 final float h = y - mInitialTouchY;
621 trackMovement(event);
Selim Cinek173f2d02015-04-29 15:36:56 -0700622 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
623 float hAbs = Math.abs(h);
624 if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
625 && hAbs > Math.abs(x - mInitialTouchX)) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200626 cancelHeightAnimator();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700627 startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100628 return true;
629 }
630 }
631 break;
Selim Cinek31094df2014-08-14 19:28:15 +0200632 case MotionEvent.ACTION_CANCEL:
633 case MotionEvent.ACTION_UP:
Selim Cinek547a06b2014-11-27 14:06:04 +0100634 if (mVelocityTracker != null) {
635 mVelocityTracker.recycle();
636 mVelocityTracker = null;
637 }
Selim Cinek31094df2014-08-14 19:28:15 +0200638 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100639 }
640 return false;
641 }
642
Selim Cinekab1dc952014-10-30 20:20:29 +0100643 /**
644 * @return Whether a pair of coordinates are inside the visible view content bounds.
645 */
646 protected abstract boolean isInContentBounds(float x, float y);
647
Selim Cinek831941f2015-06-17 15:09:30 -0700648 protected void cancelHeightAnimator() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200649 if (mHeightAnimator != null) {
Selim Cinekd18b86f2017-06-21 09:44:52 -0700650 if (mHeightAnimator.isRunning()) {
651 mPanelUpdateWhenAnimatorEnds = false;
652 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200653 mHeightAnimator.cancel();
654 }
655 endClosing();
656 }
657
658 private void endClosing() {
659 if (mClosing) {
660 mClosing = false;
661 onClosingFinished();
662 }
663 }
664
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100665 private void initVelocityTracker() {
666 if (mVelocityTracker != null) {
667 mVelocityTracker.recycle();
668 }
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200669 mVelocityTracker = VelocityTrackerFactory.obtain(getContext());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100670 }
671
672 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200673 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100674 }
675
676 protected float getContentHeight() {
677 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400678 }
679
Daniel Sandler08d05e32012-08-08 16:39:54 -0400680 @Override
681 protected void onFinishInflate() {
682 super.onFinishInflate();
683 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400684 }
685
Jorim Jaggi069cd032014-05-15 03:09:01 +0200686 @Override
687 protected void onConfigurationChanged(Configuration newConfig) {
688 super.onConfigurationChanged(newConfig);
689 loadDimens();
Jorim Jaggi069cd032014-05-15 03:09:01 +0200690 }
691
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200692 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200693 * @param vel the current vertical velocity of the motion
694 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200695 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200696 */
Selim Cinek9db71052015-04-24 18:54:30 -0700697 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
698 if (isFalseTouch(x, y)) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200699 return true;
700 }
Jorim Jaggib7240132014-06-30 01:39:07 +0200701 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200702 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200703 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200704 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400705 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200706 }
707
Selim Cinek9db71052015-04-24 18:54:30 -0700708 /**
709 * @param x the final x-coordinate when the finger was lifted
710 * @param y the final y-coordinate when the finger was lifted
711 * @return whether this motion should be regarded as a false touch
712 */
713 private boolean isFalseTouch(float x, float y) {
714 if (!mStatusBar.isFalsingThresholdNeeded()) {
715 return false;
716 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700717 if (mFalsingManager.isClassiferEnabled()) {
718 return mFalsingManager.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700719 }
Selim Cinek9db71052015-04-24 18:54:30 -0700720 if (!mTouchAboveFalsingThreshold) {
721 return true;
722 }
723 if (mUpwardsWhenTresholdReached) {
724 return false;
725 }
726 return !isDirectionUpwards(x, y);
Selim Cinek5386fb32014-09-03 16:37:36 +0200727 }
728
Jorim Jaggi1d480692014-05-20 19:41:58 +0200729 protected void fling(float vel, boolean expand) {
Selim Cinek9db71052015-04-24 18:54:30 -0700730 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700731 }
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200732
Selim Cinek9db71052015-04-24 18:54:30 -0700733 protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
734 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
735 }
736
737 protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
738 boolean expandBecauseOfFalsing) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700739 cancelPeek();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800740 float target = expand ? getMaxPanelHeight() : 0;
Jorim Jaggi3e02adb2015-05-13 17:50:26 -0700741 if (!expand) {
742 mClosing = true;
743 }
Selim Cinek9db71052015-04-24 18:54:30 -0700744 flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700745 }
746
747 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700748 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200749 // Hack to make the expand transition look nice when clear all button is visible - we make
750 // the animation only to the last notification, and then jump to the maximum panel height so
751 // clear all just fades in and the decelerating motion is towards the last notification.
752 final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
753 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
754 && !isClearAllVisible();
755 if (clearAllExpandHack) {
756 target = getMaxPanelHeight() - getClearAllHeight();
757 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200758 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200759 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200760 return;
761 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200762 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200763 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200764 if (expand) {
Selim Cinek61190fb2016-12-07 12:16:45 -0800765 if (expandBecauseOfFalsing && vel < 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200766 vel = 0;
767 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200768 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
Jorim Jaggi6626f542016-08-22 13:08:44 -0700769 if (vel == 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200770 animator.setDuration(350);
771 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200772 } else {
Selim Cinek2411f762016-12-28 17:05:08 +0100773 if (shouldUseDismissingAnimation()) {
Selim Cinekdf5501b2017-04-14 20:01:27 -0700774 if (vel == 0) {
775 animator.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
776 long duration = (long) (200 + mExpandedHeight / getHeight() * 100);
777 animator.setDuration(duration);
778 } else {
779 mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
780 getHeight());
781 }
Selim Cinek2411f762016-12-28 17:05:08 +0100782 } else {
783 mFlingAnimationUtilsClosing
784 .apply(animator, mExpandedHeight, target, vel, getHeight());
785 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200786
787 // Make it shorter if we run a canned animation
788 if (vel == 0) {
Selim Cinek593ee202016-12-28 15:01:16 +0100789 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200790 }
Selim Cinek2627d722018-01-19 12:16:49 -0800791 if (mFixedDuration != NO_FIXED_DURATION) {
792 animator.setDuration(mFixedDuration);
793 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200794 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200795 animator.addListener(new AnimatorListenerAdapter() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200796 private boolean mCancelled;
797
798 @Override
799 public void onAnimationCancel(Animator animation) {
800 mCancelled = true;
801 }
802
Jorim Jaggi1d480692014-05-20 19:41:58 +0200803 @Override
804 public void onAnimationEnd(Animator animation) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200805 if (clearAllExpandHack && !mCancelled) {
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200806 setExpandedHeightInternal(getMaxPanelHeight());
807 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700808 setAnimator(null);
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200809 if (!mCancelled) {
810 notifyExpandingFinished();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200811 }
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700812 notifyBarPanelExpansionChanged();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200813 }
814 });
Selim Cinekbe2c4432017-05-30 12:11:09 -0700815 setAnimator(animator);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200816 animator.start();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400817 }
818
Selim Cinek2411f762016-12-28 17:05:08 +0100819 protected abstract boolean shouldUseDismissingAnimation();
820
Daniel Sandler08d05e32012-08-08 16:39:54 -0400821 @Override
822 protected void onAttachedToWindow() {
823 super.onAttachedToWindow();
Daniel Sandler978f8532012-08-15 15:48:16 -0400824 mViewName = getResources().getResourceName(getId());
825 }
826
827 public String getName() {
828 return mViewName;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400829 }
830
Daniel Sandler08d05e32012-08-08 16:39:54 -0400831 public void setExpandedHeight(float height) {
John Spurlock97642182013-07-29 17:58:39 -0400832 if (DEBUG) logf("setExpandedHeight(%.1f)", height);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200833 setExpandedHeightInternal(height + getOverExpansionPixels());
Daniel Sandler08d05e32012-08-08 16:39:54 -0400834 }
835
Daniel Sandler50508132012-08-16 14:10:53 -0400836 @Override
837 protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
Daniel Sandler50508132012-08-16 14:10:53 -0400838 super.onLayout(changed, left, top, right, bottom);
Selim Cinek5fbc6322016-01-15 17:17:58 -0800839 mStatusBar.onPanelLaidOut();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100840 requestPanelHeightUpdate();
Selim Cinek31094df2014-08-14 19:28:15 +0200841 mHasLayoutedSinceDown = true;
842 if (mUpdateFlingOnLayout) {
843 abortAnimations();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700844 fling(mUpdateFlingVelocity, true /* expands */);
Selim Cinek31094df2014-08-14 19:28:15 +0200845 mUpdateFlingOnLayout = false;
846 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100847 }
848
849 protected void requestPanelHeightUpdate() {
850 float currentMaxPanelHeight = getMaxPanelHeight();
851
Selim Cinekbe2c4432017-05-30 12:11:09 -0700852 if (isFullyCollapsed()) {
853 return;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100854 }
Selim Cinekbe2c4432017-05-30 12:11:09 -0700855
856 if (currentMaxPanelHeight == mExpandedHeight) {
857 return;
858 }
859
860 if (mPeekAnimator != null || mPeekTouching) {
861 return;
862 }
863
864 if (mTracking && !isTrackingBlocked()) {
865 return;
866 }
867
868 if (mHeightAnimator != null) {
869 mPanelUpdateWhenAnimatorEnds = true;
870 return;
871 }
872
873 setExpandedHeight(currentMaxPanelHeight);
Daniel Sandler50508132012-08-16 14:10:53 -0400874 }
875
Daniel Sandler08d05e32012-08-08 16:39:54 -0400876 public void setExpandedHeightInternal(float h) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700877 if (mExpandLatencyTracking && h != 0f) {
878 DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance(mContext).onActionEnd(
879 LatencyTracker.ACTION_EXPAND_PANEL));
880 mExpandLatencyTracking = false;
881 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200882 float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
883 if (mHeightAnimator == null) {
884 float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
885 if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
886 setOverExpansion(overExpansionPixels, true /* isPixels */);
887 }
888 mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
889 } else {
890 mExpandedHeight = h;
891 if (mOverExpandedBeforeFling) {
892 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
893 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100894 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400895
Jorim Jaggi45e2d8f2017-05-16 14:23:19 +0200896 // If we are closing the panel and we are almost there due to a slow decelerating
897 // interpolator, abort the animation.
898 if (mExpandedHeight < 1f && mExpandedHeight != 0f && mClosing) {
899 mExpandedHeight = 0f;
900 if (mHeightAnimator != null) {
901 mHeightAnimator.end();
902 }
903 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800904 mExpandedFraction = Math.min(1f,
905 fhWithoutOverExpansion == 0 ? 0 : mExpandedHeight / fhWithoutOverExpansion);
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +0100906 onHeightUpdated(mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200907 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400908 }
909
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200910 /**
911 * @return true if the panel tracking should be temporarily blocked; this is used when a
912 * conflicting gesture (opening QS) is happening
913 */
914 protected abstract boolean isTrackingBlocked();
915
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200916 protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
Selim Cinek24120a52014-05-26 10:05:42 +0200917
Jorim Jaggi90129582014-06-02 14:44:49 +0200918 protected abstract void onHeightUpdated(float expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100919
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200920 protected abstract float getOverExpansionAmount();
921
922 protected abstract float getOverExpansionPixels();
923
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100924 /**
925 * This returns the maximum height of the panel. Children should override this if their
926 * desired height is not the full height.
927 *
928 * @return the default implementation simply returns the maximum height.
929 */
Selim Cinek31094df2014-08-14 19:28:15 +0200930 protected abstract int getMaxPanelHeight();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400931
932 public void setExpandedFraction(float frac) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100933 setExpandedHeight(getMaxPanelHeight() * frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400934 }
935
936 public float getExpandedHeight() {
937 return mExpandedHeight;
938 }
939
940 public float getExpandedFraction() {
941 return mExpandedFraction;
942 }
943
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700944 public boolean isFullyExpanded() {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100945 return mExpandedHeight >= getMaxPanelHeight();
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700946 }
947
948 public boolean isFullyCollapsed() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800949 return mExpandedFraction <= 0.0f;
Daniel Sandler67eab792012-10-02 17:08:23 -0400950 }
951
952 public boolean isCollapsing() {
953 return mClosing;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700954 }
955
John Spurlocka4b70af2013-08-17 14:05:49 -0400956 public boolean isTracking() {
957 return mTracking;
958 }
959
Daniel Sandler08d05e32012-08-08 16:39:54 -0400960 public void setBar(PanelBar panelBar) {
961 mBar = panelBar;
962 }
963
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700964 public void collapse(boolean delayed, float speedUpFactor) {
John Spurlock97642182013-07-29 17:58:39 -0400965 if (DEBUG) logf("collapse: " + this);
Selim Cinek9bb05632016-12-15 14:14:29 -0800966 if (canPanelBeCollapsed()) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200967 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200968 notifyExpandingStarted();
Jorim Jaggi3b866be2015-06-30 11:31:10 -0700969
970 // Set after notifyExpandingStarted, as notifyExpandingStarted resets the closing state.
971 mClosing = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200972 if (delayed) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700973 mNextCollapseSpeedUpFactor = speedUpFactor;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200974 postDelayed(mFlingCollapseRunnable, 120);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200975 } else {
Selim Cinek9db71052015-04-24 18:54:30 -0700976 fling(0, false /* expand */, speedUpFactor, false /* expandBecauseOfFalsing */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200977 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400978 }
979 }
980
Selim Cinek9bb05632016-12-15 14:14:29 -0800981 public boolean canPanelBeCollapsed() {
982 return !isFullyCollapsed() && !mTracking && !mClosing;
983 }
984
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200985 private final Runnable mFlingCollapseRunnable = new Runnable() {
986 @Override
987 public void run() {
Selim Cinek9db71052015-04-24 18:54:30 -0700988 fling(0, false /* expand */, mNextCollapseSpeedUpFactor,
989 false /* expandBecauseOfFalsing */);
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200990 }
991 };
992
John Spurlock97642182013-07-29 17:58:39 -0400993 public void cancelPeek() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800994 boolean cancelled = false;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200995 if (mPeekAnimator != null) {
Selim Cinek529c5322016-04-06 20:03:45 -0700996 cancelled = true;
John Spurlock97642182013-07-29 17:58:39 -0400997 mPeekAnimator.cancel();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400998 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200999
Selim Cinek529c5322016-04-06 20:03:45 -07001000 if (cancelled) {
1001 // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
1002 // notify mBar that we might have closed ourselves.
1003 notifyBarPanelExpansionChanged();
1004 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001005 }
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001006
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001007 public void expand(final boolean animate) {
1008 if (!isFullyCollapsed() && !isCollapsing()) {
1009 return;
1010 }
1011
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001012 mInstantExpanding = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07001013 mAnimateAfterExpanding = animate;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001014 mUpdateFlingOnLayout = false;
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001015 abortAnimations();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001016 cancelPeek();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001017 if (mTracking) {
1018 onTrackingStopped(true /* expands */); // The panel is expanded after this call.
Jorim Jaggie62d5892014-09-02 16:31:19 +02001019 }
1020 if (mExpanding) {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001021 notifyExpandingFinished();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001022 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001023 notifyBarPanelExpansionChanged();
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001024
1025 // Wait for window manager to pickup the change, so we know the maximum height of the panel
1026 // then.
1027 getViewTreeObserver().addOnGlobalLayoutListener(
1028 new ViewTreeObserver.OnGlobalLayoutListener() {
1029 @Override
1030 public void onGlobalLayout() {
Jorim Jaggic5804af2016-04-25 18:51:16 -07001031 if (!mInstantExpanding) {
1032 getViewTreeObserver().removeOnGlobalLayoutListener(this);
1033 return;
1034 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001035 if (mStatusBar.getStatusBarWindow().getHeight()
1036 != mStatusBar.getStatusBarHeight()) {
1037 getViewTreeObserver().removeOnGlobalLayoutListener(this);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001038 if (mAnimateAfterExpanding) {
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001039 notifyExpandingStarted();
1040 fling(0, true /* expand */);
1041 } else {
1042 setExpandedFraction(1f);
1043 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001044 mInstantExpanding = false;
1045 }
1046 }
1047 });
1048
1049 // Make sure a layout really happens.
1050 requestLayout();
1051 }
1052
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001053 public void instantCollapse() {
1054 abortAnimations();
1055 setExpandedFraction(0f);
1056 if (mExpanding) {
1057 notifyExpandingFinished();
1058 }
Jorim Jaggic5804af2016-04-25 18:51:16 -07001059 if (mInstantExpanding) {
1060 mInstantExpanding = false;
1061 notifyBarPanelExpansionChanged();
1062 }
Selim Cinek6bb4a9b2014-10-09 17:48:05 -07001063 }
1064
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001065 private void abortAnimations() {
1066 cancelPeek();
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001067 cancelHeightAnimator();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +02001068 removeCallbacks(mPostCollapseRunnable);
1069 removeCallbacks(mFlingCollapseRunnable);
Jorim Jaggi0a27be82014-06-11 03:22:39 +02001070 }
1071
Selim Cinekdbbcfbe2014-10-24 17:52:35 +02001072 protected void onClosingFinished() {
1073 mBar.onClosingFinished();
1074 }
1075
1076
Jorim Jaggi90129582014-06-02 14:44:49 +02001077 protected void startUnlockHintAnimation() {
1078
1079 // We don't need to hint the user if an animation is already running or the user is changing
1080 // the expansion.
1081 if (mHeightAnimator != null || mTracking) {
1082 return;
1083 }
1084 cancelPeek();
Jorim Jaggib472b3472014-06-30 19:56:24 +02001085 notifyExpandingStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001086 startUnlockHintAnimationPhase1(new Runnable() {
1087 @Override
1088 public void run() {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001089 notifyExpandingFinished();
Selim Cinekec29d342017-05-05 18:31:49 -07001090 onUnlockHintFinished();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001091 mHintAnimationRunning = false;
1092 }
1093 });
Selim Cinekec29d342017-05-05 18:31:49 -07001094 onUnlockHintStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001095 mHintAnimationRunning = true;
Jorim Jaggi90129582014-06-02 14:44:49 +02001096 }
1097
Selim Cinekec29d342017-05-05 18:31:49 -07001098 protected void onUnlockHintFinished() {
1099 mStatusBar.onHintFinished();
1100 }
1101
1102 protected void onUnlockHintStarted() {
1103 mStatusBar.onUnlockHintStarted();
1104 }
1105
Jorim Jaggi90129582014-06-02 14:44:49 +02001106 /**
1107 * Phase 1: Move everything upwards.
1108 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001109 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001110 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1111 ValueAnimator animator = createHeightAnimator(target);
1112 animator.setDuration(250);
Selim Cinekc18010f2016-01-20 13:41:30 -08001113 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi90129582014-06-02 14:44:49 +02001114 animator.addListener(new AnimatorListenerAdapter() {
1115 private boolean mCancelled;
1116
1117 @Override
1118 public void onAnimationCancel(Animator animation) {
1119 mCancelled = true;
1120 }
1121
1122 @Override
1123 public void onAnimationEnd(Animator animation) {
1124 if (mCancelled) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001125 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001126 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +02001127 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001128 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +02001129 }
1130 }
1131 });
1132 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001133 setAnimator(animator);
Adrian Roos8d4e99f2017-05-25 18:03:58 -07001134
1135 View[] viewsToAnimate = {
1136 mKeyguardBottomArea.getIndicationArea(),
1137 mStatusBar.getAmbientIndicationContainer()};
1138 for (View v : viewsToAnimate) {
1139 if (v == null) {
1140 continue;
1141 }
1142 v.animate()
1143 .translationY(-mHintDistance)
1144 .setDuration(250)
1145 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
1146 .withEndAction(() -> v.animate()
1147 .translationY(0)
1148 .setDuration(450)
1149 .setInterpolator(mBounceInterpolator)
1150 .start())
1151 .start();
1152 }
Jorim Jaggi90129582014-06-02 14:44:49 +02001153 }
1154
Selim Cinekbe2c4432017-05-30 12:11:09 -07001155 private void setAnimator(ValueAnimator animator) {
1156 mHeightAnimator = animator;
1157 if (animator == null && mPanelUpdateWhenAnimatorEnds) {
1158 mPanelUpdateWhenAnimatorEnds = false;
1159 requestPanelHeightUpdate();
1160 }
1161 }
1162
Jorim Jaggi90129582014-06-02 14:44:49 +02001163 /**
1164 * Phase 2: Bounce down.
1165 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001166 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001167 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1168 animator.setDuration(450);
1169 animator.setInterpolator(mBounceInterpolator);
1170 animator.addListener(new AnimatorListenerAdapter() {
1171 @Override
1172 public void onAnimationEnd(Animator animation) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07001173 setAnimator(null);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001174 onAnimationFinished.run();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001175 notifyBarPanelExpansionChanged();
Jorim Jaggi90129582014-06-02 14:44:49 +02001176 }
1177 });
1178 animator.start();
Selim Cinekbe2c4432017-05-30 12:11:09 -07001179 setAnimator(animator);
Jorim Jaggi90129582014-06-02 14:44:49 +02001180 }
1181
1182 private ValueAnimator createHeightAnimator(float targetHeight) {
1183 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1184 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1185 @Override
1186 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001187 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +02001188 }
1189 });
1190 return animator;
1191 }
1192
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001193 protected void notifyBarPanelExpansionChanged() {
Selim Cinek48ff9b42016-11-09 19:31:51 -08001194 mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
Selim Cinek0fccc722015-07-29 17:04:36 -07001195 || mPeekAnimator != null || mInstantExpanding || isPanelVisibleBecauseOfHeadsUp()
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001196 || mTracking || mHeightAnimator != null);
Jorim Jaggib472b3472014-06-30 19:56:24 +02001197 }
1198
Selim Cinek0fccc722015-07-29 17:04:36 -07001199 protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1200
Jorim Jaggi90129582014-06-02 14:44:49 +02001201 /**
1202 * Gets called when the user performs a click anywhere in the empty area of the panel.
1203 *
1204 * @return whether the panel will be expanded after the action performed by this method
1205 */
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001206 protected boolean onEmptySpaceClick(float x) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001207 if (mHintAnimationRunning) {
1208 return true;
1209 }
Selim Cinek6746c282015-04-21 19:58:31 -07001210 return onMiddleClicked();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001211 }
1212
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001213 protected final Runnable mPostCollapseRunnable = new Runnable() {
Jorim Jaggi488b7922014-08-05 21:12:02 +02001214 @Override
1215 public void run() {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -07001216 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
Jorim Jaggi488b7922014-08-05 21:12:02 +02001217 }
1218 };
Jorim Jaggi488b7922014-08-05 21:12:02 +02001219
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001220 protected abstract boolean onMiddleClicked();
Jorim Jaggi90129582014-06-02 14:44:49 +02001221
Jorim Jaggid7912d22014-09-30 17:38:19 +02001222 protected abstract boolean isDozing();
1223
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001224 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +02001225 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001226 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001227 + "]",
1228 this.getClass().getSimpleName(),
1229 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001230 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001231 mClosing?"T":"f",
1232 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001233 mJustPeeked?"T":"f",
1234 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001235 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1236 mTouchDisabled?"T":"f"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001237 ));
1238 }
Selim Cinek3c4635c2014-05-29 02:12:47 +02001239
1240 public abstract void resetViews();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001241
1242 protected abstract float getPeekHeight();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02001243 /**
1244 * @return whether "Clear all" button will be visible when the panel is fully expanded
1245 */
1246 protected abstract boolean fullyExpandedClearAllVisible();
1247
1248 protected abstract boolean isClearAllVisible();
1249
1250 /**
1251 * @return the height of the clear all button, in pixels
1252 */
1253 protected abstract int getClearAllHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001254
1255 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
1256 mHeadsUpManager = headsUpManager;
1257 }
Selim Cinek2627d722018-01-19 12:16:49 -08001258
1259 public void setLaunchingNotification(boolean launchingNotification) {
1260 mLaunchingNotification = launchingNotification;
1261 }
1262
1263 public void collapseWithDuration(int animationDuration) {
1264 mFixedDuration = animationDuration;
1265 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
1266 mFixedDuration = NO_FIXED_DURATION;
1267 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001268}