blob: fa74cc183b78f4da78458ae520db4153db7eff21 [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;
Daniel Sandler08d05e32012-08-08 16:39:54 -040027import android.util.AttributeSet;
John Spurlockcd686b52013-06-05 10:13:46 -040028import android.util.Log;
Jun Mukaide750b42015-10-01 18:35:33 +090029import android.view.InputDevice;
Daniel Sandler08d05e32012-08-08 16:39:54 -040030import android.view.MotionEvent;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010031import android.view.ViewConfiguration;
Jorim Jaggi0a27be82014-06-11 03:22:39 +020032import android.view.ViewTreeObserver;
Jorim Jaggi90129582014-06-02 14:44:49 +020033import android.view.animation.Interpolator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040034import android.widget.FrameLayout;
35
Chris Wren27a52fa2017-02-01 14:21:43 -050036import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jorim Jaggie05256e2016-09-08 14:58:20 -070037import com.android.systemui.DejankUtils;
Christoph Studerb0183992014-12-22 21:02:26 +010038import com.android.systemui.EventLogConstants;
39import com.android.systemui.EventLogTags;
Winsonc0d70582016-01-29 10:24:39 -080040import com.android.systemui.Interpolators;
Jorim Jaggid0565172016-09-15 16:31:14 -070041import com.android.keyguard.LatencyTracker;
Daniel Sandler08d05e32012-08-08 16:39:54 -040042import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070043import com.android.systemui.classifier.FalsingManager;
John Spurlock813552c2014-09-19 08:30:21 -040044import com.android.systemui.doze.DozeLog;
Jorim Jaggi1d480692014-05-20 19:41:58 +020045import com.android.systemui.statusbar.FlingAnimationUtils;
Jorim Jaggi90129582014-06-02 14:44:49 +020046import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070047import com.android.systemui.statusbar.policy.HeadsUpManager;
Daniel Sandler08d05e32012-08-08 16:39:54 -040048
John Spurlockde84f0e2013-06-12 12:41:00 -040049import java.io.FileDescriptor;
50import java.io.PrintWriter;
John Spurlockde84f0e2013-06-12 12:41:00 -040051
Selim Cinek4c6969a2014-05-26 19:22:17 +020052public abstract class PanelView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040053 public static final boolean DEBUG = PanelBar.DEBUG;
Daniel Sandler08d05e32012-08-08 16:39:54 -040054 public static final String TAG = PanelView.class.getSimpleName();
Selim Cinek48ff9b42016-11-09 19:31:51 -080055 private static final int INITIAL_OPENING_PEEK_DURATION = 200;
56 private static final int PEEK_ANIMATION_DURATION = 360;
57 private long mDownTime;
58 private float mMinExpandHeight;
Chris Wren27a52fa2017-02-01 14:21:43 -050059 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinek173f2d02015-04-29 15:36:56 -070060
John Spurlock97642182013-07-29 17:58:39 -040061 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040062 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040063 }
64
Jason Monk2a6ea9c2017-01-26 11:14:51 -050065 protected StatusBar mStatusBar;
Selim Cinek684a4422015-04-15 16:18:39 -070066 protected HeadsUpManager mHeadsUpManager;
67
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040068 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020069 private float mHintDistance;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010070 private float mInitialOffsetOnTouch;
Selim Cinek79d79c42015-05-21 16:14:45 -070071 private boolean mCollapsedAndHeadsUpOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040072 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020073 protected float mExpandedHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +020074 private boolean mPanelClosedOnDown;
75 private boolean mHasLayoutedSinceDown;
76 private float mUpdateFlingVelocity;
77 private boolean mUpdateFlingOnLayout;
Jorim Jaggib7a33032014-08-20 16:21:36 +020078 private boolean mPeekTouching;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040079 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040080 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020081 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020082 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040083 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020084 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020085 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020086 private boolean mOverExpandedBeforeFling;
Selim Cinek19c8c702014-08-25 22:09:19 +020087 private boolean mTouchAboveFalsingThreshold;
88 private int mUnlockFalsingThreshold;
Selim Cinekab1dc952014-10-30 20:20:29 +010089 private boolean mTouchStartedInEmptyArea;
Selim Cinek547a06b2014-11-27 14:06:04 +010090 private boolean mMotionAborted;
Selim Cinek9db71052015-04-24 18:54:30 -070091 private boolean mUpwardsWhenTresholdReached;
Selim Cinek173f2d02015-04-29 15:36:56 -070092 private boolean mAnimatingOnDown;
Daniel Sandler08d05e32012-08-08 16:39:54 -040093
Jorim Jaggi1d480692014-05-20 19:41:58 +020094 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040095 private ObjectAnimator mPeekAnimator;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +020096 private VelocityTrackerInterface mVelocityTracker;
Jorim Jaggi1d480692014-05-20 19:41:58 +020097 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek48ff9b42016-11-09 19:31:51 -080098 private FlingAnimationUtils mFlingAnimationUtilsClosing;
Selim Cinek2411f762016-12-28 17:05:08 +010099 private FlingAnimationUtils mFlingAnimationUtilsDismissing;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700100 private FalsingManager mFalsingManager;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400101
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200102 /**
103 * Whether an instant expand request is currently pending and we are just waiting for layout.
104 */
105 private boolean mInstantExpanding;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700106 private boolean mAnimateAfterExpanding;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200107
Daniel Sandler08d05e32012-08-08 16:39:54 -0400108 PanelBar mBar;
109
Daniel Sandler50508132012-08-16 14:10:53 -0400110 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200111 private float mInitialTouchY;
112 private float mInitialTouchX;
Jorim Jaggid41083a2014-09-12 02:54:40 +0200113 private boolean mTouchDisabled;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400114
Jorim Jaggi90129582014-06-02 14:44:49 +0200115 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200116 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +0200117
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700118 /**
119 * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
120 */
121 private float mNextCollapseSpeedUpFactor = 1.0f;
122
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700123 protected boolean mExpanding;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200124 private boolean mGestureWaitForTouchSlop;
Selim Cinek9db71052015-04-24 18:54:30 -0700125 private boolean mIgnoreXTouchSlop;
Jorim Jaggie05256e2016-09-08 14:58:20 -0700126 private boolean mExpandLatencyTracking;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200127
Selim Cinek1685e632014-04-08 02:27:49 +0200128 protected void onExpandingFinished() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200129 mBar.onExpandingFinished();
Selim Cinek1685e632014-04-08 02:27:49 +0200130 }
131
132 protected void onExpandingStarted() {
133 }
134
Jorim Jaggib472b3472014-06-30 19:56:24 +0200135 private void notifyExpandingStarted() {
136 if (!mExpanding) {
137 mExpanding = true;
138 onExpandingStarted();
139 }
140 }
141
Jorim Jaggi1d071ce2015-07-22 14:05:06 -0700142 protected final void notifyExpandingFinished() {
Selim Cinekb0e4f9e2015-11-02 13:42:58 -0800143 endClosing();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200144 if (mExpanding) {
145 mExpanding = false;
146 onExpandingFinished();
147 }
148 }
149
Selim Cinek48ff9b42016-11-09 19:31:51 -0800150 private void runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished) {
151 mPeekHeight = peekHeight;
John Spurlock97642182013-07-29 17:58:39 -0400152 if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200153 if (mHeightAnimator != null) {
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400154 return;
155 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800156 if (mPeekAnimator != null) {
157 mPeekAnimator.cancel();
158 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200159 mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800160 .setDuration(duration);
Selim Cinekc18010f2016-01-20 13:41:30 -0800161 mPeekAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200162 mPeekAnimator.addListener(new AnimatorListenerAdapter() {
163 private boolean mCancelled;
164
165 @Override
166 public void onAnimationCancel(Animator animation) {
167 mCancelled = true;
168 }
169
170 @Override
171 public void onAnimationEnd(Animator animation) {
172 mPeekAnimator = null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800173 if (!mCancelled && collapseWhenFinished) {
Selim Cineka0f5c762015-06-22 14:44:46 -0400174 postOnAnimation(mPostCollapseRunnable);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200175 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800176
Jorim Jaggib472b3472014-06-30 19:56:24 +0200177 }
178 });
179 notifyExpandingStarted();
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400180 mPeekAnimator.start();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200181 mJustPeeked = true;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400182 }
183
Daniel Sandler08d05e32012-08-08 16:39:54 -0400184 public PanelView(Context context, AttributeSet attrs) {
185 super(context, attrs);
Selim Cinek593ee202016-12-28 15:01:16 +0100186 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f /* maxLengthSeconds */,
187 0.6f /* speedUpFactor */);
188 mFlingAnimationUtilsClosing = new FlingAnimationUtils(context, 0.5f /* maxLengthSeconds */,
189 0.6f /* speedUpFactor */);
Selim Cinek2411f762016-12-28 17:05:08 +0100190 mFlingAnimationUtilsDismissing = new FlingAnimationUtils(context,
191 0.5f /* maxLengthSeconds */, 0.2f /* speedUpFactor */, 0.6f /* x2 */,
192 0.84f /* y2 */);
Jorim Jaggi90129582014-06-02 14:44:49 +0200193 mBounceInterpolator = new BounceInterpolator();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700194 mFalsingManager = FalsingManager.getInstance(context);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400195 }
196
Jorim Jaggi069cd032014-05-15 03:09:01 +0200197 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400198 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100199 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
200 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200201 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200202 mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400203 }
204
205 private void trackMovement(MotionEvent event) {
206 // Add movement to velocity tracker using raw screen X and Y coordinates instead
207 // of window coordinates because the window frame may be moving at the same time.
208 float deltaX = event.getRawX() - event.getX();
209 float deltaY = event.getRawY() - event.getY();
210 event.offsetLocation(deltaX, deltaY);
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400211 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400212 event.offsetLocation(-deltaX, -deltaY);
213 }
214
Jorim Jaggid41083a2014-09-12 02:54:40 +0200215 public void setTouchDisabled(boolean disabled) {
216 mTouchDisabled = disabled;
Selim Cinek3127daf02016-07-22 18:04:23 -0700217 if (mTouchDisabled && mTracking) {
218 onTrackingStopped(true /* expanded */);
219 }
Jorim Jaggid41083a2014-09-12 02:54:40 +0200220 }
221
Jorim Jaggie05256e2016-09-08 14:58:20 -0700222 public void startExpandLatencyTracking() {
223 if (LatencyTracker.isEnabled(mContext)) {
224 LatencyTracker.getInstance(mContext).onActionStart(
225 LatencyTracker.ACTION_EXPAND_PANEL);
226 mExpandLatencyTracking = true;
227 }
228 }
229
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400230 @Override
231 public boolean onTouchEvent(MotionEvent event) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100232 if (mInstantExpanding || mTouchDisabled
233 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200234 return false;
235 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100236
Jun Mukaicf9933c2015-07-08 17:34:26 -0700237 // On expanding, single mouse click expands the panel instead of dragging.
Jun Mukaic99243a2015-10-15 02:59:57 -0700238 if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
Jun Mukaicf9933c2015-07-08 17:34:26 -0700239 if (event.getAction() == MotionEvent.ACTION_UP) {
240 expand(true);
241 }
242 return true;
243 }
244
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100245 /*
246 * We capture touch events here and update the expand height here in case according to
247 * the users fingers. This also handles multi-touch.
248 *
Chris Wren5d53df42015-06-26 11:26:03 -0400249 * If the user just clicks shortly, we show a quick peek of the shade.
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100250 *
251 * Flinging is also enabled in order to open or close the shade.
252 */
253
254 int pointerIndex = event.findPointerIndex(mTrackingPointer);
255 if (pointerIndex < 0) {
256 pointerIndex = 0;
257 mTrackingPointer = event.getPointerId(pointerIndex);
258 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200259 final float x = event.getX(pointerIndex);
Selim Cinek547a06b2014-11-27 14:06:04 +0100260 final float y = event.getY(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100261
Jorim Jaggib472b3472014-06-30 19:56:24 +0200262 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek684a4422015-04-15 16:18:39 -0700263 mGestureWaitForTouchSlop = isFullyCollapsed() || hasConflictingGestures();
264 mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200265 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200266
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100267 switch (event.getActionMasked()) {
268 case MotionEvent.ACTION_DOWN:
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700269 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200270 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800271 mMinExpandHeight = 0.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700272 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek31094df2014-08-14 19:28:15 +0200273 mHasLayoutedSinceDown = false;
274 mUpdateFlingOnLayout = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100275 mMotionAborted = false;
Jorim Jaggib7a33032014-08-20 16:21:36 +0200276 mPeekTouching = mPanelClosedOnDown;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800277 mDownTime = SystemClock.uptimeMillis();
Selim Cinek19c8c702014-08-25 22:09:19 +0200278 mTouchAboveFalsingThreshold = false;
Selim Cinek79d79c42015-05-21 16:14:45 -0700279 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
280 && mHeadsUpManager.hasPinnedHeadsUp();
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200281 if (mVelocityTracker == null) {
282 initVelocityTracker();
283 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100284 trackMovement(event);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800285 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
286 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200287 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200288 cancelPeek();
289 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800290 || mPeekAnimator != null;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200291 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200292 }
Selim Cinek79d79c42015-05-21 16:14:45 -0700293 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()) {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800294 startOpening();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100295 }
296 break;
297
298 case MotionEvent.ACTION_POINTER_UP:
299 final int upPointer = event.getPointerId(event.getActionIndex());
300 if (mTrackingPointer == upPointer) {
301 // gesture is ongoing, find a new pointer to track
302 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
303 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200304 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100305 mTrackingPointer = event.getPointerId(newIndex);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700306 startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100307 }
308 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100309 case MotionEvent.ACTION_POINTER_DOWN:
310 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
311 mMotionAborted = true;
312 endMotionEvent(event, x, y, true /* forceCancel */);
313 return false;
314 }
315 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100316 case MotionEvent.ACTION_MOVE:
Selim Cinekd5ab6452016-12-08 16:34:00 -0800317 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200318 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200319
320 // If the panel was collapsed when touching, we only need to check for the
321 // y-component of the gesture, as we have no conflicting horizontal gesture.
322 if (Math.abs(h) > mTouchSlop
323 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek48ff9b42016-11-09 19:31:51 -0800324 || mIgnoreXTouchSlop)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200325 mTouchSlopExceeded = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700326 if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
Jorim Jaggi0b1528a2014-10-28 22:47:46 +0100327 if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700328 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200329 h = 0;
330 }
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200331 cancelHeightAnimator();
Jorim Jaggi90129582014-06-02 14:44:49 +0200332 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200333 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200334 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800335 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200336 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200337 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100338 mPeekAnimator.cancel();
339 }
340 mJustPeeked = false;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800341 } else if (mPeekAnimator == null && mJustPeeked) {
342 // The initial peek has finished, but we haven't dragged as far yet, lets
343 // speed it up by starting at the peek height.
344 mInitialOffsetOnTouch = mExpandedHeight;
345 mInitialTouchY = y;
346 mMinExpandHeight = mExpandedHeight;
347 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100348 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800349 newHeight = Math.max(newHeight, mMinExpandHeight);
Selim Cinek29ed3c92014-09-23 20:44:35 +0200350 if (-h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200351 mTouchAboveFalsingThreshold = true;
Selim Cinek9db71052015-04-24 18:54:30 -0700352 mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
Selim Cinek19c8c702014-08-25 22:09:19 +0200353 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800354 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
355 !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000356 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100357 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100358 break;
359
360 case MotionEvent.ACTION_UP:
361 case MotionEvent.ACTION_CANCEL:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100362 trackMovement(event);
Selim Cinek547a06b2014-11-27 14:06:04 +0100363 endMotionEvent(event, x, y, false /* forceCancel */);
364 break;
365 }
Selim Cinek9db71052015-04-24 18:54:30 -0700366 return !mGestureWaitForTouchSlop || mTracking;
367 }
368
Selim Cinek48ff9b42016-11-09 19:31:51 -0800369 private void startOpening() {;
370 runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
371 false /* collapseWhenFinished */);
372 notifyBarPanelExpansionChanged();
373 }
374
375 protected abstract float getOpeningHeight();
376
Selim Cinek9db71052015-04-24 18:54:30 -0700377 /**
378 * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
379 * horizontal direction
380 */
381 private boolean isDirectionUpwards(float x, float y) {
382 float xDiff = x - mInitialTouchX;
383 float yDiff = y - mInitialTouchY;
384 if (yDiff >= 0) {
385 return false;
386 }
387 return Math.abs(yDiff) >= Math.abs(xDiff);
Selim Cinek547a06b2014-11-27 14:06:04 +0100388 }
389
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700390 protected void startExpandMotion(float newX, float newY, boolean startTracking,
391 float expandedHeight) {
392 mInitialOffsetOnTouch = expandedHeight;
393 mInitialTouchY = newY;
394 mInitialTouchX = newX;
395 if (startTracking) {
396 mTouchSlopExceeded = true;
Selim Cinekdef35a82016-05-03 15:52:51 -0700397 setExpandedHeight(mInitialOffsetOnTouch);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700398 onTrackingStarted();
399 }
400 }
401
Selim Cinek547a06b2014-11-27 14:06:04 +0100402 private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
403 mTrackingPointer = -1;
404 if ((mTracking && mTouchSlopExceeded)
405 || Math.abs(x - mInitialTouchX) > mTouchSlop
406 || Math.abs(y - mInitialTouchY) > mTouchSlop
407 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
408 || forceCancel) {
409 float vel = 0f;
410 float vectorVel = 0f;
411 if (mVelocityTracker != null) {
412 mVelocityTracker.computeCurrentVelocity(1000);
413 vel = mVelocityTracker.getYVelocity();
414 vectorVel = (float) Math.hypot(
415 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
416 }
Selim Cinek9db71052015-04-24 18:54:30 -0700417 boolean expand = flingExpands(vel, vectorVel, x, y)
Selim Cinek547a06b2014-11-27 14:06:04 +0100418 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
419 || forceCancel;
Selim Cinek547a06b2014-11-27 14:06:04 +0100420 DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
421 mStatusBar.isFalsingThresholdNeeded(),
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700422 mStatusBar.isWakeUpComingFromTouch());
Christoph Studerb0183992014-12-22 21:02:26 +0100423 // Log collapse gesture if on lock screen.
424 if (!expand && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
425 float displayDensity = mStatusBar.getDisplayDensity();
426 int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
427 int velocityDp = (int) Math.abs(vel / displayDensity);
Chris Wren27a52fa2017-02-01 14:21:43 -0500428 mLockscreenGestureLogger.write(
429 MetricsEvent.ACTION_LS_UNLOCK,
Christoph Studerb0183992014-12-22 21:02:26 +0100430 heightDp, velocityDp);
431 }
Selim Cinek9db71052015-04-24 18:54:30 -0700432 fling(vel, expand, isFalseTouch(x, y));
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700433 onTrackingStopped(expand);
Selim Cinek547a06b2014-11-27 14:06:04 +0100434 mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
435 if (mUpdateFlingOnLayout) {
436 mUpdateFlingVelocity = vel;
437 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800438 } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking) {
439 long timePassed = SystemClock.uptimeMillis() - mDownTime;
440 if (timePassed < ViewConfiguration.getLongPressTimeout()) {
441 // Lets show the user that he can actually expand the panel
442 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
443 } else {
444 // We need to collapse the panel since we peeked to the small height.
445 postOnAnimation(mPostCollapseRunnable);
446 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100447 } else {
448 boolean expands = onEmptySpaceClick(mInitialTouchX);
449 onTrackingStopped(expands);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100450 }
Selim Cinek547a06b2014-11-27 14:06:04 +0100451
452 if (mVelocityTracker != null) {
453 mVelocityTracker.recycle();
454 mVelocityTracker = null;
455 }
456 mPeekTouching = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100457 }
458
Selim Cinekd5ab6452016-12-08 16:34:00 -0800459 protected float getCurrentExpandVelocity() {
460 if (mVelocityTracker == null) {
461 return 0;
462 }
463 mVelocityTracker.computeCurrentVelocity(1000);
464 return mVelocityTracker.getYVelocity();
465 }
466
Selim Cinek29ed3c92014-09-23 20:44:35 +0200467 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700468 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek29ed3c92014-09-23 20:44:35 +0200469 return (int) (mUnlockFalsingThreshold * factor);
470 }
471
Selim Cinek4c6969a2014-05-26 19:22:17 +0200472 protected abstract boolean hasConflictingGestures();
473
Selim Cinek9db71052015-04-24 18:54:30 -0700474 protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
475
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200476 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200477 mTracking = false;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800478 mBar.onTrackingStopped(expand);
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700479 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200480 }
481
482 protected void onTrackingStarted() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200483 endClosing();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200484 mTracking = true;
Xiaohui Chen9f967112016-01-07 14:14:06 -0800485 mBar.onTrackingStarted();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200486 notifyExpandingStarted();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700487 notifyBarPanelExpansionChanged();
Selim Cinek1685e632014-04-08 02:27:49 +0200488 }
489
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100490 @Override
491 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinek547a06b2014-11-27 14:06:04 +0100492 if (mInstantExpanding
493 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200494 return false;
495 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100496
497 /*
Chris Wren5d53df42015-06-26 11:26:03 -0400498 * If the user drags anywhere inside the panel we intercept it if the movement is
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100499 * upwards. This allows closing the shade from anywhere inside the panel.
500 *
501 * We only do this if the current content is scrolled to the bottom,
502 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
503 * possible.
504 */
505 int pointerIndex = event.findPointerIndex(mTrackingPointer);
506 if (pointerIndex < 0) {
507 pointerIndex = 0;
508 mTrackingPointer = event.getPointerId(pointerIndex);
509 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200510 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100511 final float y = event.getY(pointerIndex);
512 boolean scrolledToBottom = isScrolledToBottom();
513
514 switch (event.getActionMasked()) {
515 case MotionEvent.ACTION_DOWN:
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200516 mStatusBar.userActivity();
Selim Cinek173f2d02015-04-29 15:36:56 -0700517 mAnimatingOnDown = mHeightAnimator != null;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800518 mMinExpandHeight = 0.0f;
519 mDownTime = SystemClock.uptimeMillis();
520 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
521 || mPeekAnimator != null) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200522 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200523 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200524 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200525 return true;
526 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100527 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200528 mInitialTouchX = x;
Selim Cinekab1dc952014-10-30 20:20:29 +0100529 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
Jorim Jaggi90129582014-06-02 14:44:49 +0200530 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200531 mJustPeeked = false;
Selim Cinek547a06b2014-11-27 14:06:04 +0100532 mMotionAborted = false;
Selim Cinek684a4422015-04-15 16:18:39 -0700533 mPanelClosedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700534 mCollapsedAndHeadsUpOnDown = false;
Selim Cinek31094df2014-08-14 19:28:15 +0200535 mHasLayoutedSinceDown = false;
536 mUpdateFlingOnLayout = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200537 mTouchAboveFalsingThreshold = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100538 initVelocityTracker();
539 trackMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100540 break;
541 case MotionEvent.ACTION_POINTER_UP:
542 final int upPointer = event.getPointerId(event.getActionIndex());
543 if (mTrackingPointer == upPointer) {
544 // gesture is ongoing, find a new pointer to track
545 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
546 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200547 mInitialTouchX = event.getX(newIndex);
548 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100549 }
550 break;
Selim Cinek547a06b2014-11-27 14:06:04 +0100551 case MotionEvent.ACTION_POINTER_DOWN:
552 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
553 mMotionAborted = true;
554 if (mVelocityTracker != null) {
555 mVelocityTracker.recycle();
556 mVelocityTracker = null;
557 }
558 }
559 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100560 case MotionEvent.ACTION_MOVE:
561 final float h = y - mInitialTouchY;
562 trackMovement(event);
Selim Cinek173f2d02015-04-29 15:36:56 -0700563 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
564 float hAbs = Math.abs(h);
565 if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
566 && hAbs > Math.abs(x - mInitialTouchX)) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200567 cancelHeightAnimator();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700568 startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100569 return true;
570 }
571 }
572 break;
Selim Cinek31094df2014-08-14 19:28:15 +0200573 case MotionEvent.ACTION_CANCEL:
574 case MotionEvent.ACTION_UP:
Selim Cinek547a06b2014-11-27 14:06:04 +0100575 if (mVelocityTracker != null) {
576 mVelocityTracker.recycle();
577 mVelocityTracker = null;
578 }
Selim Cinek31094df2014-08-14 19:28:15 +0200579 break;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100580 }
581 return false;
582 }
583
Selim Cinekab1dc952014-10-30 20:20:29 +0100584 /**
585 * @return Whether a pair of coordinates are inside the visible view content bounds.
586 */
587 protected abstract boolean isInContentBounds(float x, float y);
588
Selim Cinek831941f2015-06-17 15:09:30 -0700589 protected void cancelHeightAnimator() {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200590 if (mHeightAnimator != null) {
591 mHeightAnimator.cancel();
592 }
593 endClosing();
594 }
595
596 private void endClosing() {
597 if (mClosing) {
598 mClosing = false;
599 onClosingFinished();
600 }
601 }
602
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100603 private void initVelocityTracker() {
604 if (mVelocityTracker != null) {
605 mVelocityTracker.recycle();
606 }
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200607 mVelocityTracker = VelocityTrackerFactory.obtain(getContext());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100608 }
609
610 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200611 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100612 }
613
614 protected float getContentHeight() {
615 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400616 }
617
Daniel Sandler08d05e32012-08-08 16:39:54 -0400618 @Override
619 protected void onFinishInflate() {
620 super.onFinishInflate();
621 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400622 }
623
Jorim Jaggi069cd032014-05-15 03:09:01 +0200624 @Override
625 protected void onConfigurationChanged(Configuration newConfig) {
626 super.onConfigurationChanged(newConfig);
627 loadDimens();
Jorim Jaggi069cd032014-05-15 03:09:01 +0200628 }
629
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200630 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200631 * @param vel the current vertical velocity of the motion
632 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200633 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200634 */
Selim Cinek9db71052015-04-24 18:54:30 -0700635 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
636 if (isFalseTouch(x, y)) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200637 return true;
638 }
Jorim Jaggib7240132014-06-30 01:39:07 +0200639 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200640 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200641 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200642 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400643 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200644 }
645
Selim Cinek9db71052015-04-24 18:54:30 -0700646 /**
647 * @param x the final x-coordinate when the finger was lifted
648 * @param y the final y-coordinate when the finger was lifted
649 * @return whether this motion should be regarded as a false touch
650 */
651 private boolean isFalseTouch(float x, float y) {
652 if (!mStatusBar.isFalsingThresholdNeeded()) {
653 return false;
654 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700655 if (mFalsingManager.isClassiferEnabled()) {
656 return mFalsingManager.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700657 }
Selim Cinek9db71052015-04-24 18:54:30 -0700658 if (!mTouchAboveFalsingThreshold) {
659 return true;
660 }
661 if (mUpwardsWhenTresholdReached) {
662 return false;
663 }
664 return !isDirectionUpwards(x, y);
Selim Cinek5386fb32014-09-03 16:37:36 +0200665 }
666
Jorim Jaggi1d480692014-05-20 19:41:58 +0200667 protected void fling(float vel, boolean expand) {
Selim Cinek9db71052015-04-24 18:54:30 -0700668 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700669 }
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200670
Selim Cinek9db71052015-04-24 18:54:30 -0700671 protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
672 fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
673 }
674
675 protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
676 boolean expandBecauseOfFalsing) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700677 cancelPeek();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800678 float target = expand ? getMaxPanelHeight() : 0;
Jorim Jaggi3e02adb2015-05-13 17:50:26 -0700679 if (!expand) {
680 mClosing = true;
681 }
Selim Cinek9db71052015-04-24 18:54:30 -0700682 flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700683 }
684
685 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700686 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200687 // Hack to make the expand transition look nice when clear all button is visible - we make
688 // the animation only to the last notification, and then jump to the maximum panel height so
689 // clear all just fades in and the decelerating motion is towards the last notification.
690 final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
691 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
692 && !isClearAllVisible();
693 if (clearAllExpandHack) {
694 target = getMaxPanelHeight() - getClearAllHeight();
695 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200696 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200697 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200698 return;
699 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200700 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200701 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200702 if (expand) {
Selim Cinek61190fb2016-12-07 12:16:45 -0800703 if (expandBecauseOfFalsing && vel < 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200704 vel = 0;
705 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200706 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
Jorim Jaggi6626f542016-08-22 13:08:44 -0700707 if (vel == 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +0200708 animator.setDuration(350);
709 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200710 } else {
Selim Cinek2411f762016-12-28 17:05:08 +0100711 if (shouldUseDismissingAnimation()) {
712 mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
713 getHeight());
714 } else {
715 mFlingAnimationUtilsClosing
716 .apply(animator, mExpandedHeight, target, vel, getHeight());
717 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200718
719 // Make it shorter if we run a canned animation
720 if (vel == 0) {
Selim Cinek593ee202016-12-28 15:01:16 +0100721 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200722 }
723 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200724 animator.addListener(new AnimatorListenerAdapter() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200725 private boolean mCancelled;
726
727 @Override
728 public void onAnimationCancel(Animator animation) {
729 mCancelled = true;
730 }
731
Jorim Jaggi1d480692014-05-20 19:41:58 +0200732 @Override
733 public void onAnimationEnd(Animator animation) {
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +0200734 if (clearAllExpandHack && !mCancelled) {
Jorim Jaggi2ae259d2014-08-04 23:35:47 +0200735 setExpandedHeightInternal(getMaxPanelHeight());
736 }
737 mHeightAnimator = null;
738 if (!mCancelled) {
739 notifyExpandingFinished();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200740 }
Jorim Jaggieb8f11a2015-05-20 18:42:16 -0700741 notifyBarPanelExpansionChanged();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200742 }
743 });
Jorim Jaggi1d480692014-05-20 19:41:58 +0200744 mHeightAnimator = animator;
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200745 animator.start();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400746 }
747
Selim Cinek2411f762016-12-28 17:05:08 +0100748 protected abstract boolean shouldUseDismissingAnimation();
749
Daniel Sandler08d05e32012-08-08 16:39:54 -0400750 @Override
751 protected void onAttachedToWindow() {
752 super.onAttachedToWindow();
Daniel Sandler978f8532012-08-15 15:48:16 -0400753 mViewName = getResources().getResourceName(getId());
754 }
755
756 public String getName() {
757 return mViewName;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400758 }
759
Daniel Sandler08d05e32012-08-08 16:39:54 -0400760 public void setExpandedHeight(float height) {
John Spurlock97642182013-07-29 17:58:39 -0400761 if (DEBUG) logf("setExpandedHeight(%.1f)", height);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200762 setExpandedHeightInternal(height + getOverExpansionPixels());
Daniel Sandler08d05e32012-08-08 16:39:54 -0400763 }
764
Daniel Sandler50508132012-08-16 14:10:53 -0400765 @Override
766 protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
Daniel Sandler50508132012-08-16 14:10:53 -0400767 super.onLayout(changed, left, top, right, bottom);
Selim Cinek5fbc6322016-01-15 17:17:58 -0800768 mStatusBar.onPanelLaidOut();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100769 requestPanelHeightUpdate();
Selim Cinek31094df2014-08-14 19:28:15 +0200770 mHasLayoutedSinceDown = true;
771 if (mUpdateFlingOnLayout) {
772 abortAnimations();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700773 fling(mUpdateFlingVelocity, true /* expands */);
Selim Cinek31094df2014-08-14 19:28:15 +0200774 mUpdateFlingOnLayout = false;
775 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100776 }
777
778 protected void requestPanelHeightUpdate() {
779 float currentMaxPanelHeight = getMaxPanelHeight();
780
781 // If the user isn't actively poking us, let's update the height
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200782 if ((!mTracking || isTrackingBlocked())
783 && mHeightAnimator == null
Selim Cinek684a4422015-04-15 16:18:39 -0700784 && !isFullyCollapsed()
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200785 && currentMaxPanelHeight != mExpandedHeight
Selim Cinek31094df2014-08-14 19:28:15 +0200786 && mPeekAnimator == null
Jorim Jaggib7a33032014-08-20 16:21:36 +0200787 && !mPeekTouching) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200788 setExpandedHeight(currentMaxPanelHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100789 }
Daniel Sandler50508132012-08-16 14:10:53 -0400790 }
791
Daniel Sandler08d05e32012-08-08 16:39:54 -0400792 public void setExpandedHeightInternal(float h) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700793 if (mExpandLatencyTracking && h != 0f) {
794 DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance(mContext).onActionEnd(
795 LatencyTracker.ACTION_EXPAND_PANEL));
796 mExpandLatencyTracking = false;
797 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200798 float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
799 if (mHeightAnimator == null) {
800 float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
801 if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
802 setOverExpansion(overExpansionPixels, true /* isPixels */);
803 }
804 mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
805 } else {
806 mExpandedHeight = h;
807 if (mOverExpandedBeforeFling) {
808 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
809 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100810 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400811
Selim Cinek48ff9b42016-11-09 19:31:51 -0800812 mExpandedFraction = Math.min(1f,
813 fhWithoutOverExpansion == 0 ? 0 : mExpandedHeight / fhWithoutOverExpansion);
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +0100814 onHeightUpdated(mExpandedHeight);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200815 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400816 }
817
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200818 /**
819 * @return true if the panel tracking should be temporarily blocked; this is used when a
820 * conflicting gesture (opening QS) is happening
821 */
822 protected abstract boolean isTrackingBlocked();
823
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200824 protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
Selim Cinek24120a52014-05-26 10:05:42 +0200825
Jorim Jaggi90129582014-06-02 14:44:49 +0200826 protected abstract void onHeightUpdated(float expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100827
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200828 protected abstract float getOverExpansionAmount();
829
830 protected abstract float getOverExpansionPixels();
831
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100832 /**
833 * This returns the maximum height of the panel. Children should override this if their
834 * desired height is not the full height.
835 *
836 * @return the default implementation simply returns the maximum height.
837 */
Selim Cinek31094df2014-08-14 19:28:15 +0200838 protected abstract int getMaxPanelHeight();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400839
840 public void setExpandedFraction(float frac) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100841 setExpandedHeight(getMaxPanelHeight() * frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400842 }
843
844 public float getExpandedHeight() {
845 return mExpandedHeight;
846 }
847
848 public float getExpandedFraction() {
849 return mExpandedFraction;
850 }
851
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700852 public boolean isFullyExpanded() {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100853 return mExpandedHeight >= getMaxPanelHeight();
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700854 }
855
856 public boolean isFullyCollapsed() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800857 return mExpandedFraction <= 0.0f;
Daniel Sandler67eab792012-10-02 17:08:23 -0400858 }
859
860 public boolean isCollapsing() {
861 return mClosing;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700862 }
863
John Spurlocka4b70af2013-08-17 14:05:49 -0400864 public boolean isTracking() {
865 return mTracking;
866 }
867
Daniel Sandler08d05e32012-08-08 16:39:54 -0400868 public void setBar(PanelBar panelBar) {
869 mBar = panelBar;
870 }
871
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700872 public void collapse(boolean delayed, float speedUpFactor) {
John Spurlock97642182013-07-29 17:58:39 -0400873 if (DEBUG) logf("collapse: " + this);
Selim Cinek9bb05632016-12-15 14:14:29 -0800874 if (canPanelBeCollapsed()) {
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200875 cancelHeightAnimator();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200876 notifyExpandingStarted();
Jorim Jaggi3b866be2015-06-30 11:31:10 -0700877
878 // Set after notifyExpandingStarted, as notifyExpandingStarted resets the closing state.
879 mClosing = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200880 if (delayed) {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700881 mNextCollapseSpeedUpFactor = speedUpFactor;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200882 postDelayed(mFlingCollapseRunnable, 120);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200883 } else {
Selim Cinek9db71052015-04-24 18:54:30 -0700884 fling(0, false /* expand */, speedUpFactor, false /* expandBecauseOfFalsing */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200885 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400886 }
887 }
888
Selim Cinek9bb05632016-12-15 14:14:29 -0800889 public boolean canPanelBeCollapsed() {
890 return !isFullyCollapsed() && !mTracking && !mClosing;
891 }
892
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200893 private final Runnable mFlingCollapseRunnable = new Runnable() {
894 @Override
895 public void run() {
Selim Cinek9db71052015-04-24 18:54:30 -0700896 fling(0, false /* expand */, mNextCollapseSpeedUpFactor,
897 false /* expandBecauseOfFalsing */);
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200898 }
899 };
900
John Spurlock97642182013-07-29 17:58:39 -0400901 public void cancelPeek() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800902 boolean cancelled = false;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200903 if (mPeekAnimator != null) {
Selim Cinek529c5322016-04-06 20:03:45 -0700904 cancelled = true;
John Spurlock97642182013-07-29 17:58:39 -0400905 mPeekAnimator.cancel();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400906 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200907
Selim Cinek529c5322016-04-06 20:03:45 -0700908 if (cancelled) {
909 // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
910 // notify mBar that we might have closed ourselves.
911 notifyBarPanelExpansionChanged();
912 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400913 }
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500914
Oren Blasberg8d3fea12015-07-10 14:21:44 -0700915 public void expand(final boolean animate) {
916 if (!isFullyCollapsed() && !isCollapsing()) {
917 return;
918 }
919
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200920 mInstantExpanding = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -0700921 mAnimateAfterExpanding = animate;
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200922 mUpdateFlingOnLayout = false;
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200923 abortAnimations();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200924 cancelPeek();
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200925 if (mTracking) {
926 onTrackingStopped(true /* expands */); // The panel is expanded after this call.
Jorim Jaggie62d5892014-09-02 16:31:19 +0200927 }
928 if (mExpanding) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200929 notifyExpandingFinished();
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200930 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700931 notifyBarPanelExpansionChanged();
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200932
933 // Wait for window manager to pickup the change, so we know the maximum height of the panel
934 // then.
935 getViewTreeObserver().addOnGlobalLayoutListener(
936 new ViewTreeObserver.OnGlobalLayoutListener() {
937 @Override
938 public void onGlobalLayout() {
Jorim Jaggic5804af2016-04-25 18:51:16 -0700939 if (!mInstantExpanding) {
940 getViewTreeObserver().removeOnGlobalLayoutListener(this);
941 return;
942 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200943 if (mStatusBar.getStatusBarWindow().getHeight()
944 != mStatusBar.getStatusBarHeight()) {
945 getViewTreeObserver().removeOnGlobalLayoutListener(this);
Jorim Jaggi6626f542016-08-22 13:08:44 -0700946 if (mAnimateAfterExpanding) {
Oren Blasberg8d3fea12015-07-10 14:21:44 -0700947 notifyExpandingStarted();
948 fling(0, true /* expand */);
949 } else {
950 setExpandedFraction(1f);
951 }
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200952 mInstantExpanding = false;
953 }
954 }
955 });
956
957 // Make sure a layout really happens.
958 requestLayout();
959 }
960
Selim Cinek6bb4a9b2014-10-09 17:48:05 -0700961 public void instantCollapse() {
962 abortAnimations();
963 setExpandedFraction(0f);
964 if (mExpanding) {
965 notifyExpandingFinished();
966 }
Jorim Jaggic5804af2016-04-25 18:51:16 -0700967 if (mInstantExpanding) {
968 mInstantExpanding = false;
969 notifyBarPanelExpansionChanged();
970 }
Selim Cinek6bb4a9b2014-10-09 17:48:05 -0700971 }
972
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200973 private void abortAnimations() {
974 cancelPeek();
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200975 cancelHeightAnimator();
Jorim Jaggi5cbfe542014-09-10 22:23:08 +0200976 removeCallbacks(mPostCollapseRunnable);
977 removeCallbacks(mFlingCollapseRunnable);
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200978 }
979
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200980 protected void onClosingFinished() {
981 mBar.onClosingFinished();
982 }
983
984
Jorim Jaggi90129582014-06-02 14:44:49 +0200985 protected void startUnlockHintAnimation() {
986
987 // We don't need to hint the user if an animation is already running or the user is changing
988 // the expansion.
989 if (mHeightAnimator != null || mTracking) {
990 return;
991 }
992 cancelPeek();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200993 notifyExpandingStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200994 startUnlockHintAnimationPhase1(new Runnable() {
995 @Override
996 public void run() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200997 notifyExpandingFinished();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200998 mStatusBar.onHintFinished();
999 mHintAnimationRunning = false;
1000 }
1001 });
Jorim Jaggi90129582014-06-02 14:44:49 +02001002 mStatusBar.onUnlockHintStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001003 mHintAnimationRunning = true;
Jorim Jaggi90129582014-06-02 14:44:49 +02001004 }
1005
1006 /**
1007 * Phase 1: Move everything upwards.
1008 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001009 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001010 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1011 ValueAnimator animator = createHeightAnimator(target);
1012 animator.setDuration(250);
Selim Cinekc18010f2016-01-20 13:41:30 -08001013 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi90129582014-06-02 14:44:49 +02001014 animator.addListener(new AnimatorListenerAdapter() {
1015 private boolean mCancelled;
1016
1017 @Override
1018 public void onAnimationCancel(Animator animation) {
1019 mCancelled = true;
1020 }
1021
1022 @Override
1023 public void onAnimationEnd(Animator animation) {
1024 if (mCancelled) {
1025 mHeightAnimator = null;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001026 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +02001027 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001028 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +02001029 }
1030 }
1031 });
1032 animator.start();
1033 mHeightAnimator = animator;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +01001034 mKeyguardBottomArea.getIndicationArea().animate()
Selim Cinek5256d932014-10-22 20:05:03 +02001035 .translationY(-mHintDistance)
Selim Cinekf99d0002014-06-13 07:36:01 +02001036 .setDuration(250)
Selim Cinekc18010f2016-01-20 13:41:30 -08001037 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Selim Cinekf99d0002014-06-13 07:36:01 +02001038 .withEndAction(new Runnable() {
1039 @Override
1040 public void run() {
Bartosz Fabianowski5f045002016-12-01 10:36:18 +01001041 mKeyguardBottomArea.getIndicationArea().animate()
Selim Cinek5256d932014-10-22 20:05:03 +02001042 .translationY(0)
Selim Cinekf99d0002014-06-13 07:36:01 +02001043 .setDuration(450)
1044 .setInterpolator(mBounceInterpolator)
1045 .start();
1046 }
1047 })
1048 .start();
Jorim Jaggi90129582014-06-02 14:44:49 +02001049 }
1050
1051 /**
1052 * Phase 2: Bounce down.
1053 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001054 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +02001055 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1056 animator.setDuration(450);
1057 animator.setInterpolator(mBounceInterpolator);
1058 animator.addListener(new AnimatorListenerAdapter() {
1059 @Override
1060 public void onAnimationEnd(Animator animation) {
1061 mHeightAnimator = null;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001062 onAnimationFinished.run();
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001063 notifyBarPanelExpansionChanged();
Jorim Jaggi90129582014-06-02 14:44:49 +02001064 }
1065 });
1066 animator.start();
1067 mHeightAnimator = animator;
1068 }
1069
1070 private ValueAnimator createHeightAnimator(float targetHeight) {
1071 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1072 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1073 @Override
1074 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001075 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +02001076 }
1077 });
1078 return animator;
1079 }
1080
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001081 protected void notifyBarPanelExpansionChanged() {
Selim Cinek48ff9b42016-11-09 19:31:51 -08001082 mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
Selim Cinek0fccc722015-07-29 17:04:36 -07001083 || mPeekAnimator != null || mInstantExpanding || isPanelVisibleBecauseOfHeadsUp()
Jorim Jaggieb8f11a2015-05-20 18:42:16 -07001084 || mTracking || mHeightAnimator != null);
Jorim Jaggib472b3472014-06-30 19:56:24 +02001085 }
1086
Selim Cinek0fccc722015-07-29 17:04:36 -07001087 protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1088
Jorim Jaggi90129582014-06-02 14:44:49 +02001089 /**
1090 * Gets called when the user performs a click anywhere in the empty area of the panel.
1091 *
1092 * @return whether the panel will be expanded after the action performed by this method
1093 */
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001094 protected boolean onEmptySpaceClick(float x) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001095 if (mHintAnimationRunning) {
1096 return true;
1097 }
Selim Cinek6746c282015-04-21 19:58:31 -07001098 return onMiddleClicked();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001099 }
1100
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001101 protected final Runnable mPostCollapseRunnable = new Runnable() {
Jorim Jaggi488b7922014-08-05 21:12:02 +02001102 @Override
1103 public void run() {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -07001104 collapse(false /* delayed */, 1.0f /* speedUpFactor */);
Jorim Jaggi488b7922014-08-05 21:12:02 +02001105 }
1106 };
Jorim Jaggi488b7922014-08-05 21:12:02 +02001107
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001108 protected abstract boolean onMiddleClicked();
Jorim Jaggi90129582014-06-02 14:44:49 +02001109
Jorim Jaggid7912d22014-09-30 17:38:19 +02001110 protected abstract boolean isDozing();
1111
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001112 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +02001113 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001114 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001115 + "]",
1116 this.getClass().getSimpleName(),
1117 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001118 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001119 mClosing?"T":"f",
1120 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001121 mJustPeeked?"T":"f",
1122 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi50d87a72014-09-12 21:43:35 +02001123 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1124 mTouchDisabled?"T":"f"
Daniel Sandler37a38aa2013-02-13 17:15:57 -05001125 ));
1126 }
Selim Cinek3c4635c2014-05-29 02:12:47 +02001127
1128 public abstract void resetViews();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001129
1130 protected abstract float getPeekHeight();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02001131 /**
1132 * @return whether "Clear all" button will be visible when the panel is fully expanded
1133 */
1134 protected abstract boolean fullyExpandedClearAllVisible();
1135
1136 protected abstract boolean isClearAllVisible();
1137
1138 /**
1139 * @return the height of the clear all button, in pixels
1140 */
1141 protected abstract int getClearAllHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001142
1143 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
1144 mHeadsUpManager = headsUpManager;
1145 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001146}