blob: fc0f2d56a1b8756827427a67b20616792e47162e [file] [log] [blame]
Daniel Sandler08d05e32012-08-08 16:39:54 -04001/*
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
17package com.android.systemui.statusbar.phone;
18
Jorim Jaggid7daab72014-05-06 22:22:20 +020019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Jorim Jaggi75c95042014-05-16 19:09:59 +020021import android.animation.ObjectAnimator;
Jorim Jaggid7daab72014-05-06 22:22:20 +020022import android.animation.ValueAnimator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040023import android.content.Context;
Selim Cinek4c6969a2014-05-26 19:22:17 +020024import android.content.res.Configuration;
Daniel Sandler08d05e32012-08-08 16:39:54 -040025import android.util.AttributeSet;
Daniel Sandler040c2e42012-10-17 00:56:33 -040026import android.view.MotionEvent;
Jorim Jaggid7daab72014-05-06 22:22:20 +020027import android.view.VelocityTracker;
Daniel Sandler13522a22012-09-27 14:46:58 -040028import android.view.View;
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +020029import android.view.ViewGroup;
Jorim Jaggi75c95042014-05-16 19:09:59 +020030import android.view.ViewTreeObserver;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070031import android.view.accessibility.AccessibilityEvent;
Jorim Jaggi75c95042014-05-16 19:09:59 +020032import android.view.animation.AnimationUtils;
33import android.view.animation.Interpolator;
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +020034import android.widget.LinearLayout;
Selim Cinekf99d0002014-06-13 07:36:01 +020035import android.widget.TextView;
Daniel Sandler13522a22012-09-27 14:46:58 -040036
Chet Haase4d179dc2012-08-22 07:14:42 -070037import com.android.systemui.R;
Jorim Jaggie65e3102014-07-01 22:00:50 +020038import com.android.systemui.qs.QSPanel;
Jorim Jaggibe565df2014-04-28 17:51:23 +020039import com.android.systemui.statusbar.ExpandableView;
Jorim Jaggi87cd5e72014-05-12 23:29:10 +020040import com.android.systemui.statusbar.FlingAnimationUtils;
Daniel Sandler151f00d2012-10-02 22:33:08 -040041import com.android.systemui.statusbar.GestureRecorder;
Jorim Jaggi605f1902014-06-25 05:23:42 +020042import com.android.systemui.statusbar.MirrorView;
Jorim Jaggiecbab362014-04-23 16:13:15 +020043import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010044import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Jorim Jaggi75c95042014-05-16 19:09:59 +020045import com.android.systemui.statusbar.stack.StackStateAnimator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040046
Selim Cinek4c6969a2014-05-26 19:22:17 +020047import java.util.ArrayList;
48
Jorim Jaggibe565df2014-04-28 17:51:23 +020049public class NotificationPanelView extends PanelView implements
Jorim Jaggid7daab72014-05-06 22:22:20 +020050 ExpandableView.OnHeightChangedListener, ObservableScrollView.Listener,
Jorim Jaggi290600a2014-05-30 17:02:20 +020051 View.OnClickListener, NotificationStackScrollLayout.OnOverscrollTopChangedListener,
52 KeyguardPageSwipeHelper.Callback {
Chet Haase4d179dc2012-08-22 07:14:42 -070053
Selim Cinekf99d0002014-06-13 07:36:01 +020054 // Cap and total height of Roboto font. Needs to be adjusted when font for the big clock is
55 // changed.
56 private static final int CAP_HEIGHT = 1456;
57 private static final int FONT_HEIGHT = 2163;
58
Jorim Jaggi2580a9762014-06-25 03:08:25 +020059 private static final float HEADER_RUBBERBAND_FACTOR = 2.15f;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020060 private static final float LOCK_ICON_ACTIVE_SCALE = 1.2f;
Selim Cineka02fe522014-05-30 17:01:21 +020061
Selim Cinek4c6969a2014-05-26 19:22:17 +020062 private KeyguardPageSwipeHelper mPageSwiper;
Jorim Jaggid7daab72014-05-06 22:22:20 +020063 private StatusBarHeaderView mHeader;
John Spurlockaf8d6c42014-05-07 17:49:08 -040064 private View mQsContainer;
Jorim Jaggie65e3102014-07-01 22:00:50 +020065 private QSPanel mQsPanel;
John Spurlock73203eb2014-04-15 16:14:46 -040066 private View mKeyguardStatusView;
Jorim Jaggid7daab72014-05-06 22:22:20 +020067 private ObservableScrollView mScrollView;
Selim Cinekf99d0002014-06-13 07:36:01 +020068 private TextView mClockView;
Jorim Jaggi54045422014-07-03 18:30:40 +020069 private View mReserveNotificationSpace;
Jorim Jaggi605f1902014-06-25 05:23:42 +020070 private MirrorView mSystemIconsCopy;
71
Selim Cinekb6d85eb2014-03-28 20:21:01 +010072 private NotificationStackScrollLayout mNotificationStackScroller;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +020073 private int mNotificationTopPadding;
Jorim Jaggi98fb09c2014-05-01 22:40:56 +020074 private boolean mAnimateNextTopPaddingChange;
Chet Haase4d179dc2012-08-22 07:14:42 -070075
Jorim Jaggid7daab72014-05-06 22:22:20 +020076 private int mTrackingPointer;
77 private VelocityTracker mVelocityTracker;
Selim Cinek4c6969a2014-05-26 19:22:17 +020078 private boolean mQsTracking;
Jorim Jaggifc1a8242014-05-12 19:30:05 +020079
80 /**
Jorim Jaggidc96d632014-07-01 18:48:52 +020081 * If set, the ongoing touch gesture might both trigger the expansion in {@link PanelView} and
82 * the expansion for quick settings.
83 */
84 private boolean mConflictingQsExpansionGesture;
85
86 /**
Jorim Jaggifc1a8242014-05-12 19:30:05 +020087 * Whether we are currently handling a motion gesture in #onInterceptTouchEvent, but haven't
88 * intercepted yet.
89 */
90 private boolean mIntercepting;
Jorim Jaggid7daab72014-05-06 22:22:20 +020091 private boolean mQsExpanded;
Jorim Jaggi30c305c2014-07-01 23:34:41 +020092 private boolean mQsExpandedWhenExpandingStarted;
John Spurlockbc3a5e92014-05-30 16:20:05 -040093 private boolean mQsFullyExpanded;
Jorim Jaggif62f2bb2014-05-25 22:28:41 +020094 private boolean mKeyguardShowing;
Jorim Jaggi56306252014-07-03 00:40:09 +020095 private int mStatusBarState;
Jorim Jaggid7daab72014-05-06 22:22:20 +020096 private float mInitialHeightOnTouch;
97 private float mInitialTouchX;
98 private float mInitialTouchY;
Jorim Jaggifc1a8242014-05-12 19:30:05 +020099 private float mLastTouchX;
100 private float mLastTouchY;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200101 private float mQsExpansionHeight;
102 private int mQsMinExpansionHeight;
103 private int mQsMaxExpansionHeight;
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200104 private int mQsPeekHeight;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200105 private boolean mStackScrollerOverscrolling;
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200106 private boolean mQsExpansionFromOverscroll;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200107 private boolean mQsExpansionEnabled = true;
108 private ValueAnimator mQsExpansionAnimator;
Jorim Jaggi87cd5e72014-05-12 23:29:10 +0200109 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek9dbbca82014-05-15 15:23:37 +0200110 private int mStatusBarMinHeight;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200111 private boolean mUnlockIconActive;
Jorim Jaggi457cc352014-06-02 22:47:42 +0200112 private int mNotificationsHeaderCollideDistance;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200113 private int mUnlockMoveDistance;
John Spurlock3e04cc82014-05-30 12:34:03 -0400114
Jorim Jaggi75c95042014-05-16 19:09:59 +0200115 private Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi457cc352014-06-02 22:47:42 +0200116 private Interpolator mFastOutLinearInterpolator;
Jorim Jaggi75c95042014-05-16 19:09:59 +0200117 private ObjectAnimator mClockAnimator;
118 private int mClockAnimationTarget = -1;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200119 private int mTopPaddingAdjustment;
120 private KeyguardClockPositionAlgorithm mClockPositionAlgorithm =
121 new KeyguardClockPositionAlgorithm();
122 private KeyguardClockPositionAlgorithm.Result mClockPositionResult =
123 new KeyguardClockPositionAlgorithm.Result();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200124 private boolean mIsExpanding;
Selim Cinekf99d0002014-06-13 07:36:01 +0200125
Selim Cinek4c6969a2014-05-26 19:22:17 +0200126 private boolean mBlockTouches;
127 private ArrayList<View> mSwipeTranslationViews = new ArrayList<>();
Selim Cinekf54090e2014-06-17 17:24:51 -0700128 private int mNotificationScrimWaitDistance;
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200129 private boolean mTwoFingerQsExpand;
130 private boolean mTwoFingerQsExpandPossible;
Jorim Jaggi56306252014-07-03 00:40:09 +0200131
132 /**
133 * If we are in a panel collapsing motion, we reset scrollY of our scroll view but still
134 * need to take this into account in our panel height calculation.
135 */
136 private int mScrollYOverride = -1;
Jorim Jaggibd003102014-07-04 00:02:42 +0200137 private boolean mQsAnimatorExpand;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200138
Daniel Sandler08d05e32012-08-08 16:39:54 -0400139 public NotificationPanelView(Context context, AttributeSet attrs) {
140 super(context, attrs);
Jorim Jaggi605f1902014-06-25 05:23:42 +0200141 mSystemIconsCopy = new MirrorView(context);
Daniel Sandler13522a22012-09-27 14:46:58 -0400142 }
Chet Haase4d179dc2012-08-22 07:14:42 -0700143
Daniel Sandler040c2e42012-10-17 00:56:33 -0400144 public void setStatusBar(PhoneStatusBar bar) {
145 mStatusBar = bar;
146 }
147
Daniel Sandler13522a22012-09-27 14:46:58 -0400148 @Override
149 protected void onFinishInflate() {
150 super.onFinishInflate();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200151 mHeader = (StatusBarHeaderView) findViewById(R.id.header);
Jorim Jaggi853b0702014-07-05 04:31:14 +0200152 mHeader.setOnClickListener(this);
John Spurlock73203eb2014-04-15 16:14:46 -0400153 mKeyguardStatusView = findViewById(R.id.keyguard_status_view);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400154 mQsContainer = findViewById(R.id.quick_settings_container);
Jorim Jaggie65e3102014-07-01 22:00:50 +0200155 mQsPanel = (QSPanel) findViewById(R.id.quick_settings_panel);
Selim Cinekf99d0002014-06-13 07:36:01 +0200156 mClockView = (TextView) findViewById(R.id.clock_view);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200157 mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
158 mScrollView.setListener(this);
Jorim Jaggi54045422014-07-03 18:30:40 +0200159 mReserveNotificationSpace = findViewById(R.id.reserve_notification_space);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100160 mNotificationStackScroller = (NotificationStackScrollLayout)
161 findViewById(R.id.notification_stack_scroller);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200162 mNotificationStackScroller.setOnHeightChangedListener(this);
Jorim Jaggi290600a2014-05-30 17:02:20 +0200163 mNotificationStackScroller.setOverscrollTopChangedListener(this);
Jorim Jaggi56306252014-07-03 00:40:09 +0200164 mNotificationStackScroller.setScrollView(mScrollView);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200165 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
166 android.R.interpolator.fast_out_slow_in);
Jorim Jaggi457cc352014-06-02 22:47:42 +0200167 mFastOutLinearInterpolator = AnimationUtils.loadInterpolator(getContext(),
168 android.R.interpolator.fast_out_linear_in);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200169 mKeyguardBottomArea = (KeyguardBottomAreaView) findViewById(R.id.keyguard_bottom_area);
170 mSwipeTranslationViews.add(mNotificationStackScroller);
Jorim Jaggia27b0042014-06-14 03:58:56 +0000171 mSwipeTranslationViews.add(mKeyguardStatusView);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200172 mPageSwiper = new KeyguardPageSwipeHelper(this, getContext());
Jorim Jaggi069cd032014-05-15 03:09:01 +0200173 }
174
175 @Override
176 protected void loadDimens() {
177 super.loadDimens();
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200178 mNotificationTopPadding = getResources().getDimensionPixelSize(
179 R.dimen.notifications_top_padding);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200180 mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.4f);
Selim Cinek9dbbca82014-05-15 15:23:37 +0200181 mStatusBarMinHeight = getResources().getDimensionPixelSize(
182 com.android.internal.R.dimen.status_bar_height);
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200183 mQsPeekHeight = getResources().getDimensionPixelSize(R.dimen.qs_peek_height);
Jorim Jaggi457cc352014-06-02 22:47:42 +0200184 mNotificationsHeaderCollideDistance =
185 getResources().getDimensionPixelSize(R.dimen.header_notifications_collide_distance);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200186 mUnlockMoveDistance = getResources().getDimensionPixelOffset(R.dimen.unlock_move_distance);
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200187 mClockPositionAlgorithm.loadDimens(getResources());
Selim Cinekf54090e2014-06-17 17:24:51 -0700188 mNotificationScrimWaitDistance =
189 getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200190 }
191
192 @Override
193 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
194 super.onLayout(changed, left, top, right, bottom);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200195
Selim Cinekf99d0002014-06-13 07:36:01 +0200196 // Update Clock Pivot
197 mKeyguardStatusView.setPivotX(getWidth() / 2);
198 mKeyguardStatusView.setPivotY(
199 (FONT_HEIGHT - CAP_HEIGHT) / 2048f * mClockView.getTextSize());
200
Jorim Jaggid7daab72014-05-06 22:22:20 +0200201 // Calculate quick setting heights.
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200202 mQsMinExpansionHeight = mHeader.getCollapsedHeight() + mQsPeekHeight;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200203 mQsMaxExpansionHeight = mHeader.getExpandedHeight() + mQsContainer.getHeight();
John Spurlock2684d5e2014-05-28 20:27:44 -0400204 if (mQsExpanded) {
John Spurlockbc3a5e92014-05-30 16:20:05 -0400205 if (mQsFullyExpanded) {
Selim Cinek1408eb52014-06-02 14:45:38 +0200206 mQsExpansionHeight = mQsMaxExpansionHeight;
207 requestScrollerTopPaddingUpdate(false /* animate */);
John Spurlockbc3a5e92014-05-30 16:20:05 -0400208 }
John Spurlock2684d5e2014-05-28 20:27:44 -0400209 } else {
Jorim Jaggi290600a2014-05-30 17:02:20 +0200210 if (!mStackScrollerOverscrolling) {
211 setQsExpansion(mQsMinExpansionHeight);
212 }
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200213 positionClockAndNotifications();
214 mNotificationStackScroller.setStackHeight(getExpandedHeight());
Jorim Jaggid7daab72014-05-06 22:22:20 +0200215 }
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200216 }
217
Jorim Jaggi069cd032014-05-15 03:09:01 +0200218 /**
219 * Positions the clock and notifications dynamically depending on how many notifications are
220 * showing.
221 */
222 private void positionClockAndNotifications() {
Selim Cinekf99d0002014-06-13 07:36:01 +0200223 boolean animate = mNotificationStackScroller.isAddOrRemoveAnimationPending();
Selim Cinek1408eb52014-06-02 14:45:38 +0200224 int stackScrollerPadding;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200225 if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200226 int bottom = mHeader.getCollapsedHeight();
Selim Cinek1408eb52014-06-02 14:45:38 +0200227 stackScrollerPadding = bottom + mQsPeekHeight
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200228 + mNotificationTopPadding;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200229 mTopPaddingAdjustment = 0;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200230 } else {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200231 mClockPositionAlgorithm.setup(
232 mStatusBar.getMaxKeyguardNotifications(),
233 getMaxPanelHeight(),
234 getExpandedHeight(),
235 mNotificationStackScroller.getNotGoneChildCount(),
236 getHeight(),
237 mKeyguardStatusView.getHeight());
238 mClockPositionAlgorithm.run(mClockPositionResult);
Selim Cinekf99d0002014-06-13 07:36:01 +0200239 if (animate || mClockAnimator != null) {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200240 startClockAnimation(mClockPositionResult.clockY);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200241 } else {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200242 mKeyguardStatusView.setY(mClockPositionResult.clockY);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200243 }
Selim Cinekf99d0002014-06-13 07:36:01 +0200244 updateClock(mClockPositionResult.clockAlpha, mClockPositionResult.clockScale);
Selim Cinek1408eb52014-06-02 14:45:38 +0200245 stackScrollerPadding = mClockPositionResult.stackScrollerPadding;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200246 mTopPaddingAdjustment = mClockPositionResult.stackScrollerPaddingAdjustment;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200247 }
Selim Cinek1408eb52014-06-02 14:45:38 +0200248 mNotificationStackScroller.setIntrinsicPadding(stackScrollerPadding);
Selim Cinekf99d0002014-06-13 07:36:01 +0200249 requestScrollerTopPaddingUpdate(animate);
Jorim Jaggi069cd032014-05-15 03:09:01 +0200250 }
251
Jorim Jaggi75c95042014-05-16 19:09:59 +0200252 private void startClockAnimation(int y) {
253 if (mClockAnimationTarget == y) {
254 return;
255 }
256 mClockAnimationTarget = y;
257 getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
258 @Override
259 public boolean onPreDraw() {
260 getViewTreeObserver().removeOnPreDrawListener(this);
261 if (mClockAnimator != null) {
262 mClockAnimator.removeAllListeners();
263 mClockAnimator.cancel();
264 }
Jorim Jaggia1b1c7a2014-06-03 16:29:05 +0200265 mClockAnimator = ObjectAnimator
266 .ofFloat(mKeyguardStatusView, View.Y, mClockAnimationTarget);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200267 mClockAnimator.setInterpolator(mFastOutSlowInInterpolator);
268 mClockAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
269 mClockAnimator.addListener(new AnimatorListenerAdapter() {
270 @Override
271 public void onAnimationEnd(Animator animation) {
272 mClockAnimator = null;
273 mClockAnimationTarget = -1;
274 }
275 });
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200276 mClockAnimator.start();
Jorim Jaggi75c95042014-05-16 19:09:59 +0200277 return true;
278 }
279 });
280 }
281
Selim Cinekf99d0002014-06-13 07:36:01 +0200282 private void updateClock(float alpha, float scale) {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200283 mKeyguardStatusView.setAlpha(alpha);
Selim Cinekf99d0002014-06-13 07:36:01 +0200284 mKeyguardStatusView.setScaleX(scale);
285 mKeyguardStatusView.setScaleY(scale);
Jorim Jaggi069cd032014-05-15 03:09:01 +0200286 }
287
Selim Cinekc27437b2014-05-14 10:23:33 +0200288 public void animateToFullShade() {
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200289 mAnimateNextTopPaddingChange = true;
Selim Cinekc27437b2014-05-14 10:23:33 +0200290 mNotificationStackScroller.goToFullShade();
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200291 requestLayout();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400292 }
293
Jorim Jaggid7daab72014-05-06 22:22:20 +0200294 public void setQsExpansionEnabled(boolean qsExpansionEnabled) {
295 mQsExpansionEnabled = qsExpansionEnabled;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200296 }
297
Selim Cinek3c4635c2014-05-29 02:12:47 +0200298 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +0200299 public void resetViews() {
300 mBlockTouches = false;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200301 mUnlockIconActive = false;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200302 mPageSwiper.reset();
303 closeQs();
Jorim Jaggidbbf45e2014-06-25 21:54:48 +0200304 mNotificationStackScroller.setOverScrollAmount(0f, true /* onTop */, false /* animate */,
305 true /* cancelAnimators */);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200306 }
307
Jorim Jaggid7daab72014-05-06 22:22:20 +0200308 public void closeQs() {
309 cancelAnimation();
310 setQsExpansion(mQsMinExpansionHeight);
311 }
312
Jorim Jaggibd003102014-07-04 00:02:42 +0200313 public void animateCloseQs() {
314 if (mQsExpansionAnimator != null) {
315 if (!mQsAnimatorExpand) {
316 return;
317 }
318 float height = mQsExpansionHeight;
319 mQsExpansionAnimator.cancel();
320 setQsExpansion(height);
321 }
322 flingSettings(0 /* vel */, false);
323 }
324
Jorim Jaggid7daab72014-05-06 22:22:20 +0200325 public void openQs() {
326 cancelAnimation();
327 if (mQsExpansionEnabled) {
328 setQsExpansion(mQsMaxExpansionHeight);
329 }
330 }
331
Daniel Sandler08d05e32012-08-08 16:39:54 -0400332 @Override
333 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -0400334 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
335 if (gr != null) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200336 gr.tag("fling " + ((vel > 0) ? "open" : "closed"), "notifications,v=" + vel);
Daniel Sandler151f00d2012-10-02 22:33:08 -0400337 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400338 super.fling(vel, always);
339 }
Chet Haase4d179dc2012-08-22 07:14:42 -0700340
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700341 @Override
342 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
343 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
344 event.getText()
345 .add(getContext().getString(R.string.accessibility_desc_notification_shade));
346 return true;
347 }
348
349 return super.dispatchPopulateAccessibilityEvent(event);
350 }
351
Daniel Sandler040c2e42012-10-17 00:56:33 -0400352 @Override
John Spurlock73203eb2014-04-15 16:14:46 -0400353 public boolean onInterceptTouchEvent(MotionEvent event) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200354 if (mBlockTouches) {
355 return false;
356 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200357 int pointerIndex = event.findPointerIndex(mTrackingPointer);
358 if (pointerIndex < 0) {
359 pointerIndex = 0;
360 mTrackingPointer = event.getPointerId(pointerIndex);
John Spurlock73203eb2014-04-15 16:14:46 -0400361 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200362 final float x = event.getX(pointerIndex);
363 final float y = event.getY(pointerIndex);
364
365 switch (event.getActionMasked()) {
366 case MotionEvent.ACTION_DOWN:
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200367 mIntercepting = true;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200368 mInitialTouchY = y;
369 mInitialTouchX = x;
370 initVelocityTracker();
371 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200372 if (shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, 0)) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200373 getParent().requestDisallowInterceptTouchEvent(true);
374 }
Jorim Jaggi54045422014-07-03 18:30:40 +0200375 if (mQsExpansionAnimator != null) {
376 onQsExpansionStarted();
377 mInitialHeightOnTouch = mQsExpansionHeight;
378 mQsTracking = true;
379 mIntercepting = false;
380 mNotificationStackScroller.removeLongPressCallback();
381 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200382 break;
383 case MotionEvent.ACTION_POINTER_UP:
384 final int upPointer = event.getPointerId(event.getActionIndex());
385 if (mTrackingPointer == upPointer) {
386 // gesture is ongoing, find a new pointer to track
387 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
388 mTrackingPointer = event.getPointerId(newIndex);
389 mInitialTouchX = event.getX(newIndex);
390 mInitialTouchY = event.getY(newIndex);
391 }
392 break;
393
394 case MotionEvent.ACTION_MOVE:
395 final float h = y - mInitialTouchY;
396 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200397 if (mQsTracking) {
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200398
399 // Already tracking because onOverscrolled was called. We need to update here
400 // so we don't stop for a frame until the next touch event gets handled in
401 // onTouchEvent.
402 setQsExpansion(h + mInitialHeightOnTouch);
403 trackMovement(event);
404 mIntercepting = false;
405 return true;
406 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200407 if (Math.abs(h) > mTouchSlop && Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek4c6969a2014-05-26 19:22:17 +0200408 && shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, h)) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200409 onQsExpansionStarted();
410 mInitialHeightOnTouch = mQsExpansionHeight;
411 mInitialTouchY = y;
412 mInitialTouchX = x;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200413 mQsTracking = true;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200414 mIntercepting = false;
Selim Cinek1408eb52014-06-02 14:45:38 +0200415 mNotificationStackScroller.removeLongPressCallback();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200416 return true;
417 }
418 break;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200419
420 case MotionEvent.ACTION_CANCEL:
421 case MotionEvent.ACTION_UP:
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200422 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200423 if (mQsTracking) {
424 flingQsWithCurrentVelocity();
425 mQsTracking = false;
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200426 }
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200427 mIntercepting = false;
428 break;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200429 }
430 return !mQsExpanded && super.onInterceptTouchEvent(event);
John Spurlock73203eb2014-04-15 16:14:46 -0400431 }
432
433 @Override
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200434 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
435
Jorim Jaggice50b812014-05-24 16:29:57 +0200436 // Block request when interacting with the scroll view so we can still intercept the
437 // scrolling when QS is expanded.
Jorim Jaggi3f48f462014-07-08 16:53:29 +0200438 if (mScrollView.isHandlingTouchEvent()) {
Jorim Jaggice50b812014-05-24 16:29:57 +0200439 return;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200440 }
Jorim Jaggice50b812014-05-24 16:29:57 +0200441 super.requestDisallowInterceptTouchEvent(disallowIntercept);
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200442 }
443
Selim Cinek4c6969a2014-05-26 19:22:17 +0200444 private void flingQsWithCurrentVelocity() {
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200445 float vel = getCurrentVelocity();
Jorim Jaggidc96d632014-07-01 18:48:52 +0200446 flingSettings(vel, flingExpandsQs(vel));
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200447 }
448
Jorim Jaggidc96d632014-07-01 18:48:52 +0200449 private boolean flingExpandsQs(float vel) {
450 if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
451 return getQsExpansionFraction() > 0.5f;
452 } else {
453 return vel > 0;
454 }
455 }
456
457 private float getQsExpansionFraction() {
458 return (mQsExpansionHeight - mQsMinExpansionHeight)
Jorim Jaggi54045422014-07-03 18:30:40 +0200459 / (getTempQsMaxExpansion() - mQsMinExpansionHeight);
Jorim Jaggidc96d632014-07-01 18:48:52 +0200460 }
Jorim Jaggi54045422014-07-03 18:30:40 +0200461
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200462 @Override
Daniel Sandler040c2e42012-10-17 00:56:33 -0400463 public boolean onTouchEvent(MotionEvent event) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200464 if (mBlockTouches) {
465 return false;
466 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100467 // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference
468 // implementation.
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200469 if ((!mIsExpanding || mHintAnimationRunning)
470 && !mQsExpanded
471 && mStatusBar.getBarState() != StatusBarState.SHADE) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200472 mPageSwiper.onTouchEvent(event);
473 if (mPageSwiper.isSwipingInProgress()) {
474 return true;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200475 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200476 }
Jorim Jaggidc96d632014-07-01 18:48:52 +0200477 if (event.getActionMasked() == MotionEvent.ACTION_DOWN && getExpandedFraction() == 1f
478 && mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200479
Jorim Jaggidc96d632014-07-01 18:48:52 +0200480 // Down in the empty area while fully expanded - go to QS.
481 mQsTracking = true;
482 mConflictingQsExpansionGesture = true;
483 onQsExpansionStarted();
484 mInitialHeightOnTouch = mQsExpansionHeight;
485 mInitialTouchY = event.getX();
486 mInitialTouchX = event.getY();
487 }
Jorim Jaggi853b0702014-07-05 04:31:14 +0200488 if (mExpandedHeight != 0) {
489 handleQsDown(event);
490 }
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200491 if (!mTwoFingerQsExpand && (mQsTracking || mQsExpanded)) {
Jorim Jaggidc96d632014-07-01 18:48:52 +0200492 onQsTouch(event);
493 if (!mConflictingQsExpansionGesture) {
494 return true;
495 }
496 }
497 if (event.getActionMasked() == MotionEvent.ACTION_CANCEL
498 || event.getActionMasked() == MotionEvent.ACTION_UP) {
499 mConflictingQsExpansionGesture = false;
500 }
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200501 if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mExpandedHeight == 0) {
502 mTwoFingerQsExpandPossible = true;
503 }
504 if (mTwoFingerQsExpandPossible && event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN
505 && event.getPointerCount() == 2
506 && event.getY(event.getActionIndex()) < mStatusBarMinHeight) {
507 mTwoFingerQsExpand = true;
508 requestPanelHeightUpdate();
509 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200510 super.onTouchEvent(event);
511 return true;
512 }
513
Jorim Jaggi853b0702014-07-05 04:31:14 +0200514 private void handleQsDown(MotionEvent event) {
515 if (event.getActionMasked() == MotionEvent.ACTION_DOWN
516 && shouldQuickSettingsIntercept(event.getX(), event.getY(), 0)) {
517 mQsTracking = true;
518 onQsExpansionStarted();
519 mInitialHeightOnTouch = mQsExpansionHeight;
520 mInitialTouchY = event.getX();
521 mInitialTouchX = event.getY();
522 }
523 }
524
Selim Cinek4c6969a2014-05-26 19:22:17 +0200525 @Override
Jorim Jaggidc96d632014-07-01 18:48:52 +0200526 protected boolean flingExpands(float vel, float vectorVel) {
527 boolean expands = super.flingExpands(vel, vectorVel);
528
529 // If we are already running a QS expansion, make sure that we keep the panel open.
530 if (mQsExpansionAnimator != null) {
531 expands = true;
532 }
533 return expands;
534 }
535
536 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +0200537 protected boolean hasConflictingGestures() {
538 return mStatusBar.getBarState() != StatusBarState.SHADE;
539 }
540
Jorim Jaggidc96d632014-07-01 18:48:52 +0200541 private void onQsTouch(MotionEvent event) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200542 int pointerIndex = event.findPointerIndex(mTrackingPointer);
543 if (pointerIndex < 0) {
544 pointerIndex = 0;
545 mTrackingPointer = event.getPointerId(pointerIndex);
546 }
547 final float y = event.getY(pointerIndex);
548 final float x = event.getX(pointerIndex);
549
550 switch (event.getActionMasked()) {
551 case MotionEvent.ACTION_DOWN:
552 mQsTracking = true;
553 mInitialTouchY = y;
554 mInitialTouchX = x;
555 onQsExpansionStarted();
556 mInitialHeightOnTouch = mQsExpansionHeight;
557 initVelocityTracker();
558 trackMovement(event);
559 break;
560
561 case MotionEvent.ACTION_POINTER_UP:
562 final int upPointer = event.getPointerId(event.getActionIndex());
563 if (mTrackingPointer == upPointer) {
564 // gesture is ongoing, find a new pointer to track
565 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
566 final float newY = event.getY(newIndex);
567 final float newX = event.getX(newIndex);
568 mTrackingPointer = event.getPointerId(newIndex);
569 mInitialHeightOnTouch = mQsExpansionHeight;
570 mInitialTouchY = newY;
571 mInitialTouchX = newX;
572 }
573 break;
574
575 case MotionEvent.ACTION_MOVE:
576 final float h = y - mInitialTouchY;
577 setQsExpansion(h + mInitialHeightOnTouch);
578 trackMovement(event);
579 break;
580
581 case MotionEvent.ACTION_UP:
582 case MotionEvent.ACTION_CANCEL:
583 mQsTracking = false;
584 mTrackingPointer = -1;
585 trackMovement(event);
Jorim Jaggidc96d632014-07-01 18:48:52 +0200586 float fraction = getQsExpansionFraction();
587 if ((fraction != 0f || y >= mInitialTouchY)
588 && (fraction != 1f || y <= mInitialTouchY)) {
589 flingQsWithCurrentVelocity();
Jorim Jaggi54045422014-07-03 18:30:40 +0200590 } else {
591 mScrollYOverride = -1;
Jorim Jaggidc96d632014-07-01 18:48:52 +0200592 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200593 if (mVelocityTracker != null) {
594 mVelocityTracker.recycle();
595 mVelocityTracker = null;
596 }
597 break;
598 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200599 }
600
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200601 @Override
602 public void onOverscrolled(int amount) {
603 if (mIntercepting) {
604 onQsExpansionStarted(amount);
605 mInitialHeightOnTouch = mQsExpansionHeight;
606 mInitialTouchY = mLastTouchY;
607 mInitialTouchX = mLastTouchX;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200608 mQsTracking = true;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200609 }
610 }
611
Jorim Jaggi290600a2014-05-30 17:02:20 +0200612 @Override
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200613 public void onOverscrollTopChanged(float amount, boolean isRubberbanded) {
Jorim Jaggi290600a2014-05-30 17:02:20 +0200614 cancelAnimation();
615 float rounded = amount >= 1f ? amount : 0f;
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200616 mStackScrollerOverscrolling = rounded != 0f && isRubberbanded;
617 mQsExpansionFromOverscroll = rounded != 0f;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200618 setQsExpansion(mQsMinExpansionHeight + rounded);
619 updateQsState();
620 }
621
Selim Cinek1408eb52014-06-02 14:45:38 +0200622 @Override
623 public void flingTopOverscroll(float velocity, boolean open) {
Selim Cinek1408eb52014-06-02 14:45:38 +0200624 setQsExpansion(mQsExpansionHeight);
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200625 flingSettings(velocity, open, new Runnable() {
626 @Override
627 public void run() {
628 mStackScrollerOverscrolling = false;
629 mQsExpansionFromOverscroll = false;
Jorim Jaggi56306252014-07-03 00:40:09 +0200630 updateQsState();
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200631 }
632 });
Selim Cinek1408eb52014-06-02 14:45:38 +0200633 }
634
Jorim Jaggid7daab72014-05-06 22:22:20 +0200635 private void onQsExpansionStarted() {
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200636 onQsExpansionStarted(0);
637 }
638
639 private void onQsExpansionStarted(int overscrollAmount) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200640 cancelAnimation();
641
642 // Reset scroll position and apply that position to the expanded height.
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200643 float height = mQsExpansionHeight - mScrollView.getScrollY() - overscrollAmount;
Jorim Jaggi54045422014-07-03 18:30:40 +0200644 if (mScrollView.getScrollY() != 0) {
645 mScrollYOverride = mScrollView.getScrollY();
646 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200647 mScrollView.scrollTo(0, 0);
648 setQsExpansion(height);
649 }
650
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200651 private void setQsExpanded(boolean expanded) {
652 boolean changed = mQsExpanded != expanded;
653 if (changed) {
654 mQsExpanded = expanded;
655 updateQsState();
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200656 requestPanelHeightUpdate();
Jorim Jaggi56306252014-07-03 00:40:09 +0200657 mNotificationStackScroller.setInterceptDelegateEnabled(expanded);
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200658 mStatusBar.setQsExpanded(expanded);
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200659 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200660 }
661
Jorim Jaggi56306252014-07-03 00:40:09 +0200662 public void setBarState(int statusBarState) {
663 boolean keyguardShowing = statusBarState == StatusBarState.KEYGUARD
664 || statusBarState == StatusBarState.SHADE_LOCKED;
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200665 if (!mKeyguardShowing && keyguardShowing) {
666 setQsTranslation(mQsExpansionHeight);
667 mHeader.setTranslationY(0f);
668 }
Jorim Jaggi56306252014-07-03 00:40:09 +0200669 mStatusBarState = statusBarState;
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200670 mKeyguardShowing = keyguardShowing;
671 updateQsState();
672 }
673
674 private void updateQsState() {
Jorim Jaggi290600a2014-05-30 17:02:20 +0200675 boolean expandVisually = mQsExpanded || mStackScrollerOverscrolling;
676 mHeader.setExpanded(expandVisually, mStackScrollerOverscrolling);
Jorim Jaggi56306252014-07-03 00:40:09 +0200677 mNotificationStackScroller.setScrollingEnabled(mStatusBarState != StatusBarState.KEYGUARD
678 && (!mQsExpanded || mQsExpansionFromOverscroll));
Jorim Jaggi290600a2014-05-30 17:02:20 +0200679 mQsPanel.setVisibility(expandVisually ? View.VISIBLE : View.INVISIBLE);
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200680 mQsContainer.setVisibility(
681 mKeyguardShowing && !expandVisually ? View.INVISIBLE : View.VISIBLE);
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200682 mScrollView.setTouchEnabled(mQsExpanded);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200683 }
684
685 private void setQsExpansion(float height) {
686 height = Math.min(Math.max(height, mQsMinExpansionHeight), mQsMaxExpansionHeight);
John Spurlockbc3a5e92014-05-30 16:20:05 -0400687 mQsFullyExpanded = height == mQsMaxExpansionHeight;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200688 if (height > mQsMinExpansionHeight && !mQsExpanded && !mStackScrollerOverscrolling) {
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200689 setQsExpanded(true);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200690 } else if (height <= mQsMinExpansionHeight && mQsExpanded) {
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200691 setQsExpanded(false);
John Spurlock73203eb2014-04-15 16:14:46 -0400692 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200693 mQsExpansionHeight = height;
Jorim Jaggi54045422014-07-03 18:30:40 +0200694 mHeader.setExpansion(getQsExpansionFraction());
Jorim Jaggid7daab72014-05-06 22:22:20 +0200695 setQsTranslation(height);
Selim Cinek1408eb52014-06-02 14:45:38 +0200696 requestScrollerTopPaddingUpdate(false /* animate */);
Selim Cinekf54090e2014-06-17 17:24:51 -0700697 updateNotificationScrim(height);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200698 }
699
Selim Cinekf54090e2014-06-17 17:24:51 -0700700 private void updateNotificationScrim(float height) {
701 int startDistance = mQsMinExpansionHeight + mNotificationScrimWaitDistance;
702 float progress = (height - startDistance) / (mQsMaxExpansionHeight - startDistance);
703 progress = Math.max(0.0f, Math.min(progress, 1.0f));
704 mNotificationStackScroller.setScrimAlpha(progress);
705 }
706
Jorim Jaggid7daab72014-05-06 22:22:20 +0200707 private void setQsTranslation(float height) {
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200708 mQsContainer.setY(height - mQsContainer.getHeight() + getHeaderTranslation());
Jorim Jaggid7daab72014-05-06 22:22:20 +0200709 }
710
Selim Cinek1408eb52014-06-02 14:45:38 +0200711 private void requestScrollerTopPaddingUpdate(boolean animate) {
712 mNotificationStackScroller.updateTopPadding(mQsExpansionHeight,
713 mScrollView.getScrollY(),
714 mAnimateNextTopPaddingChange || animate);
Selim Cinek758afb12014-06-04 18:46:12 +0200715 mAnimateNextTopPaddingChange = false;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200716 }
717
718 private void trackMovement(MotionEvent event) {
719 if (mVelocityTracker != null) mVelocityTracker.addMovement(event);
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200720 mLastTouchX = event.getX();
721 mLastTouchY = event.getY();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200722 }
723
724 private void initVelocityTracker() {
725 if (mVelocityTracker != null) {
726 mVelocityTracker.recycle();
727 }
728 mVelocityTracker = VelocityTracker.obtain();
729 }
730
731 private float getCurrentVelocity() {
732 if (mVelocityTracker == null) {
733 return 0;
734 }
735 mVelocityTracker.computeCurrentVelocity(1000);
736 return mVelocityTracker.getYVelocity();
737 }
738
739 private void cancelAnimation() {
740 if (mQsExpansionAnimator != null) {
741 mQsExpansionAnimator.cancel();
742 }
743 }
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200744
Jorim Jaggid7daab72014-05-06 22:22:20 +0200745 private void flingSettings(float vel, boolean expand) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200746 flingSettings(vel, expand, null);
747 }
748
749 private void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200750 float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight;
Jorim Jaggi9cd731a2014-05-22 14:26:06 +0200751 if (target == mQsExpansionHeight) {
Jorim Jaggi54045422014-07-03 18:30:40 +0200752 mScrollYOverride = -1;
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200753 if (onFinishRunnable != null) {
754 onFinishRunnable.run();
755 }
Jorim Jaggi9cd731a2014-05-22 14:26:06 +0200756 return;
757 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200758 ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target);
Jorim Jaggi87cd5e72014-05-12 23:29:10 +0200759 mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200760 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
761 @Override
762 public void onAnimationUpdate(ValueAnimator animation) {
763 setQsExpansion((Float) animation.getAnimatedValue());
764 }
765 });
766 animator.addListener(new AnimatorListenerAdapter() {
767 @Override
768 public void onAnimationEnd(Animator animation) {
Jorim Jaggi54045422014-07-03 18:30:40 +0200769 mScrollYOverride = -1;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200770 mQsExpansionAnimator = null;
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200771 if (onFinishRunnable != null) {
772 onFinishRunnable.run();
773 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200774 }
775 });
776 animator.start();
777 mQsExpansionAnimator = animator;
Jorim Jaggibd003102014-07-04 00:02:42 +0200778 mQsAnimatorExpand = expand;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200779 }
780
781 /**
782 * @return Whether we should intercept a gesture to open Quick Settings.
783 */
Selim Cinek4c6969a2014-05-26 19:22:17 +0200784 private boolean shouldQuickSettingsIntercept(float x, float y, float yDiff) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200785 if (!mQsExpansionEnabled) {
786 return false;
787 }
Jorim Jaggibc5f4962014-05-12 00:00:52 +0200788 boolean onHeader = x >= mHeader.getLeft() && x <= mHeader.getRight()
John Spurlock3e04cc82014-05-30 12:34:03 -0400789 && y >= mHeader.getTop() && y <= mHeader.getBottom();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200790 if (mQsExpanded) {
John Spurlock3e04cc82014-05-30 12:34:03 -0400791 return onHeader || (mScrollView.isScrolledToBottom() && yDiff < 0);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200792 } else {
793 return onHeader;
794 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100795 }
796
797 @Override
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +0200798 public void setVisibility(int visibility) {
799 int oldVisibility = getVisibility();
800 super.setVisibility(visibility);
801 if (visibility != oldVisibility) {
802 reparentStatusIcons(visibility == VISIBLE);
803 }
804 }
805
806 /**
807 * When the notification panel gets expanded, we need to move the status icons in the header
808 * card.
809 */
810 private void reparentStatusIcons(boolean toHeader) {
811 if (mStatusBar == null) {
812 return;
813 }
814 LinearLayout systemIcons = mStatusBar.getSystemIcons();
Jorim Jaggi605f1902014-06-25 05:23:42 +0200815 ViewGroup parent = ((ViewGroup) systemIcons.getParent());
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +0200816 if (toHeader) {
Jorim Jaggi605f1902014-06-25 05:23:42 +0200817 int index = parent.indexOfChild(systemIcons);
818 parent.removeView(systemIcons);
819 mSystemIconsCopy.setMirroredView(
820 systemIcons, systemIcons.getWidth(), systemIcons.getHeight());
821 parent.addView(mSystemIconsCopy, index);
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +0200822 mHeader.attachSystemIcons(systemIcons);
823 } else {
Jorim Jaggi605f1902014-06-25 05:23:42 +0200824 ViewGroup newParent = mStatusBar.getSystemIconArea();
825 int index = newParent.indexOfChild(mSystemIconsCopy);
826 parent.removeView(systemIcons);
Jorim Jaggi13c1b1f2014-05-11 21:55:00 +0200827 mHeader.onSystemIconsDetached();
Jorim Jaggi605f1902014-06-25 05:23:42 +0200828 mSystemIconsCopy.setMirroredView(null, 0, 0);
829 newParent.removeView(mSystemIconsCopy);
830 newParent.addView(systemIcons, index);
Jorim Jaggi0d74eeb2014-05-09 22:05:24 +0200831 }
832 }
833
834 @Override
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100835 protected boolean isScrolledToBottom() {
Selim Cinekb688bf72014-06-16 16:36:51 -0700836 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
837 return true;
838 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100839 if (!isInSettings()) {
840 return mNotificationStackScroller.isScrolledToBottom();
Chris Wren64161cc2012-12-17 16:49:30 -0500841 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100842 return super.isScrolledToBottom();
843 }
844
845 @Override
846 protected int getMaxPanelHeight() {
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200847 int min = mStatusBarMinHeight;
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200848 if (mStatusBar.getBarState() != StatusBarState.KEYGUARD
849 && mNotificationStackScroller.getNotGoneChildCount() == 0) {
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200850 int minHeight = (int) ((mQsMinExpansionHeight + getOverExpansionAmount())
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200851 * HEADER_RUBBERBAND_FACTOR);
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200852 min = Math.max(min, minHeight);
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200853 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200854 int maxHeight;
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200855 if (mTwoFingerQsExpand || mQsExpanded || mIsExpanding && mQsExpandedWhenExpandingStarted) {
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200856 maxHeight = (int) calculatePanelHeightQsExpanded();
857 } else {
858 int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin();
859 maxHeight = mNotificationStackScroller.getHeight() - emptyBottomMargin
860 - mTopPaddingAdjustment;
861 maxHeight += mNotificationStackScroller.getTopPaddingOverflow();
862 }
863 maxHeight = Math.max(maxHeight, min);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200864 return maxHeight;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100865 }
866
867 private boolean isInSettings() {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200868 return mQsExpanded;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100869 }
870
871 @Override
872 protected void onHeightUpdated(float expandedHeight) {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200873 if (!mQsExpanded) {
874 positionClockAndNotifications();
875 }
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200876 if (mTwoFingerQsExpand || mQsExpanded && !mQsTracking && mQsExpansionAnimator == null
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200877 && !mQsExpansionFromOverscroll) {
878 float panelHeightQsCollapsed = mNotificationStackScroller.getIntrinsicPadding()
879 + mNotificationStackScroller.getMinStackHeight()
880 + mNotificationStackScroller.getNotificationTopPadding();
881 float panelHeightQsExpanded = calculatePanelHeightQsExpanded();
882 float t = (expandedHeight - panelHeightQsCollapsed)
883 / (panelHeightQsExpanded - panelHeightQsCollapsed);
Jorim Jaggi54045422014-07-03 18:30:40 +0200884
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200885 setQsExpansion(mQsMinExpansionHeight
Jorim Jaggi54045422014-07-03 18:30:40 +0200886 + t * (getTempQsMaxExpansion() - mQsMinExpansionHeight));
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200887 }
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200888 mNotificationStackScroller.setStackHeight(expandedHeight);
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200889 updateHeader();
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200890 updateUnlockIcon();
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200891 updateNotificationTranslucency();
892 }
893
Jorim Jaggi54045422014-07-03 18:30:40 +0200894 /**
895 * @return a temporary override of {@link #mQsMaxExpansionHeight}, which is needed when
896 * collapsing QS / the panel when QS was scrolled
897 */
898 private int getTempQsMaxExpansion() {
899 int qsTempMaxExpansion = mQsMaxExpansionHeight;
900 if (mScrollYOverride != -1) {
901 qsTempMaxExpansion -= mScrollYOverride;
902 }
903 return qsTempMaxExpansion;
904 }
905
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200906 private float calculatePanelHeightQsExpanded() {
907 float notificationHeight = mNotificationStackScroller.getHeight()
908 - mNotificationStackScroller.getEmptyBottomMargin()
909 - mNotificationStackScroller.getTopPadding();
910 float totalHeight = mQsMaxExpansionHeight + notificationHeight
911 + mNotificationStackScroller.getNotificationTopPadding();
912 if (totalHeight > mNotificationStackScroller.getHeight()) {
913 float fullyCollapsedHeight = mQsMaxExpansionHeight
914 + mNotificationStackScroller.getMinStackHeight()
Jorim Jaggi56306252014-07-03 00:40:09 +0200915 + mNotificationStackScroller.getNotificationTopPadding()
916 - getScrollViewScrollY();
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200917 totalHeight = Math.max(fullyCollapsedHeight, mNotificationStackScroller.getHeight());
918 }
919 return totalHeight;
920 }
921
Jorim Jaggi56306252014-07-03 00:40:09 +0200922 private int getScrollViewScrollY() {
923 if (mScrollYOverride != -1) {
924 return mScrollYOverride;
925 } else {
926 return mScrollView.getScrollY();
927 }
928 }
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200929 private void updateNotificationTranslucency() {
Jorim Jaggiad46ffef2014-07-04 18:05:06 +0200930 float alpha = (getNotificationsTopY() + mNotificationStackScroller.getItemHeight())
931 / (mQsMinExpansionHeight + mNotificationStackScroller.getItemHeight() / 2);
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200932 alpha = Math.max(0, Math.min(alpha, 1));
933 alpha = (float) Math.pow(alpha, 0.75);
934
935 // TODO: Draw a rect with DST_OUT over the notifications to achieve the same effect -
936 // this would be much more efficient.
937 mNotificationStackScroller.setAlpha(alpha);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200938 }
939
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200940 @Override
941 protected float getOverExpansionAmount() {
942 return mNotificationStackScroller.getCurrentOverScrollAmount(true /* top */);
943 }
944
945 @Override
946 protected float getOverExpansionPixels() {
947 return mNotificationStackScroller.getCurrentOverScrolledPixels(true /* top */);
948 }
949
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200950 private void updateUnlockIcon() {
951 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
952 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
953 boolean active = getMaxPanelHeight() - getExpandedHeight() > mUnlockMoveDistance;
954 if (active && !mUnlockIconActive && mTracking) {
955 mKeyguardBottomArea.getLockIcon().animate()
956 .alpha(1f)
957 .scaleY(LOCK_ICON_ACTIVE_SCALE)
958 .scaleX(LOCK_ICON_ACTIVE_SCALE)
959 .setInterpolator(mFastOutLinearInterpolator)
960 .setDuration(150);
961 } else if (!active && mUnlockIconActive && mTracking) {
962 mKeyguardBottomArea.getLockIcon().animate()
963 .alpha(KeyguardPageSwipeHelper.SWIPE_RESTING_ALPHA_AMOUNT)
964 .scaleY(1f)
965 .scaleX(1f)
966 .setInterpolator(mFastOutLinearInterpolator)
967 .setDuration(150);
968 }
969 mUnlockIconActive = active;
970 }
Jorim Jaggi457cc352014-06-02 22:47:42 +0200971 }
972
973 /**
974 * Hides the header when notifications are colliding with it.
975 */
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200976 private void updateHeader() {
Jorim Jaggi457cc352014-06-02 22:47:42 +0200977 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
978 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200979 updateHeaderKeyguard();
Jorim Jaggi457cc352014-06-02 22:47:42 +0200980 } else {
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200981 updateHeaderShade();
Jorim Jaggi457cc352014-06-02 22:47:42 +0200982 }
983
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100984 }
985
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200986 private void updateHeaderShade() {
987 mHeader.setAlpha(1f);
988 mHeader.setTranslationY(getHeaderTranslation());
989 setQsTranslation(mQsExpansionHeight);
990 }
991
992 private float getHeaderTranslation() {
993 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
994 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
995 return 0;
996 }
997 if (mNotificationStackScroller.getNotGoneChildCount() == 0) {
998 if (mExpandedHeight / HEADER_RUBBERBAND_FACTOR >= mQsMinExpansionHeight) {
999 return 0;
1000 } else {
1001 return mExpandedHeight / HEADER_RUBBERBAND_FACTOR - mQsMinExpansionHeight;
1002 }
1003 }
1004 return Math.min(0, mNotificationStackScroller.getTranslationY()) / HEADER_RUBBERBAND_FACTOR;
1005 }
1006
1007 private void updateHeaderKeyguard() {
1008 mHeader.setTranslationY(0f);
1009 float alpha;
1010 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
1011
1012 // When on Keyguard, we hide the header as soon as the top card of the notification
1013 // stack scroller is close enough (collision distance) to the bottom of the header.
Jorim Jaggiad46ffef2014-07-04 18:05:06 +02001014 alpha = getNotificationsTopY()
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001015 /
1016 (mQsMinExpansionHeight + mNotificationsHeaderCollideDistance);
1017
1018 } else {
1019
1020 // In SHADE_LOCKED, the top card is already really close to the header. Hide it as
1021 // soon as we start translating the stack.
Jorim Jaggiad46ffef2014-07-04 18:05:06 +02001022 alpha = getNotificationsTopY() / mQsMinExpansionHeight;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001023 }
1024 alpha = Math.max(0, Math.min(alpha, 1));
1025 alpha = (float) Math.pow(alpha, 0.75);
1026 mHeader.setAlpha(alpha);
1027 mKeyguardBottomArea.setAlpha(alpha);
1028 setQsTranslation(mQsExpansionHeight);
1029 }
1030
Jorim Jaggiad46ffef2014-07-04 18:05:06 +02001031 private float getNotificationsTopY() {
1032 if (mNotificationStackScroller.getNotGoneChildCount() == 0) {
1033 return getExpandedHeight();
1034 }
1035 return mNotificationStackScroller.getNotificationsTopY();
1036 }
1037
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001038 @Override
Selim Cinek1685e632014-04-08 02:27:49 +02001039 protected void onExpandingStarted() {
1040 super.onExpandingStarted();
1041 mNotificationStackScroller.onExpansionStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001042 mIsExpanding = true;
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001043 mQsExpandedWhenExpandingStarted = mQsExpanded;
Jorim Jaggi56306252014-07-03 00:40:09 +02001044 if (mQsExpanded) {
Jorim Jaggi56306252014-07-03 00:40:09 +02001045 onQsExpansionStarted();
1046 }
Selim Cinek1685e632014-04-08 02:27:49 +02001047 }
1048
1049 @Override
1050 protected void onExpandingFinished() {
1051 super.onExpandingFinished();
1052 mNotificationStackScroller.onExpansionStopped();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001053 mIsExpanding = false;
Jorim Jaggi56306252014-07-03 00:40:09 +02001054 mScrollYOverride = -1;
Jorim Jaggie65e3102014-07-01 22:00:50 +02001055 if (mExpandedHeight == 0f) {
1056 mHeader.setListening(false);
1057 mQsPanel.setListening(false);
1058 } else {
1059 mHeader.setListening(true);
1060 mQsPanel.setListening(true);
1061 }
Jorim Jaggi1e2554b2014-07-10 23:07:00 +02001062 mTwoFingerQsExpand = false;
1063 mTwoFingerQsExpandPossible = false;
Jorim Jaggie65e3102014-07-01 22:00:50 +02001064 }
1065
1066 @Override
1067 public void instantExpand() {
1068 super.instantExpand();
1069 mHeader.setListening(true);
1070 mQsPanel.setListening(true);
Selim Cinek1685e632014-04-08 02:27:49 +02001071 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001072
1073 @Override
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001074 protected void setOverExpansion(float overExpansion, boolean isPixels) {
Jorim Jaggi1e2554b2014-07-10 23:07:00 +02001075 if (mConflictingQsExpansionGesture || mTwoFingerQsExpand) {
Jorim Jaggidc96d632014-07-01 18:48:52 +02001076 return;
1077 }
Selim Cinek1408eb52014-06-02 14:45:38 +02001078 if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001079 mNotificationStackScroller.setOnHeightChangedListener(null);
1080 if (isPixels) {
1081 mNotificationStackScroller.setOverScrolledPixels(
1082 overExpansion, true /* onTop */, false /* animate */);
1083 } else {
1084 mNotificationStackScroller.setOverScrollAmount(
1085 overExpansion, true /* onTop */, false /* animate */);
1086 }
1087 mNotificationStackScroller.setOnHeightChangedListener(this);
Selim Cinek1408eb52014-06-02 14:45:38 +02001088 }
Selim Cinek24120a52014-05-26 10:05:42 +02001089 }
1090
1091 @Override
Jorim Jaggi282a6152014-06-02 23:37:53 +02001092 protected void onTrackingStarted() {
1093 super.onTrackingStarted();
1094 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1095 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
1096 mPageSwiper.animateHideLeftRightIcon();
1097 }
1098 }
1099
1100 @Override
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +02001101 protected void onTrackingStopped(boolean expand) {
1102 super.onTrackingStopped(expand);
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001103 if (expand) {
1104 mNotificationStackScroller.setOverScrolledPixels(
1105 0.0f, true /* onTop */, true /* animate */);
1106 }
Jorim Jaggi282a6152014-06-02 23:37:53 +02001107 if (expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1108 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) {
1109 mPageSwiper.showAllIcons(true);
1110 }
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001111 if (!expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1112 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) {
1113 mKeyguardBottomArea.getLockIcon().animate()
1114 .alpha(0f)
1115 .scaleX(2f)
1116 .scaleY(2f)
1117 .setInterpolator(mFastOutLinearInterpolator)
1118 .setDuration(100);
1119 }
Selim Cinek24120a52014-05-26 10:05:42 +02001120 }
1121
Selim Cinek24120a52014-05-26 10:05:42 +02001122 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001123 public void onHeightChanged(ExpandableView view) {
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001124
1125 // Block update if we are in quick settings and just the top padding changed
1126 // (i.e. view == null).
1127 if (view == null && mQsExpanded) {
1128 return;
1129 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001130 requestPanelHeightUpdate();
1131 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001132
1133 @Override
1134 public void onScrollChanged() {
1135 if (mQsExpanded) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001136 requestScrollerTopPaddingUpdate(false /* animate */);
Jorim Jaggi56306252014-07-03 00:40:09 +02001137 requestPanelHeightUpdate();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001138 }
1139 }
1140
1141 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +02001142 protected void onConfigurationChanged(Configuration newConfig) {
1143 super.onConfigurationChanged(newConfig);
1144 mPageSwiper.onConfigurationChanged();
1145 }
1146
1147 @Override
Jorim Jaggid7daab72014-05-06 22:22:20 +02001148 public void onClick(View v) {
Jorim Jaggi853b0702014-07-05 04:31:14 +02001149 if (v == mHeader) {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001150 onQsExpansionStarted();
1151 if (mQsExpanded) {
1152 flingSettings(0 /* vel */, false /* expand */);
1153 } else if (mQsExpansionEnabled) {
1154 flingSettings(0 /* vel */, true /* expand */);
1155 }
1156 }
1157 }
Selim Cinek4c6969a2014-05-26 19:22:17 +02001158
1159 @Override
1160 public void onAnimationToSideStarted(boolean rightPage) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001161 boolean start = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? rightPage : !rightPage;
1162 if (start) {
Selim Cinek4c6969a2014-05-26 19:22:17 +02001163 mKeyguardBottomArea.launchPhone();
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001164 } else {
1165 mKeyguardBottomArea.launchCamera();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001166 }
1167 mBlockTouches = true;
1168 }
1169
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001170 @Override
1171 protected void onEdgeClicked(boolean right) {
1172 if ((right && getRightIcon().getVisibility() != View.VISIBLE)
1173 || (!right && getLeftIcon().getVisibility() != View.VISIBLE)) {
1174 return;
1175 }
1176 mHintAnimationRunning = true;
1177 mPageSwiper.startHintAnimation(right, new Runnable() {
1178 @Override
1179 public void run() {
1180 mHintAnimationRunning = false;
1181 mStatusBar.onHintFinished();
1182 }
1183 });
Jorim Jaggi93a2bb22014-06-02 19:57:28 +02001184 startHighlightIconAnimation(right ? getRightIcon() : getLeftIcon());
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001185 boolean start = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? right : !right;
1186 if (start) {
1187 mStatusBar.onPhoneHintStarted();
1188 } else {
1189 mStatusBar.onCameraHintStarted();
1190 }
1191 }
Selim Cinek4c6969a2014-05-26 19:22:17 +02001192
1193 @Override
Jorim Jaggi93a2bb22014-06-02 19:57:28 +02001194 protected void startUnlockHintAnimation() {
1195 super.startUnlockHintAnimation();
1196 startHighlightIconAnimation(getCenterIcon());
1197 }
1198
1199 /**
1200 * Starts the highlight (making it fully opaque) animation on an icon.
1201 */
1202 private void startHighlightIconAnimation(final View icon) {
1203 icon.animate()
1204 .alpha(1.0f)
1205 .setDuration(KeyguardPageSwipeHelper.HINT_PHASE1_DURATION)
1206 .setInterpolator(mFastOutSlowInInterpolator)
1207 .withEndAction(new Runnable() {
1208 @Override
1209 public void run() {
1210 icon.animate().alpha(KeyguardPageSwipeHelper.SWIPE_RESTING_ALPHA_AMOUNT)
1211 .setDuration(KeyguardPageSwipeHelper.HINT_PHASE1_DURATION)
1212 .setInterpolator(mFastOutSlowInInterpolator);
1213 }
1214 });
1215 }
1216
1217 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +02001218 public float getPageWidth() {
1219 return getWidth();
1220 }
1221
1222 @Override
1223 public ArrayList<View> getTranslationViews() {
1224 return mSwipeTranslationViews;
1225 }
1226
1227 @Override
1228 public View getLeftIcon() {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001229 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
1230 ? mKeyguardBottomArea.getCameraImageView()
1231 : mKeyguardBottomArea.getPhoneImageView();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001232 }
1233
1234 @Override
1235 public View getCenterIcon() {
1236 return mKeyguardBottomArea.getLockIcon();
1237 }
1238
1239 @Override
1240 public View getRightIcon() {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001241 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
1242 ? mKeyguardBottomArea.getPhoneImageView()
1243 : mKeyguardBottomArea.getCameraImageView();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001244 }
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001245
1246 @Override
1247 protected float getPeekHeight() {
1248 if (mNotificationStackScroller.getNotGoneChildCount() > 0) {
1249 return mNotificationStackScroller.getPeekHeight();
1250 } else {
Jorim Jaggib472b3472014-06-30 19:56:24 +02001251 return mQsMinExpansionHeight * HEADER_RUBBERBAND_FACTOR;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001252 }
1253 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001254
1255 @Override
1256 protected float getCannedFlingDurationFactor() {
1257 if (mQsExpanded) {
1258 return 0.7f;
1259 } else {
1260 return 0.6f;
1261 }
1262 }
1263
1264 @Override
1265 protected boolean isTrackingBlocked() {
1266 return mConflictingQsExpansionGesture && mQsExpanded;
1267 }
Jorim Jaggi54045422014-07-03 18:30:40 +02001268
1269 public void notifyVisibleChildrenChanged() {
1270 if (mNotificationStackScroller.getNotGoneChildCount() != 0) {
1271 mReserveNotificationSpace.setVisibility(View.VISIBLE);
1272 } else {
1273 mReserveNotificationSpace.setVisibility(View.GONE);
1274 }
1275 }
Jorim Jaggibd003102014-07-04 00:02:42 +02001276
1277 public boolean isQsExpanded() {
1278 return mQsExpanded;
1279 }
Jorim Jaggi853b0702014-07-05 04:31:14 +02001280
1281 @Override
1282 public boolean shouldDelayChildPressedState() {
1283 return true;
1284 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04001285}