blob: 4accd86cce98334ebc26737edbe3cdf9679b9924 [file] [log] [blame]
Daniel Sandlerc4f2a562012-05-04 11:55:46 -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
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070019import android.annotation.ColorInt;
20import android.annotation.DrawableRes;
21import android.annotation.LayoutRes;
John Spurlock257f2832013-09-21 18:41:53 -040022import android.app.StatusBarManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040023import android.content.Context;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070024import android.content.res.Configuration;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070025import android.content.res.TypedArray;
Daniel Sandler198a0302012-08-17 16:04:31 -040026import android.graphics.Canvas;
27import android.graphics.Paint;
Selim Cineka0fad3b2014-09-19 17:20:05 +020028import android.graphics.PorterDuff;
29import android.graphics.PorterDuffXfermode;
John Spurlockfba91202014-04-22 12:58:26 -040030import android.graphics.Rect;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070031import android.graphics.drawable.Drawable;
Jaewan Kim50269362016-12-23 11:22:02 +090032import android.media.AudioManager;
John Spurlock0b99ea92014-10-01 15:32:22 -040033import android.media.session.MediaSessionLegacyHelper;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070034import android.net.Uri;
35import android.os.Bundle;
Selim Cineka0fad3b2014-09-19 17:20:05 +020036import android.os.IBinder;
Adrian Roos8008bd12017-02-22 15:02:09 +010037import android.os.SystemClock;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040038import android.util.AttributeSet;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070039import android.view.ActionMode;
Selim Cinek48a92a52017-05-02 20:02:30 -070040import android.view.InputDevice;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070041import android.view.InputQueue;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040042import android.view.KeyEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070043import android.view.LayoutInflater;
44import android.view.Menu;
45import android.view.MenuItem;
Chris Wren5de6e942012-05-16 14:22:21 -040046import android.view.MotionEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070047import android.view.SurfaceHolder;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070048import android.view.View;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070049import android.view.ViewGroup;
50import android.view.ViewTreeObserver;
51import android.view.Window;
Selim Cineka0fad3b2014-09-19 17:20:05 +020052import android.view.WindowManager;
53import android.view.WindowManagerGlobal;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040054import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040055
Selim Cinekf8c4add2017-06-08 09:54:58 -070056import com.android.internal.annotations.VisibleForTesting;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070057import com.android.internal.view.FloatingActionMode;
58import com.android.internal.widget.FloatingToolbar;
Chris Wren5de6e942012-05-16 14:22:21 -040059import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070060import com.android.systemui.classifier.FalsingManager;
Jorim Jaggiecbab362014-04-23 16:13:15 +020061import com.android.systemui.statusbar.DragDownHelper;
62import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010063import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040064
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040065
Jorim Jaggiecbab362014-04-23 16:13:15 +020066public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040067 public static final String TAG = "StatusBarWindowView";
Jason Monk2a6ea9c2017-01-26 11:14:51 -050068 public static final boolean DEBUG = StatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040069
Jorim Jaggiecbab362014-04-23 16:13:15 +020070 private DragDownHelper mDragDownHelper;
Adrian Roos8008bd12017-02-22 15:02:09 +010071 private DoubleTapHelper mDoubleTapHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010072 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070073 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020074 private View mBrightnessMirror;
Chris Wren5de6e942012-05-16 14:22:21 -040075
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070076 private int mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -070077 private int mLeftInset = 0;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070078
Jason Monk2a6ea9c2017-01-26 11:14:51 -050079 private StatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +020080 private final Paint mTransparentSrcPaint = new Paint();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070081 private FalsingManager mFalsingManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040082
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070083 // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by
84 // DecorView, but since this is a special window we have to roll our own.
85 private View mFloatingActionModeOriginatingView;
86 private ActionMode mFloatingActionMode;
87 private FloatingToolbar mFloatingToolbar;
88 private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener;
Selim Cinek48a92a52017-05-02 20:02:30 -070089 private boolean mTouchCancelled;
90 private boolean mTouchActive;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070091
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040092 public StatusBarWindowView(Context context, AttributeSet attrs) {
93 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040094 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +020095 mTransparentSrcPaint.setColor(0);
96 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070097 mFalsingManager = FalsingManager.getInstance(context);
Adrian Roos8008bd12017-02-22 15:02:09 +010098 mDoubleTapHelper = new DoubleTapHelper(this, active -> {}, () -> {
99 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), this);
100 return true;
101 }, null, null);
Chris Wren5de6e942012-05-16 14:22:21 -0400102 }
103
104 @Override
John Spurlockfba91202014-04-22 12:58:26 -0400105 protected boolean fitSystemWindows(Rect insets) {
106 if (getFitsSystemWindows()) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700107 boolean paddingChanged = insets.top != getPaddingTop()
Jorim Jaggi416493b2014-09-13 03:57:32 +0200108 || insets.bottom != getPaddingBottom();
Jorim Jaggiaa806142015-05-20 18:04:16 -0700109
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700110 // Super-special right inset handling, because scrims and backdrop need to ignore it.
Adrian Roos85d202b2016-06-02 16:27:47 -0700111 if (insets.right != mRightInset || insets.left != mLeftInset) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700112 mRightInset = insets.right;
Adrian Roos85d202b2016-06-02 16:27:47 -0700113 mLeftInset = insets.left;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700114 applyMargins();
115 }
Adrian Roos85d202b2016-06-02 16:27:47 -0700116 // Drop top inset, and pass through bottom inset.
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700117 if (paddingChanged) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700118 setPadding(0, 0, 0, 0);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200119 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200120 insets.left = 0;
121 insets.top = 0;
122 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400123 } else {
Adrian Roos85d202b2016-06-02 16:27:47 -0700124 if (mRightInset != 0 || mLeftInset != 0) {
Adrian Roose49e4092015-06-10 18:50:18 -0700125 mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -0700126 mLeftInset = 0;
Adrian Roose49e4092015-06-10 18:50:18 -0700127 applyMargins();
128 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200129 boolean changed = getPaddingLeft() != 0
130 || getPaddingRight() != 0
131 || getPaddingTop() != 0
132 || getPaddingBottom() != 0;
133 if (changed) {
134 setPadding(0, 0, 0, 0);
135 }
Jorim Jaggiaa806142015-05-20 18:04:16 -0700136 insets.top = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400137 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200138 return false;
John Spurlockfba91202014-04-22 12:58:26 -0400139 }
140
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700141 private void applyMargins() {
142 final int N = getChildCount();
143 for (int i = 0; i < N; i++) {
144 View child = getChildAt(i);
145 if (child.getLayoutParams() instanceof LayoutParams) {
146 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Adrian Roos85d202b2016-06-02 16:27:47 -0700147 if (!lp.ignoreRightInset
148 && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700149 lp.rightMargin = mRightInset;
Adrian Roos85d202b2016-06-02 16:27:47 -0700150 lp.leftMargin = mLeftInset;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700151 child.requestLayout();
152 }
153 }
154 }
155 }
156
157 @Override
158 public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
159 return new LayoutParams(getContext(), attrs);
160 }
161
162 @Override
163 protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
164 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
165 }
166
John Spurlockfba91202014-04-22 12:58:26 -0400167 @Override
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400168 protected void onFinishInflate() {
169 super.onFinishInflate();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100170 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
171 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700172 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Adrian Roos9dc32092014-09-02 23:34:10 +0200173 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400174 }
175
dooyoung.hwange4b841e2016-11-16 08:59:23 +0900176 @Override
177 public void onViewAdded(View child) {
178 super.onViewAdded(child);
179 if (child.getId() == R.id.brightness_mirror) {
180 mBrightnessMirror = child;
181 }
182 }
183
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500184 public void setService(StatusBar service) {
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400185 mService = service;
Selim Cinekf8c4add2017-06-08 09:54:58 -0700186 setDragDownHelper(new DragDownHelper(getContext(), this, mStackScrollLayout, mService));
187 }
188
189 @VisibleForTesting
190 void setDragDownHelper(DragDownHelper dragDownHelper) {
191 mDragDownHelper = dragDownHelper;
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400192 }
193
194 @Override
195 protected void onAttachedToWindow () {
196 super.onAttachedToWindow();
Daniel Sandlerb10d8852013-05-08 15:57:06 -0400197
Selim Cineka0fad3b2014-09-19 17:20:05 +0200198 // We need to ensure that our window doesn't suffer from overdraw which would normally
199 // occur if our window is translucent. Since we are drawing the whole window anyway with
200 // the scrim, we don't need the window to be cleared in the beginning.
Jorim Jaggi0e664392014-09-27 01:30:22 +0200201 if (mService.isScrimSrcModeEnabled()) {
202 IBinder windowToken = getWindowToken();
203 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
204 lp.token = windowToken;
205 setLayoutParams(lp);
206 WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
207 setWillNotDraw(false);
208 } else {
209 setWillNotDraw(!DEBUG);
210 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400211 }
212
213 @Override
214 public boolean dispatchKeyEvent(KeyEvent event) {
Adrian Roos56cf73a2016-07-18 14:23:32 -0700215 if (mService.interceptMediaKey(event)) {
216 return true;
217 }
218 if (super.dispatchKeyEvent(event)) {
219 return true;
220 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400221 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
222 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200223 case KeyEvent.KEYCODE_BACK:
224 if (!down) {
225 mService.onBackPressed();
226 }
227 return true;
228 case KeyEvent.KEYCODE_MENU:
229 if (!down) {
230 return mService.onMenuPressed();
231 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200232 case KeyEvent.KEYCODE_SPACE:
233 if (!down) {
234 return mService.onSpacePressed();
235 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400236 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400237 case KeyEvent.KEYCODE_VOLUME_DOWN:
238 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400239 if (mService.isDozing()) {
Jaewan Kim50269362016-12-23 11:22:02 +0900240 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
241 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
John Spurlock0b99ea92014-10-01 15:32:22 -0400242 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400243 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400244 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400245 }
Adrian Roos56cf73a2016-07-18 14:23:32 -0700246 return false;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400247 }
Chris Wren5de6e942012-05-16 14:22:21 -0400248
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700249 public void setTouchActive(boolean touchActive) {
250 mTouchActive = touchActive;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700251 }
252
Chris Wren5de6e942012-05-16 14:22:21 -0400253 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200254 public boolean dispatchTouchEvent(MotionEvent ev) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700255 boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN;
Adrian Roosa6c03f82017-07-26 16:20:30 +0200256 boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL;
257 if (!isCancel && mService.shouldIgnoreTouch()) {
258 return false;
259 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700260 if (isDown && mNotificationPanel.isFullyCollapsed()) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700261 mNotificationPanel.startExpandLatencyTracking();
262 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700263 if (isDown) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700264 setTouchActive(true);
Selim Cinek48a92a52017-05-02 20:02:30 -0700265 mTouchCancelled = false;
266 } else if (ev.getActionMasked() == MotionEvent.ACTION_UP
267 || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700268 setTouchActive(false);
Selim Cinek48a92a52017-05-02 20:02:30 -0700269 }
270 if (mTouchCancelled) {
271 return false;
272 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700273 mFalsingManager.onTouchEvent(ev, getWidth(), getHeight());
Adrian Roos9dc32092014-09-02 23:34:10 +0200274 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
275 // Disallow new pointers while the brightness mirror is visible. This is so that you
276 // can't touch anything other than the brightness slider while the mirror is showing
277 // and the rest of the panel is transparent.
278 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
279 return false;
280 }
281 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700282 if (isDown) {
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700283 mStackScrollLayout.closeControlsIfOutsideTouch(ev);
284 }
Adrian Roos67cca742017-04-13 16:52:51 -0700285 if (mService.isDozing()) {
286 mService.mDozeScrimController.extendPulse();
287 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700288
Adrian Roos9dc32092014-09-02 23:34:10 +0200289 return super.dispatchTouchEvent(ev);
290 }
291
292 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400293 public boolean onInterceptTouchEvent(MotionEvent ev) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700294 if (mService.isDozing() && !mStackScrollLayout.hasPulsingNotifications()) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100295 // Capture all touch events in always-on.
Adrian Roosebea7a72016-10-26 12:51:26 -0700296 return true;
297 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700298 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100299 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200300 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200301 && mService.getBarState() == StatusBarState.KEYGUARD
Adrian Roos500263a2017-01-23 14:49:54 -0800302 && !mService.isBouncerShowing()
303 && !mService.isDozing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200304 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700305 }
306 if (!intercept) {
307 super.onInterceptTouchEvent(ev);
308 }
Chris Wren5de6e942012-05-16 14:22:21 -0400309 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700310 MotionEvent cancellation = MotionEvent.obtain(ev);
311 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100312 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200313 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700314 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400315 }
316 return intercept;
317 }
318
319 @Override
320 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100321 boolean handled = false;
322 if (mService.isDozing()) {
323 mDoubleTapHelper.onTouchEvent(ev);
324 handled = true;
325 }
Selim Cinekf8c4add2017-06-08 09:54:58 -0700326 if ((mService.getBarState() == StatusBarState.KEYGUARD && !handled)
327 || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100328 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200329 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700330 }
331 if (!handled) {
332 handled = super.onTouchEvent(ev);
333 }
John Spurlock257f2832013-09-21 18:41:53 -0400334 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500335 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400336 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
337 }
Chris Wren5de6e942012-05-16 14:22:21 -0400338 return handled;
339 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400340
341 @Override
342 public void onDraw(Canvas canvas) {
343 super.onDraw(canvas);
Jorim Jaggi0e664392014-09-27 01:30:22 +0200344 if (mService.isScrimSrcModeEnabled()) {
345 // We need to ensure that our window is always drawn fully even when we have paddings,
346 // since we simulate it to be opaque.
347 int paddedBottom = getHeight() - getPaddingBottom();
348 int paddedRight = getWidth() - getPaddingRight();
349 if (getPaddingTop() != 0) {
350 canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
351 }
352 if (getPaddingBottom() != 0) {
353 canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
354 }
355 if (getPaddingLeft() != 0) {
356 canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
357 mTransparentSrcPaint);
358 }
359 if (getPaddingRight() != 0) {
360 canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
361 mTransparentSrcPaint);
362 }
Selim Cineka0fad3b2014-09-19 17:20:05 +0200363 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400364 if (DEBUG) {
365 Paint pt = new Paint();
366 pt.setColor(0x80FFFF00);
367 pt.setStrokeWidth(12.0f);
368 pt.setStyle(Paint.Style.STROKE);
369 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
370 }
371 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400372
373 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200374 if (mStackScrollLayout != null) {
375 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400376 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400377 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700378
Selim Cinek48a92a52017-05-02 20:02:30 -0700379 public void cancelCurrentTouch() {
380 if (mTouchActive) {
381 final long now = SystemClock.uptimeMillis();
382 MotionEvent event = MotionEvent.obtain(now, now,
383 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
384 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
385 dispatchTouchEvent(event);
386 event.recycle();
387 mTouchCancelled = true;
388 }
389 }
390
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700391 public class LayoutParams extends FrameLayout.LayoutParams {
392
393 public boolean ignoreRightInset;
394
395 public LayoutParams(int width, int height) {
396 super(width, height);
397 }
398
399 public LayoutParams(Context c, AttributeSet attrs) {
400 super(c, attrs);
401
402 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
403 ignoreRightInset = a.getBoolean(
404 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
405 a.recycle();
406 }
407 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700408
409 @Override
410 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
411 int type) {
412 if (type == ActionMode.TYPE_FLOATING) {
413 return startActionMode(originalView, callback, type);
414 }
415 return super.startActionModeForChild(originalView, callback, type);
416 }
417
418 private ActionMode createFloatingActionMode(
419 View originatingView, ActionMode.Callback2 callback) {
420 if (mFloatingActionMode != null) {
421 mFloatingActionMode.finish();
422 }
423 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700424 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700425 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100426 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700427 mFloatingActionModeOriginatingView = originatingView;
428 mFloatingToolbarPreDrawListener =
429 new ViewTreeObserver.OnPreDrawListener() {
430 @Override
431 public boolean onPreDraw() {
432 mode.updateViewLocationInWindow();
433 return true;
434 }
435 };
436 return mode;
437 }
438
439 private void setHandledFloatingActionMode(ActionMode mode) {
440 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700441 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
442 mFloatingActionModeOriginatingView.getViewTreeObserver()
443 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
444 }
445
446 private void cleanupFloatingActionModeViews() {
447 if (mFloatingToolbar != null) {
448 mFloatingToolbar.dismiss();
449 mFloatingToolbar = null;
450 }
451 if (mFloatingActionModeOriginatingView != null) {
452 if (mFloatingToolbarPreDrawListener != null) {
453 mFloatingActionModeOriginatingView.getViewTreeObserver()
454 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
455 mFloatingToolbarPreDrawListener = null;
456 }
457 mFloatingActionModeOriginatingView = null;
458 }
459 }
460
461 private ActionMode startActionMode(
462 View originatingView, ActionMode.Callback callback, int type) {
463 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
464 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
465 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
466 setHandledFloatingActionMode(mode);
467 } else {
468 mode = null;
469 }
470 return mode;
471 }
472
473 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
474 private final ActionMode.Callback mWrapped;
475
476 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
477 mWrapped = wrapped;
478 }
479
480 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
481 return mWrapped.onCreateActionMode(mode, menu);
482 }
483
484 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
485 requestFitSystemWindows();
486 return mWrapped.onPrepareActionMode(mode, menu);
487 }
488
489 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
490 return mWrapped.onActionItemClicked(mode, item);
491 }
492
493 public void onDestroyActionMode(ActionMode mode) {
494 mWrapped.onDestroyActionMode(mode);
495 if (mode == mFloatingActionMode) {
496 cleanupFloatingActionModeViews();
497 mFloatingActionMode = null;
498 }
499 requestFitSystemWindows();
500 }
501
502 @Override
503 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
504 if (mWrapped instanceof ActionMode.Callback2) {
505 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
506 } else {
507 super.onGetContentRect(mode, view, outRect);
508 }
509 }
510 }
511
512 /**
513 * Minimal window to satisfy FloatingToolbar.
514 */
515 private Window mFakeWindow = new Window(mContext) {
516 @Override
517 public void takeSurface(SurfaceHolder.Callback2 callback) {
518 }
519
520 @Override
521 public void takeInputQueue(InputQueue.Callback callback) {
522 }
523
524 @Override
525 public boolean isFloating() {
526 return false;
527 }
528
529 @Override
530 public void alwaysReadCloseOnTouchAttr() {
531 }
532
533 @Override
534 public void setContentView(@LayoutRes int layoutResID) {
535 }
536
537 @Override
538 public void setContentView(View view) {
539 }
540
541 @Override
542 public void setContentView(View view, ViewGroup.LayoutParams params) {
543 }
544
545 @Override
546 public void addContentView(View view, ViewGroup.LayoutParams params) {
547 }
548
549 @Override
550 public void clearContentView() {
551 }
552
553 @Override
554 public View getCurrentFocus() {
555 return null;
556 }
557
558 @Override
559 public LayoutInflater getLayoutInflater() {
560 return null;
561 }
562
563 @Override
564 public void setTitle(CharSequence title) {
565 }
566
567 @Override
568 public void setTitleColor(@ColorInt int textColor) {
569 }
570
571 @Override
572 public void openPanel(int featureId, KeyEvent event) {
573 }
574
575 @Override
576 public void closePanel(int featureId) {
577 }
578
579 @Override
580 public void togglePanel(int featureId, KeyEvent event) {
581 }
582
583 @Override
584 public void invalidatePanelMenu(int featureId) {
585 }
586
587 @Override
588 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
589 return false;
590 }
591
592 @Override
593 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
594 return false;
595 }
596
597 @Override
598 public void closeAllPanels() {
599 }
600
601 @Override
602 public boolean performContextMenuIdentifierAction(int id, int flags) {
603 return false;
604 }
605
606 @Override
607 public void onConfigurationChanged(Configuration newConfig) {
608 }
609
610 @Override
611 public void setBackgroundDrawable(Drawable drawable) {
612 }
613
614 @Override
615 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
616 }
617
618 @Override
619 public void setFeatureDrawableUri(int featureId, Uri uri) {
620 }
621
622 @Override
623 public void setFeatureDrawable(int featureId, Drawable drawable) {
624 }
625
626 @Override
627 public void setFeatureDrawableAlpha(int featureId, int alpha) {
628 }
629
630 @Override
631 public void setFeatureInt(int featureId, int value) {
632 }
633
634 @Override
635 public void takeKeyEvents(boolean get) {
636 }
637
638 @Override
639 public boolean superDispatchKeyEvent(KeyEvent event) {
640 return false;
641 }
642
643 @Override
644 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
645 return false;
646 }
647
648 @Override
649 public boolean superDispatchTouchEvent(MotionEvent event) {
650 return false;
651 }
652
653 @Override
654 public boolean superDispatchTrackballEvent(MotionEvent event) {
655 return false;
656 }
657
658 @Override
659 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
660 return false;
661 }
662
663 @Override
664 public View getDecorView() {
665 return StatusBarWindowView.this;
666 }
667
668 @Override
669 public View peekDecorView() {
670 return null;
671 }
672
673 @Override
674 public Bundle saveHierarchyState() {
675 return null;
676 }
677
678 @Override
679 public void restoreHierarchyState(Bundle savedInstanceState) {
680 }
681
682 @Override
683 protected void onActive() {
684 }
685
686 @Override
687 public void setChildDrawable(int featureId, Drawable drawable) {
688 }
689
690 @Override
691 public void setChildInt(int featureId, int value) {
692 }
693
694 @Override
695 public boolean isShortcutKey(int keyCode, KeyEvent event) {
696 return false;
697 }
698
699 @Override
700 public void setVolumeControlStream(int streamType) {
701 }
702
703 @Override
704 public int getVolumeControlStream() {
705 return 0;
706 }
707
708 @Override
709 public int getStatusBarColor() {
710 return 0;
711 }
712
713 @Override
714 public void setStatusBarColor(@ColorInt int color) {
715 }
716
717 @Override
718 public int getNavigationBarColor() {
719 return 0;
720 }
721
722 @Override
723 public void setNavigationBarColor(@ColorInt int color) {
724 }
725
726 @Override
727 public void setDecorCaptionShade(int decorCaptionShade) {
728 }
729
730 @Override
731 public void setResizingCaptionDrawable(Drawable drawable) {
732 }
733
734 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700735 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700736 }
737
738 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700739 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
740 }
741
742 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700743 public void reportActivityRelaunched() {
744 }
745 };
746
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400747}
748