1 /*
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 
17 package com.android.systemui.statusbar.phone;
18 
19 import android.animation.Animator;
20 import android.animation.AnimatorListenerAdapter;
21 import android.animation.ObjectAnimator;
22 import android.animation.ValueAnimator;
23 import android.content.Context;
24 import android.content.res.Configuration;
25 import android.content.res.Resources;
26 import android.os.SystemClock;
27 import android.os.VibrationEffect;
28 import android.util.AttributeSet;
29 import android.util.Log;
30 import android.view.InputDevice;
31 import android.view.MotionEvent;
32 import android.view.VelocityTracker;
33 import android.view.View;
34 import android.view.ViewConfiguration;
35 import android.view.ViewTreeObserver;
36 import android.view.animation.Interpolator;
37 import android.widget.FrameLayout;
38 
39 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
40 import com.android.internal.util.LatencyTracker;
41 import com.android.systemui.DejankUtils;
42 import com.android.systemui.Dependency;
43 import com.android.systemui.Interpolators;
44 import com.android.systemui.R;
45 import com.android.systemui.doze.DozeLog;
46 import com.android.systemui.plugins.FalsingManager;
47 import com.android.systemui.plugins.statusbar.StatusBarStateController;
48 import com.android.systemui.statusbar.FlingAnimationUtils;
49 import com.android.systemui.statusbar.StatusBarState;
50 import com.android.systemui.statusbar.SysuiStatusBarStateController;
51 import com.android.systemui.statusbar.VibratorHelper;
52 import com.android.systemui.statusbar.policy.KeyguardMonitor;
53 
54 import java.io.FileDescriptor;
55 import java.io.PrintWriter;
56 import java.util.ArrayList;
57 
58 public abstract class PanelView extends FrameLayout {
59     public static final boolean DEBUG = PanelBar.DEBUG;
60     public static final String TAG = PanelView.class.getSimpleName();
61     private static final int INITIAL_OPENING_PEEK_DURATION = 200;
62     private static final int PEEK_ANIMATION_DURATION = 360;
63     private static final int NO_FIXED_DURATION = -1;
64     protected long mDownTime;
65     protected boolean mTouchSlopExceededBeforeDown;
66     private float mMinExpandHeight;
67     private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
68     private boolean mPanelUpdateWhenAnimatorEnds;
69     private boolean mVibrateOnOpening;
70     protected boolean mLaunchingNotification;
71     private int mFixedDuration = NO_FIXED_DURATION;
72     protected ArrayList<PanelExpansionListener> mExpansionListeners = new ArrayList<>();
73 
logf(String fmt, Object... args)74     private final void logf(String fmt, Object... args) {
75         Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
76     }
77 
78     protected StatusBar mStatusBar;
79     protected HeadsUpManagerPhone mHeadsUpManager;
80 
81     private float mPeekHeight;
82     private float mHintDistance;
83     private float mInitialOffsetOnTouch;
84     private boolean mCollapsedAndHeadsUpOnDown;
85     private float mExpandedFraction = 0;
86     protected float mExpandedHeight = 0;
87     private boolean mPanelClosedOnDown;
88     private boolean mHasLayoutedSinceDown;
89     private float mUpdateFlingVelocity;
90     private boolean mUpdateFlingOnLayout;
91     private boolean mPeekTouching;
92     private boolean mJustPeeked;
93     private boolean mClosing;
94     protected boolean mTracking;
95     private boolean mTouchSlopExceeded;
96     private int mTrackingPointer;
97     protected int mTouchSlop;
98     protected boolean mHintAnimationRunning;
99     private boolean mOverExpandedBeforeFling;
100     private boolean mTouchAboveFalsingThreshold;
101     private int mUnlockFalsingThreshold;
102     private boolean mTouchStartedInEmptyArea;
103     private boolean mMotionAborted;
104     private boolean mUpwardsWhenTresholdReached;
105     private boolean mAnimatingOnDown;
106 
107     private ValueAnimator mHeightAnimator;
108     private ObjectAnimator mPeekAnimator;
109     private final VelocityTracker mVelocityTracker = VelocityTracker.obtain();
110     private FlingAnimationUtils mFlingAnimationUtils;
111     private FlingAnimationUtils mFlingAnimationUtilsClosing;
112     private FlingAnimationUtils mFlingAnimationUtilsDismissing;
113     private final FalsingManager mFalsingManager;
114     private final VibratorHelper mVibratorHelper;
115 
116     /**
117      * Whether an instant expand request is currently pending and we are just waiting for layout.
118      */
119     private boolean mInstantExpanding;
120     private boolean mAnimateAfterExpanding;
121 
122     PanelBar mBar;
123 
124     private String mViewName;
125     private float mInitialTouchY;
126     private float mInitialTouchX;
127     private boolean mTouchDisabled;
128 
129     /**
130      * Whether or not the PanelView can be expanded or collapsed with a drag.
131      */
132     private boolean mNotificationsDragEnabled;
133 
134     private Interpolator mBounceInterpolator;
135     protected KeyguardBottomAreaView mKeyguardBottomArea;
136 
137     /**
138      * Speed-up factor to be used when {@link #mFlingCollapseRunnable} runs the next time.
139      */
140     private float mNextCollapseSpeedUpFactor = 1.0f;
141 
142     protected boolean mExpanding;
143     private boolean mGestureWaitForTouchSlop;
144     private boolean mIgnoreXTouchSlop;
145     private boolean mExpandLatencyTracking;
146     protected final KeyguardMonitor mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
147     protected final SysuiStatusBarStateController mStatusBarStateController =
148             (SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class);
149 
onExpandingFinished()150     protected void onExpandingFinished() {
151         mBar.onExpandingFinished();
152     }
153 
onExpandingStarted()154     protected void onExpandingStarted() {
155     }
156 
notifyExpandingStarted()157     private void notifyExpandingStarted() {
158         if (!mExpanding) {
159             mExpanding = true;
160             onExpandingStarted();
161         }
162     }
163 
notifyExpandingFinished()164     protected final void notifyExpandingFinished() {
165         endClosing();
166         if (mExpanding) {
167             mExpanding = false;
168             onExpandingFinished();
169         }
170     }
171 
runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished)172     private void runPeekAnimation(long duration, float peekHeight, boolean collapseWhenFinished) {
173         mPeekHeight = peekHeight;
174         if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
175         if (mHeightAnimator != null) {
176             return;
177         }
178         if (mPeekAnimator != null) {
179             mPeekAnimator.cancel();
180         }
181         mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
182                 .setDuration(duration);
183         mPeekAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
184         mPeekAnimator.addListener(new AnimatorListenerAdapter() {
185             private boolean mCancelled;
186 
187             @Override
188             public void onAnimationCancel(Animator animation) {
189                 mCancelled = true;
190             }
191 
192             @Override
193             public void onAnimationEnd(Animator animation) {
194                 mPeekAnimator = null;
195                 if (!mCancelled && collapseWhenFinished) {
196                     postOnAnimation(mPostCollapseRunnable);
197                 }
198 
199             }
200         });
201         notifyExpandingStarted();
202         mPeekAnimator.start();
203         mJustPeeked = true;
204     }
205 
PanelView(Context context, AttributeSet attrs)206     public PanelView(Context context, AttributeSet attrs) {
207         super(context, attrs);
208         mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f /* maxLengthSeconds */,
209                 0.6f /* speedUpFactor */);
210         mFlingAnimationUtilsClosing = new FlingAnimationUtils(context, 0.5f /* maxLengthSeconds */,
211                 0.6f /* speedUpFactor */);
212         mFlingAnimationUtilsDismissing = new FlingAnimationUtils(context,
213                 0.5f /* maxLengthSeconds */, 0.2f /* speedUpFactor */, 0.6f /* x2 */,
214                 0.84f /* y2 */);
215         mBounceInterpolator = new BounceInterpolator();
216         mFalsingManager = Dependency.get(FalsingManager.class);  // TODO: inject into a controller.
217         mNotificationsDragEnabled =
218                 getResources().getBoolean(R.bool.config_enableNotificationShadeDrag);
219         mVibratorHelper = Dependency.get(VibratorHelper.class);
220         mVibrateOnOpening = mContext.getResources().getBoolean(
221                 R.bool.config_vibrateOnIconAnimation);
222     }
223 
loadDimens()224     protected void loadDimens() {
225         final Resources res = getContext().getResources();
226         final ViewConfiguration configuration = ViewConfiguration.get(getContext());
227         mTouchSlop = configuration.getScaledTouchSlop();
228         mHintDistance = res.getDimension(R.dimen.hint_move_distance);
229         mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
230     }
231 
addMovement(MotionEvent event)232     private void addMovement(MotionEvent event) {
233         // Add movement to velocity tracker using raw screen X and Y coordinates instead
234         // of window coordinates because the window frame may be moving at the same time.
235         float deltaX = event.getRawX() - event.getX();
236         float deltaY = event.getRawY() - event.getY();
237         event.offsetLocation(deltaX, deltaY);
238         mVelocityTracker.addMovement(event);
239         event.offsetLocation(-deltaX, -deltaY);
240     }
241 
setTouchAndAnimationDisabled(boolean disabled)242     public void setTouchAndAnimationDisabled(boolean disabled) {
243         mTouchDisabled = disabled;
244         if (mTouchDisabled) {
245             cancelHeightAnimator();
246             if (mTracking) {
247                 onTrackingStopped(true /* expanded */);
248             }
249             notifyExpandingFinished();
250         }
251     }
252 
startExpandLatencyTracking()253     public void startExpandLatencyTracking() {
254         if (LatencyTracker.isEnabled(mContext)) {
255             LatencyTracker.getInstance(mContext).onActionStart(
256                     LatencyTracker.ACTION_EXPAND_PANEL);
257             mExpandLatencyTracking = true;
258         }
259     }
260 
261     @Override
onTouchEvent(MotionEvent event)262     public boolean onTouchEvent(MotionEvent event) {
263         if (mInstantExpanding
264                 || (mTouchDisabled && event.getActionMasked() != MotionEvent.ACTION_CANCEL)
265                 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
266             return false;
267         }
268 
269         // If dragging should not expand the notifications shade, then return false.
270         if (!mNotificationsDragEnabled) {
271             if (mTracking) {
272                 // Turn off tracking if it's on or the shade can get stuck in the down position.
273                 onTrackingStopped(true /* expand */);
274             }
275             return false;
276         }
277 
278         // On expanding, single mouse click expands the panel instead of dragging.
279         if (isFullyCollapsed() && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
280             if (event.getAction() == MotionEvent.ACTION_UP) {
281                 expand(true);
282             }
283             return true;
284         }
285 
286         /*
287          * We capture touch events here and update the expand height here in case according to
288          * the users fingers. This also handles multi-touch.
289          *
290          * If the user just clicks shortly, we show a quick peek of the shade.
291          *
292          * Flinging is also enabled in order to open or close the shade.
293          */
294 
295         int pointerIndex = event.findPointerIndex(mTrackingPointer);
296         if (pointerIndex < 0) {
297             pointerIndex = 0;
298             mTrackingPointer = event.getPointerId(pointerIndex);
299         }
300         final float x = event.getX(pointerIndex);
301         final float y = event.getY(pointerIndex);
302 
303         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
304             mGestureWaitForTouchSlop = shouldGestureWaitForTouchSlop();
305             mIgnoreXTouchSlop = isFullyCollapsed() || shouldGestureIgnoreXTouchSlop(x, y);
306         }
307 
308         switch (event.getActionMasked()) {
309             case MotionEvent.ACTION_DOWN:
310                 startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
311                 mJustPeeked = false;
312                 mMinExpandHeight = 0.0f;
313                 mPanelClosedOnDown = isFullyCollapsed();
314                 mHasLayoutedSinceDown = false;
315                 mUpdateFlingOnLayout = false;
316                 mMotionAborted = false;
317                 mPeekTouching = mPanelClosedOnDown;
318                 mDownTime = SystemClock.uptimeMillis();
319                 mTouchAboveFalsingThreshold = false;
320                 mCollapsedAndHeadsUpOnDown = isFullyCollapsed()
321                         && mHeadsUpManager.hasPinnedHeadsUp();
322                 addMovement(event);
323                 if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning)
324                         || mPeekAnimator != null) {
325                     mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
326                             || mPeekAnimator != null || mTouchSlopExceededBeforeDown;
327                     cancelHeightAnimator();
328                     cancelPeek();
329                     onTrackingStarted();
330                 }
331                 if (isFullyCollapsed() && !mHeadsUpManager.hasPinnedHeadsUp()
332                         && !mStatusBar.isBouncerShowing()) {
333                     startOpening(event);
334                 }
335                 break;
336 
337             case MotionEvent.ACTION_POINTER_UP:
338                 final int upPointer = event.getPointerId(event.getActionIndex());
339                 if (mTrackingPointer == upPointer) {
340                     // gesture is ongoing, find a new pointer to track
341                     final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
342                     final float newY = event.getY(newIndex);
343                     final float newX = event.getX(newIndex);
344                     mTrackingPointer = event.getPointerId(newIndex);
345                     startExpandMotion(newX, newY, true /* startTracking */, mExpandedHeight);
346                 }
347                 break;
348             case MotionEvent.ACTION_POINTER_DOWN:
349                 if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
350                     mMotionAborted = true;
351                     endMotionEvent(event, x, y, true /* forceCancel */);
352                     return false;
353                 }
354                 break;
355             case MotionEvent.ACTION_MOVE:
356                 addMovement(event);
357                 float h = y - mInitialTouchY;
358 
359                 // If the panel was collapsed when touching, we only need to check for the
360                 // y-component of the gesture, as we have no conflicting horizontal gesture.
361                 if (Math.abs(h) > mTouchSlop
362                         && (Math.abs(h) > Math.abs(x - mInitialTouchX)
363                         || mIgnoreXTouchSlop)) {
364                     mTouchSlopExceeded = true;
365                     if (mGestureWaitForTouchSlop && !mTracking && !mCollapsedAndHeadsUpOnDown) {
366                         if (!mJustPeeked && mInitialOffsetOnTouch != 0f) {
367                             startExpandMotion(x, y, false /* startTracking */, mExpandedHeight);
368                             h = 0;
369                         }
370                         cancelHeightAnimator();
371                         onTrackingStarted();
372                     }
373                 }
374                 float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
375                 if (newHeight > mPeekHeight) {
376                     if (mPeekAnimator != null) {
377                         mPeekAnimator.cancel();
378                     }
379                     mJustPeeked = false;
380                 } else if (mPeekAnimator == null && mJustPeeked) {
381                     // The initial peek has finished, but we haven't dragged as far yet, lets
382                     // speed it up by starting at the peek height.
383                     mInitialOffsetOnTouch = mExpandedHeight;
384                     mInitialTouchY = y;
385                     mMinExpandHeight = mExpandedHeight;
386                     mJustPeeked = false;
387                 }
388                 newHeight = Math.max(newHeight, mMinExpandHeight);
389                 if (-h >= getFalsingThreshold()) {
390                     mTouchAboveFalsingThreshold = true;
391                     mUpwardsWhenTresholdReached = isDirectionUpwards(x, y);
392                 }
393                 if (!mJustPeeked && (!mGestureWaitForTouchSlop || mTracking) &&
394                         !isTrackingBlocked()) {
395                     setExpandedHeightInternal(newHeight);
396                 }
397                 break;
398 
399             case MotionEvent.ACTION_UP:
400             case MotionEvent.ACTION_CANCEL:
401                 addMovement(event);
402                 endMotionEvent(event, x, y, false /* forceCancel */);
403                 break;
404         }
405         return !mGestureWaitForTouchSlop || mTracking;
406     }
407 
startOpening(MotionEvent event)408     private void startOpening(MotionEvent event) {
409         runPeekAnimation(INITIAL_OPENING_PEEK_DURATION, getOpeningHeight(),
410                 false /* collapseWhenFinished */);
411         notifyBarPanelExpansionChanged();
412         maybeVibrateOnOpening();
413 
414         //TODO: keyguard opens QS a different way; log that too?
415 
416         // Log the position of the swipe that opened the panel
417         float width = mStatusBar.getDisplayWidth();
418         float height = mStatusBar.getDisplayHeight();
419         int rot = mStatusBar.getRotation();
420 
421         mLockscreenGestureLogger.writeAtFractionalPosition(MetricsEvent.ACTION_PANEL_VIEW_EXPAND,
422                 (int) (event.getX() / width * 100),
423                 (int) (event.getY() / height * 100),
424                 rot);
425     }
426 
maybeVibrateOnOpening()427     protected void maybeVibrateOnOpening() {
428         if (mVibrateOnOpening) {
429             mVibratorHelper.vibrate(VibrationEffect.EFFECT_TICK);
430         }
431     }
432 
getOpeningHeight()433     protected abstract float getOpeningHeight();
434 
435     /**
436      * @return whether the swiping direction is upwards and above a 45 degree angle compared to the
437      * horizontal direction
438      */
isDirectionUpwards(float x, float y)439     private boolean isDirectionUpwards(float x, float y) {
440         float xDiff = x - mInitialTouchX;
441         float yDiff = y - mInitialTouchY;
442         if (yDiff >= 0) {
443             return false;
444         }
445         return Math.abs(yDiff) >= Math.abs(xDiff);
446     }
447 
startExpandingFromPeek()448     protected void startExpandingFromPeek() {
449         mStatusBar.handlePeekToExpandTransistion();
450     }
451 
startExpandMotion(float newX, float newY, boolean startTracking, float expandedHeight)452     protected void startExpandMotion(float newX, float newY, boolean startTracking,
453             float expandedHeight) {
454         mInitialOffsetOnTouch = expandedHeight;
455         mInitialTouchY = newY;
456         mInitialTouchX = newX;
457         if (startTracking) {
458             mTouchSlopExceeded = true;
459             setExpandedHeight(mInitialOffsetOnTouch);
460             onTrackingStarted();
461         }
462     }
463 
endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel)464     private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) {
465         mTrackingPointer = -1;
466         if ((mTracking && mTouchSlopExceeded)
467                 || Math.abs(x - mInitialTouchX) > mTouchSlop
468                 || Math.abs(y - mInitialTouchY) > mTouchSlop
469                 || event.getActionMasked() == MotionEvent.ACTION_CANCEL
470                 || forceCancel) {
471             mVelocityTracker.computeCurrentVelocity(1000);
472             float vel = mVelocityTracker.getYVelocity();
473             float vectorVel = (float) Math.hypot(
474                     mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
475 
476             boolean expand = flingExpands(vel, vectorVel, x, y)
477                     || event.getActionMasked() == MotionEvent.ACTION_CANCEL
478                     || forceCancel;
479             DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
480                     mStatusBar.isFalsingThresholdNeeded(),
481                     mStatusBar.isWakeUpComingFromTouch());
482                     // Log collapse gesture if on lock screen.
483                     if (!expand && mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
484                         float displayDensity = mStatusBar.getDisplayDensity();
485                         int heightDp = (int) Math.abs((y - mInitialTouchY) / displayDensity);
486                         int velocityDp = (int) Math.abs(vel / displayDensity);
487                         mLockscreenGestureLogger.write(
488                                 MetricsEvent.ACTION_LS_UNLOCK,
489                                 heightDp, velocityDp);
490                     }
491             fling(vel, expand, isFalseTouch(x, y));
492             onTrackingStopped(expand);
493             mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
494             if (mUpdateFlingOnLayout) {
495                 mUpdateFlingVelocity = vel;
496             }
497         } else if (mPanelClosedOnDown && !mHeadsUpManager.hasPinnedHeadsUp() && !mTracking
498                 && !mStatusBar.isBouncerShowing() && !mKeyguardMonitor.isKeyguardFadingAway()) {
499             long timePassed = SystemClock.uptimeMillis() - mDownTime;
500             if (timePassed < ViewConfiguration.getLongPressTimeout()) {
501                 // Lets show the user that he can actually expand the panel
502                 runPeekAnimation(PEEK_ANIMATION_DURATION, getPeekHeight(), true /* collapseWhenFinished */);
503             } else {
504                 // We need to collapse the panel since we peeked to the small height.
505                 postOnAnimation(mPostCollapseRunnable);
506             }
507         } else if (!mStatusBar.isBouncerShowing()) {
508             boolean expands = onEmptySpaceClick(mInitialTouchX);
509             onTrackingStopped(expands);
510         }
511 
512         mVelocityTracker.clear();
513         mPeekTouching = false;
514     }
515 
getCurrentExpandVelocity()516     protected float getCurrentExpandVelocity() {
517         mVelocityTracker.computeCurrentVelocity(1000);
518         return mVelocityTracker.getYVelocity();
519     }
520 
getFalsingThreshold()521     private int getFalsingThreshold() {
522         float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
523         return (int) (mUnlockFalsingThreshold * factor);
524     }
525 
shouldGestureWaitForTouchSlop()526     protected abstract boolean shouldGestureWaitForTouchSlop();
527 
shouldGestureIgnoreXTouchSlop(float x, float y)528     protected abstract boolean shouldGestureIgnoreXTouchSlop(float x, float y);
529 
onTrackingStopped(boolean expand)530     protected void onTrackingStopped(boolean expand) {
531         mTracking = false;
532         mBar.onTrackingStopped(expand);
533         notifyBarPanelExpansionChanged();
534     }
535 
onTrackingStarted()536     protected void onTrackingStarted() {
537         endClosing();
538         mTracking = true;
539         mBar.onTrackingStarted();
540         notifyExpandingStarted();
541         notifyBarPanelExpansionChanged();
542     }
543 
544     @Override
onInterceptTouchEvent(MotionEvent event)545     public boolean onInterceptTouchEvent(MotionEvent event) {
546         if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled
547                 || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
548             return false;
549         }
550 
551         /*
552          * If the user drags anywhere inside the panel we intercept it if the movement is
553          * upwards. This allows closing the shade from anywhere inside the panel.
554          *
555          * We only do this if the current content is scrolled to the bottom,
556          * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
557          * possible.
558          */
559         int pointerIndex = event.findPointerIndex(mTrackingPointer);
560         if (pointerIndex < 0) {
561             pointerIndex = 0;
562             mTrackingPointer = event.getPointerId(pointerIndex);
563         }
564         final float x = event.getX(pointerIndex);
565         final float y = event.getY(pointerIndex);
566         boolean scrolledToBottom = isScrolledToBottom();
567 
568         switch (event.getActionMasked()) {
569             case MotionEvent.ACTION_DOWN:
570                 mStatusBar.userActivity();
571                 mAnimatingOnDown = mHeightAnimator != null;
572                 mMinExpandHeight = 0.0f;
573                 mDownTime = SystemClock.uptimeMillis();
574                 if (mAnimatingOnDown && mClosing && !mHintAnimationRunning
575                         || mPeekAnimator != null) {
576                     cancelHeightAnimator();
577                     cancelPeek();
578                     mTouchSlopExceeded = true;
579                     return true;
580                 }
581                 mInitialTouchY = y;
582                 mInitialTouchX = x;
583                 mTouchStartedInEmptyArea = !isInContentBounds(x, y);
584                 mTouchSlopExceeded = mTouchSlopExceededBeforeDown;
585                 mJustPeeked = false;
586                 mMotionAborted = false;
587                 mPanelClosedOnDown = isFullyCollapsed();
588                 mCollapsedAndHeadsUpOnDown = false;
589                 mHasLayoutedSinceDown = false;
590                 mUpdateFlingOnLayout = false;
591                 mTouchAboveFalsingThreshold = false;
592                 addMovement(event);
593                 break;
594             case MotionEvent.ACTION_POINTER_UP:
595                 final int upPointer = event.getPointerId(event.getActionIndex());
596                 if (mTrackingPointer == upPointer) {
597                     // gesture is ongoing, find a new pointer to track
598                     final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
599                     mTrackingPointer = event.getPointerId(newIndex);
600                     mInitialTouchX = event.getX(newIndex);
601                     mInitialTouchY = event.getY(newIndex);
602                 }
603                 break;
604             case MotionEvent.ACTION_POINTER_DOWN:
605                 if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
606                     mMotionAborted = true;
607                     mVelocityTracker.clear();
608                 }
609                 break;
610             case MotionEvent.ACTION_MOVE:
611                 final float h = y - mInitialTouchY;
612                 addMovement(event);
613                 if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) {
614                     float hAbs = Math.abs(h);
615                     if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))
616                             && hAbs > Math.abs(x - mInitialTouchX)) {
617                         cancelHeightAnimator();
618                         startExpandMotion(x, y, true /* startTracking */, mExpandedHeight);
619                         return true;
620                     }
621                 }
622                 break;
623             case MotionEvent.ACTION_CANCEL:
624             case MotionEvent.ACTION_UP:
625                 mVelocityTracker.clear();
626                 break;
627         }
628         return false;
629     }
630 
631     /**
632      * @return Whether a pair of coordinates are inside the visible view content bounds.
633      */
isInContentBounds(float x, float y)634     protected abstract boolean isInContentBounds(float x, float y);
635 
cancelHeightAnimator()636     protected void cancelHeightAnimator() {
637         if (mHeightAnimator != null) {
638             if (mHeightAnimator.isRunning()) {
639                 mPanelUpdateWhenAnimatorEnds = false;
640             }
641             mHeightAnimator.cancel();
642         }
643         endClosing();
644     }
645 
endClosing()646     private void endClosing() {
647         if (mClosing) {
648             mClosing = false;
649             onClosingFinished();
650         }
651     }
652 
isScrolledToBottom()653     protected boolean isScrolledToBottom() {
654         return true;
655     }
656 
getContentHeight()657     protected float getContentHeight() {
658         return mExpandedHeight;
659     }
660 
661     @Override
onFinishInflate()662     protected void onFinishInflate() {
663         super.onFinishInflate();
664         loadDimens();
665     }
666 
667     @Override
onConfigurationChanged(Configuration newConfig)668     protected void onConfigurationChanged(Configuration newConfig) {
669         super.onConfigurationChanged(newConfig);
670         loadDimens();
671     }
672 
673     /**
674      * @param vel the current vertical velocity of the motion
675      * @param vectorVel the length of the vectorial velocity
676      * @return whether a fling should expands the panel; contracts otherwise
677      */
flingExpands(float vel, float vectorVel, float x, float y)678     protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
679         if (mFalsingManager.isUnlockingDisabled()) {
680             return true;
681         }
682 
683         if (isFalseTouch(x, y)) {
684             return true;
685         }
686         if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
687             return shouldExpandWhenNotFlinging();
688         } else {
689             return vel > 0;
690         }
691     }
692 
shouldExpandWhenNotFlinging()693     protected boolean shouldExpandWhenNotFlinging() {
694         return getExpandedFraction() > 0.5f;
695     }
696 
697     /**
698      * @param x the final x-coordinate when the finger was lifted
699      * @param y the final y-coordinate when the finger was lifted
700      * @return whether this motion should be regarded as a false touch
701      */
isFalseTouch(float x, float y)702     private boolean isFalseTouch(float x, float y) {
703         if (!mStatusBar.isFalsingThresholdNeeded()) {
704             return false;
705         }
706         if (mFalsingManager.isClassiferEnabled()) {
707             return mFalsingManager.isFalseTouch();
708         }
709         if (!mTouchAboveFalsingThreshold) {
710             return true;
711         }
712         if (mUpwardsWhenTresholdReached) {
713             return false;
714         }
715         return !isDirectionUpwards(x, y);
716     }
717 
fling(float vel, boolean expand)718     protected void fling(float vel, boolean expand) {
719         fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, false);
720     }
721 
fling(float vel, boolean expand, boolean expandBecauseOfFalsing)722     protected void fling(float vel, boolean expand, boolean expandBecauseOfFalsing) {
723         fling(vel, expand, 1.0f /* collapseSpeedUpFactor */, expandBecauseOfFalsing);
724     }
725 
fling(float vel, boolean expand, float collapseSpeedUpFactor, boolean expandBecauseOfFalsing)726     protected void fling(float vel, boolean expand, float collapseSpeedUpFactor,
727             boolean expandBecauseOfFalsing) {
728         cancelPeek();
729         float target = expand ? getMaxPanelHeight() : 0;
730         if (!expand) {
731             mClosing = true;
732         }
733         flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
734     }
735 
flingToHeight(float vel, boolean expand, float target, float collapseSpeedUpFactor, boolean expandBecauseOfFalsing)736     protected void flingToHeight(float vel, boolean expand, float target,
737             float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
738         // Hack to make the expand transition look nice when clear all button is visible - we make
739         // the animation only to the last notification, and then jump to the maximum panel height so
740         // clear all just fades in and the decelerating motion is towards the last notification.
741         final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
742                 && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
743                 && !isClearAllVisible();
744         if (clearAllExpandHack) {
745             target = getMaxPanelHeight() - getClearAllHeight();
746         }
747         if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
748             notifyExpandingFinished();
749             return;
750         }
751         mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
752         ValueAnimator animator = createHeightAnimator(target);
753         if (expand) {
754             if (expandBecauseOfFalsing && vel < 0) {
755                 vel = 0;
756             }
757             mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
758             if (vel == 0) {
759                 animator.setDuration(350);
760             }
761         } else {
762             if (shouldUseDismissingAnimation()) {
763                 if (vel == 0) {
764                     animator.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
765                     long duration = (long) (200 + mExpandedHeight / getHeight() * 100);
766                     animator.setDuration(duration);
767                 } else {
768                     mFlingAnimationUtilsDismissing.apply(animator, mExpandedHeight, target, vel,
769                             getHeight());
770                 }
771             } else {
772                 mFlingAnimationUtilsClosing
773                         .apply(animator, mExpandedHeight, target, vel, getHeight());
774             }
775 
776             // Make it shorter if we run a canned animation
777             if (vel == 0) {
778                 animator.setDuration((long) (animator.getDuration() / collapseSpeedUpFactor));
779             }
780             if (mFixedDuration != NO_FIXED_DURATION) {
781                 animator.setDuration(mFixedDuration);
782             }
783         }
784         animator.addListener(new AnimatorListenerAdapter() {
785             private boolean mCancelled;
786 
787             @Override
788             public void onAnimationCancel(Animator animation) {
789                 mCancelled = true;
790             }
791 
792             @Override
793             public void onAnimationEnd(Animator animation) {
794                 if (clearAllExpandHack && !mCancelled) {
795                     setExpandedHeightInternal(getMaxPanelHeight());
796                 }
797                 setAnimator(null);
798                 if (!mCancelled) {
799                     notifyExpandingFinished();
800                 }
801                 notifyBarPanelExpansionChanged();
802             }
803         });
804         setAnimator(animator);
805         animator.start();
806     }
807 
shouldUseDismissingAnimation()808     protected abstract boolean shouldUseDismissingAnimation();
809 
810     @Override
onAttachedToWindow()811     protected void onAttachedToWindow() {
812         super.onAttachedToWindow();
813         mViewName = getResources().getResourceName(getId());
814     }
815 
getName()816     public String getName() {
817         return mViewName;
818     }
819 
setExpandedHeight(float height)820     public void setExpandedHeight(float height) {
821         if (DEBUG) logf("setExpandedHeight(%.1f)", height);
822         setExpandedHeightInternal(height + getOverExpansionPixels());
823     }
824 
825     @Override
onLayout(boolean changed, int left, int top, int right, int bottom)826     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
827         super.onLayout(changed, left, top, right, bottom);
828         mStatusBar.onPanelLaidOut();
829         requestPanelHeightUpdate();
830         mHasLayoutedSinceDown = true;
831         if (mUpdateFlingOnLayout) {
832             abortAnimations();
833             fling(mUpdateFlingVelocity, true /* expands */);
834             mUpdateFlingOnLayout = false;
835         }
836     }
837 
requestPanelHeightUpdate()838     protected void requestPanelHeightUpdate() {
839         float currentMaxPanelHeight = getMaxPanelHeight();
840 
841         if (isFullyCollapsed()) {
842             return;
843         }
844 
845         if (currentMaxPanelHeight == mExpandedHeight) {
846             return;
847         }
848 
849         if (mPeekAnimator != null || mPeekTouching) {
850             return;
851         }
852 
853         if (mTracking && !isTrackingBlocked()) {
854             return;
855         }
856 
857         if (mHeightAnimator != null) {
858             mPanelUpdateWhenAnimatorEnds = true;
859             return;
860         }
861 
862         setExpandedHeight(currentMaxPanelHeight);
863     }
864 
setExpandedHeightInternal(float h)865     public void setExpandedHeightInternal(float h) {
866         if (mExpandLatencyTracking && h != 0f) {
867             DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance(mContext).onActionEnd(
868                     LatencyTracker.ACTION_EXPAND_PANEL));
869             mExpandLatencyTracking = false;
870         }
871         float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
872         if (mHeightAnimator == null) {
873             float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
874             if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
875                 setOverExpansion(overExpansionPixels, true /* isPixels */);
876             }
877             mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
878         } else {
879             mExpandedHeight = h;
880             if (mOverExpandedBeforeFling) {
881                 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
882             }
883         }
884 
885         // If we are closing the panel and we are almost there due to a slow decelerating
886         // interpolator, abort the animation.
887         if (mExpandedHeight < 1f && mExpandedHeight != 0f && mClosing) {
888             mExpandedHeight = 0f;
889             if (mHeightAnimator != null) {
890                 mHeightAnimator.end();
891             }
892         }
893         mExpandedFraction = Math.min(1f,
894                 fhWithoutOverExpansion == 0 ? 0 : mExpandedHeight / fhWithoutOverExpansion);
895         onHeightUpdated(mExpandedHeight);
896         notifyBarPanelExpansionChanged();
897     }
898 
899     /**
900      * @return true if the panel tracking should be temporarily blocked; this is used when a
901      *         conflicting gesture (opening QS) is happening
902      */
isTrackingBlocked()903     protected abstract boolean isTrackingBlocked();
904 
setOverExpansion(float overExpansion, boolean isPixels)905     protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
906 
onHeightUpdated(float expandedHeight)907     protected abstract void onHeightUpdated(float expandedHeight);
908 
getOverExpansionAmount()909     protected abstract float getOverExpansionAmount();
910 
getOverExpansionPixels()911     protected abstract float getOverExpansionPixels();
912 
913     /**
914      * This returns the maximum height of the panel. Children should override this if their
915      * desired height is not the full height.
916      *
917      * @return the default implementation simply returns the maximum height.
918      */
getMaxPanelHeight()919     protected abstract int getMaxPanelHeight();
920 
setExpandedFraction(float frac)921     public void setExpandedFraction(float frac) {
922         setExpandedHeight(getMaxPanelHeight() * frac);
923     }
924 
getExpandedHeight()925     public float getExpandedHeight() {
926         return mExpandedHeight;
927     }
928 
getExpandedFraction()929     public float getExpandedFraction() {
930         return mExpandedFraction;
931     }
932 
isFullyExpanded()933     public boolean isFullyExpanded() {
934         return mExpandedHeight >= getMaxPanelHeight();
935     }
936 
isFullyCollapsed()937     public boolean isFullyCollapsed() {
938         return mExpandedFraction <= 0.0f;
939     }
940 
isCollapsing()941     public boolean isCollapsing() {
942         return mClosing || mLaunchingNotification;
943     }
944 
isTracking()945     public boolean isTracking() {
946         return mTracking;
947     }
948 
setBar(PanelBar panelBar)949     public void setBar(PanelBar panelBar) {
950         mBar = panelBar;
951     }
952 
collapse(boolean delayed, float speedUpFactor)953     public void collapse(boolean delayed, float speedUpFactor) {
954         if (DEBUG) logf("collapse: " + this);
955         if (canPanelBeCollapsed()) {
956             cancelHeightAnimator();
957             notifyExpandingStarted();
958 
959             // Set after notifyExpandingStarted, as notifyExpandingStarted resets the closing state.
960             mClosing = true;
961             if (delayed) {
962                 mNextCollapseSpeedUpFactor = speedUpFactor;
963                 postDelayed(mFlingCollapseRunnable, 120);
964             } else {
965                 fling(0, false /* expand */, speedUpFactor, false /* expandBecauseOfFalsing */);
966             }
967         }
968     }
969 
canPanelBeCollapsed()970     public boolean canPanelBeCollapsed() {
971         return !isFullyCollapsed() && !mTracking && !mClosing;
972     }
973 
974     private final Runnable mFlingCollapseRunnable = new Runnable() {
975         @Override
976         public void run() {
977             fling(0, false /* expand */, mNextCollapseSpeedUpFactor,
978                     false /* expandBecauseOfFalsing */);
979         }
980     };
981 
cancelPeek()982     public void cancelPeek() {
983         boolean cancelled = false;
984         if (mPeekAnimator != null) {
985             cancelled = true;
986             mPeekAnimator.cancel();
987         }
988 
989         if (cancelled) {
990             // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
991             // notify mBar that we might have closed ourselves.
992             notifyBarPanelExpansionChanged();
993         }
994     }
995 
expand(final boolean animate)996     public void expand(final boolean animate) {
997         if (!isFullyCollapsed() && !isCollapsing()) {
998             return;
999         }
1000 
1001         mInstantExpanding = true;
1002         mAnimateAfterExpanding = animate;
1003         mUpdateFlingOnLayout = false;
1004         abortAnimations();
1005         cancelPeek();
1006         if (mTracking) {
1007             onTrackingStopped(true /* expands */); // The panel is expanded after this call.
1008         }
1009         if (mExpanding) {
1010             notifyExpandingFinished();
1011         }
1012         notifyBarPanelExpansionChanged();
1013 
1014         // Wait for window manager to pickup the change, so we know the maximum height of the panel
1015         // then.
1016         getViewTreeObserver().addOnGlobalLayoutListener(
1017                 new ViewTreeObserver.OnGlobalLayoutListener() {
1018                     @Override
1019                     public void onGlobalLayout() {
1020                         if (!mInstantExpanding) {
1021                             getViewTreeObserver().removeOnGlobalLayoutListener(this);
1022                             return;
1023                         }
1024                         if (mStatusBar.getStatusBarWindow().getHeight()
1025                                 != mStatusBar.getStatusBarHeight()) {
1026                             getViewTreeObserver().removeOnGlobalLayoutListener(this);
1027                             if (mAnimateAfterExpanding) {
1028                                 notifyExpandingStarted();
1029                                 fling(0, true /* expand */);
1030                             } else {
1031                                 setExpandedFraction(1f);
1032                             }
1033                             mInstantExpanding = false;
1034                         }
1035                     }
1036                 });
1037 
1038         // Make sure a layout really happens.
1039         requestLayout();
1040     }
1041 
instantCollapse()1042     public void instantCollapse() {
1043         abortAnimations();
1044         setExpandedFraction(0f);
1045         if (mExpanding) {
1046             notifyExpandingFinished();
1047         }
1048         if (mInstantExpanding) {
1049             mInstantExpanding = false;
1050             notifyBarPanelExpansionChanged();
1051         }
1052     }
1053 
abortAnimations()1054     private void abortAnimations() {
1055         cancelPeek();
1056         cancelHeightAnimator();
1057         removeCallbacks(mPostCollapseRunnable);
1058         removeCallbacks(mFlingCollapseRunnable);
1059     }
1060 
onClosingFinished()1061     protected void onClosingFinished() {
1062         mBar.onClosingFinished();
1063     }
1064 
1065 
startUnlockHintAnimation()1066     protected void startUnlockHintAnimation() {
1067 
1068         // We don't need to hint the user if an animation is already running or the user is changing
1069         // the expansion.
1070         if (mHeightAnimator != null || mTracking) {
1071             return;
1072         }
1073         cancelPeek();
1074         notifyExpandingStarted();
1075         startUnlockHintAnimationPhase1(() -> {
1076             notifyExpandingFinished();
1077             onUnlockHintFinished();
1078             mHintAnimationRunning = false;
1079         });
1080         onUnlockHintStarted();
1081         mHintAnimationRunning = true;
1082     }
1083 
onUnlockHintFinished()1084     protected void onUnlockHintFinished() {
1085         mStatusBar.onHintFinished();
1086     }
1087 
onUnlockHintStarted()1088     protected void onUnlockHintStarted() {
1089         mStatusBar.onUnlockHintStarted();
1090     }
1091 
isUnlockHintRunning()1092     public boolean isUnlockHintRunning() {
1093         return mHintAnimationRunning;
1094     }
1095 
1096     /**
1097      * Phase 1: Move everything upwards.
1098      */
startUnlockHintAnimationPhase1(final Runnable onAnimationFinished)1099     private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
1100         float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
1101         ValueAnimator animator = createHeightAnimator(target);
1102         animator.setDuration(250);
1103         animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
1104         animator.addListener(new AnimatorListenerAdapter() {
1105             private boolean mCancelled;
1106 
1107             @Override
1108             public void onAnimationCancel(Animator animation) {
1109                 mCancelled = true;
1110             }
1111 
1112             @Override
1113             public void onAnimationEnd(Animator animation) {
1114                 if (mCancelled) {
1115                     setAnimator(null);
1116                     onAnimationFinished.run();
1117                 } else {
1118                     startUnlockHintAnimationPhase2(onAnimationFinished);
1119                 }
1120             }
1121         });
1122         animator.start();
1123         setAnimator(animator);
1124 
1125         View[] viewsToAnimate = {
1126                 mKeyguardBottomArea.getIndicationArea(),
1127                 mStatusBar.getAmbientIndicationContainer()};
1128         for (View v : viewsToAnimate) {
1129             if (v == null) {
1130                 continue;
1131             }
1132             v.animate()
1133                     .translationY(-mHintDistance)
1134                     .setDuration(250)
1135                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
1136                     .withEndAction(() -> v.animate()
1137                             .translationY(0)
1138                             .setDuration(450)
1139                             .setInterpolator(mBounceInterpolator)
1140                             .start())
1141                     .start();
1142         }
1143     }
1144 
setAnimator(ValueAnimator animator)1145     private void setAnimator(ValueAnimator animator) {
1146         mHeightAnimator = animator;
1147         if (animator == null && mPanelUpdateWhenAnimatorEnds) {
1148             mPanelUpdateWhenAnimatorEnds = false;
1149             requestPanelHeightUpdate();
1150         }
1151     }
1152 
1153     /**
1154      * Phase 2: Bounce down.
1155      */
startUnlockHintAnimationPhase2(final Runnable onAnimationFinished)1156     private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
1157         ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
1158         animator.setDuration(450);
1159         animator.setInterpolator(mBounceInterpolator);
1160         animator.addListener(new AnimatorListenerAdapter() {
1161             @Override
1162             public void onAnimationEnd(Animator animation) {
1163                 setAnimator(null);
1164                 onAnimationFinished.run();
1165                 notifyBarPanelExpansionChanged();
1166             }
1167         });
1168         animator.start();
1169         setAnimator(animator);
1170     }
1171 
createHeightAnimator(float targetHeight)1172     private ValueAnimator createHeightAnimator(float targetHeight) {
1173         ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
1174         animator.addUpdateListener(
1175                 animation -> setExpandedHeightInternal((float) animation.getAnimatedValue()));
1176         return animator;
1177     }
1178 
notifyBarPanelExpansionChanged()1179     protected void notifyBarPanelExpansionChanged() {
1180         if (mBar != null) {
1181             mBar.panelExpansionChanged(mExpandedFraction, mExpandedFraction > 0f
1182                     || mPeekAnimator != null || mInstantExpanding
1183                     || isPanelVisibleBecauseOfHeadsUp() || mTracking || mHeightAnimator != null);
1184         }
1185         for (int i = 0; i < mExpansionListeners.size(); i++) {
1186             mExpansionListeners.get(i).onPanelExpansionChanged(mExpandedFraction, mTracking);
1187         }
1188     }
1189 
addExpansionListener(PanelExpansionListener panelExpansionListener)1190     public void addExpansionListener(PanelExpansionListener panelExpansionListener) {
1191         mExpansionListeners.add(panelExpansionListener);
1192     }
1193 
isPanelVisibleBecauseOfHeadsUp()1194     protected abstract boolean isPanelVisibleBecauseOfHeadsUp();
1195 
1196     /**
1197      * Gets called when the user performs a click anywhere in the empty area of the panel.
1198      *
1199      * @return whether the panel will be expanded after the action performed by this method
1200      */
onEmptySpaceClick(float x)1201     protected boolean onEmptySpaceClick(float x) {
1202         if (mHintAnimationRunning) {
1203             return true;
1204         }
1205         return onMiddleClicked();
1206     }
1207 
1208     protected final Runnable mPostCollapseRunnable = new Runnable() {
1209         @Override
1210         public void run() {
1211             collapse(false /* delayed */, 1.0f /* speedUpFactor */);
1212         }
1213     };
1214 
onMiddleClicked()1215     protected abstract boolean onMiddleClicked();
1216 
isDozing()1217     protected abstract boolean isDozing();
1218 
dump(FileDescriptor fd, PrintWriter pw, String[] args)1219     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1220         pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
1221                 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
1222                 + "]",
1223                 this.getClass().getSimpleName(),
1224                 getExpandedHeight(),
1225                 getMaxPanelHeight(),
1226                 mClosing?"T":"f",
1227                 mTracking?"T":"f",
1228                 mJustPeeked?"T":"f",
1229                 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
1230                 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":""),
1231                 mTouchDisabled?"T":"f"
1232         ));
1233     }
1234 
resetViews(boolean animate)1235     public abstract void resetViews(boolean animate);
1236 
getPeekHeight()1237     protected abstract float getPeekHeight();
1238     /**
1239      * @return whether "Clear all" button will be visible when the panel is fully expanded
1240      */
fullyExpandedClearAllVisible()1241     protected abstract boolean fullyExpandedClearAllVisible();
1242 
isClearAllVisible()1243     protected abstract boolean isClearAllVisible();
1244 
1245     /**
1246      * @return the height of the clear all button, in pixels
1247      */
getClearAllHeight()1248     protected abstract int getClearAllHeight();
1249 
setHeadsUpManager(HeadsUpManagerPhone headsUpManager)1250     public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
1251         mHeadsUpManager = headsUpManager;
1252     }
1253 
setLaunchingNotification(boolean launchingNotification)1254     public void setLaunchingNotification(boolean launchingNotification) {
1255         mLaunchingNotification = launchingNotification;
1256     }
1257 
collapseWithDuration(int animationDuration)1258     public void collapseWithDuration(int animationDuration) {
1259         mFixedDuration = animationDuration;
1260         collapse(false /* delayed */, 1.0f /* speedUpFactor */);
1261         mFixedDuration = NO_FIXED_DURATION;
1262     }
1263 }
1264