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 | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 30 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 31 | import android.view.animation.AnimationUtils; |
| 32 | import android.view.animation.Interpolator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
| 34 | |
| 35 | import com.android.systemui.R; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 36 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 37 | import com.android.systemui.statusbar.StatusBarState; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 38 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 39 | import java.io.FileDescriptor; |
| 40 | import java.io.PrintWriter; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 41 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 42 | public abstract class PanelView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 43 | public static final boolean DEBUG = PanelBar.DEBUG; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 44 | public static final String TAG = PanelView.class.getSimpleName(); |
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; |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 53 | private int mEdgeTapAreaWidth; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 54 | private float mInitialOffsetOnTouch; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 55 | private float mExpandedFraction = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 56 | protected float mExpandedHeight = 0; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 57 | private boolean mJustPeeked; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 58 | private boolean mClosing; |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 59 | protected boolean mTracking; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 60 | private boolean mTouchSlopExceeded; |
John Spurlock | 48fa91a | 2013-08-15 09:29:31 -0400 | [diff] [blame] | 61 | private int mTrackingPointer; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 62 | protected int mTouchSlop; |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 63 | protected boolean mHintAnimationRunning; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 64 | private boolean mOverExpandedBeforeFling; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 65 | private float mOriginalIndicationY; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 66 | |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 67 | private ValueAnimator mHeightAnimator; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 68 | private ObjectAnimator mPeekAnimator; |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 69 | private VelocityTrackerInterface mVelocityTracker; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 70 | private FlingAnimationUtils mFlingAnimationUtils; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 71 | |
Jorim Jaggi | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 72 | /** |
| 73 | * Whether an instant expand request is currently pending and we are just waiting for layout. |
| 74 | */ |
| 75 | private boolean mInstantExpanding; |
| 76 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 77 | PanelBar mBar; |
| 78 | |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 79 | protected int mMaxPanelHeight = -1; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 80 | private String mViewName; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 81 | private float mInitialTouchY; |
| 82 | private float mInitialTouchX; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 83 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 84 | private Interpolator mLinearOutSlowInInterpolator; |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 85 | private Interpolator mFastOutSlowInInterpolator; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 86 | private Interpolator mBounceInterpolator; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 87 | protected KeyguardBottomAreaView mKeyguardBottomArea; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 88 | |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 89 | 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 Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 101 | protected void onExpandingFinished() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame^] | 102 | mClosing = false; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 103 | mBar.onExpandingFinished(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | protected void onExpandingStarted() { |
| 107 | } |
| 108 | |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 109 | private void notifyExpandingStarted() { |
| 110 | if (!mExpanding) { |
| 111 | mExpanding = true; |
| 112 | onExpandingStarted(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private void notifyExpandingFinished() { |
| 117 | if (mExpanding) { |
| 118 | mExpanding = false; |
| 119 | onExpandingFinished(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | private void schedulePeek() { |
| 124 | mPeekPending = true; |
| 125 | long timeout = ViewConfiguration.getTapTimeout(); |
| 126 | postOnAnimationDelayed(mPeekRunnable, timeout); |
| 127 | notifyBarPanelExpansionChanged(); |
| 128 | } |
| 129 | |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 130 | private void runPeekAnimation() { |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 131 | mPeekHeight = getPeekHeight(); |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 132 | if (DEBUG) logf("peek to height=%.1f", mPeekHeight); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 133 | if (mHeightAnimator != null) { |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 134 | return; |
| 135 | } |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 136 | mPeekAnimator = ObjectAnimator.ofFloat(this, "expandedHeight", mPeekHeight) |
| 137 | .setDuration(250); |
| 138 | mPeekAnimator.setInterpolator(mLinearOutSlowInInterpolator); |
| 139 | mPeekAnimator.addListener(new AnimatorListenerAdapter() { |
| 140 | private boolean mCancelled; |
| 141 | |
| 142 | @Override |
| 143 | public void onAnimationCancel(Animator animation) { |
| 144 | mCancelled = true; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void onAnimationEnd(Animator animation) { |
| 149 | mPeekAnimator = null; |
| 150 | if (mCollapseAfterPeek && !mCancelled) { |
| 151 | postOnAnimation(new Runnable() { |
| 152 | @Override |
| 153 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame^] | 154 | collapse(false /* delayed */); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 155 | } |
| 156 | }); |
| 157 | } |
| 158 | mCollapseAfterPeek = false; |
| 159 | } |
| 160 | }); |
| 161 | notifyExpandingStarted(); |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 162 | mPeekAnimator.start(); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 163 | mJustPeeked = true; |
Daniel Sandler | 0c1b75c | 2012-10-04 12:08:54 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 166 | public PanelView(Context context, AttributeSet attrs) { |
| 167 | super(context, attrs); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 168 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.6f); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 169 | mFastOutSlowInInterpolator = |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 170 | AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 171 | mLinearOutSlowInInterpolator = |
| 172 | AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 173 | mBounceInterpolator = new BounceInterpolator(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 174 | } |
| 175 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 176 | protected void loadDimens() { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 177 | final Resources res = getContext().getResources(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 178 | final ViewConfiguration configuration = ViewConfiguration.get(getContext()); |
| 179 | mTouchSlop = configuration.getScaledTouchSlop(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 180 | mHintDistance = res.getDimension(R.dimen.hint_move_distance); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 181 | mEdgeTapAreaWidth = res.getDimensionPixelSize(R.dimen.edge_tap_area_width); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | private void trackMovement(MotionEvent event) { |
| 185 | // Add movement to velocity tracker using raw screen X and Y coordinates instead |
| 186 | // of window coordinates because the window frame may be moving at the same time. |
| 187 | float deltaX = event.getRawX() - event.getX(); |
| 188 | float deltaY = event.getRawY() - event.getY(); |
| 189 | event.offsetLocation(deltaX, deltaY); |
Daniel Sandler | b17a726 | 2012-10-05 14:32:50 -0400 | [diff] [blame] | 190 | if (mVelocityTracker != null) mVelocityTracker.addMovement(event); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 191 | event.offsetLocation(-deltaX, -deltaY); |
| 192 | } |
| 193 | |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 194 | @Override |
| 195 | public boolean onTouchEvent(MotionEvent event) { |
Jorim Jaggi | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 196 | if (mInstantExpanding) { |
| 197 | return false; |
| 198 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * We capture touch events here and update the expand height here in case according to |
| 202 | * the users fingers. This also handles multi-touch. |
| 203 | * |
| 204 | * If the user just clicks shortly, we give him a quick peek of the shade. |
| 205 | * |
| 206 | * Flinging is also enabled in order to open or close the shade. |
| 207 | */ |
| 208 | |
| 209 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 210 | if (pointerIndex < 0) { |
| 211 | pointerIndex = 0; |
| 212 | mTrackingPointer = event.getPointerId(pointerIndex); |
| 213 | } |
| 214 | final float y = event.getY(pointerIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 215 | final float x = event.getX(pointerIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 216 | |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 217 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 218 | mGestureWaitForTouchSlop = mExpandedHeight == 0f; |
| 219 | } |
| 220 | boolean waitForTouchSlop = hasConflictingGestures() || mGestureWaitForTouchSlop; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 221 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 222 | switch (event.getActionMasked()) { |
| 223 | case MotionEvent.ACTION_DOWN: |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 224 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 225 | mInitialTouchX = x; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 226 | mInitialOffsetOnTouch = mExpandedHeight; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 227 | mTouchSlopExceeded = false; |
Jorim Jaggi | 3857ac4 | 2014-06-27 18:01:12 +0200 | [diff] [blame] | 228 | mJustPeeked = false; |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 229 | if (mVelocityTracker == null) { |
| 230 | initVelocityTracker(); |
| 231 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 232 | trackMovement(event); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 233 | if (!waitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning) || |
| 234 | mPeekPending || mPeekAnimator != null) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 235 | if (mHeightAnimator != null) { |
| 236 | mHeightAnimator.cancel(); // end any outstanding animations |
| 237 | } |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 238 | cancelPeek(); |
| 239 | mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning) |
| 240 | || mPeekPending || mPeekAnimator != null; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 241 | onTrackingStarted(); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 242 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 243 | if (mExpandedHeight == 0) { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 244 | schedulePeek(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 245 | } |
| 246 | break; |
| 247 | |
| 248 | case MotionEvent.ACTION_POINTER_UP: |
| 249 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 250 | if (mTrackingPointer == upPointer) { |
| 251 | // gesture is ongoing, find a new pointer to track |
| 252 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 253 | final float newY = event.getY(newIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 254 | final float newX = event.getX(newIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 255 | mTrackingPointer = event.getPointerId(newIndex); |
| 256 | mInitialOffsetOnTouch = mExpandedHeight; |
| 257 | mInitialTouchY = newY; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 258 | mInitialTouchX = newX; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 259 | } |
| 260 | break; |
| 261 | |
| 262 | case MotionEvent.ACTION_MOVE: |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 263 | float h = y - mInitialTouchY; |
Jorim Jaggi | b724013 | 2014-06-30 01:39:07 +0200 | [diff] [blame] | 264 | |
| 265 | // If the panel was collapsed when touching, we only need to check for the |
| 266 | // y-component of the gesture, as we have no conflicting horizontal gesture. |
| 267 | if (Math.abs(h) > mTouchSlop |
| 268 | && (Math.abs(h) > Math.abs(x - mInitialTouchX) |
| 269 | || mInitialOffsetOnTouch == 0f)) { |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 270 | mTouchSlopExceeded = true; |
| 271 | if (waitForTouchSlop && !mTracking) { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 272 | if (!mJustPeeked) { |
| 273 | mInitialOffsetOnTouch = mExpandedHeight; |
| 274 | mInitialTouchX = x; |
| 275 | mInitialTouchY = y; |
| 276 | h = 0; |
| 277 | } |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 278 | if (mHeightAnimator != null) { |
| 279 | mHeightAnimator.cancel(); // end any outstanding animations |
| 280 | } |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 281 | removeCallbacks(mPeekRunnable); |
| 282 | mPeekPending = false; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 283 | onTrackingStarted(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 284 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 285 | } |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 286 | final float newHeight = Math.max(0, h + mInitialOffsetOnTouch); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 287 | if (newHeight > mPeekHeight) { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 288 | if (mPeekAnimator != null) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 289 | mPeekAnimator.cancel(); |
| 290 | } |
| 291 | mJustPeeked = false; |
| 292 | } |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 293 | if (!mJustPeeked && (!waitForTouchSlop || mTracking) && !isTrackingBlocked()) { |
Jorim Jaggi | cc69324 | 2014-06-14 03:04:35 +0000 | [diff] [blame] | 294 | setExpandedHeightInternal(newHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | trackMovement(event); |
| 298 | break; |
| 299 | |
| 300 | case MotionEvent.ACTION_UP: |
| 301 | case MotionEvent.ACTION_CANCEL: |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 302 | mTrackingPointer = -1; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 303 | trackMovement(event); |
Jorim Jaggi | 787a0af | 2014-06-04 18:57:14 +0200 | [diff] [blame] | 304 | if ((mTracking && mTouchSlopExceeded) |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 305 | || Math.abs(x - mInitialTouchX) > mTouchSlop |
| 306 | || Math.abs(y - mInitialTouchY) > mTouchSlop |
Jorim Jaggi | 787a0af | 2014-06-04 18:57:14 +0200 | [diff] [blame] | 307 | || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { |
Jorim Jaggi | b724013 | 2014-06-30 01:39:07 +0200 | [diff] [blame] | 308 | float vel = 0f; |
| 309 | float vectorVel = 0f; |
| 310 | if (mVelocityTracker != null) { |
| 311 | mVelocityTracker.computeCurrentVelocity(1000); |
| 312 | vel = mVelocityTracker.getYVelocity(); |
| 313 | vectorVel = (float) Math.hypot( |
| 314 | mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); |
| 315 | } |
| 316 | boolean expand = flingExpands(vel, vectorVel); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 317 | onTrackingStopped(expand); |
| 318 | fling(vel, expand); |
| 319 | } else { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 320 | boolean expands = onEmptySpaceClick(mInitialTouchX); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 321 | onTrackingStopped(expands); |
| 322 | } |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 323 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 324 | if (mVelocityTracker != null) { |
| 325 | mVelocityTracker.recycle(); |
| 326 | mVelocityTracker = null; |
| 327 | } |
| 328 | break; |
| 329 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 330 | return !waitForTouchSlop || mTracking; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 333 | protected abstract boolean hasConflictingGestures(); |
| 334 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 335 | protected void onTrackingStopped(boolean expand) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 336 | mTracking = false; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 337 | mBar.onTrackingStopped(PanelView.this, expand); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | protected void onTrackingStarted() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 341 | mTracking = true; |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 342 | mCollapseAfterPeek = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 343 | mBar.onTrackingStarted(PanelView.this); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 344 | notifyExpandingStarted(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 347 | @Override |
| 348 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Jorim Jaggi | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 349 | if (mInstantExpanding) { |
| 350 | return false; |
| 351 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * If the user drags anywhere inside the panel we intercept it if he moves his finger |
| 355 | * upwards. This allows closing the shade from anywhere inside the panel. |
| 356 | * |
| 357 | * We only do this if the current content is scrolled to the bottom, |
| 358 | * i.e isScrolledToBottom() is true and therefore there is no conflicting scrolling gesture |
| 359 | * possible. |
| 360 | */ |
| 361 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 362 | if (pointerIndex < 0) { |
| 363 | pointerIndex = 0; |
| 364 | mTrackingPointer = event.getPointerId(pointerIndex); |
| 365 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 366 | final float x = event.getX(pointerIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 367 | final float y = event.getY(pointerIndex); |
| 368 | boolean scrolledToBottom = isScrolledToBottom(); |
| 369 | |
| 370 | switch (event.getActionMasked()) { |
| 371 | case MotionEvent.ACTION_DOWN: |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 372 | mStatusBar.userActivity(); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 373 | if (mHeightAnimator != null && !mHintAnimationRunning || |
| 374 | mPeekPending || mPeekAnimator != null) { |
| 375 | if (mHeightAnimator != null) { |
| 376 | mHeightAnimator.cancel(); // end any outstanding animations |
| 377 | } |
| 378 | cancelPeek(); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 379 | mTouchSlopExceeded = true; |
Selim Cinek | 172e914 | 2014-05-07 19:38:00 +0200 | [diff] [blame] | 380 | return true; |
| 381 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 382 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 383 | mInitialTouchX = x; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 384 | mTouchSlopExceeded = false; |
Jorim Jaggi | 3857ac4 | 2014-06-27 18:01:12 +0200 | [diff] [blame] | 385 | mJustPeeked = false; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 386 | initVelocityTracker(); |
| 387 | trackMovement(event); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 388 | break; |
| 389 | case MotionEvent.ACTION_POINTER_UP: |
| 390 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 391 | if (mTrackingPointer == upPointer) { |
| 392 | // gesture is ongoing, find a new pointer to track |
| 393 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 394 | mTrackingPointer = event.getPointerId(newIndex); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 395 | mInitialTouchX = event.getX(newIndex); |
| 396 | mInitialTouchY = event.getY(newIndex); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 397 | } |
| 398 | break; |
| 399 | |
| 400 | case MotionEvent.ACTION_MOVE: |
| 401 | final float h = y - mInitialTouchY; |
| 402 | trackMovement(event); |
| 403 | if (scrolledToBottom) { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 404 | if (h < -mTouchSlop && h < -Math.abs(x - mInitialTouchX)) { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 405 | if (mHeightAnimator != null) { |
| 406 | mHeightAnimator.cancel(); |
| 407 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 408 | mInitialOffsetOnTouch = mExpandedHeight; |
| 409 | mInitialTouchY = y; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 410 | mInitialTouchX = x; |
Selim Cinek | 91c39ef | 2014-04-07 21:18:09 +0200 | [diff] [blame] | 411 | mTracking = true; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 412 | mTouchSlopExceeded = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 413 | onTrackingStarted(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 414 | return true; |
| 415 | } |
| 416 | } |
| 417 | break; |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | private void initVelocityTracker() { |
| 423 | if (mVelocityTracker != null) { |
| 424 | mVelocityTracker.recycle(); |
| 425 | } |
Jorim Jaggi | b7b61dd | 2014-05-21 15:45:07 +0200 | [diff] [blame] | 426 | mVelocityTracker = VelocityTrackerFactory.obtain(getContext()); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | protected boolean isScrolledToBottom() { |
Selim Cinek | 172e914 | 2014-05-07 19:38:00 +0200 | [diff] [blame] | 430 | return true; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | protected float getContentHeight() { |
| 434 | return mExpandedHeight; |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 435 | } |
| 436 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 437 | @Override |
| 438 | protected void onFinishInflate() { |
| 439 | super.onFinishInflate(); |
| 440 | loadDimens(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 441 | } |
| 442 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 443 | @Override |
| 444 | protected void onConfigurationChanged(Configuration newConfig) { |
| 445 | super.onConfigurationChanged(newConfig); |
| 446 | loadDimens(); |
| 447 | mMaxPanelHeight = -1; |
| 448 | } |
| 449 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 450 | /** |
Jorim Jaggi | b724013 | 2014-06-30 01:39:07 +0200 | [diff] [blame] | 451 | * @param vel the current vertical velocity of the motion |
| 452 | * @param vectorVel the length of the vectorial velocity |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 453 | * @return whether a fling should expands the panel; contracts otherwise |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 454 | */ |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 455 | protected boolean flingExpands(float vel, float vectorVel) { |
Jorim Jaggi | b724013 | 2014-06-30 01:39:07 +0200 | [diff] [blame] | 456 | if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 457 | return getExpandedFraction() > 0.5f; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 458 | } else { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 459 | return vel > 0; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 460 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | protected void fling(float vel, boolean expand) { |
| 464 | cancelPeek(); |
| 465 | float target = expand ? getMaxPanelHeight() : 0.0f; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 466 | |
| 467 | // Hack to make the expand transition look nice when clear all button is visible - we make |
| 468 | // the animation only to the last notification, and then jump to the maximum panel height so |
| 469 | // clear all just fades in and the decelerating motion is towards the last notification. |
| 470 | final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible() |
| 471 | && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight() |
| 472 | && !isClearAllVisible(); |
| 473 | if (clearAllExpandHack) { |
| 474 | target = getMaxPanelHeight() - getClearAllHeight(); |
| 475 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 476 | if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 477 | notifyExpandingFinished(); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 478 | return; |
| 479 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 480 | mOverExpandedBeforeFling = getOverExpansionAmount() > 0f; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 481 | ValueAnimator animator = createHeightAnimator(target); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 482 | if (expand) { |
| 483 | mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight()); |
| 484 | } else { |
| 485 | mFlingAnimationUtils.applyDismissing(animator, mExpandedHeight, target, vel, |
| 486 | getHeight()); |
| 487 | |
| 488 | // Make it shorter if we run a canned animation |
| 489 | if (vel == 0) { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 490 | animator.setDuration((long) |
| 491 | (animator.getDuration() * getCannedFlingDurationFactor())); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 492 | } |
| 493 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 494 | animator.addListener(new AnimatorListenerAdapter() { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 495 | private boolean mCancelled; |
| 496 | |
| 497 | @Override |
| 498 | public void onAnimationCancel(Animator animation) { |
| 499 | mCancelled = true; |
| 500 | } |
| 501 | |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 502 | @Override |
| 503 | public void onAnimationEnd(Animator animation) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 504 | if (clearAllExpandHack && !mCancelled) { |
Jorim Jaggi | 2ae259d | 2014-08-04 23:35:47 +0200 | [diff] [blame] | 505 | setExpandedHeightInternal(getMaxPanelHeight()); |
| 506 | } |
| 507 | mHeightAnimator = null; |
| 508 | if (!mCancelled) { |
| 509 | notifyExpandingFinished(); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 510 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 511 | } |
| 512 | }); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 513 | mHeightAnimator = animator; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 514 | animator.start(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | @Override |
| 518 | protected void onAttachedToWindow() { |
| 519 | super.onAttachedToWindow(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 520 | mViewName = getResources().getResourceName(getId()); |
| 521 | } |
| 522 | |
| 523 | public String getName() { |
| 524 | return mViewName; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 527 | @Override |
| 528 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 529 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 530 | |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 531 | if (DEBUG) logf("onMeasure(%d, %d) -> (%d, %d)", |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 532 | widthMeasureSpec, heightMeasureSpec, getMeasuredWidth(), getMeasuredHeight()); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 533 | |
| 534 | // Did one of our children change size? |
| 535 | int newHeight = getMeasuredHeight(); |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 536 | if (newHeight > mMaxPanelHeight) { |
| 537 | // we only adapt the max height if it's bigger |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 538 | mMaxPanelHeight = newHeight; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 539 | // 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] | 540 | if (!mTracking && mHeightAnimator == null |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 541 | && mExpandedHeight > 0 && mExpandedHeight != mMaxPanelHeight |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 542 | && mMaxPanelHeight > 0 && mPeekAnimator == null) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 543 | mExpandedHeight = mMaxPanelHeight; |
| 544 | } |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 545 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 548 | public void setExpandedHeight(float height) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 549 | if (DEBUG) logf("setExpandedHeight(%.1f)", height); |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 550 | setExpandedHeightInternal(height + getOverExpansionPixels()); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 551 | } |
| 552 | |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 553 | @Override |
| 554 | 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] | 555 | if (DEBUG) logf("onLayout: changed=%s, bottom=%d eh=%d fh=%d", changed?"T":"f", bottom, |
| 556 | (int)mExpandedHeight, mMaxPanelHeight); |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 557 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 558 | requestPanelHeightUpdate(); |
| 559 | } |
| 560 | |
| 561 | protected void requestPanelHeightUpdate() { |
| 562 | float currentMaxPanelHeight = getMaxPanelHeight(); |
| 563 | |
| 564 | // If the user isn't actively poking us, let's update the height |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 565 | if ((!mTracking || isTrackingBlocked()) |
| 566 | && mHeightAnimator == null |
| 567 | && mExpandedHeight > 0 |
| 568 | && currentMaxPanelHeight != mExpandedHeight |
| 569 | && !mPeekPending |
| 570 | && mPeekAnimator == null) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 571 | setExpandedHeight(currentMaxPanelHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 572 | } |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 575 | public void setExpandedHeightInternal(float h) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 576 | float fhWithoutOverExpansion = getMaxPanelHeight() - getOverExpansionAmount(); |
| 577 | if (mHeightAnimator == null) { |
| 578 | float overExpansionPixels = Math.max(0, h - fhWithoutOverExpansion); |
| 579 | if (getOverExpansionPixels() != overExpansionPixels && mTracking) { |
| 580 | setOverExpansion(overExpansionPixels, true /* isPixels */); |
| 581 | } |
| 582 | mExpandedHeight = Math.min(h, fhWithoutOverExpansion) + getOverExpansionAmount(); |
| 583 | } else { |
| 584 | mExpandedHeight = h; |
| 585 | if (mOverExpandedBeforeFling) { |
| 586 | setOverExpansion(Math.max(0, h - fhWithoutOverExpansion), false /* isPixels */); |
| 587 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 588 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 589 | |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 590 | mExpandedHeight = Math.max(0, mExpandedHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 591 | onHeightUpdated(mExpandedHeight); |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 592 | mExpandedFraction = Math.min(1f, fhWithoutOverExpansion == 0 |
| 593 | ? 0 |
| 594 | : mExpandedHeight / fhWithoutOverExpansion); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 595 | notifyBarPanelExpansionChanged(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 598 | /** |
| 599 | * @return true if the panel tracking should be temporarily blocked; this is used when a |
| 600 | * conflicting gesture (opening QS) is happening |
| 601 | */ |
| 602 | protected abstract boolean isTrackingBlocked(); |
| 603 | |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 604 | protected abstract void setOverExpansion(float overExpansion, boolean isPixels); |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 605 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 606 | protected abstract void onHeightUpdated(float expandedHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 607 | |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 608 | protected abstract float getOverExpansionAmount(); |
| 609 | |
| 610 | protected abstract float getOverExpansionPixels(); |
| 611 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 612 | /** |
| 613 | * This returns the maximum height of the panel. Children should override this if their |
| 614 | * desired height is not the full height. |
| 615 | * |
| 616 | * @return the default implementation simply returns the maximum height. |
| 617 | */ |
| 618 | protected int getMaxPanelHeight() { |
Selim Cinek | b84a107 | 2014-05-15 19:10:18 +0200 | [diff] [blame] | 619 | mMaxPanelHeight = Math.max(mMaxPanelHeight, getHeight()); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 620 | return mMaxPanelHeight; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | public void setExpandedFraction(float frac) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 624 | setExpandedHeight(getMaxPanelHeight() * frac); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | public float getExpandedHeight() { |
| 628 | return mExpandedHeight; |
| 629 | } |
| 630 | |
| 631 | public float getExpandedFraction() { |
| 632 | return mExpandedFraction; |
| 633 | } |
| 634 | |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 635 | public boolean isFullyExpanded() { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 636 | return mExpandedHeight >= getMaxPanelHeight(); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | public boolean isFullyCollapsed() { |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 640 | return mExpandedHeight <= 0; |
| 641 | } |
| 642 | |
| 643 | public boolean isCollapsing() { |
| 644 | return mClosing; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 645 | } |
| 646 | |
John Spurlock | a4b70af | 2013-08-17 14:05:49 -0400 | [diff] [blame] | 647 | public boolean isTracking() { |
| 648 | return mTracking; |
| 649 | } |
| 650 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 651 | public void setBar(PanelBar panelBar) { |
| 652 | mBar = panelBar; |
| 653 | } |
| 654 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame^] | 655 | public void collapse(boolean delayed) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 656 | if (DEBUG) logf("collapse: " + this); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 657 | if (mPeekPending || mPeekAnimator != null) { |
| 658 | mCollapseAfterPeek = true; |
| 659 | if (mPeekPending) { |
| 660 | |
| 661 | // We know that the whole gesture is just a peek triggered by a simple click, so |
| 662 | // better start it now. |
| 663 | removeCallbacks(mPeekRunnable); |
| 664 | mPeekRunnable.run(); |
| 665 | } |
Jorim Jaggi | fb98a50 | 2014-07-11 02:12:03 +0200 | [diff] [blame] | 666 | } else if (!isFullyCollapsed() && !mTracking) { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 667 | if (mHeightAnimator != null) { |
| 668 | mHeightAnimator.cancel(); |
| 669 | } |
Daniel Sandler | 750bb9b | 2012-10-03 16:24:00 -0400 | [diff] [blame] | 670 | mClosing = true; |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 671 | notifyExpandingStarted(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame^] | 672 | if (delayed) { |
| 673 | postDelayed(new Runnable() { |
| 674 | @Override |
| 675 | public void run() { |
| 676 | fling(0, false /* expand */); |
| 677 | } |
| 678 | }, 120); |
| 679 | } else { |
| 680 | fling(0, false /* expand */); |
| 681 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
| 685 | public void expand() { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 686 | if (DEBUG) logf("expand: " + this); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 687 | if (isFullyCollapsed()) { |
| 688 | mBar.startOpeningPanel(this); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 689 | notifyExpandingStarted(); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 690 | fling(0, true /* expand */); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 691 | } else if (DEBUG) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 692 | if (DEBUG) logf("skipping expansion: is expanded"); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | public void cancelPeek() { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 697 | if (mPeekAnimator != null) { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 698 | mPeekAnimator.cancel(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 699 | } |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 700 | removeCallbacks(mPeekRunnable); |
| 701 | mPeekPending = false; |
| 702 | |
| 703 | // When peeking, we already tell mBar that we expanded ourselves. Make sure that we also |
| 704 | // notify mBar that we might have closed ourselves. |
| 705 | notifyBarPanelExpansionChanged(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 706 | } |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 707 | |
Jorim Jaggi | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 708 | public void instantExpand() { |
| 709 | mInstantExpanding = true; |
| 710 | abortAnimations(); |
| 711 | if (mTracking) { |
| 712 | onTrackingStopped(true /* expands */); // The panel is expanded after this call. |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 713 | notifyExpandingFinished(); |
Jorim Jaggi | 0a27be8 | 2014-06-11 03:22:39 +0200 | [diff] [blame] | 714 | } |
| 715 | setVisibility(VISIBLE); |
| 716 | |
| 717 | // Wait for window manager to pickup the change, so we know the maximum height of the panel |
| 718 | // then. |
| 719 | getViewTreeObserver().addOnGlobalLayoutListener( |
| 720 | new ViewTreeObserver.OnGlobalLayoutListener() { |
| 721 | @Override |
| 722 | public void onGlobalLayout() { |
| 723 | if (mStatusBar.getStatusBarWindow().getHeight() |
| 724 | != mStatusBar.getStatusBarHeight()) { |
| 725 | getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 726 | setExpandedFraction(1f); |
| 727 | mInstantExpanding = false; |
| 728 | } |
| 729 | } |
| 730 | }); |
| 731 | |
| 732 | // Make sure a layout really happens. |
| 733 | requestLayout(); |
| 734 | } |
| 735 | |
| 736 | private void abortAnimations() { |
| 737 | cancelPeek(); |
| 738 | if (mHeightAnimator != null) { |
| 739 | mHeightAnimator.cancel(); |
| 740 | } |
| 741 | } |
| 742 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 743 | protected void startUnlockHintAnimation() { |
| 744 | |
| 745 | // We don't need to hint the user if an animation is already running or the user is changing |
| 746 | // the expansion. |
| 747 | if (mHeightAnimator != null || mTracking) { |
| 748 | return; |
| 749 | } |
| 750 | cancelPeek(); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 751 | notifyExpandingStarted(); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 752 | startUnlockHintAnimationPhase1(new Runnable() { |
| 753 | @Override |
| 754 | public void run() { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 755 | notifyExpandingFinished(); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 756 | mStatusBar.onHintFinished(); |
| 757 | mHintAnimationRunning = false; |
| 758 | } |
| 759 | }); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 760 | mStatusBar.onUnlockHintStarted(); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 761 | mHintAnimationRunning = true; |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Phase 1: Move everything upwards. |
| 766 | */ |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 767 | private void startUnlockHintAnimationPhase1(final Runnable onAnimationFinished) { |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 768 | float target = Math.max(0, getMaxPanelHeight() - mHintDistance); |
| 769 | ValueAnimator animator = createHeightAnimator(target); |
| 770 | animator.setDuration(250); |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 771 | animator.setInterpolator(mFastOutSlowInInterpolator); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 772 | animator.addListener(new AnimatorListenerAdapter() { |
| 773 | private boolean mCancelled; |
| 774 | |
| 775 | @Override |
| 776 | public void onAnimationCancel(Animator animation) { |
| 777 | mCancelled = true; |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public void onAnimationEnd(Animator animation) { |
| 782 | if (mCancelled) { |
| 783 | mHeightAnimator = null; |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 784 | onAnimationFinished.run(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 785 | } else { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 786 | startUnlockHintAnimationPhase2(onAnimationFinished); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | }); |
| 790 | animator.start(); |
| 791 | mHeightAnimator = animator; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 792 | mOriginalIndicationY = mKeyguardBottomArea.getIndicationView().getY(); |
| 793 | mKeyguardBottomArea.getIndicationView().animate() |
| 794 | .y(mOriginalIndicationY - mHintDistance) |
| 795 | .setDuration(250) |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 796 | .setInterpolator(mFastOutSlowInInterpolator) |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 797 | .withEndAction(new Runnable() { |
| 798 | @Override |
| 799 | public void run() { |
| 800 | mKeyguardBottomArea.getIndicationView().animate() |
| 801 | .y(mOriginalIndicationY) |
| 802 | .setDuration(450) |
| 803 | .setInterpolator(mBounceInterpolator) |
| 804 | .start(); |
| 805 | } |
| 806 | }) |
| 807 | .start(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Phase 2: Bounce down. |
| 812 | */ |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 813 | private void startUnlockHintAnimationPhase2(final Runnable onAnimationFinished) { |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 814 | ValueAnimator animator = createHeightAnimator(getMaxPanelHeight()); |
| 815 | animator.setDuration(450); |
| 816 | animator.setInterpolator(mBounceInterpolator); |
| 817 | animator.addListener(new AnimatorListenerAdapter() { |
| 818 | @Override |
| 819 | public void onAnimationEnd(Animator animation) { |
| 820 | mHeightAnimator = null; |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 821 | onAnimationFinished.run(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 822 | } |
| 823 | }); |
| 824 | animator.start(); |
| 825 | mHeightAnimator = animator; |
| 826 | } |
| 827 | |
| 828 | private ValueAnimator createHeightAnimator(float targetHeight) { |
| 829 | ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight); |
| 830 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 831 | @Override |
| 832 | public void onAnimationUpdate(ValueAnimator animation) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 833 | setExpandedHeightInternal((Float) animation.getAnimatedValue()); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 834 | } |
| 835 | }); |
| 836 | return animator; |
| 837 | } |
| 838 | |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 839 | private void notifyBarPanelExpansionChanged() { |
| 840 | mBar.panelExpansionChanged(this, mExpandedFraction, mExpandedFraction > 0f || mPeekPending |
| 841 | || mPeekAnimator != null); |
| 842 | } |
| 843 | |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 844 | /** |
| 845 | * Gets called when the user performs a click anywhere in the empty area of the panel. |
| 846 | * |
| 847 | * @return whether the panel will be expanded after the action performed by this method |
| 848 | */ |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 849 | private boolean onEmptySpaceClick(float x) { |
| 850 | if (mHintAnimationRunning) { |
| 851 | return true; |
| 852 | } |
Jorim Jaggi | 6539a83 | 2014-06-03 23:33:09 +0200 | [diff] [blame] | 853 | if (x < mEdgeTapAreaWidth |
| 854 | && mStatusBar.getBarState() == StatusBarState.KEYGUARD) { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 855 | onEdgeClicked(false /* right */); |
| 856 | return true; |
Jorim Jaggi | 6539a83 | 2014-06-03 23:33:09 +0200 | [diff] [blame] | 857 | } else if (x > getWidth() - mEdgeTapAreaWidth |
| 858 | && mStatusBar.getBarState() == StatusBarState.KEYGUARD) { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 859 | onEdgeClicked(true /* right */); |
| 860 | return true; |
| 861 | } else { |
| 862 | return onMiddleClicked(); |
| 863 | } |
| 864 | } |
| 865 | |
Jorim Jaggi | 488b792 | 2014-08-05 21:12:02 +0200 | [diff] [blame] | 866 | private final Runnable mPostCollapseRunnable = new Runnable() { |
| 867 | @Override |
| 868 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame^] | 869 | collapse(false /* delayed */); |
Jorim Jaggi | 488b792 | 2014-08-05 21:12:02 +0200 | [diff] [blame] | 870 | } |
| 871 | }; |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 872 | private boolean onMiddleClicked() { |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 873 | switch (mStatusBar.getBarState()) { |
| 874 | case StatusBarState.KEYGUARD: |
| 875 | startUnlockHintAnimation(); |
| 876 | return true; |
| 877 | case StatusBarState.SHADE_LOCKED: |
Jorim Jaggi | 6539a83 | 2014-06-03 23:33:09 +0200 | [diff] [blame] | 878 | mStatusBar.goToKeyguard(); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 879 | return true; |
| 880 | case StatusBarState.SHADE: |
Jorim Jaggi | 488b792 | 2014-08-05 21:12:02 +0200 | [diff] [blame] | 881 | |
| 882 | // This gets called in the middle of the touch handling, where the state is still |
| 883 | // that we are tracking the panel. Collapse the panel after this is done. |
| 884 | post(mPostCollapseRunnable); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 885 | return false; |
| 886 | default: |
| 887 | return true; |
| 888 | } |
| 889 | } |
| 890 | |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 891 | protected abstract void onEdgeClicked(boolean right); |
| 892 | |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 893 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Selim Cinek | a3e5bcb | 2014-04-07 20:07:22 +0200 | [diff] [blame] | 894 | pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s" |
John Spurlock | 5072883 | 2014-04-17 19:05:28 -0400 | [diff] [blame] | 895 | + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s" |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 896 | + "]", |
| 897 | this.getClass().getSimpleName(), |
| 898 | getExpandedHeight(), |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 899 | getMaxPanelHeight(), |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 900 | mClosing?"T":"f", |
| 901 | mTracking?"T":"f", |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 902 | mJustPeeked?"T":"f", |
| 903 | mPeekAnimator, ((mPeekAnimator!=null && mPeekAnimator.isStarted())?" (started)":""), |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 904 | mHeightAnimator, ((mHeightAnimator !=null && mHeightAnimator.isStarted())?" (started)":"") |
Daniel Sandler | 37a38aa | 2013-02-13 17:15:57 -0500 | [diff] [blame] | 905 | )); |
| 906 | } |
Selim Cinek | 3c4635c | 2014-05-29 02:12:47 +0200 | [diff] [blame] | 907 | |
| 908 | public abstract void resetViews(); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 909 | |
| 910 | protected abstract float getPeekHeight(); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 911 | |
| 912 | protected abstract float getCannedFlingDurationFactor(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 913 | |
| 914 | /** |
| 915 | * @return whether "Clear all" button will be visible when the panel is fully expanded |
| 916 | */ |
| 917 | protected abstract boolean fullyExpandedClearAllVisible(); |
| 918 | |
| 919 | protected abstract boolean isClearAllVisible(); |
| 920 | |
| 921 | /** |
| 922 | * @return the height of the clear all button, in pixels |
| 923 | */ |
| 924 | protected abstract int getClearAllHeight(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 925 | } |