blob: 2c5ece60cb25f361ea1acb24eb4399e5f2c9879e [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;
26import android.util.AttributeSet;
John Spurlockcd686b52013-06-05 10:13:46 -040027import android.util.Log;
Daniel Sandler08d05e32012-08-08 16:39:54 -040028import android.view.MotionEvent;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010029import android.view.ViewConfiguration;
Jorim Jaggi0a27be82014-06-11 03:22:39 +020030import android.view.ViewTreeObserver;
Jorim Jaggi90129582014-06-02 14:44:49 +020031import android.view.animation.AnimationUtils;
32import android.view.animation.Interpolator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040033import android.widget.FrameLayout;
34
35import com.android.systemui.R;
Jorim Jaggi1d480692014-05-20 19:41:58 +020036import com.android.systemui.statusbar.FlingAnimationUtils;
Jorim Jaggi90129582014-06-02 14:44:49 +020037import com.android.systemui.statusbar.StatusBarState;
Daniel Sandler08d05e32012-08-08 16:39:54 -040038
John Spurlockde84f0e2013-06-12 12:41:00 -040039import java.io.FileDescriptor;
40import java.io.PrintWriter;
John Spurlockde84f0e2013-06-12 12:41:00 -040041
Selim Cinek4c6969a2014-05-26 19:22:17 +020042public abstract class PanelView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040043 public static final boolean DEBUG = PanelBar.DEBUG;
Daniel Sandler08d05e32012-08-08 16:39:54 -040044 public static final String TAG = PanelView.class.getSimpleName();
Daniel Sandlere7c5bbb2013-03-05 13:36:21 -050045
John Spurlock97642182013-07-29 17:58:39 -040046 private final void logf(String fmt, Object... args) {
John Spurlockcd686b52013-06-05 10:13:46 -040047 Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
Daniel Sandler08d05e32012-08-08 16:39:54 -040048 }
49
Jorim Jaggi90129582014-06-02 14:44:49 +020050 protected PhoneStatusBar mStatusBar;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040051 private float mPeekHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +020052 private float mHintDistance;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020053 private int mEdgeTapAreaWidth;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010054 private float mInitialOffsetOnTouch;
Daniel Sandler08d05e32012-08-08 16:39:54 -040055 private float mExpandedFraction = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +020056 protected float mExpandedHeight = 0;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040057 private boolean mJustPeeked;
Daniel Sandler50508132012-08-16 14:10:53 -040058 private boolean mClosing;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020059 protected boolean mTracking;
Jorim Jaggi90129582014-06-02 14:44:49 +020060 private boolean mTouchSlopExceeded;
John Spurlock48fa91a2013-08-15 09:29:31 -040061 private int mTrackingPointer;
Jorim Jaggid7daab72014-05-06 22:22:20 +020062 protected int mTouchSlop;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +020063 protected boolean mHintAnimationRunning;
Jorim Jaggi47c85a32014-06-05 17:25:40 +020064 private boolean mOverExpandedBeforeFling;
Selim Cinekf99d0002014-06-13 07:36:01 +020065 private float mOriginalIndicationY;
Daniel Sandler08d05e32012-08-08 16:39:54 -040066
Jorim Jaggi1d480692014-05-20 19:41:58 +020067 private ValueAnimator mHeightAnimator;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -040068 private ObjectAnimator mPeekAnimator;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +020069 private VelocityTrackerInterface mVelocityTracker;
Jorim Jaggi1d480692014-05-20 19:41:58 +020070 private FlingAnimationUtils mFlingAnimationUtils;
Daniel Sandler08d05e32012-08-08 16:39:54 -040071
Jorim Jaggi0a27be82014-06-11 03:22:39 +020072 /**
73 * Whether an instant expand request is currently pending and we are just waiting for layout.
74 */
75 private boolean mInstantExpanding;
76
Daniel Sandler08d05e32012-08-08 16:39:54 -040077 PanelBar mBar;
78
Selim Cinekb84a1072014-05-15 19:10:18 +020079 protected int mMaxPanelHeight = -1;
Daniel Sandler50508132012-08-16 14:10:53 -040080 private String mViewName;
Jorim Jaggid7daab72014-05-06 22:22:20 +020081 private float mInitialTouchY;
82 private float mInitialTouchX;
Daniel Sandler08d05e32012-08-08 16:39:54 -040083
Jorim Jaggi90129582014-06-02 14:44:49 +020084 private Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggib472b3472014-06-30 19:56:24 +020085 private Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi90129582014-06-02 14:44:49 +020086 private Interpolator mBounceInterpolator;
Selim Cinekf99d0002014-06-13 07:36:01 +020087 protected KeyguardBottomAreaView mKeyguardBottomArea;
Jorim Jaggi90129582014-06-02 14:44:49 +020088
Jorim Jaggib472b3472014-06-30 19:56:24 +020089 private boolean mPeekPending;
90 private boolean mCollapseAfterPeek;
91 private boolean mExpanding;
92 private boolean mGestureWaitForTouchSlop;
93 private Runnable mPeekRunnable = new Runnable() {
94 @Override
95 public void run() {
96 mPeekPending = false;
97 runPeekAnimation();
98 }
99 };
100
Selim Cinek1685e632014-04-08 02:27:49 +0200101 protected void onExpandingFinished() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200102 mBar.onExpandingFinished();
Selim Cinek1685e632014-04-08 02:27:49 +0200103 }
104
105 protected void onExpandingStarted() {
106 }
107
Jorim Jaggib472b3472014-06-30 19:56:24 +0200108 private void notifyExpandingStarted() {
109 if (!mExpanding) {
110 mExpanding = true;
111 onExpandingStarted();
112 }
113 }
114
115 private void notifyExpandingFinished() {
116 if (mExpanding) {
117 mExpanding = false;
118 onExpandingFinished();
119 }
120 }
121
122 private void schedulePeek() {
123 mPeekPending = true;
124 long timeout = ViewConfiguration.getTapTimeout();
125 postOnAnimationDelayed(mPeekRunnable, timeout);
126 notifyBarPanelExpansionChanged();
127 }
128
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400129 private void runPeekAnimation() {
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200130 mPeekHeight = getPeekHeight();
John Spurlock97642182013-07-29 17:58:39 -0400131 if (DEBUG) logf("peek to height=%.1f", mPeekHeight);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200132 if (mHeightAnimator != null) {
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400133 return;
134 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200135 mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight)
136 .setDuration(250);
137 mPeekAnimator.setInterpolator(mLinearOutSlowInInterpolator);
138 mPeekAnimator.addListener(new AnimatorListenerAdapter() {
139 private boolean mCancelled;
140
141 @Override
142 public void onAnimationCancel(Animator animation) {
143 mCancelled = true;
144 }
145
146 @Override
147 public void onAnimationEnd(Animator animation) {
148 mPeekAnimator = null;
149 if (mCollapseAfterPeek && !mCancelled) {
150 postOnAnimation(new Runnable() {
151 @Override
152 public void run() {
153 collapse();
154 }
155 });
156 }
157 mCollapseAfterPeek = false;
158 }
159 });
160 notifyExpandingStarted();
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400161 mPeekAnimator.start();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200162 mJustPeeked = true;
Daniel Sandler0c1b75c2012-10-04 12:08:54 -0400163 }
164
Daniel Sandler08d05e32012-08-08 16:39:54 -0400165 public PanelView(Context context, AttributeSet attrs) {
166 super(context, attrs);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200167 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200168 mFastOutSlowInInterpolator =
Jorim Jaggi90129582014-06-02 14:44:49 +0200169 AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200170 mLinearOutSlowInInterpolator =
171 AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in);
Jorim Jaggi90129582014-06-02 14:44:49 +0200172 mBounceInterpolator = new BounceInterpolator();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400173 }
174
Jorim Jaggi069cd032014-05-15 03:09:01 +0200175 protected void loadDimens() {
Daniel Sandler08d05e32012-08-08 16:39:54 -0400176 final Resources res = getContext().getResources();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100177 final ViewConfiguration configuration = ViewConfiguration.get(getContext());
178 mTouchSlop = configuration.getScaledTouchSlop();
Jorim Jaggi90129582014-06-02 14:44:49 +0200179 mHintDistance = res.getDimension(R.dimen.hint_move_distance);
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200180 mEdgeTapAreaWidth = res.getDimensionPixelSize(R.dimen.edge_tap_area_width);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400181 }
182
183 private void trackMovement(MotionEvent event) {
184 // Add movement to velocity tracker using raw screen X and Y coordinates instead
185 // of window coordinates because the window frame may be moving at the same time.
186 float deltaX = event.getRawX() - event.getX();
187 float deltaY = event.getRawY() - event.getY();
188 event.offsetLocation(deltaX, deltaY);
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400189 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400190 event.offsetLocation(-deltaX, -deltaY);
191 }
192
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400193 @Override
194 public boolean onTouchEvent(MotionEvent event) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200195 if (mInstantExpanding) {
196 return false;
197 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100198
199 /*
200 * We capture touch events here and update the expand height here in case according to
201 * the users fingers. This also handles multi-touch.
202 *
203 * If the user just clicks shortly, we give him a quick peek of the shade.
204 *
205 * Flinging is also enabled in order to open or close the shade.
206 */
207
208 int pointerIndex = event.findPointerIndex(mTrackingPointer);
209 if (pointerIndex < 0) {
210 pointerIndex = 0;
211 mTrackingPointer = event.getPointerId(pointerIndex);
212 }
213 final float y = event.getY(pointerIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200214 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100215
Jorim Jaggib472b3472014-06-30 19:56:24 +0200216 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
217 mGestureWaitForTouchSlop = mExpandedHeight == 0f;
218 }
219 boolean waitForTouchSlop = hasConflictingGestures() || mGestureWaitForTouchSlop;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200220
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100221 switch (event.getActionMasked()) {
222 case MotionEvent.ACTION_DOWN:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100223 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200224 mInitialTouchX = x;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200225 mInitialOffsetOnTouch = mExpandedHeight;
Jorim Jaggi90129582014-06-02 14:44:49 +0200226 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200227 mJustPeeked = false;
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200228 if (mVelocityTracker == null) {
229 initVelocityTracker();
230 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100231 trackMovement(event);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200232 if (!waitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning) ||
233 mPeekPending || mPeekAnimator != null) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200234 if (mHeightAnimator != null) {
235 mHeightAnimator.cancel(); // end any outstanding animations
236 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200237 cancelPeek();
238 mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning)
239 || mPeekPending || mPeekAnimator != null;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200240 onTrackingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200241 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100242 if (mExpandedHeight == 0) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200243 schedulePeek();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100244 }
245 break;
246
247 case MotionEvent.ACTION_POINTER_UP:
248 final int upPointer = event.getPointerId(event.getActionIndex());
249 if (mTrackingPointer == upPointer) {
250 // gesture is ongoing, find a new pointer to track
251 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
252 final float newY = event.getY(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200253 final float newX = event.getX(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100254 mTrackingPointer = event.getPointerId(newIndex);
255 mInitialOffsetOnTouch = mExpandedHeight;
256 mInitialTouchY = newY;
Jorim Jaggia6310292014-04-16 14:11:52 +0200257 mInitialTouchX = newX;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100258 }
259 break;
260
261 case MotionEvent.ACTION_MOVE:
Selim Cinek4c6969a2014-05-26 19:22:17 +0200262 float h = y - mInitialTouchY;
Jorim Jaggib7240132014-06-30 01:39:07 +0200263
264 // If the panel was collapsed when touching, we only need to check for the
265 // y-component of the gesture, as we have no conflicting horizontal gesture.
266 if (Math.abs(h) > mTouchSlop
267 && (Math.abs(h) > Math.abs(x - mInitialTouchX)
268 || mInitialOffsetOnTouch == 0f)) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200269 mTouchSlopExceeded = true;
270 if (waitForTouchSlop && !mTracking) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200271 if (!mJustPeeked) {
272 mInitialOffsetOnTouch = mExpandedHeight;
273 mInitialTouchX = x;
274 mInitialTouchY = y;
275 h = 0;
276 }
Jorim Jaggi90129582014-06-02 14:44:49 +0200277 if (mHeightAnimator != null) {
278 mHeightAnimator.cancel(); // end any outstanding animations
279 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200280 removeCallbacks(mPeekRunnable);
281 mPeekPending = false;
Jorim Jaggi90129582014-06-02 14:44:49 +0200282 onTrackingStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200283 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200284 }
Jorim Jaggi93439da2014-06-30 23:53:39 +0200285 final float newHeight = Math.max(0, h + mInitialOffsetOnTouch);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200286 if (newHeight > mPeekHeight) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200287 if (mPeekAnimator != null) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100288 mPeekAnimator.cancel();
289 }
290 mJustPeeked = false;
291 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200292 if (!mJustPeeked && (!waitForTouchSlop || mTracking) && !isTrackingBlocked()) {
Jorim Jaggicc693242014-06-14 03:04:35 +0000293 setExpandedHeightInternal(newHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100294 }
295
296 trackMovement(event);
297 break;
298
299 case MotionEvent.ACTION_UP:
300 case MotionEvent.ACTION_CANCEL:
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100301 mTrackingPointer = -1;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100302 trackMovement(event);
Jorim Jaggi787a0af2014-06-04 18:57:14 +0200303 if ((mTracking && mTouchSlopExceeded)
Jorim Jaggidc96d632014-07-01 18:48:52 +0200304 || Math.abs(x - mInitialTouchX) > mTouchSlop
305 || Math.abs(y - mInitialTouchY) > mTouchSlop
Jorim Jaggi787a0af2014-06-04 18:57:14 +0200306 || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Jorim Jaggib7240132014-06-30 01:39:07 +0200307 float vel = 0f;
308 float vectorVel = 0f;
309 if (mVelocityTracker != null) {
310 mVelocityTracker.computeCurrentVelocity(1000);
311 vel = mVelocityTracker.getYVelocity();
312 vectorVel = (float) Math.hypot(
313 mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
314 }
315 boolean expand = flingExpands(vel, vectorVel);
Jorim Jaggi90129582014-06-02 14:44:49 +0200316 onTrackingStopped(expand);
317 fling(vel, expand);
318 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200319 boolean expands = onEmptySpaceClick(mInitialTouchX);
Jorim Jaggi90129582014-06-02 14:44:49 +0200320 onTrackingStopped(expands);
321 }
Jorim Jaggidc96d632014-07-01 18:48:52 +0200322
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100323 if (mVelocityTracker != null) {
324 mVelocityTracker.recycle();
325 mVelocityTracker = null;
326 }
327 break;
328 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200329 return !waitForTouchSlop || mTracking;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100330 }
331
Selim Cinek4c6969a2014-05-26 19:22:17 +0200332 protected abstract boolean hasConflictingGestures();
333
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200334 protected void onTrackingStopped(boolean expand) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200335 mTracking = false;
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200336 mBar.onTrackingStopped(PanelView.this, expand);
Selim Cinek1685e632014-04-08 02:27:49 +0200337 }
338
339 protected void onTrackingStarted() {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200340 mTracking = true;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200341 mCollapseAfterPeek = false;
Selim Cinek1685e632014-04-08 02:27:49 +0200342 mBar.onTrackingStarted(PanelView.this);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200343 notifyExpandingStarted();
Selim Cinek1685e632014-04-08 02:27:49 +0200344 }
345
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100346 @Override
347 public boolean onInterceptTouchEvent(MotionEvent event) {
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200348 if (mInstantExpanding) {
349 return false;
350 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100351
352 /*
353 * If the user drags anywhere inside the panel we intercept it if he moves his finger
354 * upwards. This allows closing the shade from anywhere inside the panel.
355 *
356 * We only do this if the current content is scrolled to the bottom,
357 * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture
358 * possible.
359 */
360 int pointerIndex = event.findPointerIndex(mTrackingPointer);
361 if (pointerIndex < 0) {
362 pointerIndex = 0;
363 mTrackingPointer = event.getPointerId(pointerIndex);
364 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200365 final float x = event.getX(pointerIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100366 final float y = event.getY(pointerIndex);
367 boolean scrolledToBottom = isScrolledToBottom();
368
369 switch (event.getActionMasked()) {
370 case MotionEvent.ACTION_DOWN:
Jorim Jaggib472b3472014-06-30 19:56:24 +0200371 if (mHeightAnimator != null && !mHintAnimationRunning ||
372 mPeekPending || mPeekAnimator != null) {
373 if (mHeightAnimator != null) {
374 mHeightAnimator.cancel(); // end any outstanding animations
375 }
376 cancelPeek();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200377 mTouchSlopExceeded = true;
Selim Cinek172e9142014-05-07 19:38:00 +0200378 return true;
379 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100380 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200381 mInitialTouchX = x;
Jorim Jaggi90129582014-06-02 14:44:49 +0200382 mTouchSlopExceeded = false;
Jorim Jaggi3857ac42014-06-27 18:01:12 +0200383 mJustPeeked = false;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100384 initVelocityTracker();
385 trackMovement(event);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100386 break;
387 case MotionEvent.ACTION_POINTER_UP:
388 final int upPointer = event.getPointerId(event.getActionIndex());
389 if (mTrackingPointer == upPointer) {
390 // gesture is ongoing, find a new pointer to track
391 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
392 mTrackingPointer = event.getPointerId(newIndex);
Jorim Jaggia6310292014-04-16 14:11:52 +0200393 mInitialTouchX = event.getX(newIndex);
394 mInitialTouchY = event.getY(newIndex);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100395 }
396 break;
397
398 case MotionEvent.ACTION_MOVE:
399 final float h = y - mInitialTouchY;
400 trackMovement(event);
401 if (scrolledToBottom) {
Jorim Jaggia6310292014-04-16 14:11:52 +0200402 if (h < -mTouchSlop && h < -Math.abs(x - mInitialTouchX)) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200403 if (mHeightAnimator != null) {
404 mHeightAnimator.cancel();
405 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100406 mInitialOffsetOnTouch = mExpandedHeight;
407 mInitialTouchY = y;
Jorim Jaggia6310292014-04-16 14:11:52 +0200408 mInitialTouchX = x;
Selim Cinek91c39ef2014-04-07 21:18:09 +0200409 mTracking = true;
Jorim Jaggi90129582014-06-02 14:44:49 +0200410 mTouchSlopExceeded = true;
Selim Cinek1685e632014-04-08 02:27:49 +0200411 onTrackingStarted();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100412 return true;
413 }
414 }
415 break;
416 }
417 return false;
418 }
419
420 private void initVelocityTracker() {
421 if (mVelocityTracker != null) {
422 mVelocityTracker.recycle();
423 }
Jorim Jaggib7b61dd2014-05-21 15:45:07 +0200424 mVelocityTracker = VelocityTrackerFactory.obtain(getContext());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100425 }
426
427 protected boolean isScrolledToBottom() {
Selim Cinek172e9142014-05-07 19:38:00 +0200428 return true;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100429 }
430
431 protected float getContentHeight() {
432 return mExpandedHeight;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400433 }
434
Daniel Sandler08d05e32012-08-08 16:39:54 -0400435 @Override
436 protected void onFinishInflate() {
437 super.onFinishInflate();
438 loadDimens();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400439 }
440
Jorim Jaggi069cd032014-05-15 03:09:01 +0200441 @Override
442 protected void onConfigurationChanged(Configuration newConfig) {
443 super.onConfigurationChanged(newConfig);
444 loadDimens();
445 mMaxPanelHeight = -1;
446 }
447
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200448 /**
Jorim Jaggib7240132014-06-30 01:39:07 +0200449 * @param vel the current vertical velocity of the motion
450 * @param vectorVel the length of the vectorial velocity
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200451 * @return whether a fling should expands the panel; contracts otherwise
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200452 */
Jorim Jaggidc96d632014-07-01 18:48:52 +0200453 protected boolean flingExpands(float vel, float vectorVel) {
Jorim Jaggib7240132014-06-30 01:39:07 +0200454 if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200455 return getExpandedFraction() > 0.5f;
Selim Cinek1685e632014-04-08 02:27:49 +0200456 } else {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200457 return vel > 0;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400458 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200459 }
460
461 protected void fling(float vel, boolean expand) {
462 cancelPeek();
463 float target = expand ? getMaxPanelHeight() : 0.0f;
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200464 if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200465 notifyExpandingFinished();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200466 return;
467 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200468 mOverExpandedBeforeFling = getOverExpansionAmount() > 0f;
Jorim Jaggi90129582014-06-02 14:44:49 +0200469 ValueAnimator animator = createHeightAnimator(target);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200470 if (expand) {
471 mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight());
472 } else {
473 mFlingAnimationUtils.applyDismissing(animator, mExpandedHeight, target, vel,
474 getHeight());
475
476 // Make it shorter if we run a canned animation
477 if (vel == 0) {
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200478 animator.setDuration((long)
479 (animator.getDuration() * getCannedFlingDurationFactor()));
Jorim Jaggi1d480692014-05-20 19:41:58 +0200480 }
481 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200482 animator.addListener(new AnimatorListenerAdapter() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200483 private boolean mCancelled;
484
485 @Override
486 public void onAnimationCancel(Animator animation) {
487 mCancelled = true;
488 }
489
Jorim Jaggi1d480692014-05-20 19:41:58 +0200490 @Override
491 public void onAnimationEnd(Animator animation) {
492 mHeightAnimator = null;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200493 if (!mCancelled) {
494 notifyExpandingFinished();
495 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200496 }
497 });
Jorim Jaggi1d480692014-05-20 19:41:58 +0200498 mHeightAnimator = animator;
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200499 animator.start();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400500 }
501
502 @Override
503 protected void onAttachedToWindow() {
504 super.onAttachedToWindow();
Daniel Sandler978f8532012-08-15 15:48:16 -0400505 mViewName = getResources().getResourceName(getId());
506 }
507
508 public String getName() {
509 return mViewName;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400510 }
511
Daniel Sandler08d05e32012-08-08 16:39:54 -0400512 @Override
513 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
514 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
515
John Spurlock97642182013-07-29 17:58:39 -0400516 if (DEBUG) logf("onMeasure(%d, %d) -> (%d, %d)",
Daniel Sandler08d05e32012-08-08 16:39:54 -0400517 widthMeasureSpec, heightMeasureSpec, getMeasuredWidth(), getMeasuredHeight());
Daniel Sandler198a0302012-08-17 16:04:31 -0400518
519 // Did one of our children change size?
520 int newHeight = getMeasuredHeight();
Selim Cinekb84a1072014-05-15 19:10:18 +0200521 if (newHeight > mMaxPanelHeight) {
522 // we only adapt the max height if it's bigger
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100523 mMaxPanelHeight = newHeight;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200524 // If the user isn't actively poking us, let's rubberband to the content
Jorim Jaggi1d480692014-05-20 19:41:58 +0200525 if (!mTracking && mHeightAnimator == null
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200526 && mExpandedHeight > 0 && mExpandedHeight != mMaxPanelHeight
Jorim Jaggib472b3472014-06-30 19:56:24 +0200527 && mMaxPanelHeight > 0 && mPeekAnimator == null) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200528 mExpandedHeight = mMaxPanelHeight;
529 }
Daniel Sandler50508132012-08-16 14:10:53 -0400530 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400531 }
532
Daniel Sandler08d05e32012-08-08 16:39:54 -0400533 public void setExpandedHeight(float height) {
John Spurlock97642182013-07-29 17:58:39 -0400534 if (DEBUG) logf("setExpandedHeight(%.1f)", height);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200535 setExpandedHeightInternal(height + getOverExpansionPixels());
Daniel Sandler08d05e32012-08-08 16:39:54 -0400536 }
537
Daniel Sandler50508132012-08-16 14:10:53 -0400538 @Override
539 protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100540 if (DEBUG) logf("onLayout: changed=%s, bottom=%d eh=%d fh=%d", changed?"T":"f", bottom,
541 (int)mExpandedHeight, mMaxPanelHeight);
Daniel Sandler50508132012-08-16 14:10:53 -0400542 super.onLayout(changed, left, top, right, bottom);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100543 requestPanelHeightUpdate();
544 }
545
546 protected void requestPanelHeightUpdate() {
547 float currentMaxPanelHeight = getMaxPanelHeight();
548
549 // If the user isn't actively poking us, let's update the height
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200550 if ((!mTracking || isTrackingBlocked())
551 && mHeightAnimator == null
552 && mExpandedHeight > 0
553 && currentMaxPanelHeight != mExpandedHeight
554 && !mPeekPending
555 && mPeekAnimator == null) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200556 setExpandedHeight(currentMaxPanelHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100557 }
Daniel Sandler50508132012-08-16 14:10:53 -0400558 }
559
Daniel Sandler08d05e32012-08-08 16:39:54 -0400560 public void setExpandedHeightInternal(float h) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200561 float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount();
562 if (mHeightAnimator == null) {
563 float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion);
564 if (getOverExpansionPixels() != overExpansionPixels && mTracking) {
565 setOverExpansion(overExpansionPixels, true /* isPixels */);
566 }
567 mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount();
568 } else {
569 mExpandedHeight = h;
570 if (mOverExpandedBeforeFling) {
571 setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */);
572 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100573 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400574
Jorim Jaggi93439da2014-06-30 23:53:39 +0200575 mExpandedHeight = Math.max(0, mExpandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100576 onHeightUpdated(mExpandedHeight);
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200577 mExpandedFraction = Math.min(1f, fhWithoutOverExpansion == 0
578 ? 0
579 : mExpandedHeight / fhWithoutOverExpansion);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200580 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400581 }
582
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200583 /**
584 * @return true if the panel tracking should be temporarily blocked; this is used when a
585 * conflicting gesture (opening QS) is happening
586 */
587 protected abstract boolean isTrackingBlocked();
588
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200589 protected abstract void setOverExpansion(float overExpansion, boolean isPixels);
Selim Cinek24120a52014-05-26 10:05:42 +0200590
Jorim Jaggi90129582014-06-02 14:44:49 +0200591 protected abstract void onHeightUpdated(float expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100592
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200593 protected abstract float getOverExpansionAmount();
594
595 protected abstract float getOverExpansionPixels();
596
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100597 /**
598 * This returns the maximum height of the panel. Children should override this if their
599 * desired height is not the full height.
600 *
601 * @return the default implementation simply returns the maximum height.
602 */
603 protected int getMaxPanelHeight() {
Selim Cinekb84a1072014-05-15 19:10:18 +0200604 mMaxPanelHeight = Math.max(mMaxPanelHeight, getHeight());
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100605 return mMaxPanelHeight;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400606 }
607
608 public void setExpandedFraction(float frac) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100609 setExpandedHeight(getMaxPanelHeight() * frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400610 }
611
612 public float getExpandedHeight() {
613 return mExpandedHeight;
614 }
615
616 public float getExpandedFraction() {
617 return mExpandedFraction;
618 }
619
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700620 public boolean isFullyExpanded() {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100621 return mExpandedHeight >= getMaxPanelHeight();
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700622 }
623
624 public boolean isFullyCollapsed() {
Daniel Sandler67eab792012-10-02 17:08:23 -0400625 return mExpandedHeight <= 0;
626 }
627
628 public boolean isCollapsing() {
629 return mClosing;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700630 }
631
John Spurlocka4b70af2013-08-17 14:05:49 -0400632 public boolean isTracking() {
633 return mTracking;
634 }
635
Daniel Sandler08d05e32012-08-08 16:39:54 -0400636 public void setBar(PanelBar panelBar) {
637 mBar = panelBar;
638 }
639
Daniel Sandler08d05e32012-08-08 16:39:54 -0400640 public void collapse() {
641 // TODO: abort animation or ongoing touch
John Spurlock97642182013-07-29 17:58:39 -0400642 if (DEBUG) logf("collapse: " + this);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200643 if (mPeekPending || mPeekAnimator != null) {
644 mCollapseAfterPeek = true;
645 if (mPeekPending) {
646
647 // We know that the whole gesture is just a peek triggered by a simple click, so
648 // better start it now.
649 removeCallbacks(mPeekRunnable);
650 mPeekRunnable.run();
651 }
652 } else if (!isFullyCollapsed()) {
Jorim Jaggi1d480692014-05-20 19:41:58 +0200653 if (mHeightAnimator != null) {
654 mHeightAnimator.cancel();
655 }
Daniel Sandler750bb9b2012-10-03 16:24:00 -0400656 mClosing = true;
Jorim Jaggib472b3472014-06-30 19:56:24 +0200657 notifyExpandingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200658 fling(0, false /* expand */);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400659 }
660 }
661
662 public void expand() {
John Spurlock97642182013-07-29 17:58:39 -0400663 if (DEBUG) logf("expand: " + this);
Daniel Sandler198a0302012-08-17 16:04:31 -0400664 if (isFullyCollapsed()) {
665 mBar.startOpeningPanel(this);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200666 notifyExpandingStarted();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200667 fling(0, true /* expand */);
Daniel Sandler198a0302012-08-17 16:04:31 -0400668 } else if (DEBUG) {
John Spurlock97642182013-07-29 17:58:39 -0400669 if (DEBUG) logf("skipping expansion: is expanded");
670 }
671 }
672
673 public void cancelPeek() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200674 if (mPeekAnimator != null) {
John Spurlock97642182013-07-29 17:58:39 -0400675 mPeekAnimator.cancel();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400676 }
Jorim Jaggib472b3472014-06-30 19:56:24 +0200677 removeCallbacks(mPeekRunnable);
678 mPeekPending = false;
679
680 // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also
681 // notify mBar that we might have closed ourselves.
682 notifyBarPanelExpansionChanged();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400683 }
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500684
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200685 public void instantExpand() {
686 mInstantExpanding = true;
687 abortAnimations();
688 if (mTracking) {
689 onTrackingStopped(true /* expands */); // The panel is expanded after this call.
Jorim Jaggib472b3472014-06-30 19:56:24 +0200690 notifyExpandingFinished();
Jorim Jaggi0a27be82014-06-11 03:22:39 +0200691 }
692 setVisibility(VISIBLE);
693
694 // Wait for window manager to pickup the change, so we know the maximum height of the panel
695 // then.
696 getViewTreeObserver().addOnGlobalLayoutListener(
697 new ViewTreeObserver.OnGlobalLayoutListener() {
698 @Override
699 public void onGlobalLayout() {
700 if (mStatusBar.getStatusBarWindow().getHeight()
701 != mStatusBar.getStatusBarHeight()) {
702 getViewTreeObserver().removeOnGlobalLayoutListener(this);
703 setExpandedFraction(1f);
704 mInstantExpanding = false;
705 }
706 }
707 });
708
709 // Make sure a layout really happens.
710 requestLayout();
711 }
712
713 private void abortAnimations() {
714 cancelPeek();
715 if (mHeightAnimator != null) {
716 mHeightAnimator.cancel();
717 }
718 }
719
Jorim Jaggi90129582014-06-02 14:44:49 +0200720 protected void startUnlockHintAnimation() {
721
722 // We don't need to hint the user if an animation is already running or the user is changing
723 // the expansion.
724 if (mHeightAnimator != null || mTracking) {
725 return;
726 }
727 cancelPeek();
Jorim Jaggib472b3472014-06-30 19:56:24 +0200728 notifyExpandingStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200729 startUnlockHintAnimationPhase1(new Runnable() {
730 @Override
731 public void run() {
Jorim Jaggib472b3472014-06-30 19:56:24 +0200732 notifyExpandingFinished();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200733 mStatusBar.onHintFinished();
734 mHintAnimationRunning = false;
735 }
736 });
Jorim Jaggi90129582014-06-02 14:44:49 +0200737 mStatusBar.onUnlockHintStarted();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200738 mHintAnimationRunning = true;
Jorim Jaggi90129582014-06-02 14:44:49 +0200739 }
740
741 /**
742 * Phase 1: Move everything upwards.
743 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200744 private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200745 float target = Math.max(0, getMaxPanelHeight() - mHintDistance);
746 ValueAnimator animator = createHeightAnimator(target);
747 animator.setDuration(250);
Jorim Jaggib472b3472014-06-30 19:56:24 +0200748 animator.setInterpolator(mFastOutSlowInInterpolator);
Jorim Jaggi90129582014-06-02 14:44:49 +0200749 animator.addListener(new AnimatorListenerAdapter() {
750 private boolean mCancelled;
751
752 @Override
753 public void onAnimationCancel(Animator animation) {
754 mCancelled = true;
755 }
756
757 @Override
758 public void onAnimationEnd(Animator animation) {
759 if (mCancelled) {
760 mHeightAnimator = null;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200761 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +0200762 } else {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200763 startUnlockHintAnimationPhase2(onAnimationFinished);
Jorim Jaggi90129582014-06-02 14:44:49 +0200764 }
765 }
766 });
767 animator.start();
768 mHeightAnimator = animator;
Selim Cinekf99d0002014-06-13 07:36:01 +0200769 mOriginalIndicationY = mKeyguardBottomArea.getIndicationView().getY();
770 mKeyguardBottomArea.getIndicationView().animate()
771 .y(mOriginalIndicationY - mHintDistance)
772 .setDuration(250)
Jorim Jaggib472b3472014-06-30 19:56:24 +0200773 .setInterpolator(mFastOutSlowInInterpolator)
Selim Cinekf99d0002014-06-13 07:36:01 +0200774 .withEndAction(new Runnable() {
775 @Override
776 public void run() {
777 mKeyguardBottomArea.getIndicationView().animate()
778 .y(mOriginalIndicationY)
779 .setDuration(450)
780 .setInterpolator(mBounceInterpolator)
781 .start();
782 }
783 })
784 .start();
Jorim Jaggi90129582014-06-02 14:44:49 +0200785 }
786
787 /**
788 * Phase 2: Bounce down.
789 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200790 private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) {
Jorim Jaggi90129582014-06-02 14:44:49 +0200791 ValueAnimator animator = createHeightAnimator(getMaxPanelHeight());
792 animator.setDuration(450);
793 animator.setInterpolator(mBounceInterpolator);
794 animator.addListener(new AnimatorListenerAdapter() {
795 @Override
796 public void onAnimationEnd(Animator animation) {
797 mHeightAnimator = null;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200798 onAnimationFinished.run();
Jorim Jaggi90129582014-06-02 14:44:49 +0200799 }
800 });
801 animator.start();
802 mHeightAnimator = animator;
803 }
804
805 private ValueAnimator createHeightAnimator(float targetHeight) {
806 ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
807 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
808 @Override
809 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200810 setExpandedHeightInternal((Float) animation.getAnimatedValue());
Jorim Jaggi90129582014-06-02 14:44:49 +0200811 }
812 });
813 return animator;
814 }
815
Jorim Jaggib472b3472014-06-30 19:56:24 +0200816 private void notifyBarPanelExpansionChanged() {
817 mBar.panelExpansionChanged(this, mExpandedFraction, mExpandedFraction > 0f || mPeekPending
818 || mPeekAnimator != null);
819 }
820
Jorim Jaggi90129582014-06-02 14:44:49 +0200821 /**
822 * Gets called when the user performs a click anywhere in the empty area of the panel.
823 *
824 * @return whether the panel will be expanded after the action performed by this method
825 */
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200826 private boolean onEmptySpaceClick(float x) {
827 if (mHintAnimationRunning) {
828 return true;
829 }
Jorim Jaggi6539a832014-06-03 23:33:09 +0200830 if (x < mEdgeTapAreaWidth
831 && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200832 onEdgeClicked(false /* right */);
833 return true;
Jorim Jaggi6539a832014-06-03 23:33:09 +0200834 } else if (x > getWidth() - mEdgeTapAreaWidth
835 && mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200836 onEdgeClicked(true /* right */);
837 return true;
838 } else {
839 return onMiddleClicked();
840 }
841 }
842
843 private boolean onMiddleClicked() {
Jorim Jaggi90129582014-06-02 14:44:49 +0200844 switch (mStatusBar.getBarState()) {
845 case StatusBarState.KEYGUARD:
846 startUnlockHintAnimation();
847 return true;
848 case StatusBarState.SHADE_LOCKED:
Jorim Jaggi6539a832014-06-03 23:33:09 +0200849 mStatusBar.goToKeyguard();
Jorim Jaggi90129582014-06-02 14:44:49 +0200850 return true;
851 case StatusBarState.SHADE:
852 collapse();
853 return false;
854 default:
855 return true;
856 }
857 }
858
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200859 protected abstract void onEdgeClicked(boolean right);
860
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500861 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Selim Cineka3e5bcb2014-04-07 20:07:22 +0200862 pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
John Spurlock50728832014-04-17 19:05:28 -0400863 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s"
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500864 + "]",
865 this.getClass().getSimpleName(),
866 getExpandedHeight(),
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100867 getMaxPanelHeight(),
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500868 mClosing?"T":"f",
869 mTracking?"T":"f",
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500870 mJustPeeked?"T":"f",
871 mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""),
Jorim Jaggi1d480692014-05-20 19:41:58 +0200872 mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":"")
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500873 ));
874 }
Selim Cinek3c4635c2014-05-29 02:12:47 +0200875
876 public abstract void resetViews();
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200877
878 protected abstract float getPeekHeight();
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200879
880 protected abstract float getCannedFlingDurationFactor();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400881}