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