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