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