blob: fc274831de67501c0f03f2110a51649c4dd773ef [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;
Zhentao Sun04f97402015-08-26 17:37:30 -070023import android.app.ActivityManager;
Jason Monk0ceef212016-11-02 14:05:23 -040024import android.app.Fragment;
Jorim Jaggi40aa8812015-09-23 12:59:22 -070025import android.app.StatusBarManager;
Daniel Sandler08d05e32012-08-08 16:39:54 -040026import android.content.Context;
Zhentao Sun04f97402015-08-26 17:37:30 -070027import android.content.pm.ResolveInfo;
Selim Cinek4c6969a2014-05-26 19:22:17 +020028import android.content.res.Configuration;
Anthony Chen04d1ea72017-04-21 14:30:11 -070029import android.content.res.Resources;
Jorim Jaggi58bef332014-11-21 18:10:32 +010030import android.graphics.Canvas;
31import android.graphics.Color;
32import android.graphics.Paint;
Jorim Jaggi613f55f2015-07-16 15:30:10 -070033import android.graphics.Rect;
Daniel Sandler08d05e32012-08-08 16:39:54 -040034import android.util.AttributeSet;
Jorim Jaggi3afddce2014-08-14 20:44:43 +020035import android.util.MathUtils;
Daniel Sandler040c2e42012-10-17 00:56:33 -040036import android.view.MotionEvent;
Jorim Jaggid7daab72014-05-06 22:22:20 +020037import android.view.VelocityTracker;
Daniel Sandler13522a22012-09-27 14:46:58 -040038import android.view.View;
Jason Monk0ceef212016-11-02 14:05:23 -040039import android.view.ViewGroup;
Jorim Jaggi75c95042014-05-16 19:09:59 +020040import android.view.ViewTreeObserver;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070041import android.view.WindowInsets;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070042import android.view.accessibility.AccessibilityEvent;
John Spurlock7e6809a2014-08-06 16:03:14 -040043import android.widget.FrameLayout;
Selim Cinekf99d0002014-06-13 07:36:01 +020044import android.widget.TextView;
Chris Wren49f06f52015-05-01 16:12:12 -040045import com.android.internal.logging.MetricsLogger;
Chris Wren27a52fa2017-02-01 14:21:43 -050046import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jorim Jaggid09def7512014-09-02 18:36:45 +020047import com.android.keyguard.KeyguardStatusView;
Jorim Jaggi613f55f2015-07-16 15:30:10 -070048import com.android.systemui.DejankUtils;
Winsonc0d70582016-01-29 10:24:39 -080049import com.android.systemui.Interpolators;
Chet Haase4d179dc2012-08-22 07:14:42 -070050import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070051import com.android.systemui.classifier.FalsingManager;
Jason Monk0ceef212016-11-02 14:05:23 -040052import com.android.systemui.fragments.FragmentHostManager;
53import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
54import com.android.systemui.plugins.qs.QS;
Selim Cinek1f3f5442015-04-10 17:54:46 -070055import com.android.systemui.statusbar.ExpandableNotificationRow;
Jorim Jaggibe565df2014-04-28 17:51:23 +020056import com.android.systemui.statusbar.ExpandableView;
Jorim Jaggi87cd5e72014-05-12 23:29:10 +020057import com.android.systemui.statusbar.FlingAnimationUtils;
Daniel Sandler151f00d2012-10-02 22:33:08 -040058import com.android.systemui.statusbar.GestureRecorder;
Selim Cinekbaa23272014-07-08 18:01:07 +020059import com.android.systemui.statusbar.KeyguardAffordanceView;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070060import com.android.systemui.statusbar.NotificationData;
Anthony Chen9e05d462017-04-07 10:10:21 -070061import com.android.systemui.statusbar.NotificationShelf;
Jorim Jaggiecbab362014-04-23 16:13:15 +020062import com.android.systemui.statusbar.StatusBarState;
Selim Cinek94c2d822016-07-13 18:50:04 -070063import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070064import com.android.systemui.statusbar.policy.HeadsUpManager;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020065import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
Selim Cineka7d4f822016-12-06 14:34:47 -080066import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010067import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Jorim Jaggi75c95042014-05-16 19:09:59 +020068import com.android.systemui.statusbar.stack.StackStateAnimator;
Daniel Sandler08d05e32012-08-08 16:39:54 -040069
Zhentao Sun04f97402015-08-26 17:37:30 -070070import java.util.List;
71
Jorim Jaggibe565df2014-04-28 17:51:23 +020072public class NotificationPanelView extends PanelView implements
Jason Monk8b9d67f2016-03-02 08:59:08 -050073 ExpandableView.OnHeightChangedListener,
Jorim Jaggi290600a2014-05-30 17:02:20 +020074 View.OnClickListener, NotificationStackScrollLayout.OnOverscrollTopChangedListener,
Selim Cinekb8f09cf2015-03-16 17:09:28 -070075 KeyguardAffordanceHelper.Callback, NotificationStackScrollLayout.OnEmptySpaceClickListener,
Selim Cineka7d4f822016-12-06 14:34:47 -080076 OnHeadsUpChangedListener, QS.HeightListener {
Chet Haase4d179dc2012-08-22 07:14:42 -070077
Jorim Jaggi58bef332014-11-21 18:10:32 +010078 private static final boolean DEBUG = false;
79
Selim Cinekf99d0002014-06-13 07:36:01 +020080 // Cap and total height of Roboto font. Needs to be adjusted when font for the big clock is
81 // changed.
82 private static final int CAP_HEIGHT = 1456;
83 private static final int FONT_HEIGHT = 2163;
84
Jorim Jaggi8dd95e02014-06-03 16:19:33 +020085 private static final float LOCK_ICON_ACTIVE_SCALE = 1.2f;
Selim Cineka02fe522014-05-30 17:01:21 +020086
Doris Ling3c00afb2016-07-19 17:04:21 -070087 static final String COUNTER_PANEL_OPEN = "panel_open";
88 static final String COUNTER_PANEL_OPEN_QS = "panel_open_qs";
Chris Wren49f06f52015-05-01 16:12:12 -040089 private static final String COUNTER_PANEL_OPEN_PEEK = "panel_open_peek";
90
Jorim Jaggi613f55f2015-07-16 15:30:10 -070091 private static final Rect mDummyDirtyRect = new Rect(0, 0, 1, 1);
92
Jorim Jaggi16423aa2014-10-28 11:42:58 +010093 public static final long DOZE_ANIMATION_DURATION = 700;
John Spurlock8b12f222014-09-09 11:54:11 -040094
Adrian Roose31f30e2017-01-25 14:48:15 -080095 private KeyguardAffordanceHelper mAffordanceHelper;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020096 private KeyguardUserSwitcher mKeyguardUserSwitcher;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020097 private KeyguardStatusBarView mKeyguardStatusBar;
Jason Monk0ceef212016-11-02 14:05:23 -040098 private QS mQs;
99 private FrameLayout mQsFrame;
Jorim Jaggid09def7512014-09-02 18:36:45 +0200100 private KeyguardStatusView mKeyguardStatusView;
Selim Cinekf99d0002014-06-13 07:36:01 +0200101 private TextView mClockView;
Jorim Jaggi54045422014-07-03 18:30:40 +0200102 private View mReserveNotificationSpace;
Jorim Jaggidd5b8862014-08-05 21:04:39 +0200103 private View mQsNavbarScrim;
Xiaohui Chen5da71352016-02-22 10:04:41 -0800104 protected NotificationsQuickSettingsContainer mNotificationContainerParent;
Xiaohui Chen9528f432016-02-12 15:03:18 -0800105 protected NotificationStackScrollLayout mNotificationStackScroller;
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200106 private boolean mAnimateNextTopPaddingChange;
Chet Haase4d179dc2012-08-22 07:14:42 -0700107
Jorim Jaggid7daab72014-05-06 22:22:20 +0200108 private int mTrackingPointer;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800109 private VelocityTracker mQsVelocityTracker;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200110 private boolean mQsTracking;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200111
112 /**
Jorim Jaggidc96d632014-07-01 18:48:52 +0200113 * If set, the ongoing touch gesture might both trigger the expansion in {@link PanelView} and
114 * the expansion for quick settings.
115 */
116 private boolean mConflictingQsExpansionGesture;
117
118 /**
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200119 * Whether we are currently handling a motion gesture in #onInterceptTouchEvent, but haven't
120 * intercepted yet.
121 */
122 private boolean mIntercepting;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700123 private boolean mPanelExpanded;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200124 private boolean mQsExpanded;
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200125 private boolean mQsExpandedWhenExpandingStarted;
John Spurlockbc3a5e92014-05-30 16:20:05 -0400126 private boolean mQsFullyExpanded;
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200127 private boolean mKeyguardShowing;
John Spurlockd54da8a2014-08-03 23:23:52 -0400128 private boolean mDozing;
Jorim Jaggi1cf6e102015-01-20 16:45:05 +0100129 private boolean mDozingOnDown;
Jiaquan He92bce832016-05-11 10:30:01 -0700130 protected int mStatusBarState;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200131 private float mInitialHeightOnTouch;
132 private float mInitialTouchX;
133 private float mInitialTouchY;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200134 private float mLastTouchX;
135 private float mLastTouchY;
Xiaohui Chen9528f432016-02-12 15:03:18 -0800136 protected float mQsExpansionHeight;
137 protected int mQsMinExpansionHeight;
138 protected int mQsMaxExpansionHeight;
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200139 private int mQsPeekHeight;
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800140 private boolean mQsOverscrollExpansionEnabled;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200141 private boolean mStackScrollerOverscrolling;
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200142 private boolean mQsExpansionFromOverscroll;
Jorim Jaggi11c071a2014-08-14 19:17:11 +0200143 private float mLastOverscroll;
Muyuan Li59690042016-03-23 16:45:16 -0700144 protected boolean mQsExpansionEnabled = true;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200145 private ValueAnimator mQsExpansionAnimator;
Jorim Jaggi87cd5e72014-05-12 23:29:10 +0200146 private FlingAnimationUtils mFlingAnimationUtils;
Selim Cinek9dbbca82014-05-15 15:23:37 +0200147 private int mStatusBarMinHeight;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200148 private boolean mUnlockIconActive;
Jorim Jaggi457cc352014-06-02 22:47:42 +0200149 private int mNotificationsHeaderCollideDistance;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200150 private int mUnlockMoveDistance;
Jorim Jaggi48bc36a2014-07-25 23:16:04 +0200151 private float mEmptyDragAmount;
John Spurlock3e04cc82014-05-30 12:34:03 -0400152
Jorim Jaggi75c95042014-05-16 19:09:59 +0200153 private ObjectAnimator mClockAnimator;
154 private int mClockAnimationTarget = -1;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200155 private int mTopPaddingAdjustment;
156 private KeyguardClockPositionAlgorithm mClockPositionAlgorithm =
157 new KeyguardClockPositionAlgorithm();
158 private KeyguardClockPositionAlgorithm.Result mClockPositionResult =
159 new KeyguardClockPositionAlgorithm.Result();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200160 private boolean mIsExpanding;
Selim Cinekf99d0002014-06-13 07:36:01 +0200161
Selim Cinek4c6969a2014-05-26 19:22:17 +0200162 private boolean mBlockTouches;
Selim Cinekf54090e2014-06-17 17:24:51 -0700163 private int mNotificationScrimWaitDistance;
Jason Monk3c68ca22015-01-30 11:30:29 -0500164 // Used for two finger gesture as well as accessibility shortcut to QS.
165 private boolean mQsExpandImmediate;
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200166 private boolean mTwoFingerQsExpandPossible;
Jorim Jaggi56306252014-07-03 00:40:09 +0200167
168 /**
169 * If we are in a panel collapsing motion, we reset scrollY of our scroll view but still
170 * need to take this into account in our panel height calculation.
171 */
Jorim Jaggibd003102014-07-04 00:02:42 +0200172 private boolean mQsAnimatorExpand;
Selim Cinekbaa23272014-07-08 18:01:07 +0200173 private boolean mIsLaunchTransitionFinished;
174 private boolean mIsLaunchTransitionRunning;
175 private Runnable mLaunchAnimationEndRunnable;
176 private boolean mOnlyAffordanceInThisMotion;
Jorim Jaggi6ff837a2014-07-31 21:46:39 +0200177 private boolean mKeyguardStatusViewAnimating;
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100178 private ValueAnimator mQsSizeChangeAnimator;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200179
Selim Cinek24176c32017-03-01 16:50:30 -0800180 private boolean mShowEmptyShadeView;
Jorim Jaggia2052ea2014-08-05 16:22:30 +0200181
Jorim Jaggidd5b8862014-08-05 21:04:39 +0200182 private boolean mQsScrimEnabled = true;
Selim Cinek90c94652014-08-18 16:46:22 +0200183 private boolean mLastAnnouncementWasQuickSettings;
Selim Cinek19c8c702014-08-25 22:09:19 +0200184 private boolean mQsTouchAboveFalsingThreshold;
185 private int mQsFalsingThreshold;
Jorim Jaggidd5b8862014-08-05 21:04:39 +0200186
Jorim Jaggi16423aa2014-10-28 11:42:58 +0100187 private float mKeyguardStatusBarAnimateAlpha = 1f;
Lucas Dupin8c08a352017-05-01 14:46:33 -0700188 private float mQsClockAlphaOverride = 1f;
Jorim Jaggi0a818222014-11-10 19:04:34 +0100189 private int mOldLayoutDirection;
Selim Cinek684a4422015-04-15 16:18:39 -0700190 private HeadsUpTouchHelper mHeadsUpTouchHelper;
191 private boolean mIsExpansionFromHeadsUp;
Selim Cinek79d79c42015-05-21 16:14:45 -0700192 private boolean mListenForHeadsUp;
Selim Cinek684a4422015-04-15 16:18:39 -0700193 private int mNavigationBarBottomHeight;
Selim Cinekd2281152015-04-10 14:37:46 -0700194 private boolean mExpandingFromHeadsUp;
Selim Cinek684a4422015-04-15 16:18:39 -0700195 private boolean mCollapsedOnDown;
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700196 private int mPositionMinSideMargin;
Selim Cineka981d082016-08-03 14:45:31 -0700197 private int mMaxFadeoutHeight;
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700198 private int mLastOrientation = -1;
Selim Cinekbbc580b2015-06-03 14:11:03 +0200199 private boolean mClosingWithAlphaFadeOut;
Selim Cinek0fccc722015-07-29 17:04:36 -0700200 private boolean mHeadsUpAnimatingAway;
Selim Cinek372d1bd2015-08-14 13:19:37 -0700201 private boolean mLaunchingAffordance;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700202 private FalsingManager mFalsingManager;
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700203 private String mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700204
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700205 private Runnable mHeadsUpExistenceChangedRunnable = new Runnable() {
206 @Override
207 public void run() {
Selim Cinekcafa87f2016-10-26 17:00:17 -0700208 setHeadsUpAnimatingAway(false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700209 notifyBarPanelExpansionChanged();
210 }
211 };
Selim Cinek53f8e7d2016-03-25 02:28:01 -0700212 private NotificationGroupManager mGroupManager;
Selim Cinek24176c32017-03-01 16:50:30 -0800213 private boolean mShowIconsWhenExpanded;
Selim Cinek378053a2016-12-07 15:41:28 -0800214 private int mIndicationBottomPadding;
Adrian Roos75fa9642017-04-18 11:34:56 -0700215 private int mAmbientIndicationBottomPadding;
Selim Cinekfcff4c62016-12-27 14:26:06 +0100216 private boolean mIsFullWidth;
Adrian Roosc934c432017-01-13 11:44:56 -0800217 private boolean mDark;
Chris Wren27a52fa2017-02-01 14:21:43 -0500218 private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
Selim Cinek24176c32017-03-01 16:50:30 -0800219 private boolean mNoVisibleNotifications = true;
Jorim Jaggi16423aa2014-10-28 11:42:58 +0100220
Daniel Sandler08d05e32012-08-08 16:39:54 -0400221 public NotificationPanelView(Context context, AttributeSet attrs) {
222 super(context, attrs);
Jorim Jaggi58bef332014-11-21 18:10:32 +0100223 setWillNotDraw(!DEBUG);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700224 mFalsingManager = FalsingManager.getInstance(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800225 mQsOverscrollExpansionEnabled =
226 getResources().getBoolean(R.bool.config_enableQuickSettingsOverscrollExpansion);
Daniel Sandler13522a22012-09-27 14:46:58 -0400227 }
Chet Haase4d179dc2012-08-22 07:14:42 -0700228
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500229 public void setStatusBar(StatusBar bar) {
Daniel Sandler040c2e42012-10-17 00:56:33 -0400230 mStatusBar = bar;
231 }
232
Daniel Sandler13522a22012-09-27 14:46:58 -0400233 @Override
234 protected void onFinishInflate() {
235 super.onFinishInflate();
Alan Viverette51efddb2017-04-05 10:00:01 -0400236 mKeyguardStatusBar = findViewById(R.id.keyguard_header);
237 mKeyguardStatusView = findViewById(R.id.keyguard_status_view);
238 mClockView = findViewById(R.id.clock_view);
Jason Monkd075b212016-05-25 12:30:51 -0400239
240 mNotificationContainerParent = (NotificationsQuickSettingsContainer)
241 findViewById(R.id.notification_container_parent);
242 mNotificationStackScroller = (NotificationStackScrollLayout)
243 findViewById(R.id.notification_stack_scroller);
244 mNotificationStackScroller.setOnHeightChangedListener(this);
245 mNotificationStackScroller.setOverscrollTopChangedListener(this);
246 mNotificationStackScroller.setOnEmptySpaceClickListener(this);
Alan Viverette51efddb2017-04-05 10:00:01 -0400247 mKeyguardBottomArea = findViewById(R.id.keyguard_bottom_area);
Jason Monkd075b212016-05-25 12:30:51 -0400248 mQsNavbarScrim = findViewById(R.id.qs_navbar_scrim);
Adrian Roose31f30e2017-01-25 14:48:15 -0800249 mAffordanceHelper = new KeyguardAffordanceHelper(this, getContext());
250 mKeyguardBottomArea.setAffordanceHelper(mAffordanceHelper);
Jason Monkd075b212016-05-25 12:30:51 -0400251 mLastOrientation = getResources().getConfiguration().orientation;
252
Alan Viverette51efddb2017-04-05 10:00:01 -0400253 mQsFrame = findViewById(R.id.qs_frame);
Jason Monk0ceef212016-11-02 14:05:23 -0400254 }
John Spurlockbceed062014-08-10 18:04:16 -0400255
Jason Monk0ceef212016-11-02 14:05:23 -0400256 @Override
257 protected void onAttachedToWindow() {
258 super.onAttachedToWindow();
259 FragmentHostManager.get(this).addTagListener(QS.TAG, mFragmentListener);
260 }
261
262 @Override
263 protected void onDetachedFromWindow() {
264 super.onDetachedFromWindow();
265 FragmentHostManager.get(this).removeTagListener(QS.TAG, mFragmentListener);
Jorim Jaggi069cd032014-05-15 03:09:01 +0200266 }
267
268 @Override
269 protected void loadDimens() {
270 super.loadDimens();
Jorim Jaggi1d480692014-05-20 19:41:58 +0200271 mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.4f);
Selim Cinek9dbbca82014-05-15 15:23:37 +0200272 mStatusBarMinHeight = getResources().getDimensionPixelSize(
273 com.android.internal.R.dimen.status_bar_height);
Jorim Jaggif62f2bb2014-05-25 22:28:41 +0200274 mQsPeekHeight = getResources().getDimensionPixelSize(R.dimen.qs_peek_height);
Jorim Jaggi457cc352014-06-02 22:47:42 +0200275 mNotificationsHeaderCollideDistance =
276 getResources().getDimensionPixelSize(R.dimen.header_notifications_collide_distance);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200277 mUnlockMoveDistance = getResources().getDimensionPixelOffset(R.dimen.unlock_move_distance);
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200278 mClockPositionAlgorithm.loadDimens(getResources());
Selim Cinekf54090e2014-06-17 17:24:51 -0700279 mNotificationScrimWaitDistance =
280 getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance);
Selim Cinek19c8c702014-08-25 22:09:19 +0200281 mQsFalsingThreshold = getResources().getDimensionPixelSize(
282 R.dimen.qs_falsing_threshold);
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700283 mPositionMinSideMargin = getResources().getDimensionPixelSize(
284 R.dimen.notification_panel_min_side_margin);
Selim Cineka981d082016-08-03 14:45:31 -0700285 mMaxFadeoutHeight = getResources().getDimensionPixelSize(
286 R.dimen.max_notification_fadeout_height);
Selim Cinek378053a2016-12-07 15:41:28 -0800287 mIndicationBottomPadding = getResources().getDimensionPixelSize(
288 R.dimen.keyguard_indication_bottom_padding);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200289 }
290
John Spurlock7e6809a2014-08-06 16:03:14 -0400291 public void updateResources() {
Anthony Chen04d1ea72017-04-21 14:30:11 -0700292 Resources res = getResources();
293 int qsWidth = res.getDimensionPixelSize(R.dimen.qs_panel_width);
John Spurlock7e6809a2014-08-06 16:03:14 -0400294 int panelGravity = getResources().getInteger(R.integer.notification_panel_layout_gravity);
Jason Monk845b3b92016-03-10 14:38:13 -0500295 FrameLayout.LayoutParams lp =
Jason Monk0ceef212016-11-02 14:05:23 -0400296 (FrameLayout.LayoutParams) mQsFrame.getLayoutParams();
Anthony Chen04d1ea72017-04-21 14:30:11 -0700297 if (lp.width != qsWidth || lp.gravity != panelGravity) {
298 lp.width = qsWidth;
John Spurlock7e6809a2014-08-06 16:03:14 -0400299 lp.gravity = panelGravity;
Jason Monk0ceef212016-11-02 14:05:23 -0400300 mQsFrame.setLayoutParams(lp);
John Spurlock7e6809a2014-08-06 16:03:14 -0400301 }
302
Anthony Chen04d1ea72017-04-21 14:30:11 -0700303 int panelWidth = res.getDimensionPixelSize(R.dimen.notification_panel_width);
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200304 lp = (FrameLayout.LayoutParams) mNotificationStackScroller.getLayoutParams();
Selim Cinek9e87cba2017-02-17 13:01:01 -0800305 if (lp.width != panelWidth || lp.gravity != panelGravity) {
John Spurlock7e6809a2014-08-06 16:03:14 -0400306 lp.width = panelWidth;
307 lp.gravity = panelGravity;
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200308 mNotificationStackScroller.setLayoutParams(lp);
309 }
John Spurlock7e6809a2014-08-06 16:03:14 -0400310 }
311
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200312 @Override
313 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
314 super.onLayout(changed, left, top, right, bottom);
Selim Cinekfcff4c62016-12-27 14:26:06 +0100315 setIsFullWidth(mNotificationStackScroller.getWidth() == getWidth());
Jorim Jaggid7daab72014-05-06 22:22:20 +0200316
Selim Cinekf99d0002014-06-13 07:36:01 +0200317 // Update Clock Pivot
318 mKeyguardStatusView.setPivotX(getWidth() / 2);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200319 mKeyguardStatusView.setPivotY((FONT_HEIGHT - CAP_HEIGHT) / 2048f * mClockView.getTextSize());
Selim Cinekf99d0002014-06-13 07:36:01 +0200320
Jorim Jaggid7daab72014-05-06 22:22:20 +0200321 // Calculate quick setting heights.
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100322 int oldMaxHeight = mQsMaxExpansionHeight;
Jason Monk0ceef212016-11-02 14:05:23 -0400323 if (mQs != null) {
324 mQsMinExpansionHeight = mKeyguardShowing ? 0 : mQs.getQsMinExpansionHeight();
325 mQsMaxExpansionHeight = mQs.getDesiredHeight();
326 }
Selim Cinek237a7012014-09-10 18:12:18 +0200327 positionClockAndNotifications();
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100328 if (mQsExpanded && mQsFullyExpanded) {
329 mQsExpansionHeight = mQsMaxExpansionHeight;
330 requestScrollerTopPaddingUpdate(false /* animate */);
331 requestPanelHeightUpdate();
332
333 // Size has changed, start an animation.
334 if (mQsMaxExpansionHeight != oldMaxHeight) {
335 startQsSizeChangeAnimation(oldMaxHeight, mQsMaxExpansionHeight);
John Spurlockbc3a5e92014-05-30 16:20:05 -0400336 }
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100337 } else if (!mQsExpanded) {
Jorim Jaggi11c071a2014-08-14 19:17:11 +0200338 setQsExpansion(mQsMinExpansionHeight + mLastOverscroll);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200339 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700340 updateExpandedHeight(getExpandedHeight());
Jorim Jaggi0bc49172014-11-03 15:52:13 +0100341 updateHeader();
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100342
343 // If we are running a size change animation, the animation takes care of the height of
344 // the container. However, if we are not animating, we always need to make the QS container
345 // the desired height so when closing the QS detail, it stays smaller after the size change
346 // animation is finished but the detail view is still being animated away (this animation
347 // takes longer than the size change animation).
Jason Monk0ceef212016-11-02 14:05:23 -0400348 if (mQsSizeChangeAnimator == null && mQs != null) {
349 mQs.setHeightOverride(mQs.getDesiredHeight());
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100350 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700351 updateMaxHeadsUpTranslation();
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200352 }
353
Selim Cinekfcff4c62016-12-27 14:26:06 +0100354 private void setIsFullWidth(boolean isFullWidth) {
355 mIsFullWidth = isFullWidth;
356 mNotificationStackScroller.setIsFullWidth(isFullWidth);
357 }
358
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100359 private void startQsSizeChangeAnimation(int oldHeight, final int newHeight) {
360 if (mQsSizeChangeAnimator != null) {
361 oldHeight = (int) mQsSizeChangeAnimator.getAnimatedValue();
362 mQsSizeChangeAnimator.cancel();
363 }
364 mQsSizeChangeAnimator = ValueAnimator.ofInt(oldHeight, newHeight);
365 mQsSizeChangeAnimator.setDuration(300);
Selim Cinekc18010f2016-01-20 13:41:30 -0800366 mQsSizeChangeAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100367 mQsSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
368 @Override
369 public void onAnimationUpdate(ValueAnimator animation) {
370 requestScrollerTopPaddingUpdate(false /* animate */);
371 requestPanelHeightUpdate();
372 int height = (int) mQsSizeChangeAnimator.getAnimatedValue();
Jason Monk0ceef212016-11-02 14:05:23 -0400373 mQs.setHeightOverride(height);
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100374 }
375 });
376 mQsSizeChangeAnimator.addListener(new AnimatorListenerAdapter() {
377 @Override
378 public void onAnimationEnd(Animator animation) {
379 mQsSizeChangeAnimator = null;
380 }
381 });
382 mQsSizeChangeAnimator.start();
383 }
384
Jorim Jaggi069cd032014-05-15 03:09:01 +0200385 /**
386 * Positions the clock and notifications dynamically depending on how many notifications are
387 * showing.
388 */
389 private void positionClockAndNotifications() {
Selim Cinekf99d0002014-06-13 07:36:01 +0200390 boolean animate = mNotificationStackScroller.isAddOrRemoveAnimationPending();
Selim Cinek1408eb52014-06-02 14:45:38 +0200391 int stackScrollerPadding;
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200392 if (mStatusBarState != StatusBarState.KEYGUARD) {
Jason Monk0ceef212016-11-02 14:05:23 -0400393 stackScrollerPadding = (mQs != null ? mQs.getHeader().getHeight() : 0) + mQsPeekHeight;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200394 mTopPaddingAdjustment = 0;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200395 } else {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200396 mClockPositionAlgorithm.setup(
397 mStatusBar.getMaxKeyguardNotifications(),
398 getMaxPanelHeight(),
399 getExpandedHeight(),
400 mNotificationStackScroller.getNotGoneChildCount(),
401 getHeight(),
Jorim Jaggi48bc36a2014-07-25 23:16:04 +0200402 mKeyguardStatusView.getHeight(),
Adrian Roosc934c432017-01-13 11:44:56 -0800403 mEmptyDragAmount,
404 mKeyguardStatusView.getClockBottom(),
405 mDark);
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200406 mClockPositionAlgorithm.run(mClockPositionResult);
Selim Cinekf99d0002014-06-13 07:36:01 +0200407 if (animate || mClockAnimator != null) {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200408 startClockAnimation(mClockPositionResult.clockY);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200409 } else {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200410 mKeyguardStatusView.setY(mClockPositionResult.clockY);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200411 }
Selim Cinekf99d0002014-06-13 07:36:01 +0200412 updateClock(mClockPositionResult.clockAlpha, mClockPositionResult.clockScale);
Selim Cinek1408eb52014-06-02 14:45:38 +0200413 stackScrollerPadding = mClockPositionResult.stackScrollerPadding;
Jorim Jaggi7d16bb12014-05-22 04:24:50 +0200414 mTopPaddingAdjustment = mClockPositionResult.stackScrollerPaddingAdjustment;
Jorim Jaggi069cd032014-05-15 03:09:01 +0200415 }
Selim Cinek1408eb52014-06-02 14:45:38 +0200416 mNotificationStackScroller.setIntrinsicPadding(stackScrollerPadding);
Selim Cinekf99d0002014-06-13 07:36:01 +0200417 requestScrollerTopPaddingUpdate(animate);
Jorim Jaggi069cd032014-05-15 03:09:01 +0200418 }
419
Selim Cinek5f71bee2015-11-18 10:25:23 -0800420 /**
421 * @param maximum the maximum to return at most
422 * @return the maximum keyguard notifications that can fit on the screen
423 */
424 public int computeMaxKeyguardNotifications(int maximum) {
425 float minPadding = mClockPositionAlgorithm.getMinStackScrollerPadding(getHeight(),
426 mKeyguardStatusView.getHeight());
Selim Cinekcacc6042016-01-21 16:16:41 -0800427 int notificationPadding = Math.max(1, getResources().getDimensionPixelSize(
428 R.dimen.notification_divider_height));
Anthony Chen9e05d462017-04-07 10:10:21 -0700429 NotificationShelf shelf = mNotificationStackScroller.getNotificationShelf();
430 float shelfSize = shelf.getVisibility() == GONE ? 0
431 : shelf.getIntrinsicHeight() + notificationPadding;
Selim Cinek378053a2016-12-07 15:41:28 -0800432 float availableSpace = mNotificationStackScroller.getHeight() - minPadding - shelfSize
Adrian Roos75fa9642017-04-18 11:34:56 -0700433 - Math.max(mIndicationBottomPadding, mAmbientIndicationBottomPadding);
Selim Cinek5f71bee2015-11-18 10:25:23 -0800434 int count = 0;
435 for (int i = 0; i < mNotificationStackScroller.getChildCount(); i++) {
436 ExpandableView child = (ExpandableView) mNotificationStackScroller.getChildAt(i);
437 if (!(child instanceof ExpandableNotificationRow)) {
438 continue;
439 }
Selim Cinekfa760d42016-05-10 15:50:53 -0400440 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cinek53f8e7d2016-03-25 02:28:01 -0700441 boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup(
Selim Cinekfa760d42016-05-10 15:50:53 -0400442 row.getStatusBarNotification());
Selim Cinek53f8e7d2016-03-25 02:28:01 -0700443 if (suppressedSummary) {
444 continue;
445 }
Selim Cinekfa760d42016-05-10 15:50:53 -0400446 if (!mStatusBar.shouldShowOnKeyguard(row.getStatusBarNotification())) {
447 continue;
448 }
449 if (row.isRemoved()) {
450 continue;
451 }
Selim Cinek587cbf32016-01-19 11:36:18 -0800452 availableSpace -= child.getMinHeight() + notificationPadding;
Selim Cinek5f71bee2015-11-18 10:25:23 -0800453 if (availableSpace >= 0 && count < maximum) {
454 count++;
Selim Cinek281c2022016-10-13 19:14:43 -0700455 } else if (availableSpace > -shelfSize) {
456 // if we are exactly the last view, then we can show us still!
457 for (int j = i + 1; j < mNotificationStackScroller.getChildCount(); j++) {
458 if (mNotificationStackScroller.getChildAt(j)
459 instanceof ExpandableNotificationRow) {
460 return count;
461 }
462 }
463 count++;
464 return count;
Selim Cinek5f71bee2015-11-18 10:25:23 -0800465 } else {
466 return count;
467 }
468 }
469 return count;
470 }
471
Jorim Jaggi75c95042014-05-16 19:09:59 +0200472 private void startClockAnimation(int y) {
473 if (mClockAnimationTarget == y) {
474 return;
475 }
476 mClockAnimationTarget = y;
477 getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
478 @Override
479 public boolean onPreDraw() {
480 getViewTreeObserver().removeOnPreDrawListener(this);
481 if (mClockAnimator != null) {
482 mClockAnimator.removeAllListeners();
483 mClockAnimator.cancel();
484 }
Jorim Jaggia1b1c7a2014-06-03 16:29:05 +0200485 mClockAnimator = ObjectAnimator
486 .ofFloat(mKeyguardStatusView, View.Y, mClockAnimationTarget);
Selim Cinekc18010f2016-01-20 13:41:30 -0800487 mClockAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200488 mClockAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
489 mClockAnimator.addListener(new AnimatorListenerAdapter() {
490 @Override
491 public void onAnimationEnd(Animator animation) {
492 mClockAnimator = null;
493 mClockAnimationTarget = -1;
494 }
495 });
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200496 mClockAnimator.start();
Jorim Jaggi75c95042014-05-16 19:09:59 +0200497 return true;
498 }
499 });
500 }
501
Selim Cinekf99d0002014-06-13 07:36:01 +0200502 private void updateClock(float alpha, float scale) {
Jorim Jaggi6ff837a2014-07-31 21:46:39 +0200503 if (!mKeyguardStatusViewAnimating) {
Lucas Dupin8c08a352017-05-01 14:46:33 -0700504 mKeyguardStatusView.setAlpha(alpha * mQsClockAlphaOverride);
Jorim Jaggi6ff837a2014-07-31 21:46:39 +0200505 }
Selim Cinekf99d0002014-06-13 07:36:01 +0200506 mKeyguardStatusView.setScaleX(scale);
507 mKeyguardStatusView.setScaleY(scale);
Jorim Jaggi069cd032014-05-15 03:09:01 +0200508 }
509
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200510 public void animateToFullShade(long delay) {
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200511 mAnimateNextTopPaddingChange = true;
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200512 mNotificationStackScroller.goToFullShade(delay);
Jorim Jaggi98fb09c2014-05-01 22:40:56 +0200513 requestLayout();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400514 }
515
Jorim Jaggid7daab72014-05-06 22:22:20 +0200516 public void setQsExpansionEnabled(boolean qsExpansionEnabled) {
517 mQsExpansionEnabled = qsExpansionEnabled;
Jason Monk0ceef212016-11-02 14:05:23 -0400518 if (mQs == null) return;
519 mQs.setHeaderClickable(qsExpansionEnabled);
Jorim Jaggid7daab72014-05-06 22:22:20 +0200520 }
521
Selim Cinek3c4635c2014-05-29 02:12:47 +0200522 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +0200523 public void resetViews() {
Selim Cinekbaa23272014-07-08 18:01:07 +0200524 mIsLaunchTransitionFinished = false;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200525 mBlockTouches = false;
Jorim Jaggi8dd95e02014-06-03 16:19:33 +0200526 mUnlockIconActive = false;
Selim Cinek372d1bd2015-08-14 13:19:37 -0700527 if (!mLaunchingAffordance) {
Adrian Roose31f30e2017-01-25 14:48:15 -0800528 mAffordanceHelper.reset(false);
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700529 mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
Selim Cinek372d1bd2015-08-14 13:19:37 -0700530 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200531 closeQs();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700532 mStatusBar.closeAndSaveGuts(true /* leavebehind */, true /* force */,
533 true /* controls */, -1 /* x */, -1 /* y */, true /* resetMenu */);
Jorim Jaggidbbf45e2014-06-25 21:54:48 +0200534 mNotificationStackScroller.setOverScrollAmount(0f, true /* onTop */, false /* animate */,
535 true /* cancelAnimators */);
Selim Cinekb24e0a92015-06-09 20:17:30 -0700536 mNotificationStackScroller.resetScrollPosition();
Selim Cinek4c6969a2014-05-26 19:22:17 +0200537 }
538
Jorim Jaggid7daab72014-05-06 22:22:20 +0200539 public void closeQs() {
Selim Cinek831941f2015-06-17 15:09:30 -0700540 cancelQsAnimation();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200541 setQsExpansion(mQsMinExpansionHeight);
542 }
543
Jorim Jaggibd003102014-07-04 00:02:42 +0200544 public void animateCloseQs() {
545 if (mQsExpansionAnimator != null) {
546 if (!mQsAnimatorExpand) {
547 return;
548 }
549 float height = mQsExpansionHeight;
550 mQsExpansionAnimator.cancel();
551 setQsExpansion(height);
552 }
553 flingSettings(0 /* vel */, false);
554 }
555
Jorim Jaggid7daab72014-05-06 22:22:20 +0200556 public void openQs() {
Selim Cinek831941f2015-06-17 15:09:30 -0700557 cancelQsAnimation();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200558 if (mQsExpansionEnabled) {
559 setQsExpansion(mQsMaxExpansionHeight);
560 }
561 }
562
Jason Monk3c68ca22015-01-30 11:30:29 -0500563 public void expandWithQs() {
564 if (mQsExpansionEnabled) {
565 mQsExpandImmediate = true;
566 }
Oren Blasberg8d3fea12015-07-10 14:21:44 -0700567 expand(true /* animate */);
Jason Monk3c68ca22015-01-30 11:30:29 -0500568 }
569
Daniel Sandler08d05e32012-08-08 16:39:54 -0400570 @Override
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200571 public void fling(float vel, boolean expand) {
Daniel Sandler151f00d2012-10-02 22:33:08 -0400572 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
573 if (gr != null) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200574 gr.tag("fling " + ((vel > 0) ? "open" : "closed"), "notifications,v=" + vel);
Daniel Sandler151f00d2012-10-02 22:33:08 -0400575 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200576 super.fling(vel, expand);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400577 }
Chet Haase4d179dc2012-08-22 07:14:42 -0700578
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700579 @Override
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700580 protected void flingToHeight(float vel, boolean expand, float target,
Selim Cinek9db71052015-04-24 18:54:30 -0700581 float collapseSpeedUpFactor, boolean expandBecauseOfFalsing) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700582 mHeadsUpTouchHelper.notifyFling(!expand);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800583 setClosingWithAlphaFadeout(!expand && getFadeoutAlpha() == 1.0f);
Selim Cinek9db71052015-04-24 18:54:30 -0700584 super.flingToHeight(vel, expand, target, collapseSpeedUpFactor, expandBecauseOfFalsing);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700585 }
586
587 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800588 public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700589 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
Selim Cinek90c94652014-08-18 16:46:22 +0200590 event.getText().add(getKeyguardOrLockScreenString());
591 mLastAnnouncementWasQuickSettings = false;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700592 return true;
593 }
Alan Viverettea54956a2015-01-07 16:05:02 -0800594 return super.dispatchPopulateAccessibilityEventInternal(event);
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700595 }
596
Daniel Sandler040c2e42012-10-17 00:56:33 -0400597 @Override
Selim Cinek684a4422015-04-15 16:18:39 -0700598 public boolean onInterceptTouchEvent(MotionEvent event) {
Jason Monk0ceef212016-11-02 14:05:23 -0400599 if (mBlockTouches || mQs.isCustomizing()) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200600 return false;
601 }
Jorim Jaggi1cf6e102015-01-20 16:45:05 +0100602 initDownStates(event);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700603 if (mHeadsUpTouchHelper.onInterceptTouchEvent(event)) {
Selim Cinek684a4422015-04-15 16:18:39 -0700604 mIsExpansionFromHeadsUp = true;
Chris Wren49f06f52015-05-01 16:12:12 -0400605 MetricsLogger.count(mContext, COUNTER_PANEL_OPEN, 1);
606 MetricsLogger.count(mContext, COUNTER_PANEL_OPEN_PEEK, 1);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700607 return true;
608 }
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800609
610 if (mQsOverscrollExpansionEnabled && !isFullyCollapsed() && onQsIntercept(event)) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700611 return true;
612 }
613 return super.onInterceptTouchEvent(event);
614 }
615
616 private boolean onQsIntercept(MotionEvent event) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200617 int pointerIndex = event.findPointerIndex(mTrackingPointer);
618 if (pointerIndex < 0) {
619 pointerIndex = 0;
620 mTrackingPointer = event.getPointerId(pointerIndex);
John Spurlock73203eb2014-04-15 16:14:46 -0400621 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200622 final float x = event.getX(pointerIndex);
623 final float y = event.getY(pointerIndex);
624
625 switch (event.getActionMasked()) {
626 case MotionEvent.ACTION_DOWN:
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200627 mIntercepting = true;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200628 mInitialTouchY = y;
629 mInitialTouchX = x;
630 initVelocityTracker();
631 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200632 if (shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, 0)) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200633 getParent().requestDisallowInterceptTouchEvent(true);
634 }
Jorim Jaggi54045422014-07-03 18:30:40 +0200635 if (mQsExpansionAnimator != null) {
636 onQsExpansionStarted();
637 mInitialHeightOnTouch = mQsExpansionHeight;
638 mQsTracking = true;
639 mIntercepting = false;
640 mNotificationStackScroller.removeLongPressCallback();
641 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200642 break;
643 case MotionEvent.ACTION_POINTER_UP:
644 final int upPointer = event.getPointerId(event.getActionIndex());
645 if (mTrackingPointer == upPointer) {
646 // gesture is ongoing, find a new pointer to track
647 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
648 mTrackingPointer = event.getPointerId(newIndex);
649 mInitialTouchX = event.getX(newIndex);
650 mInitialTouchY = event.getY(newIndex);
651 }
652 break;
653
654 case MotionEvent.ACTION_MOVE:
655 final float h = y - mInitialTouchY;
656 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200657 if (mQsTracking) {
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200658
659 // Already tracking because onOverscrolled was called. We need to update here
660 // so we don't stop for a frame until the next touch event gets handled in
661 // onTouchEvent.
662 setQsExpansion(h + mInitialHeightOnTouch);
663 trackMovement(event);
664 mIntercepting = false;
665 return true;
666 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200667 if (Math.abs(h) > mTouchSlop && Math.abs(h) > Math.abs(x - mInitialTouchX)
Selim Cinek4c6969a2014-05-26 19:22:17 +0200668 && shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, h)) {
Jorim Jaggi58bef332014-11-21 18:10:32 +0100669 mQsTracking = true;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200670 onQsExpansionStarted();
Jorim Jaggi26aa04c2015-07-29 14:52:22 -0700671 notifyExpandingFinished();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200672 mInitialHeightOnTouch = mQsExpansionHeight;
673 mInitialTouchY = y;
674 mInitialTouchX = x;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200675 mIntercepting = false;
Selim Cinek1408eb52014-06-02 14:45:38 +0200676 mNotificationStackScroller.removeLongPressCallback();
Jorim Jaggid7daab72014-05-06 22:22:20 +0200677 return true;
678 }
679 break;
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200680
681 case MotionEvent.ACTION_CANCEL:
682 case MotionEvent.ACTION_UP:
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200683 trackMovement(event);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200684 if (mQsTracking) {
Chris Wren49f06f52015-05-01 16:12:12 -0400685 flingQsWithCurrentVelocity(y,
Jorim Jaggiaea80f42014-11-10 22:41:54 +0100686 event.getActionMasked() == MotionEvent.ACTION_CANCEL);
Selim Cinek4c6969a2014-05-26 19:22:17 +0200687 mQsTracking = false;
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200688 }
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200689 mIntercepting = false;
690 break;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200691 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700692 return false;
John Spurlock73203eb2014-04-15 16:14:46 -0400693 }
694
Selim Cinekab1dc952014-10-30 20:20:29 +0100695 @Override
696 protected boolean isInContentBounds(float x, float y) {
Selim Cinekab1dc952014-10-30 20:20:29 +0100697 float stackScrollerX = mNotificationStackScroller.getX();
Selim Cinek04fb2582015-06-02 19:58:09 +0200698 return !mNotificationStackScroller.isBelowLastNotification(x - stackScrollerX, y)
699 && stackScrollerX < x && x < stackScrollerX + mNotificationStackScroller.getWidth();
Selim Cinekab1dc952014-10-30 20:20:29 +0100700 }
701
Jorim Jaggi1cf6e102015-01-20 16:45:05 +0100702 private void initDownStates(MotionEvent event) {
Selim Cinekbaa23272014-07-08 18:01:07 +0200703 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
704 mOnlyAffordanceInThisMotion = false;
Selim Cinek19c8c702014-08-25 22:09:19 +0200705 mQsTouchAboveFalsingThreshold = mQsFullyExpanded;
Jorim Jaggi1cf6e102015-01-20 16:45:05 +0100706 mDozingOnDown = isDozing();
Selim Cinek684a4422015-04-15 16:18:39 -0700707 mCollapsedOnDown = isFullyCollapsed();
Selim Cinek79d79c42015-05-21 16:14:45 -0700708 mListenForHeadsUp = mCollapsedOnDown && mHeadsUpManager.hasPinnedHeadsUp();
Selim Cinekbaa23272014-07-08 18:01:07 +0200709 }
710 }
711
Chris Wren49f06f52015-05-01 16:12:12 -0400712 private void flingQsWithCurrentVelocity(float y, boolean isCancelMotionEvent) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800713 float vel = getCurrentQSVelocity();
Chris Wren49f06f52015-05-01 16:12:12 -0400714 final boolean expandsQs = flingExpandsQs(vel);
715 if (expandsQs) {
716 logQsSwipeDown(y);
717 }
718 flingSettings(vel, expandsQs && !isCancelMotionEvent);
719 }
720
721 private void logQsSwipeDown(float y) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800722 float vel = getCurrentQSVelocity();
Chris Wren49f06f52015-05-01 16:12:12 -0400723 final int gesture = mStatusBarState == StatusBarState.KEYGUARD
Chris Wren27a52fa2017-02-01 14:21:43 -0500724 ? MetricsEvent.ACTION_LS_QS
725 : MetricsEvent.ACTION_SHADE_QS_PULL;
726 mLockscreenGestureLogger.write(gesture,
Chris Wren49f06f52015-05-01 16:12:12 -0400727 (int) ((y - mInitialTouchY) / mStatusBar.getDisplayDensity()),
728 (int) (vel / mStatusBar.getDisplayDensity()));
Jorim Jaggic9a52ab2014-05-12 23:46:19 +0200729 }
730
Jorim Jaggidc96d632014-07-01 18:48:52 +0200731 private boolean flingExpandsQs(float vel) {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700732 if (isFalseTouch()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200733 return false;
734 }
Jorim Jaggidc96d632014-07-01 18:48:52 +0200735 if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
736 return getQsExpansionFraction() > 0.5f;
737 } else {
738 return vel > 0;
739 }
740 }
741
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700742 private boolean isFalseTouch() {
Adrian Roos6a70b882016-04-19 17:09:07 -0700743 if (!needsAntiFalsing()) {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700744 return false;
745 }
746 if (mFalsingManager.isClassiferEnabled()) {
747 return mFalsingManager.isFalseTouch();
748 }
749 return !mQsTouchAboveFalsingThreshold;
Selim Cinek5386fb32014-09-03 16:37:36 +0200750 }
751
Jorim Jaggidc96d632014-07-01 18:48:52 +0200752 private float getQsExpansionFraction() {
Jorim Jaggi11c071a2014-08-14 19:17:11 +0200753 return Math.min(1f, (mQsExpansionHeight - mQsMinExpansionHeight)
754 / (getTempQsMaxExpansion() - mQsMinExpansionHeight));
Jorim Jaggidc96d632014-07-01 18:48:52 +0200755 }
Jorim Jaggi54045422014-07-03 18:30:40 +0200756
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200757 @Override
Selim Cinek48ff9b42016-11-09 19:31:51 -0800758 protected float getOpeningHeight() {
Selim Cinekfcff4c62016-12-27 14:26:06 +0100759 return mNotificationStackScroller.getOpeningHeight();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800760 }
761
762 @Override
Daniel Sandler040c2e42012-10-17 00:56:33 -0400763 public boolean onTouchEvent(MotionEvent event) {
Jason Monk0ceef212016-11-02 14:05:23 -0400764 if (mBlockTouches || (mQs != null && mQs.isCustomizing())) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200765 return false;
766 }
Jorim Jaggi1cf6e102015-01-20 16:45:05 +0100767 initDownStates(event);
Selim Cinek79d79c42015-05-21 16:14:45 -0700768 if (mListenForHeadsUp && !mHeadsUpTouchHelper.isTrackingHeadsUp()
769 && mHeadsUpTouchHelper.onInterceptTouchEvent(event)) {
770 mIsExpansionFromHeadsUp = true;
Selim Cinek79d79c42015-05-21 16:14:45 -0700771 MetricsLogger.count(mContext, COUNTER_PANEL_OPEN_PEEK, 1);
772 }
Adrian Roos8008bd12017-02-22 15:02:09 +0100773 boolean handled = false;
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +0200774 if ((!mIsExpanding || mHintAnimationRunning)
775 && !mQsExpanded
Adrian Roos2a318412017-01-25 14:48:26 -0800776 && mStatusBar.getBarState() != StatusBarState.SHADE
777 && !mDozing) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100778 handled |= mAffordanceHelper.onTouchEvent(event);
Selim Cinekbaa23272014-07-08 18:01:07 +0200779 }
780 if (mOnlyAffordanceInThisMotion) {
781 return true;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200782 }
Adrian Roos8008bd12017-02-22 15:02:09 +0100783 handled |= mHeadsUpTouchHelper.onTouchEvent(event);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800784
785 if (mQsOverscrollExpansionEnabled && !mHeadsUpTouchHelper.isTrackingHeadsUp()
786 && handleQsTouch(event)) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700787 return true;
788 }
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700789 if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) {
Chris Wren49f06f52015-05-01 16:12:12 -0400790 MetricsLogger.count(mContext, COUNTER_PANEL_OPEN, 1);
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700791 updateVerticalPanelPosition(event.getX());
Adrian Roos8008bd12017-02-22 15:02:09 +0100792 handled = true;
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -0700793 }
Adrian Roos8008bd12017-02-22 15:02:09 +0100794 handled |= super.onTouchEvent(event);
795 return mDozing ? handled : true;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700796 }
797
Selim Cinek684a4422015-04-15 16:18:39 -0700798 private boolean handleQsTouch(MotionEvent event) {
Mady Melloraaf32f62015-05-01 17:06:50 -0700799 final int action = event.getActionMasked();
800 if (action == MotionEvent.ACTION_DOWN && getExpandedFraction() == 1f
Jorim Jaggi18bd04f2014-08-15 00:03:09 +0200801 && mStatusBar.getBarState() != StatusBarState.KEYGUARD && !mQsExpanded
802 && mQsExpansionEnabled) {
Jorim Jaggid7daab72014-05-06 22:22:20 +0200803
Jorim Jaggidc96d632014-07-01 18:48:52 +0200804 // Down in the empty area while fully expanded - go to QS.
805 mQsTracking = true;
806 mConflictingQsExpansionGesture = true;
807 onQsExpansionStarted();
808 mInitialHeightOnTouch = mQsExpansionHeight;
809 mInitialTouchY = event.getX();
810 mInitialTouchX = event.getY();
811 }
Selim Cinek684a4422015-04-15 16:18:39 -0700812 if (!isFullyCollapsed()) {
Jorim Jaggi853b0702014-07-05 04:31:14 +0200813 handleQsDown(event);
814 }
Jason Monk3c68ca22015-01-30 11:30:29 -0500815 if (!mQsExpandImmediate && mQsTracking) {
Jorim Jaggidc96d632014-07-01 18:48:52 +0200816 onQsTouch(event);
817 if (!mConflictingQsExpansionGesture) {
818 return true;
819 }
820 }
Mady Melloraaf32f62015-05-01 17:06:50 -0700821 if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
Jorim Jaggidc96d632014-07-01 18:48:52 +0200822 mConflictingQsExpansionGesture = false;
823 }
Mady Melloraaf32f62015-05-01 17:06:50 -0700824 if (action == MotionEvent.ACTION_DOWN && isFullyCollapsed()
Jorim Jaggi18bd04f2014-08-15 00:03:09 +0200825 && mQsExpansionEnabled) {
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200826 mTwoFingerQsExpandPossible = true;
827 }
Mady Mellor3a4bc792015-05-27 09:10:22 -0700828 if (mTwoFingerQsExpandPossible && isOpenQsEvent(event)
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200829 && event.getY(event.getActionIndex()) < mStatusBarMinHeight) {
Chris Wren49f06f52015-05-01 16:12:12 -0400830 MetricsLogger.count(mContext, COUNTER_PANEL_OPEN_QS, 1);
Jason Monk3c68ca22015-01-30 11:30:29 -0500831 mQsExpandImmediate = true;
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200832 requestPanelHeightUpdate();
Jorim Jaggi8599a332014-08-14 21:44:23 +0200833
834 // Normally, we start listening when the panel is expanded, but here we need to start
835 // earlier so the state is already up to date when dragging down.
836 setListening(true);
Jorim Jaggi1e2554b2014-07-10 23:07:00 +0200837 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700838 return false;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200839 }
840
Jorim Jaggie0640dd2014-08-05 23:12:40 +0200841 private boolean isInQsArea(float x, float y) {
Jason Monk0ceef212016-11-02 14:05:23 -0400842 return (x >= mQsFrame.getX()
843 && x <= mQsFrame.getX() + mQsFrame.getWidth())
Jason Monk85686d62016-03-29 12:34:28 -0400844 && (y <= mNotificationStackScroller.getBottomMostNotificationBottom()
Jason Monk0ceef212016-11-02 14:05:23 -0400845 || y <= mQs.getView().getY() + mQs.getView().getHeight());
Jorim Jaggie0640dd2014-08-05 23:12:40 +0200846 }
847
Mady Mellor3a4bc792015-05-27 09:10:22 -0700848 private boolean isOpenQsEvent(MotionEvent event) {
849 final int pointerCount = event.getPointerCount();
850 final int action = event.getActionMasked();
851
852 final boolean twoFingerDrag = action == MotionEvent.ACTION_POINTER_DOWN
853 && pointerCount == 2;
854
855 final boolean stylusButtonClickDrag = action == MotionEvent.ACTION_DOWN
856 && (event.isButtonPressed(MotionEvent.BUTTON_STYLUS_PRIMARY)
857 || event.isButtonPressed(MotionEvent.BUTTON_STYLUS_SECONDARY));
858
859 final boolean mouseButtonClickDrag = action == MotionEvent.ACTION_DOWN
860 && (event.isButtonPressed(MotionEvent.BUTTON_SECONDARY)
861 || event.isButtonPressed(MotionEvent.BUTTON_TERTIARY));
862
863 return twoFingerDrag || stylusButtonClickDrag || mouseButtonClickDrag;
864 }
865
Jorim Jaggi853b0702014-07-05 04:31:14 +0200866 private void handleQsDown(MotionEvent event) {
867 if (event.getActionMasked() == MotionEvent.ACTION_DOWN
Jorim Jaggie0640dd2014-08-05 23:12:40 +0200868 && shouldQuickSettingsIntercept(event.getX(), event.getY(), -1)) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700869 mFalsingManager.onQsDown();
Jorim Jaggi853b0702014-07-05 04:31:14 +0200870 mQsTracking = true;
871 onQsExpansionStarted();
872 mInitialHeightOnTouch = mQsExpansionHeight;
873 mInitialTouchY = event.getX();
874 mInitialTouchX = event.getY();
Jorim Jaggi8599a332014-08-14 21:44:23 +0200875
876 // If we interrupt an expansion gesture here, make sure to update the state correctly.
Jorim Jaggi26aa04c2015-07-29 14:52:22 -0700877 notifyExpandingFinished();
Jorim Jaggi853b0702014-07-05 04:31:14 +0200878 }
879 }
880
Selim Cinek4c6969a2014-05-26 19:22:17 +0200881 @Override
Selim Cinek9db71052015-04-24 18:54:30 -0700882 protected boolean flingExpands(float vel, float vectorVel, float x, float y) {
883 boolean expands = super.flingExpands(vel, vectorVel, x, y);
Jorim Jaggidc96d632014-07-01 18:48:52 +0200884
885 // If we are already running a QS expansion, make sure that we keep the panel open.
886 if (mQsExpansionAnimator != null) {
887 expands = true;
888 }
889 return expands;
890 }
891
892 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +0200893 protected boolean hasConflictingGestures() {
894 return mStatusBar.getBarState() != StatusBarState.SHADE;
895 }
896
Selim Cinek9db71052015-04-24 18:54:30 -0700897 @Override
898 protected boolean shouldGestureIgnoreXTouchSlop(float x, float y) {
Adrian Roose31f30e2017-01-25 14:48:15 -0800899 return !mAffordanceHelper.isOnAffordanceIcon(x, y);
Selim Cinek9db71052015-04-24 18:54:30 -0700900 }
901
Jorim Jaggidc96d632014-07-01 18:48:52 +0200902 private void onQsTouch(MotionEvent event) {
Selim Cinek4c6969a2014-05-26 19:22:17 +0200903 int pointerIndex = event.findPointerIndex(mTrackingPointer);
904 if (pointerIndex < 0) {
905 pointerIndex = 0;
906 mTrackingPointer = event.getPointerId(pointerIndex);
907 }
908 final float y = event.getY(pointerIndex);
909 final float x = event.getX(pointerIndex);
Chris Wren49f06f52015-05-01 16:12:12 -0400910 final float h = y - mInitialTouchY;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200911
912 switch (event.getActionMasked()) {
913 case MotionEvent.ACTION_DOWN:
914 mQsTracking = true;
915 mInitialTouchY = y;
916 mInitialTouchX = x;
917 onQsExpansionStarted();
918 mInitialHeightOnTouch = mQsExpansionHeight;
919 initVelocityTracker();
920 trackMovement(event);
921 break;
922
923 case MotionEvent.ACTION_POINTER_UP:
924 final int upPointer = event.getPointerId(event.getActionIndex());
925 if (mTrackingPointer == upPointer) {
926 // gesture is ongoing, find a new pointer to track
927 final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
928 final float newY = event.getY(newIndex);
929 final float newX = event.getX(newIndex);
930 mTrackingPointer = event.getPointerId(newIndex);
931 mInitialHeightOnTouch = mQsExpansionHeight;
932 mInitialTouchY = newY;
933 mInitialTouchX = newX;
934 }
935 break;
936
937 case MotionEvent.ACTION_MOVE:
Selim Cinek4c6969a2014-05-26 19:22:17 +0200938 setQsExpansion(h + mInitialHeightOnTouch);
Selim Cinek34cf5c42014-09-26 15:39:00 +0200939 if (h >= getFalsingThreshold()) {
Selim Cinek19c8c702014-08-25 22:09:19 +0200940 mQsTouchAboveFalsingThreshold = true;
941 }
Selim Cinek4c6969a2014-05-26 19:22:17 +0200942 trackMovement(event);
943 break;
944
945 case MotionEvent.ACTION_UP:
946 case MotionEvent.ACTION_CANCEL:
947 mQsTracking = false;
948 mTrackingPointer = -1;
949 trackMovement(event);
Selim Cinek84e6de72016-02-22 20:57:43 -0800950 float fraction = getQsExpansionFraction();
951 if (fraction != 0f || y >= mInitialTouchY) {
952 flingQsWithCurrentVelocity(y,
953 event.getActionMasked() == MotionEvent.ACTION_CANCEL);
954 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800955 if (mQsVelocityTracker != null) {
956 mQsVelocityTracker.recycle();
957 mQsVelocityTracker = null;
Selim Cinek4c6969a2014-05-26 19:22:17 +0200958 }
959 break;
960 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200961 }
962
Selim Cinek34cf5c42014-09-26 15:39:00 +0200963 private int getFalsingThreshold() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -0700964 float factor = mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek34cf5c42014-09-26 15:39:00 +0200965 return (int) (mQsFalsingThreshold * factor);
966 }
967
Jorim Jaggifc1a8242014-05-12 19:30:05 +0200968 @Override
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200969 public void onOverscrollTopChanged(float amount, boolean isRubberbanded) {
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800970 if (!mQsOverscrollExpansionEnabled) {
971 return;
972 }
973
Selim Cinek831941f2015-06-17 15:09:30 -0700974 cancelQsAnimation();
Jorim Jaggi18bd04f2014-08-15 00:03:09 +0200975 if (!mQsExpansionEnabled) {
976 amount = 0f;
977 }
Jorim Jaggi290600a2014-05-30 17:02:20 +0200978 float rounded = amount >= 1f ? amount : 0f;
Jason Monke1be3422016-02-09 10:51:40 -0500979 setOverScrolling(rounded != 0f && isRubberbanded);
Jorim Jaggi475b21d2014-07-01 18:13:24 +0200980 mQsExpansionFromOverscroll = rounded != 0f;
Jorim Jaggi11c071a2014-08-14 19:17:11 +0200981 mLastOverscroll = rounded;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200982 updateQsState();
Jorim Jaggi90e0df22014-07-30 01:10:35 +0200983 setQsExpansion(mQsMinExpansionHeight + rounded);
Jorim Jaggi290600a2014-05-30 17:02:20 +0200984 }
985
Selim Cinek1408eb52014-06-02 14:45:38 +0200986 @Override
987 public void flingTopOverscroll(float velocity, boolean open) {
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800988 if (!mQsOverscrollExpansionEnabled) {
989 return;
990 }
991
Jorim Jaggib7a33032014-08-20 16:21:36 +0200992 mLastOverscroll = 0f;
Selim Cinekf91de682016-05-11 13:01:02 -0400993 mQsExpansionFromOverscroll = false;
Selim Cinek1408eb52014-06-02 14:45:38 +0200994 setQsExpansion(mQsExpansionHeight);
Jorim Jaggi18bd04f2014-08-15 00:03:09 +0200995 flingSettings(!mQsExpansionEnabled && open ? 0f : velocity, open && mQsExpansionEnabled,
996 new Runnable() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700997 @Override
998 public void run() {
999 mStackScrollerOverscrolling = false;
Jason Monke1be3422016-02-09 10:51:40 -05001000 setOverScrolling(false);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001001 updateQsState();
1002 }
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001003 }, false /* isClick */);
Selim Cinek1408eb52014-06-02 14:45:38 +02001004 }
1005
Jason Monke1be3422016-02-09 10:51:40 -05001006 private void setOverScrolling(boolean overscrolling) {
1007 mStackScrollerOverscrolling = overscrolling;
Jason Monk0ceef212016-11-02 14:05:23 -04001008 if (mQs == null) return;
1009 mQs.setOverscrolling(overscrolling);
Jason Monke1be3422016-02-09 10:51:40 -05001010 }
1011
Jorim Jaggid7daab72014-05-06 22:22:20 +02001012 private void onQsExpansionStarted() {
Jorim Jaggifc1a8242014-05-12 19:30:05 +02001013 onQsExpansionStarted(0);
1014 }
1015
Muyuan Li0e9f5382016-04-27 15:51:15 -07001016 protected void onQsExpansionStarted(int overscrollAmount) {
Selim Cinek831941f2015-06-17 15:09:30 -07001017 cancelQsAnimation();
1018 cancelHeightAnimator();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001019
1020 // Reset scroll position and apply that position to the expanded height.
Jason Monk16ac3772016-02-10 15:39:21 -05001021 float height = mQsExpansionHeight - overscrollAmount;
Jorim Jaggid7daab72014-05-06 22:22:20 +02001022 setQsExpansion(height);
Jorim Jaggi58bef332014-11-21 18:10:32 +01001023 requestPanelHeightUpdate();
Mady Mellorc2dbe492017-03-30 13:22:03 -07001024 mNotificationStackScroller.checkSnoozeLeavebehind();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001025 }
1026
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001027 private void setQsExpanded(boolean expanded) {
1028 boolean changed = mQsExpanded != expanded;
1029 if (changed) {
1030 mQsExpanded = expanded;
1031 updateQsState();
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001032 requestPanelHeightUpdate();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001033 mFalsingManager.setQsExpanded(expanded);
Jorim Jaggib690f0d2014-07-03 23:25:44 +02001034 mStatusBar.setQsExpanded(expanded);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001035 mNotificationContainerParent.setQsExpanded(expanded);
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001036 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001037 }
1038
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001039 public void setBarState(int statusBarState, boolean keyguardFadingAway,
1040 boolean goingToFullShade) {
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001041 int oldState = mStatusBarState;
1042 boolean keyguardShowing = statusBarState == StatusBarState.KEYGUARD;
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001043 setKeyguardStatusViewVisibility(statusBarState, keyguardFadingAway, goingToFullShade);
1044 setKeyguardBottomAreaVisibility(statusBarState, goingToFullShade);
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001045
1046 mStatusBarState = statusBarState;
1047 mKeyguardShowing = keyguardShowing;
Jason Monk0ceef212016-11-02 14:05:23 -04001048 if (mQs != null) {
1049 mQs.setKeyguardShowing(mKeyguardShowing);
1050 }
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001051
Selim Cinek5f2ca6b2016-10-07 14:45:55 -04001052 if (oldState == StatusBarState.KEYGUARD
1053 && (goingToFullShade || statusBarState == StatusBarState.SHADE_LOCKED)) {
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001054 animateKeyguardStatusBarOut();
Jason Monke1be3422016-02-09 10:51:40 -05001055 long delay = mStatusBarState == StatusBarState.SHADE_LOCKED
1056 ? 0 : mStatusBar.calculateGoingToFullShadeDelay();
Jason Monk0ceef212016-11-02 14:05:23 -04001057 mQs.animateHeaderSlidingIn(delay);
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001058 } else if (oldState == StatusBarState.SHADE_LOCKED
1059 && statusBarState == StatusBarState.KEYGUARD) {
1060 animateKeyguardStatusBarIn(StackStateAnimator.ANIMATION_DURATION_STANDARD);
Jason Monk0ceef212016-11-02 14:05:23 -04001061 mQs.animateHeaderSlidingOut();
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001062 } else {
1063 mKeyguardStatusBar.setAlpha(1f);
1064 mKeyguardStatusBar.setVisibility(keyguardShowing ? View.VISIBLE : View.INVISIBLE);
Selim Cineke70d6532015-04-24 16:46:13 -07001065 if (keyguardShowing && oldState != mStatusBarState) {
Selim Cinek5f145022016-08-02 16:00:12 -07001066 mKeyguardBottomArea.onKeyguardShowingChanged();
Jason Monk0ceef212016-11-02 14:05:23 -04001067 if (mQs != null) {
1068 mQs.hideImmediately();
1069 }
Selim Cineke70d6532015-04-24 16:46:13 -07001070 }
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001071 }
Jorim Jaggi0e0942d2015-06-05 14:12:20 -07001072 if (keyguardShowing) {
1073 updateDozingVisibilities(false /* animate */);
1074 }
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07001075 resetVerticalPanelPosition();
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001076 updateQsState();
1077 }
1078
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001079 private final Runnable mAnimateKeyguardStatusViewInvisibleEndRunnable = new Runnable() {
1080 @Override
1081 public void run() {
1082 mKeyguardStatusViewAnimating = false;
1083 mKeyguardStatusView.setVisibility(View.GONE);
1084 }
1085 };
1086
1087 private final Runnable mAnimateKeyguardStatusViewVisibleEndRunnable = new Runnable() {
1088 @Override
1089 public void run() {
1090 mKeyguardStatusViewAnimating = false;
1091 }
1092 };
1093
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001094 private final Runnable mAnimateKeyguardStatusBarInvisibleEndRunnable = new Runnable() {
1095 @Override
1096 public void run() {
1097 mKeyguardStatusBar.setVisibility(View.INVISIBLE);
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001098 mKeyguardStatusBar.setAlpha(1f);
1099 mKeyguardStatusBarAnimateAlpha = 1f;
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001100 }
1101 };
1102
1103 private void animateKeyguardStatusBarOut() {
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001104 ValueAnimator anim = ValueAnimator.ofFloat(mKeyguardStatusBar.getAlpha(), 0f);
1105 anim.addUpdateListener(mStatusBarAnimateAlphaListener);
1106 anim.setStartDelay(mStatusBar.isKeyguardFadingAway()
1107 ? mStatusBar.getKeyguardFadingAwayDelay()
1108 : 0);
1109 anim.setDuration(mStatusBar.isKeyguardFadingAway()
1110 ? mStatusBar.getKeyguardFadingAwayDuration() / 2
1111 : StackStateAnimator.ANIMATION_DURATION_STANDARD);
Selim Cinekc18010f2016-01-20 13:41:30 -08001112 anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001113 anim.addListener(new AnimatorListenerAdapter() {
1114 @Override
1115 public void onAnimationEnd(Animator animation) {
1116 mAnimateKeyguardStatusBarInvisibleEndRunnable.run();
1117 }
1118 });
1119 anim.start();
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001120 }
1121
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001122 private final ValueAnimator.AnimatorUpdateListener mStatusBarAnimateAlphaListener =
1123 new ValueAnimator.AnimatorUpdateListener() {
1124 @Override
1125 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001126 mKeyguardStatusBarAnimateAlpha = (float) animation.getAnimatedValue();
1127 updateHeaderKeyguardAlpha();
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001128 }
1129 };
1130
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001131 private void animateKeyguardStatusBarIn(long duration) {
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001132 mKeyguardStatusBar.setVisibility(View.VISIBLE);
1133 mKeyguardStatusBar.setAlpha(0f);
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001134 ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
1135 anim.addUpdateListener(mStatusBarAnimateAlphaListener);
1136 anim.setDuration(duration);
Selim Cinekc18010f2016-01-20 13:41:30 -08001137 anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001138 anim.start();
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001139 }
1140
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001141 private final Runnable mAnimateKeyguardBottomAreaInvisibleEndRunnable = new Runnable() {
1142 @Override
1143 public void run() {
1144 mKeyguardBottomArea.setVisibility(View.GONE);
1145 }
1146 };
1147
1148 private void setKeyguardBottomAreaVisibility(int statusBarState,
1149 boolean goingToFullShade) {
Xiaohui Chen9528f432016-02-12 15:03:18 -08001150 mKeyguardBottomArea.animate().cancel();
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001151 if (goingToFullShade) {
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001152 mKeyguardBottomArea.animate()
1153 .alpha(0f)
1154 .setStartDelay(mStatusBar.getKeyguardFadingAwayDelay())
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001155 .setDuration(mStatusBar.getKeyguardFadingAwayDuration() / 2)
Selim Cinekc18010f2016-01-20 13:41:30 -08001156 .setInterpolator(Interpolators.ALPHA_OUT)
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001157 .withEndAction(mAnimateKeyguardBottomAreaInvisibleEndRunnable)
1158 .start();
1159 } else if (statusBarState == StatusBarState.KEYGUARD
1160 || statusBarState == StatusBarState.SHADE_LOCKED) {
Adrian Roos91ba3072017-02-14 16:50:46 +01001161 mKeyguardBottomArea.setVisibility(View.VISIBLE);
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001162 mKeyguardBottomArea.setAlpha(1f);
1163 } else {
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001164 mKeyguardBottomArea.setVisibility(View.GONE);
1165 mKeyguardBottomArea.setAlpha(1f);
1166 }
1167 }
1168
1169 private void setKeyguardStatusViewVisibility(int statusBarState, boolean keyguardFadingAway,
1170 boolean goingToFullShade) {
1171 if ((!keyguardFadingAway && mStatusBarState == StatusBarState.KEYGUARD
1172 && statusBarState != StatusBarState.KEYGUARD) || goingToFullShade) {
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001173 mKeyguardStatusView.animate().cancel();
1174 mKeyguardStatusViewAnimating = true;
1175 mKeyguardStatusView.animate()
1176 .alpha(0f)
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001177 .setStartDelay(0)
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001178 .setDuration(160)
Selim Cinekc18010f2016-01-20 13:41:30 -08001179 .setInterpolator(Interpolators.ALPHA_OUT)
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001180 .withEndAction(mAnimateKeyguardStatusViewInvisibleEndRunnable);
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001181 if (keyguardFadingAway) {
1182 mKeyguardStatusView.animate()
1183 .setStartDelay(mStatusBar.getKeyguardFadingAwayDelay())
1184 .setDuration(mStatusBar.getKeyguardFadingAwayDuration()/2)
1185 .start();
1186 }
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001187 } else if (mStatusBarState == StatusBarState.SHADE_LOCKED
1188 && statusBarState == StatusBarState.KEYGUARD) {
1189 mKeyguardStatusView.animate().cancel();
1190 mKeyguardStatusView.setVisibility(View.VISIBLE);
1191 mKeyguardStatusViewAnimating = true;
1192 mKeyguardStatusView.setAlpha(0f);
1193 mKeyguardStatusView.animate()
1194 .alpha(1f)
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02001195 .setStartDelay(0)
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001196 .setDuration(320)
Selim Cinekc18010f2016-01-20 13:41:30 -08001197 .setInterpolator(Interpolators.ALPHA_IN)
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001198 .withEndAction(mAnimateKeyguardStatusViewVisibleEndRunnable);
1199 } else if (statusBarState == StatusBarState.KEYGUARD) {
1200 mKeyguardStatusView.animate().cancel();
Jorim Jaggi5e08e692014-10-03 15:17:20 -07001201 mKeyguardStatusViewAnimating = false;
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001202 mKeyguardStatusView.setVisibility(View.VISIBLE);
1203 mKeyguardStatusView.setAlpha(1f);
1204 } else {
1205 mKeyguardStatusView.animate().cancel();
Jorim Jaggi5e08e692014-10-03 15:17:20 -07001206 mKeyguardStatusViewAnimating = false;
Jorim Jaggi6ff837a2014-07-31 21:46:39 +02001207 mKeyguardStatusView.setVisibility(View.GONE);
1208 mKeyguardStatusView.setAlpha(1f);
1209 }
1210 }
1211
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001212 private void updateQsState() {
Selim Cinekbc243a92016-09-27 16:35:13 -07001213 mNotificationStackScroller.setQsExpanded(mQsExpanded);
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001214 mNotificationStackScroller.setScrollingEnabled(
1215 mStatusBarState != StatusBarState.KEYGUARD && (!mQsExpanded
1216 || mQsExpansionFromOverscroll));
Jorim Jaggia2052ea2014-08-05 16:22:30 +02001217 updateEmptyShadeView();
Jorim Jaggidd5b8862014-08-05 21:04:39 +02001218 mQsNavbarScrim.setVisibility(mStatusBarState == StatusBarState.SHADE && mQsExpanded
1219 && !mStackScrollerOverscrolling && mQsScrimEnabled
Selim Cinek684a4422015-04-15 16:18:39 -07001220 ? View.VISIBLE
1221 : View.INVISIBLE);
Jorim Jaggibf1899e2014-08-07 02:04:18 +02001222 if (mKeyguardUserSwitcher != null && mQsExpanded && !mStackScrollerOverscrolling) {
Adrian Roos2d1ef302014-10-24 18:42:51 +02001223 mKeyguardUserSwitcher.hideIfNotSimple(true /* animate */);
Jorim Jaggibf1899e2014-08-07 02:04:18 +02001224 }
Jason Monk0ceef212016-11-02 14:05:23 -04001225 if (mQs == null) return;
1226 mQs.setExpanded(mQsExpanded);
Jorim Jaggid7daab72014-05-06 22:22:20 +02001227 }
1228
1229 private void setQsExpansion(float height) {
1230 height = Math.min(Math.max(height, mQsMinExpansionHeight), mQsMaxExpansionHeight);
Jason Monkbd28a85b2015-02-10 13:29:02 -05001231 mQsFullyExpanded = height == mQsMaxExpansionHeight && mQsMaxExpansionHeight != 0;
Jorim Jaggi290600a2014-05-30 17:02:20 +02001232 if (height > mQsMinExpansionHeight && !mQsExpanded && !mStackScrollerOverscrolling) {
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001233 setQsExpanded(true);
Jorim Jaggid7daab72014-05-06 22:22:20 +02001234 } else if (height <= mQsMinExpansionHeight && mQsExpanded) {
Jorim Jaggif62f2bb2014-05-25 22:28:41 +02001235 setQsExpanded(false);
Adrian Roos54d031b2015-06-15 18:16:58 -07001236 if (mLastAnnouncementWasQuickSettings && !mTracking && !isCollapsing()) {
Selim Cinek90c94652014-08-18 16:46:22 +02001237 announceForAccessibility(getKeyguardOrLockScreenString());
1238 mLastAnnouncementWasQuickSettings = false;
1239 }
John Spurlock73203eb2014-04-15 16:14:46 -04001240 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001241 mQsExpansionHeight = height;
Jason Monke1be3422016-02-09 10:51:40 -05001242 updateQsExpansion();
Selim Cinek1408eb52014-06-02 14:45:38 +02001243 requestScrollerTopPaddingUpdate(false /* animate */);
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001244 if (mKeyguardShowing) {
Jason Monke1be3422016-02-09 10:51:40 -05001245 updateHeaderKeyguardAlpha();
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001246 }
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001247 if (mStatusBarState == StatusBarState.SHADE_LOCKED
1248 || mStatusBarState == StatusBarState.KEYGUARD) {
1249 updateKeyguardBottomAreaAlpha();
1250 }
Jorim Jaggidd5b8862014-08-05 21:04:39 +02001251 if (mStatusBarState == StatusBarState.SHADE && mQsExpanded
1252 && !mStackScrollerOverscrolling && mQsScrimEnabled) {
1253 mQsNavbarScrim.setAlpha(getQsExpansionFraction());
1254 }
Selim Cinek90c94652014-08-18 16:46:22 +02001255
Lucas Dupin8c08a352017-05-01 14:46:33 -07001256 // Fade clock when QS is on top of it
1257 float newClockAlpha = (height - mKeyguardStatusView.getY()) /
1258 mKeyguardStatusView.getHeight();
1259 newClockAlpha = 1 - MathUtils.constrain(newClockAlpha, 0, 1);
1260 if (newClockAlpha != mQsClockAlphaOverride) {
1261 mQsClockAlphaOverride = Interpolators.ALPHA_OUT.getInterpolation(newClockAlpha);
1262 updateClock(mClockPositionResult.clockAlpha, mClockPositionResult.clockScale);
1263 }
1264
Selim Cinek90c94652014-08-18 16:46:22 +02001265 // Upon initialisation when we are not layouted yet we don't want to announce that we are
1266 // fully expanded, hence the != 0.0f check.
1267 if (height != 0.0f && mQsFullyExpanded && !mLastAnnouncementWasQuickSettings) {
1268 announceForAccessibility(getContext().getString(
1269 R.string.accessibility_desc_quick_settings));
1270 mLastAnnouncementWasQuickSettings = true;
1271 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001272 if (mQsFullyExpanded && mFalsingManager.shouldEnforceBouncer()) {
Blazej Magnowski72323322015-07-24 11:49:40 -07001273 mStatusBar.executeRunnableDismissingKeyguard(null, null /* cancelAction */,
Felipe Lemeee5d6302016-04-22 16:11:19 -07001274 false /* dismissShade */, true /* afterKeyguardGone */, false /* deferred */);
Blazej Magnowski72323322015-07-24 11:49:40 -07001275 }
Jorim Jaggi58bef332014-11-21 18:10:32 +01001276 if (DEBUG) {
1277 invalidate();
1278 }
Selim Cinek90c94652014-08-18 16:46:22 +02001279 }
1280
Xiaohui Chen9528f432016-02-12 15:03:18 -08001281 protected void updateQsExpansion() {
Jason Monk0ceef212016-11-02 14:05:23 -04001282 if (mQs == null) return;
1283 mQs.setQsExpansion(getQsExpansionFraction(), getHeaderTranslation());
Jason Monke1be3422016-02-09 10:51:40 -05001284 }
1285
Selim Cinek90c94652014-08-18 16:46:22 +02001286 private String getKeyguardOrLockScreenString() {
Jason Monk7a952882016-11-15 15:38:30 -05001287 if (mQs != null && mQs.isCustomizing()) {
Jason Monk39c98e62016-03-16 09:18:35 -04001288 return getContext().getString(R.string.accessibility_desc_quick_settings_edit);
1289 } else if (mStatusBarState == StatusBarState.KEYGUARD) {
Selim Cinek90c94652014-08-18 16:46:22 +02001290 return getContext().getString(R.string.accessibility_desc_lock_screen);
1291 } else {
1292 return getContext().getString(R.string.accessibility_desc_notification_shade);
1293 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001294 }
1295
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001296 private float calculateQsTopPadding() {
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001297 if (mKeyguardShowing
Jason Monk3c68ca22015-01-30 11:30:29 -05001298 && (mQsExpandImmediate || mIsExpanding && mQsExpandedWhenExpandingStarted)) {
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001299
1300 // Either QS pushes the notifications down when fully expanded, or QS is fully above the
1301 // notifications (mostly on tablets). maxNotifications denotes the normal top padding
1302 // on Keyguard, maxQs denotes the top padding from the quick settings panel. We need to
1303 // take the maximum and linearly interpolate with the panel expansion for a nice motion.
1304 int maxNotifications = mClockPositionResult.stackScrollerPadding
Selim Cinek33d46142016-01-15 18:58:39 -08001305 - mClockPositionResult.stackScrollerPaddingAdjustment;
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001306 int maxQs = getTempQsMaxExpansion();
1307 int max = mStatusBarState == StatusBarState.KEYGUARD
1308 ? Math.max(maxNotifications, maxQs)
1309 : maxQs;
1310 return (int) interpolate(getExpandedFraction(),
1311 mQsMinExpansionHeight, max);
Jorim Jaggi8bc983e2014-12-10 17:45:50 +01001312 } else if (mQsSizeChangeAnimator != null) {
1313 return (int) mQsSizeChangeAnimator.getAnimatedValue();
Jason Monk16ac3772016-02-10 15:39:21 -05001314 } else if (mKeyguardShowing) {
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001315
1316 // We can only do the smoother transition on Keyguard when we also are not collapsing
1317 // from a scrolled quick settings.
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001318 return interpolate(getQsExpansionFraction(),
Selim Cinek33d46142016-01-15 18:58:39 -08001319 mNotificationStackScroller.getIntrinsicPadding(),
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001320 mQsMaxExpansionHeight);
1321 } else {
1322 return mQsExpansionHeight;
1323 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001324 }
1325
Xiaohui Chen9528f432016-02-12 15:03:18 -08001326 protected void requestScrollerTopPaddingUpdate(boolean animate) {
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001327 mNotificationStackScroller.updateTopPadding(calculateQsTopPadding(),
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001328 mAnimateNextTopPaddingChange || animate,
1329 mKeyguardShowing
Jason Monk3c68ca22015-01-30 11:30:29 -05001330 && (mQsExpandImmediate || mIsExpanding && mQsExpandedWhenExpandingStarted));
Selim Cinek758afb12014-06-04 18:46:12 +02001331 mAnimateNextTopPaddingChange = false;
Jorim Jaggid7daab72014-05-06 22:22:20 +02001332 }
1333
1334 private void trackMovement(MotionEvent event) {
Selim Cinekd5ab6452016-12-08 16:34:00 -08001335 if (mQsVelocityTracker != null) mQsVelocityTracker.addMovement(event);
Jorim Jaggifc1a8242014-05-12 19:30:05 +02001336 mLastTouchX = event.getX();
1337 mLastTouchY = event.getY();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001338 }
1339
1340 private void initVelocityTracker() {
Selim Cinekd5ab6452016-12-08 16:34:00 -08001341 if (mQsVelocityTracker != null) {
1342 mQsVelocityTracker.recycle();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001343 }
Selim Cinekd5ab6452016-12-08 16:34:00 -08001344 mQsVelocityTracker = VelocityTracker.obtain();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001345 }
1346
Selim Cinekd5ab6452016-12-08 16:34:00 -08001347 private float getCurrentQSVelocity() {
1348 if (mQsVelocityTracker == null) {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001349 return 0;
1350 }
Selim Cinekd5ab6452016-12-08 16:34:00 -08001351 mQsVelocityTracker.computeCurrentVelocity(1000);
1352 return mQsVelocityTracker.getYVelocity();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001353 }
1354
Selim Cinek831941f2015-06-17 15:09:30 -07001355 private void cancelQsAnimation() {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001356 if (mQsExpansionAnimator != null) {
1357 mQsExpansionAnimator.cancel();
1358 }
1359 }
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001360
Jim Miller07e03842016-06-22 15:18:13 -07001361 public void flingSettings(float vel, boolean expand) {
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001362 flingSettings(vel, expand, null, false /* isClick */);
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001363 }
1364
Muyuan Lid6298fd2016-05-27 13:02:58 -07001365 protected void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable,
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001366 boolean isClick) {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001367 float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight;
Jorim Jaggi9cd731a2014-05-22 14:26:06 +02001368 if (target == mQsExpansionHeight) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001369 if (onFinishRunnable != null) {
1370 onFinishRunnable.run();
1371 }
Jorim Jaggi9cd731a2014-05-22 14:26:06 +02001372 return;
1373 }
Jorim Jaggi519779e2016-10-12 16:52:14 +02001374
1375 // If we move in the opposite direction, reset velocity and use a different duration.
1376 boolean oppositeDirection = false;
1377 if (vel > 0 && !expand || vel < 0 && expand) {
Selim Cinek5386fb32014-09-03 16:37:36 +02001378 vel = 0;
Jorim Jaggi519779e2016-10-12 16:52:14 +02001379 oppositeDirection = true;
Selim Cinek5386fb32014-09-03 16:37:36 +02001380 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001381 ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target);
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001382 if (isClick) {
Jorim Jaggiea4a19f2016-02-03 21:31:27 -08001383 animator.setInterpolator(Interpolators.TOUCH_RESPONSE);
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001384 animator.setDuration(368);
1385 } else {
1386 mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel);
1387 }
Jorim Jaggi519779e2016-10-12 16:52:14 +02001388 if (oppositeDirection) {
Selim Cinek5386fb32014-09-03 16:37:36 +02001389 animator.setDuration(350);
1390 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001391 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1392 @Override
1393 public void onAnimationUpdate(ValueAnimator animation) {
1394 setQsExpansion((Float) animation.getAnimatedValue());
1395 }
1396 });
1397 animator.addListener(new AnimatorListenerAdapter() {
1398 @Override
1399 public void onAnimationEnd(Animator animation) {
Mady Mellorc2dbe492017-03-30 13:22:03 -07001400 mNotificationStackScroller.resetCheckSnoozeLeavebehind();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001401 mQsExpansionAnimator = null;
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001402 if (onFinishRunnable != null) {
1403 onFinishRunnable.run();
1404 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001405 }
1406 });
1407 animator.start();
1408 mQsExpansionAnimator = animator;
Jorim Jaggibd003102014-07-04 00:02:42 +02001409 mQsAnimatorExpand = expand;
Jorim Jaggid7daab72014-05-06 22:22:20 +02001410 }
1411
1412 /**
1413 * @return Whether we should intercept a gesture to open Quick Settings.
1414 */
Selim Cinek4c6969a2014-05-26 19:22:17 +02001415 private boolean shouldQuickSettingsIntercept(float x, float y, float yDiff) {
Selim Cinek684a4422015-04-15 16:18:39 -07001416 if (!mQsExpansionEnabled || mCollapsedOnDown) {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001417 return false;
1418 }
Jason Monk0ceef212016-11-02 14:05:23 -04001419 View header = mKeyguardShowing ? mKeyguardStatusBar : mQs.getHeader();
1420 final boolean onHeader = x >= mQsFrame.getX()
1421 && x <= mQsFrame.getX() + mQsFrame.getWidth()
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001422 && y >= header.getTop() && y <= header.getBottom();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001423 if (mQsExpanded) {
Jason Monk16ac3772016-02-10 15:39:21 -05001424 return onHeader || (yDiff < 0 && isInQsArea(x, y));
Jorim Jaggid7daab72014-05-06 22:22:20 +02001425 } else {
1426 return onHeader;
1427 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001428 }
1429
1430 @Override
1431 protected boolean isScrolledToBottom() {
1432 if (!isInSettings()) {
Jorim Jaggi58bef332014-11-21 18:10:32 +01001433 return mStatusBar.getBarState() == StatusBarState.KEYGUARD
1434 || mNotificationStackScroller.isScrolledToBottom();
Jorim Jaggie0640dd2014-08-05 23:12:40 +02001435 } else {
Jason Monk16ac3772016-02-10 15:39:21 -05001436 return true;
Chris Wren64161cc2012-12-17 16:49:30 -05001437 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001438 }
1439
1440 @Override
1441 protected int getMaxPanelHeight() {
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001442 int min = mStatusBarMinHeight;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001443 if (mStatusBar.getBarState() != StatusBarState.KEYGUARD
1444 && mNotificationStackScroller.getNotGoneChildCount() == 0) {
Selim Cinek94c2d822016-07-13 18:50:04 -07001445 int minHeight = (int) (mQsMinExpansionHeight + getOverExpansionAmount());
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001446 min = Math.max(min, minHeight);
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001447 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001448 int maxHeight;
Jason Monk3c68ca22015-01-30 11:30:29 -05001449 if (mQsExpandImmediate || mQsExpanded || mIsExpanding && mQsExpandedWhenExpandingStarted) {
Jorim Jaggi58bef332014-11-21 18:10:32 +01001450 maxHeight = calculatePanelHeightQsExpanded();
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001451 } else {
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001452 maxHeight = calculatePanelHeightShade();
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001453 }
1454 maxHeight = Math.max(maxHeight, min);
Jorim Jaggi1d480692014-05-20 19:41:58 +02001455 return maxHeight;
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001456 }
1457
Jim Miller07e03842016-06-22 15:18:13 -07001458 public boolean isInSettings() {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001459 return mQsExpanded;
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001460 }
1461
Jim Miller07e03842016-06-22 15:18:13 -07001462 public boolean isExpanding() {
1463 return mIsExpanding;
1464 }
1465
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001466 @Override
1467 protected void onHeightUpdated(float expandedHeight) {
Jason Monk3c68ca22015-01-30 11:30:29 -05001468 if (!mQsExpanded || mQsExpandImmediate || mIsExpanding && mQsExpandedWhenExpandingStarted) {
Jorim Jaggi7d16bb12014-05-22 04:24:50 +02001469 positionClockAndNotifications();
1470 }
Jason Monk3c68ca22015-01-30 11:30:29 -05001471 if (mQsExpandImmediate || mQsExpanded && !mQsTracking && mQsExpansionAnimator == null
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001472 && !mQsExpansionFromOverscroll) {
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001473 float t;
1474 if (mKeyguardShowing) {
Jorim Jaggi54045422014-07-03 18:30:40 +02001475
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001476 // On Keyguard, interpolate the QS expansion linearly to the panel expansion
Selim Cinek48ff9b42016-11-09 19:31:51 -08001477 t = expandedHeight / (getMaxPanelHeight());
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001478 } else {
1479
1480 // In Shade, interpolate linearly such that QS is closed whenever panel height is
1481 // minimum QS expansion + minStackHeight
1482 float panelHeightQsCollapsed = mNotificationStackScroller.getIntrinsicPadding()
Selim Cinekd1ad9ab2016-03-01 17:52:20 -08001483 + mNotificationStackScroller.getLayoutMinHeight();
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001484 float panelHeightQsExpanded = calculatePanelHeightQsExpanded();
1485 t = (expandedHeight - panelHeightQsCollapsed)
1486 / (panelHeightQsExpanded - panelHeightQsCollapsed);
1487 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001488 setQsExpansion(mQsMinExpansionHeight
Jorim Jaggi54045422014-07-03 18:30:40 +02001489 + t * (getTempQsMaxExpansion() - mQsMinExpansionHeight));
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001490 }
Selim Cinekbc243a92016-09-27 16:35:13 -07001491 updateExpandedHeight(expandedHeight);
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001492 updateHeader();
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001493 updateUnlockIcon();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001494 updateNotificationTranslucency();
Selim Cinek4a21a7f2015-05-19 11:00:38 -07001495 updatePanelExpanded();
Selim Cinek684a4422015-04-15 16:18:39 -07001496 mNotificationStackScroller.setShadeExpanded(!isFullyCollapsed());
Jorim Jaggi58bef332014-11-21 18:10:32 +01001497 if (DEBUG) {
1498 invalidate();
1499 }
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001500 }
1501
Selim Cinek4a21a7f2015-05-19 11:00:38 -07001502 private void updatePanelExpanded() {
1503 boolean isExpanded = !isFullyCollapsed();
1504 if (mPanelExpanded != isExpanded) {
1505 mHeadsUpManager.setIsExpanded(isExpanded);
1506 mStatusBar.setPanelExpanded(isExpanded);
1507 mPanelExpanded = isExpanded;
1508 }
1509 }
1510
Jorim Jaggi54045422014-07-03 18:30:40 +02001511 /**
1512 * @return a temporary override of {@link #mQsMaxExpansionHeight}, which is needed when
1513 * collapsing QS / the panel when QS was scrolled
1514 */
1515 private int getTempQsMaxExpansion() {
Jason Monk16ac3772016-02-10 15:39:21 -05001516 return mQsMaxExpansionHeight;
Jorim Jaggi54045422014-07-03 18:30:40 +02001517 }
1518
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001519 private int calculatePanelHeightShade() {
1520 int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin();
1521 int maxHeight = mNotificationStackScroller.getHeight() - emptyBottomMargin
1522 - mTopPaddingAdjustment;
1523 maxHeight += mNotificationStackScroller.getTopPaddingOverflow();
1524 return maxHeight;
1525 }
1526
1527 private int calculatePanelHeightQsExpanded() {
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001528 float notificationHeight = mNotificationStackScroller.getHeight()
1529 - mNotificationStackScroller.getEmptyBottomMargin()
1530 - mNotificationStackScroller.getTopPadding();
Jorim Jaggi0cce70c2014-11-04 16:13:41 +01001531
1532 // When only empty shade view is visible in QS collapsed state, simulate that we would have
1533 // it in expanded QS state as well so we don't run into troubles when fading the view in/out
1534 // and expanding/collapsing the whole panel from/to quick settings.
1535 if (mNotificationStackScroller.getNotGoneChildCount() == 0
Selim Cinek24176c32017-03-01 16:50:30 -08001536 && mShowEmptyShadeView) {
Selim Cinekdb167372016-11-17 15:41:17 -08001537 notificationHeight = mNotificationStackScroller.getEmptyShadeViewHeight();
Jorim Jaggi0cce70c2014-11-04 16:13:41 +01001538 }
Jorim Jaggi8bc983e2014-12-10 17:45:50 +01001539 int maxQsHeight = mQsMaxExpansionHeight;
1540
1541 // If an animation is changing the size of the QS panel, take the animated value.
1542 if (mQsSizeChangeAnimator != null) {
1543 maxQsHeight = (int) mQsSizeChangeAnimator.getAnimatedValue();
1544 }
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001545 float totalHeight = Math.max(
Selim Cinek33d46142016-01-15 18:58:39 -08001546 maxQsHeight, mStatusBarState == StatusBarState.KEYGUARD
Jorim Jaggi58bef332014-11-21 18:10:32 +01001547 ? mClockPositionResult.stackScrollerPadding - mTopPaddingAdjustment
1548 : 0)
Selim Cinekbc243a92016-09-27 16:35:13 -07001549 + notificationHeight + mNotificationStackScroller.getTopPaddingOverflow();
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001550 if (totalHeight > mNotificationStackScroller.getHeight()) {
Jorim Jaggi8bc983e2014-12-10 17:45:50 +01001551 float fullyCollapsedHeight = maxQsHeight
Selim Cinekd1ad9ab2016-03-01 17:52:20 -08001552 + mNotificationStackScroller.getLayoutMinHeight();
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001553 totalHeight = Math.max(fullyCollapsedHeight, mNotificationStackScroller.getHeight());
1554 }
Jorim Jaggi61d37f62014-07-30 17:26:55 +02001555 return (int) totalHeight;
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001556 }
1557
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001558 private void updateNotificationTranslucency() {
Selim Cinekbbc580b2015-06-03 14:11:03 +02001559 float alpha = 1f;
1560 if (mClosingWithAlphaFadeOut && !mExpandingFromHeadsUp && !mHeadsUpManager.hasPinnedHeadsUp()) {
1561 alpha = getFadeoutAlpha();
Jorim Jaggi5ad92c52014-07-28 21:07:32 +02001562 }
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001563 mNotificationStackScroller.setAlpha(alpha);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001564 }
1565
Selim Cinekbbc580b2015-06-03 14:11:03 +02001566 private float getFadeoutAlpha() {
Selim Cinek816c8e42015-11-19 12:00:45 -08001567 float alpha = (getNotificationsTopY() + mNotificationStackScroller.getFirstItemMinHeight())
Selim Cinekdb167372016-11-17 15:41:17 -08001568 / mQsMinExpansionHeight;
Selim Cinekbbc580b2015-06-03 14:11:03 +02001569 alpha = Math.max(0, Math.min(alpha, 1));
1570 alpha = (float) Math.pow(alpha, 0.75);
1571 return alpha;
1572 }
1573
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001574 @Override
1575 protected float getOverExpansionAmount() {
1576 return mNotificationStackScroller.getCurrentOverScrollAmount(true /* top */);
1577 }
1578
1579 @Override
1580 protected float getOverExpansionPixels() {
1581 return mNotificationStackScroller.getCurrentOverScrolledPixels(true /* top */);
1582 }
1583
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001584 private void updateUnlockIcon() {
1585 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1586 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
1587 boolean active = getMaxPanelHeight() - getExpandedHeight() > mUnlockMoveDistance;
Selim Cinekbaa23272014-07-08 18:01:07 +02001588 KeyguardAffordanceView lockIcon = mKeyguardBottomArea.getLockIcon();
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001589 if (active && !mUnlockIconActive && mTracking) {
Selim Cinekc18010f2016-01-20 13:41:30 -08001590 lockIcon.setImageAlpha(1.0f, true, 150, Interpolators.FAST_OUT_LINEAR_IN, null);
Selim Cinekbaa23272014-07-08 18:01:07 +02001591 lockIcon.setImageScale(LOCK_ICON_ACTIVE_SCALE, true, 150,
Selim Cinekc18010f2016-01-20 13:41:30 -08001592 Interpolators.FAST_OUT_LINEAR_IN);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001593 } else if (!active && mUnlockIconActive && mTracking) {
Jorim Jaggi27c9b742015-04-09 10:34:49 -07001594 lockIcon.setImageAlpha(lockIcon.getRestingAlpha(), true /* animate */,
Selim Cinekc18010f2016-01-20 13:41:30 -08001595 150, Interpolators.FAST_OUT_LINEAR_IN, null);
Selim Cinekbaa23272014-07-08 18:01:07 +02001596 lockIcon.setImageScale(1.0f, true, 150,
Selim Cinekc18010f2016-01-20 13:41:30 -08001597 Interpolators.FAST_OUT_LINEAR_IN);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001598 }
1599 mUnlockIconActive = active;
1600 }
Jorim Jaggi457cc352014-06-02 22:47:42 +02001601 }
1602
1603 /**
1604 * Hides the header when notifications are colliding with it.
1605 */
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001606 private void updateHeader() {
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001607 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
Jason Monke1be3422016-02-09 10:51:40 -05001608 updateHeaderKeyguardAlpha();
Jorim Jaggi457cc352014-06-02 22:47:42 +02001609 }
Jason Monke1be3422016-02-09 10:51:40 -05001610 updateQsExpansion();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001611 }
1612
Xiaohui Chen9528f432016-02-12 15:03:18 -08001613 protected float getHeaderTranslation() {
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001614 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001615 return 0;
1616 }
Selim Cinek94c2d822016-07-13 18:50:04 -07001617 float translation = NotificationUtils.interpolate(-mQsMinExpansionHeight, 0,
1618 mNotificationStackScroller.getAppearFraction(mExpandedHeight));
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001619 return Math.min(0, translation);
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001620 }
1621
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001622 /**
1623 * @return the alpha to be used to fade out the contents on Keyguard (status bar, bottom area)
1624 * during swiping up
1625 */
1626 private float getKeyguardContentsAlpha() {
1627 float alpha;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001628 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) {
1629
1630 // When on Keyguard, we hide the header as soon as the top card of the notification
1631 // stack scroller is close enough (collision distance) to the bottom of the header.
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001632 alpha = getNotificationsTopY()
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001633 /
Jorim Jaggi3afddce2014-08-14 20:44:43 +02001634 (mKeyguardStatusBar.getHeight() + mNotificationsHeaderCollideDistance);
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001635 } else {
1636
1637 // In SHADE_LOCKED, the top card is already really close to the header. Hide it as
1638 // soon as we start translating the stack.
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001639 alpha = getNotificationsTopY() / mKeyguardStatusBar.getHeight();
Jorim Jaggi2580a9762014-06-25 03:08:25 +02001640 }
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001641 alpha = MathUtils.constrain(alpha, 0, 1);
1642 alpha = (float) Math.pow(alpha, 0.75);
1643 return alpha;
1644 }
1645
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001646 private void updateHeaderKeyguardAlpha() {
Jorim Jaggi3afddce2014-08-14 20:44:43 +02001647 float alphaQsExpansion = 1 - Math.min(1, getQsExpansionFraction() * 2);
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001648 mKeyguardStatusBar.setAlpha(Math.min(getKeyguardContentsAlpha(), alphaQsExpansion)
Jorim Jaggi16423aa2014-10-28 11:42:58 +01001649 * mKeyguardStatusBarAnimateAlpha);
Selim Cinek8f2d767f2015-06-15 20:55:04 -07001650 mKeyguardStatusBar.setVisibility(mKeyguardStatusBar.getAlpha() != 0f
1651 && !mDozing ? VISIBLE : INVISIBLE);
Jorim Jaggie4f1a202015-06-30 13:35:11 -07001652 }
1653
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001654 private void updateKeyguardBottomAreaAlpha() {
Adrian Roos14410b02015-06-10 13:35:41 -07001655 float alpha = Math.min(getKeyguardContentsAlpha(), 1 - getQsExpansionFraction());
1656 mKeyguardBottomArea.setAlpha(alpha);
1657 mKeyguardBottomArea.setImportantForAccessibility(alpha == 0f
1658 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
1659 : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001660 }
1661
Jorim Jaggiad46ffef2014-07-04 18:05:06 +02001662 private float getNotificationsTopY() {
1663 if (mNotificationStackScroller.getNotGoneChildCount() == 0) {
1664 return getExpandedHeight();
1665 }
1666 return mNotificationStackScroller.getNotificationsTopY();
1667 }
1668
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001669 @Override
Selim Cinek1685e632014-04-08 02:27:49 +02001670 protected void onExpandingStarted() {
1671 super.onExpandingStarted();
1672 mNotificationStackScroller.onExpansionStarted();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001673 mIsExpanding = true;
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001674 mQsExpandedWhenExpandingStarted = mQsFullyExpanded;
Jorim Jaggi56306252014-07-03 00:40:09 +02001675 if (mQsExpanded) {
Jorim Jaggi56306252014-07-03 00:40:09 +02001676 onQsExpansionStarted();
1677 }
Jason Monkb5ece9a2016-04-22 11:40:36 -04001678 // Since there are QS tiles in the header now, we need to make sure we start listening
1679 // immediately so they can be up to date.
Jason Monkf4e019a2016-11-03 09:07:20 -04001680 if (mQs == null) return;
Jason Monk0ceef212016-11-02 14:05:23 -04001681 mQs.setHeaderListening(true);
Selim Cinek1685e632014-04-08 02:27:49 +02001682 }
1683
1684 @Override
1685 protected void onExpandingFinished() {
1686 super.onExpandingFinished();
1687 mNotificationStackScroller.onExpansionStopped();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001688 mHeadsUpManager.onExpandingFinished();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001689 mIsExpanding = false;
Selim Cinek684a4422015-04-15 16:18:39 -07001690 if (isFullyCollapsed()) {
Jorim Jaggi613f55f2015-07-16 15:30:10 -07001691 DejankUtils.postAfterTraversal(new Runnable() {
1692 @Override
1693 public void run() {
1694 setListening(false);
1695 }
1696 });
1697
1698 // Workaround b/22639032: Make sure we invalidate something because else RenderThread
1699 // thinks we are actually drawing a frame put in reality we don't, so RT doesn't go
1700 // ahead with rendering and we jank.
1701 postOnAnimation(new Runnable() {
1702 @Override
1703 public void run() {
1704 getParent().invalidateChild(NotificationPanelView.this, mDummyDirtyRect);
1705 }
1706 });
Jorim Jaggie65e3102014-07-01 22:00:50 +02001707 } else {
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001708 setListening(true);
Jorim Jaggie65e3102014-07-01 22:00:50 +02001709 }
Jason Monk3c68ca22015-01-30 11:30:29 -05001710 mQsExpandImmediate = false;
Jorim Jaggi1e2554b2014-07-10 23:07:00 +02001711 mTwoFingerQsExpandPossible = false;
Selim Cinek684a4422015-04-15 16:18:39 -07001712 mIsExpansionFromHeadsUp = false;
1713 mNotificationStackScroller.setTrackingHeadsUp(false);
1714 mExpandingFromHeadsUp = false;
Selim Cinek3d395c62015-06-16 19:37:37 -07001715 setPanelScrimMinFraction(0.0f);
Jorim Jaggie65e3102014-07-01 22:00:50 +02001716 }
1717
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001718 private void setListening(boolean listening) {
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001719 mKeyguardStatusBar.setListening(listening);
Jason Monk0ceef212016-11-02 14:05:23 -04001720 if (mQs == null) return;
1721 mQs.setListening(listening);
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001722 }
1723
Jorim Jaggie65e3102014-07-01 22:00:50 +02001724 @Override
Oren Blasberg8d3fea12015-07-10 14:21:44 -07001725 public void expand(boolean animate) {
1726 super.expand(animate);
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001727 setListening(true);
Selim Cinek1685e632014-04-08 02:27:49 +02001728 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001729
1730 @Override
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001731 protected void setOverExpansion(float overExpansion, boolean isPixels) {
Jason Monk3c68ca22015-01-30 11:30:29 -05001732 if (mConflictingQsExpansionGesture || mQsExpandImmediate) {
Jorim Jaggidc96d632014-07-01 18:48:52 +02001733 return;
1734 }
Selim Cinek1408eb52014-06-02 14:45:38 +02001735 if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001736 mNotificationStackScroller.setOnHeightChangedListener(null);
1737 if (isPixels) {
1738 mNotificationStackScroller.setOverScrolledPixels(
1739 overExpansion, true /* onTop */, false /* animate */);
1740 } else {
1741 mNotificationStackScroller.setOverScrollAmount(
1742 overExpansion, true /* onTop */, false /* animate */);
1743 }
1744 mNotificationStackScroller.setOnHeightChangedListener(this);
Selim Cinek1408eb52014-06-02 14:45:38 +02001745 }
Selim Cinek24120a52014-05-26 10:05:42 +02001746 }
1747
1748 @Override
Jorim Jaggi282a6152014-06-02 23:37:53 +02001749 protected void onTrackingStarted() {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001750 mFalsingManager.onTrackingStarted();
Jorim Jaggi282a6152014-06-02 23:37:53 +02001751 super.onTrackingStarted();
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001752 if (mQsFullyExpanded) {
Jason Monk3c68ca22015-01-30 11:30:29 -05001753 mQsExpandImmediate = true;
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01001754 }
Jorim Jaggi282a6152014-06-02 23:37:53 +02001755 if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1756 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
Adrian Roose31f30e2017-01-25 14:48:15 -08001757 mAffordanceHelper.animateHideLeftRightIcon();
Jorim Jaggie0640dd2014-08-05 23:12:40 +02001758 }
Jorim Jaggie4b840d2015-06-30 16:19:17 -07001759 mNotificationStackScroller.onPanelTrackingStarted();
Jorim Jaggi282a6152014-06-02 23:37:53 +02001760 }
1761
1762 @Override
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +02001763 protected void onTrackingStopped(boolean expand) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001764 mFalsingManager.onTrackingStopped();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +02001765 super.onTrackingStopped(expand);
Jorim Jaggi47c85a32014-06-05 17:25:40 +02001766 if (expand) {
1767 mNotificationStackScroller.setOverScrolledPixels(
1768 0.0f, true /* onTop */, true /* animate */);
1769 }
Jorim Jaggie4b840d2015-06-30 16:19:17 -07001770 mNotificationStackScroller.onPanelTrackingStopped();
Jorim Jaggi282a6152014-06-02 23:37:53 +02001771 if (expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1772 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) {
Selim Cinekbaa23272014-07-08 18:01:07 +02001773 if (!mHintAnimationRunning) {
Adrian Roose31f30e2017-01-25 14:48:15 -08001774 mAffordanceHelper.reset(true);
Selim Cinekbaa23272014-07-08 18:01:07 +02001775 }
Jorim Jaggi282a6152014-06-02 23:37:53 +02001776 }
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001777 if (!expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD
1778 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) {
Selim Cinekbaa23272014-07-08 18:01:07 +02001779 KeyguardAffordanceView lockIcon = mKeyguardBottomArea.getLockIcon();
Selim Cinekc18010f2016-01-20 13:41:30 -08001780 lockIcon.setImageAlpha(0.0f, true, 100, Interpolators.FAST_OUT_LINEAR_IN, null);
1781 lockIcon.setImageScale(2.0f, true, 100, Interpolators.FAST_OUT_LINEAR_IN);
Jorim Jaggi8dd95e02014-06-03 16:19:33 +02001782 }
Selim Cinek24120a52014-05-26 10:05:42 +02001783 }
1784
Selim Cinek24120a52014-05-26 10:05:42 +02001785 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001786 public void onHeightChanged(ExpandableView view, boolean needsAnimation) {
Jorim Jaggi30c305c2014-07-01 23:34:41 +02001787
1788 // Block update if we are in quick settings and just the top padding changed
1789 // (i.e. view == null).
1790 if (view == null && mQsExpanded) {
1791 return;
1792 }
Selim Cinekbc243a92016-09-27 16:35:13 -07001793 ExpandableView firstChildNotGone = mNotificationStackScroller.getFirstChildNotGone();
1794 ExpandableNotificationRow firstRow = firstChildNotGone instanceof ExpandableNotificationRow
1795 ? (ExpandableNotificationRow) firstChildNotGone
1796 : null;
1797 if (firstRow != null
1798 && (view == firstRow || (firstRow.getNotificationParent() == firstRow))) {
1799 requestScrollerTopPaddingUpdate(false);
1800 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001801 requestPanelHeightUpdate();
1802 }
Jorim Jaggid7daab72014-05-06 22:22:20 +02001803
1804 @Override
Selim Cineka5e211b2014-08-11 17:35:48 +02001805 public void onReset(ExpandableView view) {
1806 }
1807
Jason Monk8b9d67f2016-03-02 08:59:08 -05001808 public void onQsHeightChanged() {
Jason Monkf4e019a2016-11-03 09:07:20 -04001809 mQsMaxExpansionHeight = mQs != null ? mQs.getDesiredHeight() : 0;
Jason Monkf50e8822016-06-01 11:19:26 -04001810 if (mQsExpanded && mQsFullyExpanded) {
Jason Monk8b9d67f2016-03-02 08:59:08 -05001811 mQsExpansionHeight = mQsMaxExpansionHeight;
Selim Cinek1408eb52014-06-02 14:45:38 +02001812 requestScrollerTopPaddingUpdate(false /* animate */);
Jorim Jaggi56306252014-07-03 00:40:09 +02001813 requestPanelHeightUpdate();
Jorim Jaggid7daab72014-05-06 22:22:20 +02001814 }
1815 }
1816
1817 @Override
Selim Cinek4c6969a2014-05-26 19:22:17 +02001818 protected void onConfigurationChanged(Configuration newConfig) {
1819 super.onConfigurationChanged(newConfig);
Adrian Roose31f30e2017-01-25 14:48:15 -08001820 mAffordanceHelper.onConfigurationChanged();
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07001821 if (newConfig.orientation != mLastOrientation) {
1822 resetVerticalPanelPosition();
1823 }
1824 mLastOrientation = newConfig.orientation;
Selim Cinek4c6969a2014-05-26 19:22:17 +02001825 }
1826
1827 @Override
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001828 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Adrian Roos5153d4a2016-03-22 10:01:56 -07001829 mNavigationBarBottomHeight = insets.getStableInsetBottom();
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001830 updateMaxHeadsUpTranslation();
1831 return insets;
1832 }
1833
1834 private void updateMaxHeadsUpTranslation() {
Selim Cinek684a4422015-04-15 16:18:39 -07001835 mNotificationStackScroller.setHeadsUpBoundaries(getHeight(), mNavigationBarBottomHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001836 }
1837
1838 @Override
Jorim Jaggi0a818222014-11-10 19:04:34 +01001839 public void onRtlPropertiesChanged(int layoutDirection) {
1840 if (layoutDirection != mOldLayoutDirection) {
Adrian Roose31f30e2017-01-25 14:48:15 -08001841 mAffordanceHelper.onRtlPropertiesChanged();
Jorim Jaggi0a818222014-11-10 19:04:34 +01001842 mOldLayoutDirection = layoutDirection;
1843 }
1844 }
1845
1846 @Override
Jorim Jaggid7daab72014-05-06 22:22:20 +02001847 public void onClick(View v) {
Jason Monkf7d9c492016-03-29 16:29:39 -04001848 if (v.getId() == R.id.expand_indicator) {
Jorim Jaggid7daab72014-05-06 22:22:20 +02001849 onQsExpansionStarted();
1850 if (mQsExpanded) {
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001851 flingSettings(0 /* vel */, false /* expand */, null, true /* isClick */);
Jorim Jaggid7daab72014-05-06 22:22:20 +02001852 } else if (mQsExpansionEnabled) {
Chris Wren27a52fa2017-02-01 14:21:43 -05001853 mLockscreenGestureLogger.write(MetricsEvent.ACTION_SHADE_QS_TAP, 0, 0);
Jorim Jaggi46ac19f2015-06-05 17:55:21 -07001854 flingSettings(0 /* vel */, true /* expand */, null, true /* isClick */);
Jorim Jaggid7daab72014-05-06 22:22:20 +02001855 }
1856 }
1857 }
Selim Cinek4c6969a2014-05-26 19:22:17 +02001858
1859 @Override
Christoph Studerb0183992014-12-22 21:02:26 +01001860 public void onAnimationToSideStarted(boolean rightPage, float translation, float vel) {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001861 boolean start = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? rightPage : !rightPage;
Selim Cinekbaa23272014-07-08 18:01:07 +02001862 mIsLaunchTransitionRunning = true;
1863 mLaunchAnimationEndRunnable = null;
Christoph Studerb0183992014-12-22 21:02:26 +01001864 float displayDensity = mStatusBar.getDisplayDensity();
1865 int lengthDp = Math.abs((int) (translation / displayDensity));
1866 int velocityDp = Math.abs((int) (vel / displayDensity));
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001867 if (start) {
Chris Wren27a52fa2017-02-01 14:21:43 -05001868 mLockscreenGestureLogger.write(MetricsEvent.ACTION_LS_DIALER, lengthDp, velocityDp);
Blazej Magnowski72323322015-07-24 11:49:40 -07001869
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001870 mFalsingManager.onLeftAffordanceOn();
1871 if (mFalsingManager.shouldEnforceBouncer()) {
Blazej Magnowski72323322015-07-24 11:49:40 -07001872 mStatusBar.executeRunnableDismissingKeyguard(new Runnable() {
1873 @Override
1874 public void run() {
1875 mKeyguardBottomArea.launchLeftAffordance();
1876 }
Felipe Lemeee5d6302016-04-22 16:11:19 -07001877 }, null, true /* dismissShade */, false /* afterKeyguardGone */,
1878 true /* deferred */);
Blazej Magnowski72323322015-07-24 11:49:40 -07001879 }
1880 else {
1881 mKeyguardBottomArea.launchLeftAffordance();
1882 }
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001883 } else {
Jorim Jaggi40aa8812015-09-23 12:59:22 -07001884 if (KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE.equals(
1885 mLastCameraLaunchSource)) {
Chris Wren27a52fa2017-02-01 14:21:43 -05001886 mLockscreenGestureLogger.write(MetricsEvent.ACTION_LS_CAMERA, lengthDp, velocityDp);
Jorim Jaggi40aa8812015-09-23 12:59:22 -07001887 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001888 mFalsingManager.onCameraOn();
1889 if (mFalsingManager.shouldEnforceBouncer()) {
Blazej Magnowski72323322015-07-24 11:49:40 -07001890 mStatusBar.executeRunnableDismissingKeyguard(new Runnable() {
1891 @Override
1892 public void run() {
Jorim Jaggifc832e32015-09-25 11:54:05 -07001893 mKeyguardBottomArea.launchCamera(mLastCameraLaunchSource);
Blazej Magnowski72323322015-07-24 11:49:40 -07001894 }
Felipe Lemeee5d6302016-04-22 16:11:19 -07001895 }, null, true /* dismissShade */, false /* afterKeyguardGone */,
1896 true /* deferred */);
Blazej Magnowski72323322015-07-24 11:49:40 -07001897 }
1898 else {
Jorim Jaggifc832e32015-09-25 11:54:05 -07001899 mKeyguardBottomArea.launchCamera(mLastCameraLaunchSource);
Blazej Magnowski72323322015-07-24 11:49:40 -07001900 }
Selim Cinek4c6969a2014-05-26 19:22:17 +02001901 }
Jorim Jaggi826730a2014-12-08 21:05:13 +01001902 mStatusBar.startLaunchTransitionTimeout();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001903 mBlockTouches = true;
1904 }
1905
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001906 @Override
Selim Cinekbaa23272014-07-08 18:01:07 +02001907 public void onAnimationToSideEnded() {
1908 mIsLaunchTransitionRunning = false;
1909 mIsLaunchTransitionFinished = true;
1910 if (mLaunchAnimationEndRunnable != null) {
1911 mLaunchAnimationEndRunnable.run();
1912 mLaunchAnimationEndRunnable = null;
1913 }
Jorim Jaggife762342016-10-13 14:33:27 +02001914 mStatusBar.readyForKeyguardDone();
Selim Cinekbaa23272014-07-08 18:01:07 +02001915 }
1916
1917 @Override
Jorim Jaggi93a2bb22014-06-02 19:57:28 +02001918 protected void startUnlockHintAnimation() {
1919 super.startUnlockHintAnimation();
1920 startHighlightIconAnimation(getCenterIcon());
1921 }
1922
1923 /**
1924 * Starts the highlight (making it fully opaque) animation on an icon.
1925 */
Selim Cinekbaa23272014-07-08 18:01:07 +02001926 private void startHighlightIconAnimation(final KeyguardAffordanceView icon) {
1927 icon.setImageAlpha(1.0f, true, KeyguardAffordanceHelper.HINT_PHASE1_DURATION,
Selim Cinekc18010f2016-01-20 13:41:30 -08001928 Interpolators.FAST_OUT_SLOW_IN, new Runnable() {
Jorim Jaggi93a2bb22014-06-02 19:57:28 +02001929 @Override
1930 public void run() {
Jorim Jaggi27c9b742015-04-09 10:34:49 -07001931 icon.setImageAlpha(icon.getRestingAlpha(),
1932 true /* animate */, KeyguardAffordanceHelper.HINT_PHASE1_DURATION,
Selim Cinekc18010f2016-01-20 13:41:30 -08001933 Interpolators.FAST_OUT_SLOW_IN, null);
Jorim Jaggi93a2bb22014-06-02 19:57:28 +02001934 }
1935 });
1936 }
1937
1938 @Override
Selim Cinek6746c282015-04-21 19:58:31 -07001939 public float getMaxTranslationDistance() {
1940 return (float) Math.hypot(getWidth(), getHeight());
Selim Cinek4c6969a2014-05-26 19:22:17 +02001941 }
1942
1943 @Override
Jorim Jaggid9449862015-05-29 14:49:08 -07001944 public void onSwipingStarted(boolean rightIcon) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001945 mFalsingManager.onAffordanceSwipingStarted(rightIcon);
Jorim Jaggid9449862015-05-29 14:49:08 -07001946 boolean camera = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? !rightIcon
1947 : rightIcon;
1948 if (camera) {
Jorim Jaggid9449862015-05-29 14:49:08 -07001949 mKeyguardBottomArea.bindCameraPrewarmService();
Jorim Jaggia86790b2015-04-02 16:32:29 -07001950 }
Selim Cinekbaa23272014-07-08 18:01:07 +02001951 requestDisallowInterceptTouchEvent(true);
1952 mOnlyAffordanceInThisMotion = true;
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01001953 mQsTracking = false;
Selim Cinek4c6969a2014-05-26 19:22:17 +02001954 }
1955
1956 @Override
Jorim Jaggia86790b2015-04-02 16:32:29 -07001957 public void onSwipingAborted() {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001958 mFalsingManager.onAffordanceSwipingAborted();
Jorim Jaggid9449862015-05-29 14:49:08 -07001959 mKeyguardBottomArea.unbindCameraPrewarmService(false /* launched */);
Jorim Jaggia86790b2015-04-02 16:32:29 -07001960 }
1961
1962 @Override
Selim Cinek6746c282015-04-21 19:58:31 -07001963 public void onIconClicked(boolean rightIcon) {
1964 if (mHintAnimationRunning) {
1965 return;
1966 }
1967 mHintAnimationRunning = true;
Adrian Roose31f30e2017-01-25 14:48:15 -08001968 mAffordanceHelper.startHintAnimation(rightIcon, new Runnable() {
Selim Cinek6746c282015-04-21 19:58:31 -07001969 @Override
1970 public void run() {
1971 mHintAnimationRunning = false;
1972 mStatusBar.onHintFinished();
1973 }
1974 });
1975 rightIcon = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? !rightIcon : rightIcon;
1976 if (rightIcon) {
1977 mStatusBar.onCameraHintStarted();
1978 } else {
Selim Cineke70d6532015-04-24 16:46:13 -07001979 if (mKeyguardBottomArea.isLeftVoiceAssist()) {
1980 mStatusBar.onVoiceAssistHintStarted();
1981 } else {
1982 mStatusBar.onPhoneHintStarted();
1983 }
Selim Cinek6746c282015-04-21 19:58:31 -07001984 }
1985 }
1986
1987 @Override
Selim Cinekbaa23272014-07-08 18:01:07 +02001988 public KeyguardAffordanceView getLeftIcon() {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02001989 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
Selim Cineke70d6532015-04-24 16:46:13 -07001990 ? mKeyguardBottomArea.getRightView()
1991 : mKeyguardBottomArea.getLeftView();
Selim Cinek4c6969a2014-05-26 19:22:17 +02001992 }
1993
1994 @Override
Selim Cinekbaa23272014-07-08 18:01:07 +02001995 public KeyguardAffordanceView getCenterIcon() {
Selim Cinek4c6969a2014-05-26 19:22:17 +02001996 return mKeyguardBottomArea.getLockIcon();
1997 }
1998
1999 @Override
Selim Cinekbaa23272014-07-08 18:01:07 +02002000 public KeyguardAffordanceView getRightIcon() {
Jorim Jaggib3f0a2f2014-06-02 19:29:39 +02002001 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
Selim Cineke70d6532015-04-24 16:46:13 -07002002 ? mKeyguardBottomArea.getLeftView()
2003 : mKeyguardBottomArea.getRightView();
Selim Cinek4c6969a2014-05-26 19:22:17 +02002004 }
Jorim Jaggi2580a9762014-06-25 03:08:25 +02002005
2006 @Override
Jorim Jaggib6cdcbc2014-07-25 21:58:29 +02002007 public View getLeftPreview() {
2008 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
Selim Cineke70d6532015-04-24 16:46:13 -07002009 ? mKeyguardBottomArea.getRightPreview()
2010 : mKeyguardBottomArea.getLeftPreview();
Jorim Jaggib6cdcbc2014-07-25 21:58:29 +02002011 }
2012
2013 @Override
2014 public View getRightPreview() {
2015 return getLayoutDirection() == LAYOUT_DIRECTION_RTL
Selim Cineke70d6532015-04-24 16:46:13 -07002016 ? mKeyguardBottomArea.getLeftPreview()
2017 : mKeyguardBottomArea.getRightPreview();
Jorim Jaggib6cdcbc2014-07-25 21:58:29 +02002018 }
2019
2020 @Override
Selim Cinek34cf5c42014-09-26 15:39:00 +02002021 public float getAffordanceFalsingFactor() {
Jorim Jaggi50ff3af2015-08-12 18:35:42 -07002022 return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinek34cf5c42014-09-26 15:39:00 +02002023 }
2024
2025 @Override
Adrian Roos6a70b882016-04-19 17:09:07 -07002026 public boolean needsAntiFalsing() {
2027 return mStatusBarState == StatusBarState.KEYGUARD;
2028 }
2029
2030 @Override
Jorim Jaggi2580a9762014-06-25 03:08:25 +02002031 protected float getPeekHeight() {
2032 if (mNotificationStackScroller.getNotGoneChildCount() > 0) {
2033 return mNotificationStackScroller.getPeekHeight();
2034 } else {
Selim Cinek94c2d822016-07-13 18:50:04 -07002035 return mQsMinExpansionHeight;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02002036 }
2037 }
Jorim Jaggi30c305c2014-07-01 23:34:41 +02002038
2039 @Override
Selim Cinek2411f762016-12-28 17:05:08 +01002040 protected boolean shouldUseDismissingAnimation() {
2041 return mStatusBarState != StatusBarState.SHADE
Selim Cinekdf5501b2017-04-14 20:01:27 -07002042 && (!mStatusBar.isKeyguardCurrentlySecure() || !isTracking());
Selim Cinek2411f762016-12-28 17:05:08 +01002043 }
2044
2045 @Override
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02002046 protected boolean fullyExpandedClearAllVisible() {
2047 return mNotificationStackScroller.isDismissViewNotGone()
Jason Monk3c68ca22015-01-30 11:30:29 -05002048 && mNotificationStackScroller.isScrolledToBottom() && !mQsExpandImmediate;
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02002049 }
2050
2051 @Override
2052 protected boolean isClearAllVisible() {
2053 return mNotificationStackScroller.isDismissViewVisible();
2054 }
2055
2056 @Override
2057 protected int getClearAllHeight() {
2058 return mNotificationStackScroller.getDismissViewHeight();
2059 }
2060
2061 @Override
Jorim Jaggi30c305c2014-07-01 23:34:41 +02002062 protected boolean isTrackingBlocked() {
2063 return mConflictingQsExpansionGesture && mQsExpanded;
2064 }
Jorim Jaggi54045422014-07-03 18:30:40 +02002065
Jorim Jaggibd003102014-07-04 00:02:42 +02002066 public boolean isQsExpanded() {
2067 return mQsExpanded;
2068 }
Jorim Jaggi853b0702014-07-05 04:31:14 +02002069
John Spurlockf7ae4422014-08-01 12:45:18 -04002070 public boolean isQsDetailShowing() {
Jason Monk0ceef212016-11-02 14:05:23 -04002071 return mQs.isShowingDetail();
John Spurlockf7ae4422014-08-01 12:45:18 -04002072 }
2073
2074 public void closeQsDetail() {
Jason Monk0ceef212016-11-02 14:05:23 -04002075 mQs.closeDetail();
John Spurlockf7ae4422014-08-01 12:45:18 -04002076 }
2077
Jorim Jaggi853b0702014-07-05 04:31:14 +02002078 @Override
2079 public boolean shouldDelayChildPressedState() {
2080 return true;
2081 }
Selim Cinekbaa23272014-07-08 18:01:07 +02002082
2083 public boolean isLaunchTransitionFinished() {
2084 return mIsLaunchTransitionFinished;
2085 }
2086
2087 public boolean isLaunchTransitionRunning() {
2088 return mIsLaunchTransitionRunning;
2089 }
2090
2091 public void setLaunchTransitionEndRunnable(Runnable r) {
2092 mLaunchAnimationEndRunnable = r;
2093 }
Jorim Jaggi48bc36a2014-07-25 23:16:04 +02002094
2095 public void setEmptyDragAmount(float amount) {
Selim Cinek5386fb32014-09-03 16:37:36 +02002096 float factor = 0.8f;
Jorim Jaggi48bc36a2014-07-25 23:16:04 +02002097 if (mNotificationStackScroller.getNotGoneChildCount() > 0) {
Selim Cinek5386fb32014-09-03 16:37:36 +02002098 factor = 0.4f;
Christoph Studerc8db24b2014-07-25 17:50:30 +02002099 } else if (!mStatusBar.hasActiveNotifications()) {
Jorim Jaggi48bc36a2014-07-25 23:16:04 +02002100 factor = 0.4f;
2101 }
2102 mEmptyDragAmount = amount * factor;
2103 positionClockAndNotifications();
2104 }
Jorim Jaggi61d37f62014-07-30 17:26:55 +02002105
2106 private static float interpolate(float t, float start, float end) {
2107 return (1 - t) * start + t * end;
2108 }
John Spurlockd54da8a2014-08-03 23:23:52 -04002109
Jorim Jaggi16423aa2014-10-28 11:42:58 +01002110 public void setDozing(boolean dozing, boolean animate) {
John Spurlockd54da8a2014-08-03 23:23:52 -04002111 if (dozing == mDozing) return;
2112 mDozing = dozing;
Jorim Jaggi83969702015-06-05 14:59:24 -07002113 if (mStatusBarState == StatusBarState.KEYGUARD) {
2114 updateDozingVisibilities(animate);
2115 }
Jorim Jaggi0e0942d2015-06-05 14:12:20 -07002116 }
2117
2118 private void updateDozingVisibilities(boolean animate) {
John Spurlockd54da8a2014-08-03 23:23:52 -04002119 if (mDozing) {
Jorim Jaggi16423aa2014-10-28 11:42:58 +01002120 mKeyguardStatusBar.setVisibility(View.INVISIBLE);
Adrian Roos91ba3072017-02-14 16:50:46 +01002121 mKeyguardBottomArea.setDozing(mDozing, animate);
John Spurlockd54da8a2014-08-03 23:23:52 -04002122 } else {
Jorim Jaggi16423aa2014-10-28 11:42:58 +01002123 mKeyguardStatusBar.setVisibility(View.VISIBLE);
Adrian Roos91ba3072017-02-14 16:50:46 +01002124 mKeyguardBottomArea.setDozing(mDozing, animate);
Jorim Jaggi16423aa2014-10-28 11:42:58 +01002125 if (animate) {
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01002126 animateKeyguardStatusBarIn(DOZE_ANIMATION_DURATION);
Jorim Jaggi16423aa2014-10-28 11:42:58 +01002127 }
John Spurlockd54da8a2014-08-03 23:23:52 -04002128 }
John Spurlockd54da8a2014-08-03 23:23:52 -04002129 }
Jorim Jaggia2052ea2014-08-05 16:22:30 +02002130
Jorim Jaggid7912d22014-09-30 17:38:19 +02002131 @Override
John Spurlockcf5d3c92014-09-21 17:55:01 -04002132 public boolean isDozing() {
2133 return mDozing;
2134 }
2135
Selim Cinek24176c32017-03-01 16:50:30 -08002136 public void showEmptyShadeView(boolean emptyShadeViewVisible) {
2137 mShowEmptyShadeView = emptyShadeViewVisible;
Jorim Jaggia2052ea2014-08-05 16:22:30 +02002138 updateEmptyShadeView();
2139 }
2140
2141 private void updateEmptyShadeView() {
2142
2143 // Hide "No notifications" in QS.
Selim Cinek24176c32017-03-01 16:50:30 -08002144 mNotificationStackScroller.updateEmptyShadeView(mShowEmptyShadeView && !mQsExpanded);
Jorim Jaggia2052ea2014-08-05 16:22:30 +02002145 }
Jorim Jaggidd5b8862014-08-05 21:04:39 +02002146
2147 public void setQsScrimEnabled(boolean qsScrimEnabled) {
2148 boolean changed = mQsScrimEnabled != qsScrimEnabled;
2149 mQsScrimEnabled = qsScrimEnabled;
2150 if (changed) {
2151 updateQsState();
2152 }
2153 }
John Spurlock7e6809a2014-08-06 16:03:14 -04002154
Jorim Jaggibf1899e2014-08-07 02:04:18 +02002155 public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) {
2156 mKeyguardUserSwitcher = keyguardUserSwitcher;
2157 }
2158
Jorim Jaggi93739112015-08-13 15:53:14 -07002159 public void onScreenTurningOn() {
Jorim Jaggid09def7512014-09-02 18:36:45 +02002160 mKeyguardStatusView.refreshTime();
2161 }
Selim Cinek3a9c10a2014-10-28 14:21:10 +01002162
2163 @Override
2164 public void onEmptySpaceClicked(float x, float y) {
2165 onEmptySpaceClick(x);
2166 }
Jorim Jaggi58bef332014-11-21 18:10:32 +01002167
Jim Miller07e03842016-06-22 15:18:13 -07002168 @Override
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01002169 protected boolean onMiddleClicked() {
2170 switch (mStatusBar.getBarState()) {
2171 case StatusBarState.KEYGUARD:
2172 if (!mDozingOnDown) {
Chris Wren27a52fa2017-02-01 14:21:43 -05002173 mLockscreenGestureLogger.write(
2174 MetricsEvent.ACTION_LS_HINT,
Jorim Jaggi1cf6e102015-01-20 16:45:05 +01002175 0 /* lengthDp - N/A */, 0 /* velocityDp - N/A */);
2176 startUnlockHintAnimation();
2177 }
2178 return true;
2179 case StatusBarState.SHADE_LOCKED:
2180 if (!mQsExpanded) {
2181 mStatusBar.goToKeyguard();
2182 }
2183 return true;
2184 case StatusBarState.SHADE:
2185
2186 // This gets called in the middle of the touch handling, where the state is still
2187 // that we are tracking the panel. Collapse the panel after this is done.
2188 post(mPostCollapseRunnable);
2189 return false;
2190 default:
2191 return true;
2192 }
2193 }
2194
Jorim Jaggi58bef332014-11-21 18:10:32 +01002195 @Override
2196 protected void dispatchDraw(Canvas canvas) {
2197 super.dispatchDraw(canvas);
2198 if (DEBUG) {
2199 Paint p = new Paint();
2200 p.setColor(Color.RED);
2201 p.setStrokeWidth(2);
2202 p.setStyle(Paint.Style.STROKE);
2203 canvas.drawLine(0, getMaxPanelHeight(), getWidth(), getMaxPanelHeight(), p);
2204 p.setColor(Color.BLUE);
2205 canvas.drawLine(0, getExpandedHeight(), getWidth(), getExpandedHeight(), p);
2206 p.setColor(Color.GREEN);
2207 canvas.drawLine(0, calculatePanelHeightQsExpanded(), getWidth(),
2208 calculatePanelHeightQsExpanded(), p);
2209 p.setColor(Color.YELLOW);
2210 canvas.drawLine(0, calculatePanelHeightShade(), getWidth(),
2211 calculatePanelHeightShade(), p);
2212 p.setColor(Color.MAGENTA);
2213 canvas.drawLine(0, calculateQsTopPadding(), getWidth(),
2214 calculateQsTopPadding(), p);
2215 p.setColor(Color.CYAN);
2216 canvas.drawLine(0, mNotificationStackScroller.getTopPadding(), getWidth(),
2217 mNotificationStackScroller.getTopPadding(), p);
2218 }
2219 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002220
2221 @Override
John Spurlockb349af572015-04-29 12:24:19 -04002222 public void onHeadsUpPinnedModeChanged(final boolean inPinnedMode) {
Selim Cinekcafa87f2016-10-26 17:00:17 -07002223 mNotificationStackScroller.setInHeadsUpPinnedMode(inPinnedMode);
Selim Cinek684a4422015-04-15 16:18:39 -07002224 if (inPinnedMode) {
2225 mHeadsUpExistenceChangedRunnable.run();
2226 updateNotificationTranslucency();
2227 } else {
Selim Cinekcafa87f2016-10-26 17:00:17 -07002228 setHeadsUpAnimatingAway(true);
Selim Cinek684a4422015-04-15 16:18:39 -07002229 mNotificationStackScroller.runAfterAnimationFinished(
2230 mHeadsUpExistenceChangedRunnable);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002231 }
2232 }
2233
Selim Cinekcafa87f2016-10-26 17:00:17 -07002234 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
2235 mHeadsUpAnimatingAway = headsUpAnimatingAway;
2236 mNotificationStackScroller.setHeadsUpAnimatingAway(headsUpAnimatingAway);
2237 }
2238
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002239 @Override
Selim Cinek684a4422015-04-15 16:18:39 -07002240 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
2241 mNotificationStackScroller.generateHeadsUpAnimation(headsUp, true);
Selim Cinek1f3f5442015-04-10 17:54:46 -07002242 }
2243
2244 @Override
Selim Cinek684a4422015-04-15 16:18:39 -07002245 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
2246 }
2247
2248 @Override
2249 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002250 mNotificationStackScroller.generateHeadsUpAnimation(entry.row, isHeadsUp);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002251 }
2252
Selim Cineka59ecc32015-04-07 10:51:49 -07002253 @Override
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002254 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
2255 super.setHeadsUpManager(headsUpManager);
Selim Cinek684a4422015-04-15 16:18:39 -07002256 mHeadsUpTouchHelper = new HeadsUpTouchHelper(headsUpManager, mNotificationStackScroller,
2257 this);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002258 }
2259
2260 public void setTrackingHeadsUp(boolean tracking) {
2261 if (tracking) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002262 mNotificationStackScroller.setTrackingHeadsUp(true);
Selim Cinekd2281152015-04-10 14:37:46 -07002263 mExpandingFromHeadsUp = true;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002264 }
Selim Cinek684a4422015-04-15 16:18:39 -07002265 // otherwise we update the state when the expansion is finished
Selim Cinekb8f09cf2015-03-16 17:09:28 -07002266 }
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002267
2268 @Override
2269 protected void onClosingFinished() {
2270 super.onClosingFinished();
2271 resetVerticalPanelPosition();
Selim Cinekbbc580b2015-06-03 14:11:03 +02002272 setClosingWithAlphaFadeout(false);
2273 }
2274
2275 private void setClosingWithAlphaFadeout(boolean closing) {
2276 mClosingWithAlphaFadeOut = closing;
2277 mNotificationStackScroller.forceNoOverlappingRendering(closing);
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002278 }
2279
2280 /**
2281 * Updates the vertical position of the panel so it is positioned closer to the touch
2282 * responsible for opening the panel.
2283 *
2284 * @param x the x-coordinate the touch event
2285 */
Xiaohui Chen9528f432016-02-12 15:03:18 -08002286 protected void updateVerticalPanelPosition(float x) {
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002287 if (mNotificationStackScroller.getWidth() * 1.75f > getWidth()) {
2288 resetVerticalPanelPosition();
2289 return;
2290 }
2291 float leftMost = mPositionMinSideMargin + mNotificationStackScroller.getWidth() / 2;
2292 float rightMost = getWidth() - mPositionMinSideMargin
2293 - mNotificationStackScroller.getWidth() / 2;
2294 if (Math.abs(x - getWidth() / 2) < mNotificationStackScroller.getWidth() / 4) {
2295 x = getWidth() / 2;
2296 }
2297 x = Math.min(rightMost, Math.max(leftMost, x));
2298 setVerticalPanelTranslation(x -
Selim Cinek3d395c62015-06-16 19:37:37 -07002299 (mNotificationStackScroller.getLeft() + mNotificationStackScroller.getWidth() / 2));
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002300 }
2301
2302 private void resetVerticalPanelPosition() {
2303 setVerticalPanelTranslation(0f);
2304 }
2305
Xiaohui Chenf43491f2016-02-01 12:19:35 -08002306 protected void setVerticalPanelTranslation(float translation) {
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002307 mNotificationStackScroller.setTranslationX(translation);
Jason Monk0ceef212016-11-02 14:05:23 -04002308 mQsFrame.setTranslationX(translation);
Jorim Jaggi6d4a27f2015-04-20 16:01:53 -07002309 }
Xiyuan Xiab3a6f1e2015-04-28 16:17:18 -07002310
Selim Cinekbc243a92016-09-27 16:35:13 -07002311 protected void updateExpandedHeight(float expandedHeight) {
Selim Cinekd5ab6452016-12-08 16:34:00 -08002312 if (mTracking) {
2313 mNotificationStackScroller.setExpandingVelocity(getCurrentExpandVelocity());
2314 }
Selim Cinekbc243a92016-09-27 16:35:13 -07002315 mNotificationStackScroller.setExpandedHeight(expandedHeight);
Xiyuan Xiab3a6f1e2015-04-28 16:17:18 -07002316 updateKeyguardBottomAreaAlpha();
Selim Cinek24176c32017-03-01 16:50:30 -08002317 updateStatusBarIcons();
Selim Cinekfcff4c62016-12-27 14:26:06 +01002318 }
2319
2320 /**
2321 * @return whether the notifications are displayed full width and don't have any margins on
2322 * the side.
2323 */
2324 public boolean isFullWidth() {
2325 return mIsFullWidth;
Selim Cinek48ff9b42016-11-09 19:31:51 -08002326 }
2327
Selim Cinek24176c32017-03-01 16:50:30 -08002328 private void updateStatusBarIcons() {
2329 boolean showIconsWhenExpanded = isFullWidth() && getExpandedHeight() < getOpeningHeight();
2330 if (showIconsWhenExpanded && mNoVisibleNotifications && isOnKeyguard()) {
2331 showIconsWhenExpanded = false;
2332 }
2333 if (showIconsWhenExpanded != mShowIconsWhenExpanded) {
2334 mShowIconsWhenExpanded = showIconsWhenExpanded;
Selim Cinek48ff9b42016-11-09 19:31:51 -08002335 mStatusBar.recomputeDisableFlags(false);
2336 }
Xiyuan Xiab3a6f1e2015-04-28 16:17:18 -07002337 }
Selim Cinek3d395c62015-06-16 19:37:37 -07002338
Selim Cinek24176c32017-03-01 16:50:30 -08002339 private boolean isOnKeyguard() {
2340 return mStatusBar.getBarState() == StatusBarState.KEYGUARD;
2341 }
2342
Selim Cinek3d395c62015-06-16 19:37:37 -07002343 public void setPanelScrimMinFraction(float minFraction) {
2344 mBar.panelScrimMinFractionChanged(minFraction);
2345 }
Chris Wren16895942015-06-23 11:22:20 -04002346
Xiaohui Chen9528f432016-02-12 15:03:18 -08002347 public void clearNotificationEffects() {
Chris Wren16895942015-06-23 11:22:20 -04002348 mStatusBar.clearNotificationEffects();
2349 }
Selim Cinek0fccc722015-07-29 17:04:36 -07002350
Jim Miller07e03842016-06-22 15:18:13 -07002351 @Override
Selim Cinek0fccc722015-07-29 17:04:36 -07002352 protected boolean isPanelVisibleBecauseOfHeadsUp() {
2353 return mHeadsUpManager.hasPinnedHeadsUp() || mHeadsUpAnimatingAway;
2354 }
Jorim Jaggi90978852015-08-18 19:55:53 -07002355
2356 @Override
2357 public boolean hasOverlappingRendering() {
2358 return !mDozing;
2359 }
Selim Cinek372d1bd2015-08-14 13:19:37 -07002360
Jorim Jaggi40aa8812015-09-23 12:59:22 -07002361 public void launchCamera(boolean animate, int source) {
2362 if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP) {
2363 mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP;
2364 } else if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_WIGGLE) {
2365 mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_WIGGLE;
Jonathan Solnita4138162017-05-10 21:06:04 -07002366 } else if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER) {
2367 mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER;
Jorim Jaggi40aa8812015-09-23 12:59:22 -07002368 } else {
2369
2370 // Default.
2371 mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
2372 }
2373
Selim Cinek372d1bd2015-08-14 13:19:37 -07002374 // If we are launching it when we are occluded already we don't want it to animate,
2375 // nor setting these flags, since the occluded state doesn't change anymore, hence it's
2376 // never reset.
2377 if (!isFullyCollapsed()) {
2378 mLaunchingAffordance = true;
2379 setLaunchingAffordance(true);
2380 } else {
2381 animate = false;
2382 }
Adrian Roose31f30e2017-01-25 14:48:15 -08002383 mAffordanceHelper.launchAffordance(animate, getLayoutDirection() == LAYOUT_DIRECTION_RTL);
Selim Cinek372d1bd2015-08-14 13:19:37 -07002384 }
2385
2386 public void onAffordanceLaunchEnded() {
2387 mLaunchingAffordance = false;
2388 setLaunchingAffordance(false);
2389 }
2390
Selim Cinek07304f5222016-05-19 18:31:36 -07002391 @Override
2392 public void setAlpha(float alpha) {
2393 super.setAlpha(alpha);
Selim Cinek48ff9b42016-11-09 19:31:51 -08002394 updateFullyVisibleState();
2395 }
2396
2397 @Override
2398 public void setVisibility(int visibility) {
2399 super.setVisibility(visibility);
2400 updateFullyVisibleState();
2401 }
2402
2403 private void updateFullyVisibleState() {
2404 mNotificationStackScroller.setParentNotFullyVisible(getAlpha() != 1.0f
2405 || getVisibility() != VISIBLE);
Selim Cinek07304f5222016-05-19 18:31:36 -07002406 }
2407
Selim Cinek372d1bd2015-08-14 13:19:37 -07002408 /**
2409 * Set whether we are currently launching an affordance. This is currently only set when
2410 * launched via a camera gesture.
2411 */
2412 private void setLaunchingAffordance(boolean launchingAffordance) {
2413 getLeftIcon().setLaunchingAffordance(launchingAffordance);
2414 getRightIcon().setLaunchingAffordance(launchingAffordance);
2415 getCenterIcon().setLaunchingAffordance(launchingAffordance);
2416 }
2417
Zhentao Sun04f97402015-08-26 17:37:30 -07002418 /**
2419 * Whether the camera application can be launched for the camera launch gesture.
2420 *
2421 * @param keyguardIsShowing whether keyguard is being shown
2422 */
2423 public boolean canCameraGestureBeLaunched(boolean keyguardIsShowing) {
2424 ResolveInfo resolveInfo = mKeyguardBottomArea.resolveCameraIntent();
2425 String packageToLaunch = (resolveInfo == null || resolveInfo.activityInfo == null)
2426 ? null : resolveInfo.activityInfo.packageName;
2427 return packageToLaunch != null &&
2428 (keyguardIsShowing || !isForegroundApp(packageToLaunch)) &&
Adrian Roose31f30e2017-01-25 14:48:15 -08002429 !mAffordanceHelper.isSwipingInProgress();
Zhentao Sun04f97402015-08-26 17:37:30 -07002430 }
2431
2432 /**
2433 * Return true if the applications with the package name is running in foreground.
2434 *
2435 * @param pkgName application package name.
2436 */
2437 private boolean isForegroundApp(String pkgName) {
2438 ActivityManager am = getContext().getSystemService(ActivityManager.class);
2439 List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
2440 return !tasks.isEmpty() && pkgName.equals(tasks.get(0).topActivity.getPackageName());
Selim Cinek372d1bd2015-08-14 13:19:37 -07002441 }
Selim Cinek53f8e7d2016-03-25 02:28:01 -07002442
2443 public void setGroupManager(NotificationGroupManager groupManager) {
2444 mGroupManager = groupManager;
2445 }
Jason Monk0ceef212016-11-02 14:05:23 -04002446
Selim Cinek24176c32017-03-01 16:50:30 -08002447 public boolean hideStatusBarIconsWhenExpanded() {
2448 return !isFullWidth() || !mShowIconsWhenExpanded;
Selim Cinek48ff9b42016-11-09 19:31:51 -08002449 }
2450
Jason Monk0ceef212016-11-02 14:05:23 -04002451 private final FragmentListener mFragmentListener = new FragmentListener() {
2452 @Override
2453 public void onFragmentViewCreated(String tag, Fragment fragment) {
2454 mQs = (QS) fragment;
2455 mQs.setPanelView(NotificationPanelView.this);
Jason Monke5b770e2017-03-03 21:49:29 -05002456 mQs.setExpandClickListener(NotificationPanelView.this);
Jason Monk0ceef212016-11-02 14:05:23 -04002457 mQs.setHeaderClickable(mQsExpansionEnabled);
2458 mQs.setKeyguardShowing(mKeyguardShowing);
2459 mQs.setOverscrolling(mStackScrollerOverscrolling);
2460
2461 // recompute internal state when qspanel height changes
2462 mQs.getView().addOnLayoutChangeListener(
2463 (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
2464 final int height = bottom - top;
2465 final int oldHeight = oldBottom - oldTop;
2466 if (height != oldHeight) {
2467 onQsHeightChanged();
2468 }
2469 });
2470 mNotificationStackScroller.setQsContainer((ViewGroup) mQs.getView());
2471 updateQsExpansion();
2472 }
2473
2474 @Override
2475 public void onFragmentViewDestroyed(String tag, Fragment fragment) {
2476 // Manual handling of fragment lifecycle is only required because this bridges
2477 // non-fragment and fragment code. Once we are using a fragment for the notification
2478 // panel, mQs will not need to be null cause it will be tied to the same lifecycle.
2479 if (fragment == mQs) {
2480 mQs = null;
2481 }
2482 }
2483 };
Adrian Roosc934c432017-01-13 11:44:56 -08002484
Selim Cinek2c2f0e22017-05-02 20:02:30 -07002485 @Override
2486 public void setTouchDisabled(boolean disabled) {
2487 super.setTouchDisabled(disabled);
2488 if (disabled && mAffordanceHelper.isSwipingInProgress() && !mIsLaunchTransitionRunning) {
2489 mAffordanceHelper.resetImmediately();
2490 }
2491 }
2492
Adrian Roosc934c432017-01-13 11:44:56 -08002493 public void setDark(boolean dark) {
2494 mDark = dark;
2495 mKeyguardStatusView.setDark(dark);
2496 positionClockAndNotifications();
2497 }
Selim Cinek24176c32017-03-01 16:50:30 -08002498
2499 public void setNoVisibleNotifications(boolean noNotifications) {
2500 mNoVisibleNotifications = noNotifications;
2501 }
Adrian Roosd83e9992017-03-16 15:17:57 -07002502
2503 public void setPulsing(boolean pulsing) {
2504 mKeyguardStatusView.setPulsing(pulsing);
2505 }
Adrian Roos75fa9642017-04-18 11:34:56 -07002506
2507 public void setAmbientIndicationBottomPadding(int ambientIndicationBottomPadding) {
2508 if (mAmbientIndicationBottomPadding != ambientIndicationBottomPadding) {
2509 mAmbientIndicationBottomPadding = ambientIndicationBottomPadding;
2510 mStatusBar.updateKeyguardMaxNotifications();
2511 }
2512 }
Daniel Sandler08d05e32012-08-08 16:39:54 -04002513}