blob: f7d0967c2378db3b2bc9f19d2e19cd1b347536af [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;
Selim Cinek2627d722018-01-19 12:16:49 -080091 private boolean mExpandAnimationRunning;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070092
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040093 public StatusBarWindowView(Context context, AttributeSet attrs) {
94 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040095 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +020096 mTransparentSrcPaint.setColor(0);
97 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070098 mFalsingManager = FalsingManager.getInstance(context);
Adrian Roos8008bd12017-02-22 15:02:09 +010099 mDoubleTapHelper = new DoubleTapHelper(this, active -> {}, () -> {
100 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), this);
101 return true;
102 }, null, null);
Chris Wren5de6e942012-05-16 14:22:21 -0400103 }
104
105 @Override
John Spurlockfba91202014-04-22 12:58:26 -0400106 protected boolean fitSystemWindows(Rect insets) {
107 if (getFitsSystemWindows()) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700108 boolean paddingChanged = insets.top != getPaddingTop()
Jorim Jaggi416493b2014-09-13 03:57:32 +0200109 || insets.bottom != getPaddingBottom();
Jorim Jaggiaa806142015-05-20 18:04:16 -0700110
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700111 // Super-special right inset handling, because scrims and backdrop need to ignore it.
Adrian Roos85d202b2016-06-02 16:27:47 -0700112 if (insets.right != mRightInset || insets.left != mLeftInset) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700113 mRightInset = insets.right;
Adrian Roos85d202b2016-06-02 16:27:47 -0700114 mLeftInset = insets.left;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700115 applyMargins();
116 }
Adrian Roos85d202b2016-06-02 16:27:47 -0700117 // Drop top inset, and pass through bottom inset.
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700118 if (paddingChanged) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700119 setPadding(0, 0, 0, 0);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200120 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200121 insets.left = 0;
122 insets.top = 0;
123 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400124 } else {
Adrian Roos85d202b2016-06-02 16:27:47 -0700125 if (mRightInset != 0 || mLeftInset != 0) {
Adrian Roose49e4092015-06-10 18:50:18 -0700126 mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -0700127 mLeftInset = 0;
Adrian Roose49e4092015-06-10 18:50:18 -0700128 applyMargins();
129 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200130 boolean changed = getPaddingLeft() != 0
131 || getPaddingRight() != 0
132 || getPaddingTop() != 0
133 || getPaddingBottom() != 0;
134 if (changed) {
135 setPadding(0, 0, 0, 0);
136 }
Jorim Jaggiaa806142015-05-20 18:04:16 -0700137 insets.top = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400138 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200139 return false;
John Spurlockfba91202014-04-22 12:58:26 -0400140 }
141
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700142 private void applyMargins() {
143 final int N = getChildCount();
144 for (int i = 0; i < N; i++) {
145 View child = getChildAt(i);
146 if (child.getLayoutParams() instanceof LayoutParams) {
147 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Adrian Roos85d202b2016-06-02 16:27:47 -0700148 if (!lp.ignoreRightInset
149 && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700150 lp.rightMargin = mRightInset;
Adrian Roos85d202b2016-06-02 16:27:47 -0700151 lp.leftMargin = mLeftInset;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700152 child.requestLayout();
153 }
154 }
155 }
156 }
157
158 @Override
159 public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
160 return new LayoutParams(getContext(), attrs);
161 }
162
163 @Override
164 protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
165 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
166 }
167
John Spurlockfba91202014-04-22 12:58:26 -0400168 @Override
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400169 protected void onFinishInflate() {
170 super.onFinishInflate();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100171 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
172 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700173 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Adrian Roos9dc32092014-09-02 23:34:10 +0200174 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400175 }
176
dooyoung.hwange4b841e2016-11-16 08:59:23 +0900177 @Override
178 public void onViewAdded(View child) {
179 super.onViewAdded(child);
180 if (child.getId() == R.id.brightness_mirror) {
181 mBrightnessMirror = child;
182 }
183 }
184
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500185 public void setService(StatusBar service) {
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400186 mService = service;
Selim Cinekf8c4add2017-06-08 09:54:58 -0700187 setDragDownHelper(new DragDownHelper(getContext(), this, mStackScrollLayout, mService));
188 }
189
190 @VisibleForTesting
191 void setDragDownHelper(DragDownHelper dragDownHelper) {
192 mDragDownHelper = dragDownHelper;
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400193 }
194
195 @Override
196 protected void onAttachedToWindow () {
197 super.onAttachedToWindow();
Daniel Sandlerb10d8852013-05-08 15:57:06 -0400198
Selim Cineka0fad3b2014-09-19 17:20:05 +0200199 // We need to ensure that our window doesn't suffer from overdraw which would normally
200 // occur if our window is translucent. Since we are drawing the whole window anyway with
201 // the scrim, we don't need the window to be cleared in the beginning.
Jorim Jaggi0e664392014-09-27 01:30:22 +0200202 if (mService.isScrimSrcModeEnabled()) {
203 IBinder windowToken = getWindowToken();
204 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
205 lp.token = windowToken;
206 setLayoutParams(lp);
207 WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
208 setWillNotDraw(false);
209 } else {
210 setWillNotDraw(!DEBUG);
211 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400212 }
213
214 @Override
215 public boolean dispatchKeyEvent(KeyEvent event) {
Adrian Roos56cf73a2016-07-18 14:23:32 -0700216 if (mService.interceptMediaKey(event)) {
217 return true;
218 }
219 if (super.dispatchKeyEvent(event)) {
220 return true;
221 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400222 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
223 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200224 case KeyEvent.KEYCODE_BACK:
225 if (!down) {
226 mService.onBackPressed();
227 }
228 return true;
229 case KeyEvent.KEYCODE_MENU:
230 if (!down) {
231 return mService.onMenuPressed();
232 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200233 case KeyEvent.KEYCODE_SPACE:
234 if (!down) {
235 return mService.onSpacePressed();
236 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400237 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400238 case KeyEvent.KEYCODE_VOLUME_DOWN:
239 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400240 if (mService.isDozing()) {
Jaewan Kim50269362016-12-23 11:22:02 +0900241 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
242 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
John Spurlock0b99ea92014-10-01 15:32:22 -0400243 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400244 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400245 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400246 }
Adrian Roos56cf73a2016-07-18 14:23:32 -0700247 return false;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400248 }
Chris Wren5de6e942012-05-16 14:22:21 -0400249
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700250 public void setTouchActive(boolean touchActive) {
251 mTouchActive = touchActive;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700252 }
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 }
Selim Cinek2627d722018-01-19 12:16:49 -0800271 if (mTouchCancelled || mExpandAnimationRunning) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700272 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
Selim Cinek2627d722018-01-19 12:16:49 -0800392 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
393 mExpandAnimationRunning = expandAnimationRunning;
394 }
395
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700396 public class LayoutParams extends FrameLayout.LayoutParams {
397
398 public boolean ignoreRightInset;
399
400 public LayoutParams(int width, int height) {
401 super(width, height);
402 }
403
404 public LayoutParams(Context c, AttributeSet attrs) {
405 super(c, attrs);
406
407 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
408 ignoreRightInset = a.getBoolean(
409 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
410 a.recycle();
411 }
412 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700413
414 @Override
415 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
416 int type) {
417 if (type == ActionMode.TYPE_FLOATING) {
418 return startActionMode(originalView, callback, type);
419 }
420 return super.startActionModeForChild(originalView, callback, type);
421 }
422
423 private ActionMode createFloatingActionMode(
424 View originatingView, ActionMode.Callback2 callback) {
425 if (mFloatingActionMode != null) {
426 mFloatingActionMode.finish();
427 }
428 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700429 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700430 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100431 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700432 mFloatingActionModeOriginatingView = originatingView;
433 mFloatingToolbarPreDrawListener =
434 new ViewTreeObserver.OnPreDrawListener() {
435 @Override
436 public boolean onPreDraw() {
437 mode.updateViewLocationInWindow();
438 return true;
439 }
440 };
441 return mode;
442 }
443
444 private void setHandledFloatingActionMode(ActionMode mode) {
445 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700446 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
447 mFloatingActionModeOriginatingView.getViewTreeObserver()
448 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
449 }
450
451 private void cleanupFloatingActionModeViews() {
452 if (mFloatingToolbar != null) {
453 mFloatingToolbar.dismiss();
454 mFloatingToolbar = null;
455 }
456 if (mFloatingActionModeOriginatingView != null) {
457 if (mFloatingToolbarPreDrawListener != null) {
458 mFloatingActionModeOriginatingView.getViewTreeObserver()
459 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
460 mFloatingToolbarPreDrawListener = null;
461 }
462 mFloatingActionModeOriginatingView = null;
463 }
464 }
465
466 private ActionMode startActionMode(
467 View originatingView, ActionMode.Callback callback, int type) {
468 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
469 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
470 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
471 setHandledFloatingActionMode(mode);
472 } else {
473 mode = null;
474 }
475 return mode;
476 }
477
478 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
479 private final ActionMode.Callback mWrapped;
480
481 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
482 mWrapped = wrapped;
483 }
484
485 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
486 return mWrapped.onCreateActionMode(mode, menu);
487 }
488
489 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
490 requestFitSystemWindows();
491 return mWrapped.onPrepareActionMode(mode, menu);
492 }
493
494 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
495 return mWrapped.onActionItemClicked(mode, item);
496 }
497
498 public void onDestroyActionMode(ActionMode mode) {
499 mWrapped.onDestroyActionMode(mode);
500 if (mode == mFloatingActionMode) {
501 cleanupFloatingActionModeViews();
502 mFloatingActionMode = null;
503 }
504 requestFitSystemWindows();
505 }
506
507 @Override
508 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
509 if (mWrapped instanceof ActionMode.Callback2) {
510 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
511 } else {
512 super.onGetContentRect(mode, view, outRect);
513 }
514 }
515 }
516
517 /**
518 * Minimal window to satisfy FloatingToolbar.
519 */
520 private Window mFakeWindow = new Window(mContext) {
521 @Override
522 public void takeSurface(SurfaceHolder.Callback2 callback) {
523 }
524
525 @Override
526 public void takeInputQueue(InputQueue.Callback callback) {
527 }
528
529 @Override
530 public boolean isFloating() {
531 return false;
532 }
533
534 @Override
535 public void alwaysReadCloseOnTouchAttr() {
536 }
537
538 @Override
539 public void setContentView(@LayoutRes int layoutResID) {
540 }
541
542 @Override
543 public void setContentView(View view) {
544 }
545
546 @Override
547 public void setContentView(View view, ViewGroup.LayoutParams params) {
548 }
549
550 @Override
551 public void addContentView(View view, ViewGroup.LayoutParams params) {
552 }
553
554 @Override
555 public void clearContentView() {
556 }
557
558 @Override
559 public View getCurrentFocus() {
560 return null;
561 }
562
563 @Override
564 public LayoutInflater getLayoutInflater() {
565 return null;
566 }
567
568 @Override
569 public void setTitle(CharSequence title) {
570 }
571
572 @Override
573 public void setTitleColor(@ColorInt int textColor) {
574 }
575
576 @Override
577 public void openPanel(int featureId, KeyEvent event) {
578 }
579
580 @Override
581 public void closePanel(int featureId) {
582 }
583
584 @Override
585 public void togglePanel(int featureId, KeyEvent event) {
586 }
587
588 @Override
589 public void invalidatePanelMenu(int featureId) {
590 }
591
592 @Override
593 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
594 return false;
595 }
596
597 @Override
598 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
599 return false;
600 }
601
602 @Override
603 public void closeAllPanels() {
604 }
605
606 @Override
607 public boolean performContextMenuIdentifierAction(int id, int flags) {
608 return false;
609 }
610
611 @Override
612 public void onConfigurationChanged(Configuration newConfig) {
613 }
614
615 @Override
616 public void setBackgroundDrawable(Drawable drawable) {
617 }
618
619 @Override
620 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
621 }
622
623 @Override
624 public void setFeatureDrawableUri(int featureId, Uri uri) {
625 }
626
627 @Override
628 public void setFeatureDrawable(int featureId, Drawable drawable) {
629 }
630
631 @Override
632 public void setFeatureDrawableAlpha(int featureId, int alpha) {
633 }
634
635 @Override
636 public void setFeatureInt(int featureId, int value) {
637 }
638
639 @Override
640 public void takeKeyEvents(boolean get) {
641 }
642
643 @Override
644 public boolean superDispatchKeyEvent(KeyEvent event) {
645 return false;
646 }
647
648 @Override
649 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
650 return false;
651 }
652
653 @Override
654 public boolean superDispatchTouchEvent(MotionEvent event) {
655 return false;
656 }
657
658 @Override
659 public boolean superDispatchTrackballEvent(MotionEvent event) {
660 return false;
661 }
662
663 @Override
664 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
665 return false;
666 }
667
668 @Override
669 public View getDecorView() {
670 return StatusBarWindowView.this;
671 }
672
673 @Override
674 public View peekDecorView() {
675 return null;
676 }
677
678 @Override
679 public Bundle saveHierarchyState() {
680 return null;
681 }
682
683 @Override
684 public void restoreHierarchyState(Bundle savedInstanceState) {
685 }
686
687 @Override
688 protected void onActive() {
689 }
690
691 @Override
692 public void setChildDrawable(int featureId, Drawable drawable) {
693 }
694
695 @Override
696 public void setChildInt(int featureId, int value) {
697 }
698
699 @Override
700 public boolean isShortcutKey(int keyCode, KeyEvent event) {
701 return false;
702 }
703
704 @Override
705 public void setVolumeControlStream(int streamType) {
706 }
707
708 @Override
709 public int getVolumeControlStream() {
710 return 0;
711 }
712
713 @Override
714 public int getStatusBarColor() {
715 return 0;
716 }
717
718 @Override
719 public void setStatusBarColor(@ColorInt int color) {
720 }
721
722 @Override
723 public int getNavigationBarColor() {
724 return 0;
725 }
726
727 @Override
728 public void setNavigationBarColor(@ColorInt int color) {
729 }
730
731 @Override
732 public void setDecorCaptionShade(int decorCaptionShade) {
733 }
734
735 @Override
736 public void setResizingCaptionDrawable(Drawable drawable) {
737 }
738
739 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700740 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700741 }
742
743 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700744 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
745 }
746
747 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700748 public void reportActivityRelaunched() {
749 }
750 };
751
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400752}
753