blob: d7f11f71050180ccb75b56e996e27f4be01d4394 [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;
251 mStackScrollLayout.setTouchActive(touchActive);
252 }
253
Chris Wren5de6e942012-05-16 14:22:21 -0400254 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200255 public boolean dispatchTouchEvent(MotionEvent ev) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700256 boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN;
Adrian Roosa6c03f82017-07-26 16:20:30 +0200257 boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL;
258 if (!isCancel && mService.shouldIgnoreTouch()) {
259 return false;
260 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700261 if (isDown && mNotificationPanel.isFullyCollapsed()) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700262 mNotificationPanel.startExpandLatencyTracking();
263 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700264 if (isDown) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700265 setTouchActive(true);
Selim Cinek48a92a52017-05-02 20:02:30 -0700266 mTouchCancelled = false;
267 } else if (ev.getActionMasked() == MotionEvent.ACTION_UP
268 || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700269 setTouchActive(false);
Selim Cinek48a92a52017-05-02 20:02:30 -0700270 }
271 if (mTouchCancelled) {
272 return false;
273 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700274 mFalsingManager.onTouchEvent(ev, getWidth(), getHeight());
Adrian Roos9dc32092014-09-02 23:34:10 +0200275 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
276 // Disallow new pointers while the brightness mirror is visible. This is so that you
277 // can't touch anything other than the brightness slider while the mirror is showing
278 // and the rest of the panel is transparent.
279 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
280 return false;
281 }
282 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700283 if (isDown) {
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700284 mStackScrollLayout.closeControlsIfOutsideTouch(ev);
285 }
Adrian Roos67cca742017-04-13 16:52:51 -0700286 if (mService.isDozing()) {
287 mService.mDozeScrimController.extendPulse();
288 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700289
Adrian Roos9dc32092014-09-02 23:34:10 +0200290 return super.dispatchTouchEvent(ev);
291 }
292
293 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400294 public boolean onInterceptTouchEvent(MotionEvent ev) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700295 if (mService.isDozing() && !mStackScrollLayout.hasPulsingNotifications()) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100296 // Capture all touch events in always-on.
Adrian Roosebea7a72016-10-26 12:51:26 -0700297 return true;
298 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700299 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100300 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200301 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200302 && mService.getBarState() == StatusBarState.KEYGUARD
Adrian Roos500263a2017-01-23 14:49:54 -0800303 && !mService.isBouncerShowing()
304 && !mService.isDozing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200305 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700306 }
307 if (!intercept) {
308 super.onInterceptTouchEvent(ev);
309 }
Chris Wren5de6e942012-05-16 14:22:21 -0400310 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700311 MotionEvent cancellation = MotionEvent.obtain(ev);
312 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100313 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200314 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700315 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400316 }
317 return intercept;
318 }
319
320 @Override
321 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100322 boolean handled = false;
323 if (mService.isDozing()) {
324 mDoubleTapHelper.onTouchEvent(ev);
325 handled = true;
326 }
Selim Cinekf8c4add2017-06-08 09:54:58 -0700327 if ((mService.getBarState() == StatusBarState.KEYGUARD && !handled)
328 || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100329 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200330 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700331 }
332 if (!handled) {
333 handled = super.onTouchEvent(ev);
334 }
John Spurlock257f2832013-09-21 18:41:53 -0400335 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500336 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400337 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
338 }
Chris Wren5de6e942012-05-16 14:22:21 -0400339 return handled;
340 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400341
342 @Override
343 public void onDraw(Canvas canvas) {
344 super.onDraw(canvas);
Jorim Jaggi0e664392014-09-27 01:30:22 +0200345 if (mService.isScrimSrcModeEnabled()) {
346 // We need to ensure that our window is always drawn fully even when we have paddings,
347 // since we simulate it to be opaque.
348 int paddedBottom = getHeight() - getPaddingBottom();
349 int paddedRight = getWidth() - getPaddingRight();
350 if (getPaddingTop() != 0) {
351 canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
352 }
353 if (getPaddingBottom() != 0) {
354 canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
355 }
356 if (getPaddingLeft() != 0) {
357 canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
358 mTransparentSrcPaint);
359 }
360 if (getPaddingRight() != 0) {
361 canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
362 mTransparentSrcPaint);
363 }
Selim Cineka0fad3b2014-09-19 17:20:05 +0200364 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400365 if (DEBUG) {
366 Paint pt = new Paint();
367 pt.setColor(0x80FFFF00);
368 pt.setStrokeWidth(12.0f);
369 pt.setStyle(Paint.Style.STROKE);
370 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
371 }
372 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400373
374 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200375 if (mStackScrollLayout != null) {
376 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400377 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400378 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700379
Selim Cinek48a92a52017-05-02 20:02:30 -0700380 public void cancelCurrentTouch() {
381 if (mTouchActive) {
382 final long now = SystemClock.uptimeMillis();
383 MotionEvent event = MotionEvent.obtain(now, now,
384 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
385 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
386 dispatchTouchEvent(event);
387 event.recycle();
388 mTouchCancelled = true;
389 }
390 }
391
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700392 public class LayoutParams extends FrameLayout.LayoutParams {
393
394 public boolean ignoreRightInset;
395
396 public LayoutParams(int width, int height) {
397 super(width, height);
398 }
399
400 public LayoutParams(Context c, AttributeSet attrs) {
401 super(c, attrs);
402
403 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
404 ignoreRightInset = a.getBoolean(
405 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
406 a.recycle();
407 }
408 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700409
410 @Override
411 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
412 int type) {
413 if (type == ActionMode.TYPE_FLOATING) {
414 return startActionMode(originalView, callback, type);
415 }
416 return super.startActionModeForChild(originalView, callback, type);
417 }
418
419 private ActionMode createFloatingActionMode(
420 View originatingView, ActionMode.Callback2 callback) {
421 if (mFloatingActionMode != null) {
422 mFloatingActionMode.finish();
423 }
424 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700425 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700426 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100427 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700428 mFloatingActionModeOriginatingView = originatingView;
429 mFloatingToolbarPreDrawListener =
430 new ViewTreeObserver.OnPreDrawListener() {
431 @Override
432 public boolean onPreDraw() {
433 mode.updateViewLocationInWindow();
434 return true;
435 }
436 };
437 return mode;
438 }
439
440 private void setHandledFloatingActionMode(ActionMode mode) {
441 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700442 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
443 mFloatingActionModeOriginatingView.getViewTreeObserver()
444 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
445 }
446
447 private void cleanupFloatingActionModeViews() {
448 if (mFloatingToolbar != null) {
449 mFloatingToolbar.dismiss();
450 mFloatingToolbar = null;
451 }
452 if (mFloatingActionModeOriginatingView != null) {
453 if (mFloatingToolbarPreDrawListener != null) {
454 mFloatingActionModeOriginatingView.getViewTreeObserver()
455 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
456 mFloatingToolbarPreDrawListener = null;
457 }
458 mFloatingActionModeOriginatingView = null;
459 }
460 }
461
462 private ActionMode startActionMode(
463 View originatingView, ActionMode.Callback callback, int type) {
464 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
465 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
466 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
467 setHandledFloatingActionMode(mode);
468 } else {
469 mode = null;
470 }
471 return mode;
472 }
473
474 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
475 private final ActionMode.Callback mWrapped;
476
477 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
478 mWrapped = wrapped;
479 }
480
481 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
482 return mWrapped.onCreateActionMode(mode, menu);
483 }
484
485 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
486 requestFitSystemWindows();
487 return mWrapped.onPrepareActionMode(mode, menu);
488 }
489
490 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
491 return mWrapped.onActionItemClicked(mode, item);
492 }
493
494 public void onDestroyActionMode(ActionMode mode) {
495 mWrapped.onDestroyActionMode(mode);
496 if (mode == mFloatingActionMode) {
497 cleanupFloatingActionModeViews();
498 mFloatingActionMode = null;
499 }
500 requestFitSystemWindows();
501 }
502
503 @Override
504 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
505 if (mWrapped instanceof ActionMode.Callback2) {
506 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
507 } else {
508 super.onGetContentRect(mode, view, outRect);
509 }
510 }
511 }
512
513 /**
514 * Minimal window to satisfy FloatingToolbar.
515 */
516 private Window mFakeWindow = new Window(mContext) {
517 @Override
518 public void takeSurface(SurfaceHolder.Callback2 callback) {
519 }
520
521 @Override
522 public void takeInputQueue(InputQueue.Callback callback) {
523 }
524
525 @Override
526 public boolean isFloating() {
527 return false;
528 }
529
530 @Override
531 public void alwaysReadCloseOnTouchAttr() {
532 }
533
534 @Override
535 public void setContentView(@LayoutRes int layoutResID) {
536 }
537
538 @Override
539 public void setContentView(View view) {
540 }
541
542 @Override
543 public void setContentView(View view, ViewGroup.LayoutParams params) {
544 }
545
546 @Override
547 public void addContentView(View view, ViewGroup.LayoutParams params) {
548 }
549
550 @Override
551 public void clearContentView() {
552 }
553
554 @Override
555 public View getCurrentFocus() {
556 return null;
557 }
558
559 @Override
560 public LayoutInflater getLayoutInflater() {
561 return null;
562 }
563
564 @Override
565 public void setTitle(CharSequence title) {
566 }
567
568 @Override
569 public void setTitleColor(@ColorInt int textColor) {
570 }
571
572 @Override
573 public void openPanel(int featureId, KeyEvent event) {
574 }
575
576 @Override
577 public void closePanel(int featureId) {
578 }
579
580 @Override
581 public void togglePanel(int featureId, KeyEvent event) {
582 }
583
584 @Override
585 public void invalidatePanelMenu(int featureId) {
586 }
587
588 @Override
589 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
590 return false;
591 }
592
593 @Override
594 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
595 return false;
596 }
597
598 @Override
599 public void closeAllPanels() {
600 }
601
602 @Override
603 public boolean performContextMenuIdentifierAction(int id, int flags) {
604 return false;
605 }
606
607 @Override
608 public void onConfigurationChanged(Configuration newConfig) {
609 }
610
611 @Override
612 public void setBackgroundDrawable(Drawable drawable) {
613 }
614
615 @Override
616 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
617 }
618
619 @Override
620 public void setFeatureDrawableUri(int featureId, Uri uri) {
621 }
622
623 @Override
624 public void setFeatureDrawable(int featureId, Drawable drawable) {
625 }
626
627 @Override
628 public void setFeatureDrawableAlpha(int featureId, int alpha) {
629 }
630
631 @Override
632 public void setFeatureInt(int featureId, int value) {
633 }
634
635 @Override
636 public void takeKeyEvents(boolean get) {
637 }
638
639 @Override
640 public boolean superDispatchKeyEvent(KeyEvent event) {
641 return false;
642 }
643
644 @Override
645 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
646 return false;
647 }
648
649 @Override
650 public boolean superDispatchTouchEvent(MotionEvent event) {
651 return false;
652 }
653
654 @Override
655 public boolean superDispatchTrackballEvent(MotionEvent event) {
656 return false;
657 }
658
659 @Override
660 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
661 return false;
662 }
663
664 @Override
665 public View getDecorView() {
666 return StatusBarWindowView.this;
667 }
668
669 @Override
670 public View peekDecorView() {
671 return null;
672 }
673
674 @Override
675 public Bundle saveHierarchyState() {
676 return null;
677 }
678
679 @Override
680 public void restoreHierarchyState(Bundle savedInstanceState) {
681 }
682
683 @Override
684 protected void onActive() {
685 }
686
687 @Override
688 public void setChildDrawable(int featureId, Drawable drawable) {
689 }
690
691 @Override
692 public void setChildInt(int featureId, int value) {
693 }
694
695 @Override
696 public boolean isShortcutKey(int keyCode, KeyEvent event) {
697 return false;
698 }
699
700 @Override
701 public void setVolumeControlStream(int streamType) {
702 }
703
704 @Override
705 public int getVolumeControlStream() {
706 return 0;
707 }
708
709 @Override
710 public int getStatusBarColor() {
711 return 0;
712 }
713
714 @Override
715 public void setStatusBarColor(@ColorInt int color) {
716 }
717
718 @Override
719 public int getNavigationBarColor() {
720 return 0;
721 }
722
723 @Override
724 public void setNavigationBarColor(@ColorInt int color) {
725 }
726
727 @Override
728 public void setDecorCaptionShade(int decorCaptionShade) {
729 }
730
731 @Override
732 public void setResizingCaptionDrawable(Drawable drawable) {
733 }
734
735 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700736 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700737 }
738
739 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700740 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
741 }
742
743 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700744 public void reportActivityRelaunched() {
745 }
746 };
747
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400748}
749