Daniel Sandler | 50a5313 | 2012-10-24 15:02:27 -0400 | [diff] [blame] | 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 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 25 | import android.content.res.Resources; |
| 26 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 27 | import android.util.Log; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 28 | import android.view.MotionEvent; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 29 | import android.view.ViewConfiguration; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 30 | import android.view.animation.AnimationUtils; |
| 31 | import android.view.animation.Interpolator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 32 | import android.widget.FrameLayout; |
| 33 | |
| 34 | import com.android.systemui.R; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 35 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 36 | import com.android.systemui.statusbar.StatusBarState; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 37 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 38 | import java.io.FileDescriptor; |
| 39 | import java.io.PrintWriter; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 40 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 41 | public abstract class PanelView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 42 | public static final boolean DEBUG = PanelBar.DEBUG; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 43 | public static final String TAG = PanelView.class.getSimpleName(); |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 44 | protected float mOverExpansion; |
Daniel Sandler | e7c5bbb | 2013-03-05 13:36:21 -0500 | [diff] [blame] | 45 | |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 46 | private final void logf(String fmt, Object... args) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 47 | Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args)); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 50 | protected PhoneStatusBar mStatusBar; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 51 | private float mPeekHeight; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 52 | private float mHintDistance; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 53 | private float mInitialOffsetOnTouch; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 54 | private float mExpandedFraction = 0; |
| 55 | private float mExpandedHeight = 0; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 56 | private boolean mJustPeeked; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 57 | private boolean mClosing; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 58 | private boolean mTracking; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 59 | private boolean mTouchSlopExceeded; |
John Spurlock | 48fa91a | 2013-08-15 09:29:31 -0400 | [diff] [blame] | 60 | private int mTrackingPointer; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 61 | protected int mTouchSlop; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 62 | |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 63 | private ValueAnimator mHeightAnimator; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 64 | private ObjectAnimator mPeekAnimator; |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 65 | private VelocityTrackerInterface mVelocityTracker; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 66 | private FlingAnimationUtils mFlingAnimationUtils; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 67 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 68 | PanelBar mBar; |
| 69 | |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 70 | protected int mMaxPanelHeight = -1; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 71 | private String mViewName; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 72 | private float mInitialTouchY; |
| 73 | private float mInitialTouchX; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 74 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 75 | private Interpolator mLinearOutSlowInInterpolator; |
| 76 | private Interpolator mBounceInterpolator; |
| 77 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 78 | protected void onExpandingFinished() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 79 | mBar.onExpandingFinished(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | protected void onExpandingStarted() { |
| 83 | } |
| 84 | |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 85 | private void runPeekAnimation() { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 86 | if (DEBUG) logf("peek to height=%.1f", mPeekHeight); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 87 | if (mHeightAnimator != null) { |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 88 | return; |
| 89 | } |
| 90 | if (mPeekAnimator == null) { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 91 | mPeekAnimator = ObjectAnimator.ofFloat(this, |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 92 | "expandedHeight", mPeekHeight) |
Daniel Sandler | 3679bf5 | 2012-10-16 21:30:28 -0400 | [diff] [blame] | 93 | .setDuration(250); |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 94 | } |
| 95 | mPeekAnimator.start(); |
| 96 | } |
| 97 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 98 | public PanelView(Context context, AttributeSet attrs) { |
| 99 | super(context, attrs); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 100 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 101 | mLinearOutSlowInInterpolator = |
| 102 | AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in); |
| 103 | mBounceInterpolator = new BounceInterpolator(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 106 | protected void loadDimens() { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 107 | final Resources res = getContext().getResources(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 108 | mPeekHeight = res.getDimension(R.dimen.peek_height) |
John Spurlock | 5072883 | 2014-04-17 19:05:28 -0400 | [diff] [blame] | 109 | + getPaddingBottom(); // our window might have a dropshadow |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 110 | |
| 111 | final ViewConfiguration configuration = ViewConfiguration.get(getContext()); |
| 112 | mTouchSlop = configuration.getScaledTouchSlop(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 113 | mHintDistance = res.getDimension(R.dimen.hint_move_distance); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | private void trackMovement(MotionEvent event) { |
| 117 | // Add movement to velocity tracker using raw screen X and Y coordinates instead |
| 118 | // of window coordinates because the window frame may be moving at the same time. |
| 119 | float deltaX = event.getRawX() - event.getX(); |
| 120 | float deltaY = event.getRawY() - event.getY(); |
| 121 | event.offsetLocation(deltaX, deltaY); |
Daniel Sandler | b17a726 | 2012-10-05 14:32:50 -0400 | [diff] [blame] | 122 | if (mVelocityTracker != null) mVelocityTracker.addMovement(event); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 123 | event.offsetLocation(-deltaX, -deltaY); |
| 124 | } |
| 125 | |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 126 | @Override |
| 127 | public boolean onTouchEvent(MotionEvent event) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * We capture touch events here and update the expand height here in case according to |
| 131 | * the users fingers. This also handles multi-touch. |
| 132 | * |
| 133 | * If the user just clicks shortly, we give him a quick peek of the shade. |
| 134 | * |
| 135 | * Flinging is also enabled in order to open or close the shade. |
| 136 | */ |
| 137 | |
| 138 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 139 | if (pointerIndex < 0) { |
| 140 | pointerIndex = 0; |
| 141 | mTrackingPointer = event.getPointerId(pointerIndex); |
| 142 | } |
| 143 | final float y = event.getY(pointerIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 144 | final float x = event.getX(pointerIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 145 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 146 | boolean waitForTouchSlop = hasConflictingGestures(); |
| 147 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 148 | switch (event.getActionMasked()) { |
| 149 | case MotionEvent.ACTION_DOWN: |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 150 | |
| 151 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 152 | mInitialTouchX = x; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 153 | mInitialOffsetOnTouch = mExpandedHeight; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 154 | mTouchSlopExceeded = false; |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 155 | if (mVelocityTracker == null) { |
| 156 | initVelocityTracker(); |
| 157 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 158 | trackMovement(event); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 159 | if (!waitForTouchSlop || mHeightAnimator != null) { |
| 160 | if (mHeightAnimator != null) { |
| 161 | mHeightAnimator.cancel(); // end any outstanding animations |
| 162 | } |
| 163 | onTrackingStarted(); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 164 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 165 | if (mExpandedHeight == 0) { |
| 166 | mJustPeeked = true; |
| 167 | runPeekAnimation(); |
| 168 | } |
| 169 | break; |
| 170 | |
| 171 | case MotionEvent.ACTION_POINTER_UP: |
| 172 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 173 | if (mTrackingPointer == upPointer) { |
| 174 | // gesture is ongoing, find a new pointer to track |
| 175 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 176 | final float newY = event.getY(newIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 177 | final float newX = event.getX(newIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 178 | mTrackingPointer = event.getPointerId(newIndex); |
| 179 | mInitialOffsetOnTouch = mExpandedHeight; |
| 180 | mInitialTouchY = newY; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 181 | mInitialTouchX = newX; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 182 | } |
| 183 | break; |
| 184 | |
| 185 | case MotionEvent.ACTION_MOVE: |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 186 | float h = y - mInitialTouchY; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 187 | if (Math.abs(h) > mTouchSlop && Math.abs(h) > Math.abs(x - mInitialTouchX)) { |
| 188 | mTouchSlopExceeded = true; |
| 189 | if (waitForTouchSlop && !mTracking) { |
| 190 | mInitialOffsetOnTouch = mExpandedHeight; |
| 191 | mInitialTouchX = x; |
| 192 | mInitialTouchY = y; |
| 193 | if (mHeightAnimator != null) { |
| 194 | mHeightAnimator.cancel(); // end any outstanding animations |
| 195 | } |
| 196 | onTrackingStarted(); |
| 197 | h = 0; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 198 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 199 | } |
| 200 | final float newHeight = h + mInitialOffsetOnTouch; |
| 201 | if (newHeight > mPeekHeight) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 202 | if (mPeekAnimator != null && mPeekAnimator.isStarted()) { |
| 203 | mPeekAnimator.cancel(); |
| 204 | } |
| 205 | mJustPeeked = false; |
| 206 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 207 | if (!mJustPeeked && (!waitForTouchSlop || mTracking)) { |
| 208 | setExpandedHeightInternal(newHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 209 | mBar.panelExpansionChanged(PanelView.this, mExpandedFraction); |
| 210 | } |
| 211 | |
| 212 | trackMovement(event); |
| 213 | break; |
| 214 | |
| 215 | case MotionEvent.ACTION_UP: |
| 216 | case MotionEvent.ACTION_CANCEL: |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 217 | mTrackingPointer = -1; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 218 | trackMovement(event); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 219 | if (mTracking && mTouchSlopExceeded) { |
| 220 | float vel = getCurrentVelocity(); |
| 221 | boolean expand = flingExpands(vel); |
| 222 | onTrackingStopped(expand); |
| 223 | fling(vel, expand); |
| 224 | } else { |
| 225 | boolean expands = onEmptySpaceClick(); |
| 226 | onTrackingStopped(expands); |
| 227 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 228 | if (mVelocityTracker != null) { |
| 229 | mVelocityTracker.recycle(); |
| 230 | mVelocityTracker = null; |
| 231 | } |
| 232 | break; |
| 233 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 234 | return !waitForTouchSlop || mTracking; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 237 | protected abstract boolean hasConflictingGestures(); |
| 238 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 239 | protected void onTrackingStopped(boolean expand) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 240 | mTracking = false; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 241 | mBar.onTrackingStopped(PanelView.this, expand); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | protected void onTrackingStarted() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 245 | mTracking = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 246 | mBar.onTrackingStarted(PanelView.this); |
| 247 | onExpandingStarted(); |
| 248 | } |
| 249 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 250 | private float getCurrentVelocity() { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 251 | |
| 252 | // the velocitytracker might be null if we got a bad input stream |
| 253 | if (mVelocityTracker == null) { |
| 254 | return 0; |
| 255 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 256 | mVelocityTracker.computeCurrentVelocity(1000); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 257 | return mVelocityTracker.getYVelocity(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 262 | |
| 263 | /* |
| 264 | * If the user drags anywhere inside the panel we intercept it if he moves his finger |
| 265 | * upwards. This allows closing the shade from anywhere inside the panel. |
| 266 | * |
| 267 | * We only do this if the current content is scrolled to the bottom, |
| 268 | * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture |
| 269 | * possible. |
| 270 | */ |
| 271 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 272 | if (pointerIndex < 0) { |
| 273 | pointerIndex = 0; |
| 274 | mTrackingPointer = event.getPointerId(pointerIndex); |
| 275 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 276 | final float x = event.getX(pointerIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 277 | final float y = event.getY(pointerIndex); |
| 278 | boolean scrolledToBottom = isScrolledToBottom(); |
| 279 | |
| 280 | switch (event.getActionMasked()) { |
| 281 | case MotionEvent.ACTION_DOWN: |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 282 | if (mHeightAnimator != null) { |
| 283 | mHeightAnimator.cancel(); // end any outstanding animations |
Selim Cinek | 172e914 | 2014-05-07 19:38:00 +0200 | [diff] [blame] | 284 | return true; |
| 285 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 286 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 287 | mInitialTouchX = x; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 288 | mTouchSlopExceeded = false; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 289 | initVelocityTracker(); |
| 290 | trackMovement(event); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 291 | break; |
| 292 | case MotionEvent.ACTION_POINTER_UP: |
| 293 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 294 | if (mTrackingPointer == upPointer) { |
| 295 | // gesture is ongoing, find a new pointer to track |
| 296 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 297 | mTrackingPointer = event.getPointerId(newIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 298 | mInitialTouchX = event.getX(newIndex); |
| 299 | mInitialTouchY = event.getY(newIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 300 | } |
| 301 | break; |
| 302 | |
| 303 | case MotionEvent.ACTION_MOVE: |
| 304 | final float h = y - mInitialTouchY; |
| 305 | trackMovement(event); |
| 306 | if (scrolledToBottom) { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 307 | if (h < -mTouchSlop && h < -Math.abs(x - mInitialTouchX)) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 308 | mInitialOffsetOnTouch = mExpandedHeight; |
| 309 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 310 | mInitialTouchX = x; |
Selim Cinek | 91c39ef | 2014-04-07 21:18:09 +0200 | [diff] [blame] | 311 | mTracking = true; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 312 | mTouchSlopExceeded = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 313 | onTrackingStarted(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | break; |
| 318 | } |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | private void initVelocityTracker() { |
| 323 | if (mVelocityTracker != null) { |
| 324 | mVelocityTracker.recycle(); |
| 325 | } |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 326 | mVelocityTracker = VelocityTrackerFactory.obtain(getContext()); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | protected boolean isScrolledToBottom() { |
Selim Cinek | 172e914 | 2014-05-07 19:38:00 +0200 | [diff] [blame] | 330 | return true; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | protected float getContentHeight() { |
| 334 | return mExpandedHeight; |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 337 | @Override |
| 338 | protected void onFinishInflate() { |
| 339 | super.onFinishInflate(); |
| 340 | loadDimens(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 343 | @Override |
| 344 | protected void onConfigurationChanged(Configuration newConfig) { |
| 345 | super.onConfigurationChanged(newConfig); |
| 346 | loadDimens(); |
| 347 | mMaxPanelHeight = -1; |
| 348 | } |
| 349 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 350 | /** |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 351 | * @param vel the current velocity of the motion |
| 352 | * @return whether a fling should expands the panel; contracts otherwise |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 353 | */ |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 354 | private boolean flingExpands(float vel) { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 355 | if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 356 | return getExpandedFraction() > 0.5f; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 357 | } else { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 358 | return vel > 0; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 359 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | protected void fling(float vel, boolean expand) { |
| 363 | cancelPeek(); |
| 364 | float target = expand ? getMaxPanelHeight() : 0.0f; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 365 | if (target == mExpandedHeight) { |
| 366 | onExpandingFinished(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 367 | mBar.panelExpansionChanged(this, mExpandedFraction); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 368 | return; |
| 369 | } |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 370 | ValueAnimator animator = createHeightAnimator(target); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 371 | if (expand) { |
| 372 | mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight()); |
| 373 | } else { |
| 374 | mFlingAnimationUtils.applyDismissing(animator, mExpandedHeight, target, vel, |
| 375 | getHeight()); |
| 376 | |
| 377 | // Make it shorter if we run a canned animation |
| 378 | if (vel == 0) { |
| 379 | animator.setDuration((long) (animator.getDuration() / 1.75f)); |
| 380 | } |
| 381 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 382 | animator.addListener(new AnimatorListenerAdapter() { |
| 383 | @Override |
| 384 | public void onAnimationEnd(Animator animation) { |
| 385 | mHeightAnimator = null; |
| 386 | onExpandingFinished(); |
| 387 | } |
| 388 | }); |
| 389 | animator.start(); |
| 390 | mHeightAnimator = animator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Override |
| 394 | protected void onAttachedToWindow() { |
| 395 | super.onAttachedToWindow(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 396 | mViewName = getResources().getResourceName(getId()); |
| 397 | } |
| 398 | |
| 399 | public String getName() { |
| 400 | return mViewName; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 403 | @Override |
| 404 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 405 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 406 | |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 407 | if (DEBUG) logf("onMeasure(%d, %d) -> (%d, %d)", |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 408 | widthMeasureSpec, heightMeasureSpec, getMeasuredWidth(), getMeasuredHeight()); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 409 | |
| 410 | // Did one of our children change size? |
| 411 | int newHeight = getMeasuredHeight(); |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 412 | if (newHeight > mMaxPanelHeight) { |
| 413 | // we only adapt the max height if it's bigger |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 414 | mMaxPanelHeight = newHeight; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 415 | // If the user isn't actively poking us, let's rubberband to the content |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 416 | if (!mTracking && mHeightAnimator == null |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 417 | && mExpandedHeight > 0 && mExpandedHeight != mMaxPanelHeight |
| 418 | && mMaxPanelHeight > 0) { |
| 419 | mExpandedHeight = mMaxPanelHeight; |
| 420 | } |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 421 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 422 | } |
| 423 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 424 | public void setExpandedHeight(float height) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 425 | if (DEBUG) logf("setExpandedHeight(%.1f)", height); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 426 | setExpandedHeightInternal(height); |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 427 | mBar.panelExpansionChanged(PanelView.this, mExpandedFraction); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 430 | @Override |
| 431 | protected void onLayout (boolean changed, int left, int top, int right, int bottom) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 432 | if (DEBUG) logf("onLayout: changed=%s, bottom=%d eh=%d fh=%d", changed?"T":"f", bottom, |
| 433 | (int)mExpandedHeight, mMaxPanelHeight); |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 434 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 435 | requestPanelHeightUpdate(); |
| 436 | } |
| 437 | |
| 438 | protected void requestPanelHeightUpdate() { |
| 439 | float currentMaxPanelHeight = getMaxPanelHeight(); |
| 440 | |
| 441 | // If the user isn't actively poking us, let's update the height |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 442 | if (!mTracking && mHeightAnimator == null |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 443 | && mExpandedHeight > 0 && currentMaxPanelHeight != mExpandedHeight) { |
| 444 | setExpandedHeightInternal(currentMaxPanelHeight); |
| 445 | } |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 446 | } |
| 447 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 448 | public void setExpandedHeightInternal(float h) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 449 | float fh = getMaxPanelHeight(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 450 | mExpandedHeight = Math.max(0, Math.min(fh, h)); |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 451 | float overExpansion = h - fh; |
| 452 | overExpansion = Math.max(0, overExpansion); |
| 453 | if (overExpansion != mOverExpansion) { |
| 454 | onOverExpansionChanged(overExpansion); |
| 455 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 456 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 457 | if (DEBUG) { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 458 | logf("setExpansion: height=%.1f fh=%.1f tracking=%s", h, fh, mTracking ? "T" : "f"); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 459 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 460 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 461 | onHeightUpdated(mExpandedHeight); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 462 | mExpandedFraction = Math.min(1f, (fh == 0) ? 0 : mExpandedHeight / fh); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 465 | protected void onOverExpansionChanged(float overExpansion) { |
| 466 | mOverExpansion = overExpansion; |
| 467 | } |
| 468 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 469 | protected abstract void onHeightUpdated(float expandedHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * This returns the maximum height of the panel. Children should override this if their |
| 473 | * desired height is not the full height. |
| 474 | * |
| 475 | * @return the default implementation simply returns the maximum height. |
| 476 | */ |
| 477 | protected int getMaxPanelHeight() { |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 478 | mMaxPanelHeight = Math.max(mMaxPanelHeight, getHeight()); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 479 | return mMaxPanelHeight; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | public void setExpandedFraction(float frac) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 483 | setExpandedHeight(getMaxPanelHeight() * frac); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | public float getExpandedHeight() { |
| 487 | return mExpandedHeight; |
| 488 | } |
| 489 | |
| 490 | public float getExpandedFraction() { |
| 491 | return mExpandedFraction; |
| 492 | } |
| 493 | |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 494 | public boolean isFullyExpanded() { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 495 | return mExpandedHeight >= getMaxPanelHeight(); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | public boolean isFullyCollapsed() { |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 499 | return mExpandedHeight <= 0; |
| 500 | } |
| 501 | |
| 502 | public boolean isCollapsing() { |
| 503 | return mClosing; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 504 | } |
| 505 | |
John Spurlock | a4b70af | 2013-08-17 14:05:49 -0400 | [diff] [blame] | 506 | public boolean isTracking() { |
| 507 | return mTracking; |
| 508 | } |
| 509 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 510 | public void setBar(PanelBar panelBar) { |
| 511 | mBar = panelBar; |
| 512 | } |
| 513 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 514 | public void collapse() { |
| 515 | // TODO: abort animation or ongoing touch |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 516 | if (DEBUG) logf("collapse: " + this); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 517 | if (!isFullyCollapsed()) { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 518 | if (mHeightAnimator != null) { |
| 519 | mHeightAnimator.cancel(); |
| 520 | } |
Daniel Sandler | 750bb9b | 2012-10-03 16:24:00 -0400 | [diff] [blame] | 521 | mClosing = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 522 | onExpandingStarted(); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 523 | fling(0, false /* expand */); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
| 527 | public void expand() { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 528 | if (DEBUG) logf("expand: " + this); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 529 | if (isFullyCollapsed()) { |
| 530 | mBar.startOpeningPanel(this); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 531 | onExpandingStarted(); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 532 | fling(0, true /* expand */); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 533 | } else if (DEBUG) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 534 | if (DEBUG) logf("skipping expansion: is expanded"); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | public void cancelPeek() { |
| 539 | if (mPeekAnimator != null && mPeekAnimator.isStarted()) { |
| 540 | mPeekAnimator.cancel(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 541 | } |
| 542 | } |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 543 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame^] | 544 | protected void startUnlockHintAnimation() { |
| 545 | |
| 546 | // We don't need to hint the user if an animation is already running or the user is changing |
| 547 | // the expansion. |
| 548 | if (mHeightAnimator != null || mTracking) { |
| 549 | return; |
| 550 | } |
| 551 | cancelPeek(); |
| 552 | onExpandingStarted(); |
| 553 | startUnlockHintAnimationPhase1(); |
| 554 | mStatusBar.onUnlockHintStarted(); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Phase 1: Move everything upwards. |
| 559 | */ |
| 560 | private void startUnlockHintAnimationPhase1() { |
| 561 | float target = Math.max(0, getMaxPanelHeight() - mHintDistance); |
| 562 | ValueAnimator animator = createHeightAnimator(target); |
| 563 | animator.setDuration(250); |
| 564 | animator.setInterpolator(mLinearOutSlowInInterpolator); |
| 565 | animator.addListener(new AnimatorListenerAdapter() { |
| 566 | private boolean mCancelled; |
| 567 | |
| 568 | @Override |
| 569 | public void onAnimationCancel(Animator animation) { |
| 570 | mCancelled = true; |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void onAnimationEnd(Animator animation) { |
| 575 | if (mCancelled) { |
| 576 | mHeightAnimator = null; |
| 577 | onExpandingFinished(); |
| 578 | mStatusBar.onUnlockHintFinished(); |
| 579 | } else { |
| 580 | startUnlockHintAnimationPhase2(); |
| 581 | } |
| 582 | } |
| 583 | }); |
| 584 | animator.start(); |
| 585 | mHeightAnimator = animator; |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Phase 2: Bounce down. |
| 590 | */ |
| 591 | private void startUnlockHintAnimationPhase2() { |
| 592 | ValueAnimator animator = createHeightAnimator(getMaxPanelHeight()); |
| 593 | animator.setDuration(450); |
| 594 | animator.setInterpolator(mBounceInterpolator); |
| 595 | animator.addListener(new AnimatorListenerAdapter() { |
| 596 | @Override |
| 597 | public void onAnimationEnd(Animator animation) { |
| 598 | mHeightAnimator = null; |
| 599 | onExpandingFinished(); |
| 600 | mStatusBar.onUnlockHintFinished(); |
| 601 | } |
| 602 | }); |
| 603 | animator.start(); |
| 604 | mHeightAnimator = animator; |
| 605 | } |
| 606 | |
| 607 | private ValueAnimator createHeightAnimator(float targetHeight) { |
| 608 | ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight); |
| 609 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 610 | @Override |
| 611 | public void onAnimationUpdate(ValueAnimator animation) { |
| 612 | setExpandedHeight((Float) animation.getAnimatedValue()); |
| 613 | } |
| 614 | }); |
| 615 | return animator; |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * Gets called when the user performs a click anywhere in the empty area of the panel. |
| 620 | * |
| 621 | * @return whether the panel will be expanded after the action performed by this method |
| 622 | */ |
| 623 | private boolean onEmptySpaceClick() { |
| 624 | switch (mStatusBar.getBarState()) { |
| 625 | case StatusBarState.KEYGUARD: |
| 626 | startUnlockHintAnimation(); |
| 627 | return true; |
| 628 | case StatusBarState.SHADE_LOCKED: |
| 629 | // TODO: Go to Keyguard again. |
| 630 | return true; |
| 631 | case StatusBarState.SHADE: |
| 632 | collapse(); |
| 633 | return false; |
| 634 | default: |
| 635 | return true; |
| 636 | } |
| 637 | } |
| 638 | |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 639 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Selim Cinek | a3e5bcb | 2014-04-07 20:07:22 +0200 | [diff] [blame] | 640 | pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s" |
John Spurlock | 5072883 | 2014-04-17 19:05:28 -0400 | [diff] [blame] | 641 | + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s" |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 642 | + "]", |
| 643 | this.getClass().getSimpleName(), |
| 644 | getExpandedHeight(), |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 645 | getMaxPanelHeight(), |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 646 | mClosing?"T":"f", |
| 647 | mTracking?"T":"f", |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 648 | mJustPeeked?"T":"f", |
| 649 | mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""), |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 650 | mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":"") |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 651 | )); |
| 652 | } |
Selim Cinek | 3c4635c | 2014-05-29 02:12:47 +0200 | [diff] [blame] | 653 | |
| 654 | public abstract void resetViews(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 655 | } |