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