Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
| 20 | import android.annotation.DrawableRes; |
| 21 | import android.annotation.LayoutRes; |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 22 | import android.app.StatusBarManager; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 25 | import android.content.res.TypedArray; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 26 | import android.graphics.Canvas; |
| 27 | import android.graphics.Paint; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 28 | import android.graphics.PorterDuff; |
| 29 | import android.graphics.PorterDuffXfermode; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 30 | import android.graphics.Rect; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 32 | import android.media.session.MediaSessionLegacyHelper; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
| 34 | import android.os.Bundle; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 35 | import android.os.IBinder; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 37 | import android.view.ActionMode; |
| 38 | import android.view.InputQueue; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 39 | import android.view.KeyEvent; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
| 41 | import android.view.Menu; |
| 42 | import android.view.MenuItem; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 43 | import android.view.MotionEvent; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 44 | import android.view.SurfaceHolder; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 45 | import android.view.View; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 46 | import android.view.ViewGroup; |
| 47 | import android.view.ViewTreeObserver; |
| 48 | import android.view.Window; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 49 | import android.view.WindowManager; |
| 50 | import android.view.WindowManagerGlobal; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 51 | import android.widget.FrameLayout; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 52 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 53 | import com.android.internal.view.FloatingActionMode; |
| 54 | import com.android.internal.widget.FloatingToolbar; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 55 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 56 | import com.android.systemui.classifier.FalsingManager; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.BaseStatusBar; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 58 | import com.android.systemui.statusbar.DragDownHelper; |
| 59 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 60 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 61 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 62 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 63 | public class StatusBarWindowView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 64 | public static final String TAG = "StatusBarWindowView"; |
| 65 | public static final boolean DEBUG = BaseStatusBar.DEBUG; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 66 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 67 | private DragDownHelper mDragDownHelper; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 68 | private NotificationStackScrollLayout mStackScrollLayout; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 69 | private NotificationPanelView mNotificationPanel; |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 70 | private View mBrightnessMirror; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 71 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 72 | private int mRightInset = 0; |
| 73 | |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 74 | private PhoneStatusBar mService; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 75 | private final Paint mTransparentSrcPaint = new Paint(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 76 | private FalsingManager mFalsingManager; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 77 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 78 | // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by |
| 79 | // DecorView, but since this is a special window we have to roll our own. |
| 80 | private View mFloatingActionModeOriginatingView; |
| 81 | private ActionMode mFloatingActionMode; |
| 82 | private FloatingToolbar mFloatingToolbar; |
| 83 | private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener; |
| 84 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 85 | public StatusBarWindowView(Context context, AttributeSet attrs) { |
| 86 | super(context, attrs); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 87 | setMotionEventSplittingEnabled(false); |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 88 | mTransparentSrcPaint.setColor(0); |
| 89 | mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 90 | mFalsingManager = FalsingManager.getInstance(context); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 94 | protected boolean fitSystemWindows(Rect insets) { |
| 95 | if (getFitsSystemWindows()) { |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 96 | boolean paddingChanged = insets.left != getPaddingLeft() |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 97 | || insets.top != getPaddingTop() |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 98 | || insets.bottom != getPaddingBottom(); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 99 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 100 | // Super-special right inset handling, because scrims and backdrop need to ignore it. |
| 101 | if (insets.right != mRightInset) { |
| 102 | mRightInset = insets.right; |
| 103 | applyMargins(); |
| 104 | } |
| 105 | // Drop top inset, apply left inset and pass through bottom inset. |
| 106 | if (paddingChanged) { |
| 107 | setPadding(insets.left, 0, 0, 0); |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 108 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 109 | insets.left = 0; |
| 110 | insets.top = 0; |
| 111 | insets.right = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 112 | } else { |
Adrian Roos | e49e409 | 2015-06-10 18:50:18 -0700 | [diff] [blame] | 113 | if (mRightInset != 0) { |
| 114 | mRightInset = 0; |
| 115 | applyMargins(); |
| 116 | } |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 117 | boolean changed = getPaddingLeft() != 0 |
| 118 | || getPaddingRight() != 0 |
| 119 | || getPaddingTop() != 0 |
| 120 | || getPaddingBottom() != 0; |
| 121 | if (changed) { |
| 122 | setPadding(0, 0, 0, 0); |
| 123 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 124 | insets.top = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 125 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 126 | return false; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 129 | private void applyMargins() { |
| 130 | final int N = getChildCount(); |
| 131 | for (int i = 0; i < N; i++) { |
| 132 | View child = getChildAt(i); |
| 133 | if (child.getLayoutParams() instanceof LayoutParams) { |
| 134 | LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 135 | if (!lp.ignoreRightInset && lp.rightMargin != mRightInset) { |
| 136 | lp.rightMargin = mRightInset; |
| 137 | child.requestLayout(); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 145 | return new LayoutParams(getContext(), attrs); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | protected FrameLayout.LayoutParams generateDefaultLayoutParams() { |
| 150 | return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
| 151 | } |
| 152 | |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 153 | @Override |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 154 | protected void onFinishInflate() { |
| 155 | super.onFinishInflate(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 156 | mStackScrollLayout = (NotificationStackScrollLayout) findViewById( |
| 157 | R.id.notification_stack_scroller); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 158 | mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 159 | mBrightnessMirror = findViewById(R.id.brightness_mirror); |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | public void setService(PhoneStatusBar service) { |
| 163 | mService = service; |
| 164 | mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | protected void onAttachedToWindow () { |
| 169 | super.onAttachedToWindow(); |
Daniel Sandler | b10d885 | 2013-05-08 15:57:06 -0400 | [diff] [blame] | 170 | |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 171 | // We need to ensure that our window doesn't suffer from overdraw which would normally |
| 172 | // occur if our window is translucent. Since we are drawing the whole window anyway with |
| 173 | // the scrim, we don't need the window to be cleared in the beginning. |
Jorim Jaggi | 0e66439 | 2014-09-27 01:30:22 +0200 | [diff] [blame] | 174 | if (mService.isScrimSrcModeEnabled()) { |
| 175 | IBinder windowToken = getWindowToken(); |
| 176 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); |
| 177 | lp.token = windowToken; |
| 178 | setLayoutParams(lp); |
| 179 | WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true); |
| 180 | setWillNotDraw(false); |
| 181 | } else { |
| 182 | setWillNotDraw(!DEBUG); |
| 183 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 188 | boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 189 | switch (event.getKeyCode()) { |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 190 | case KeyEvent.KEYCODE_BACK: |
| 191 | if (!down) { |
| 192 | mService.onBackPressed(); |
| 193 | } |
| 194 | return true; |
| 195 | case KeyEvent.KEYCODE_MENU: |
| 196 | if (!down) { |
| 197 | return mService.onMenuPressed(); |
| 198 | } |
Jorim Jaggi | 3425076 | 2014-07-03 23:51:19 +0200 | [diff] [blame] | 199 | case KeyEvent.KEYCODE_SPACE: |
| 200 | if (!down) { |
| 201 | return mService.onSpacePressed(); |
| 202 | } |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 203 | break; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 204 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 205 | case KeyEvent.KEYCODE_VOLUME_UP: |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 206 | if (mService.isDozing()) { |
| 207 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, true); |
| 208 | return true; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 209 | } |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 210 | break; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 211 | } |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 212 | if (mService.interceptMediaKey(event)) { |
| 213 | return true; |
| 214 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 215 | return super.dispatchKeyEvent(event); |
| 216 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 217 | |
| 218 | @Override |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 219 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 220 | mFalsingManager.onTouchEvent(ev, getWidth(), getHeight()); |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 221 | if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) { |
| 222 | // Disallow new pointers while the brightness mirror is visible. This is so that you |
| 223 | // can't touch anything other than the brightness slider while the mirror is showing |
| 224 | // and the rest of the panel is transparent. |
| 225 | if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { |
| 226 | return false; |
| 227 | } |
| 228 | } |
| 229 | return super.dispatchTouchEvent(ev); |
| 230 | } |
| 231 | |
| 232 | @Override |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 233 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 234 | boolean intercept = false; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 235 | if (mNotificationPanel.isFullyExpanded() |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 236 | && mStackScrollLayout.getVisibility() == View.VISIBLE |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 237 | && mService.getBarState() == StatusBarState.KEYGUARD |
| 238 | && !mService.isBouncerShowing()) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 239 | intercept = mDragDownHelper.onInterceptTouchEvent(ev); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 240 | // wake up on a touch down event, if dozing |
| 241 | if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 242 | mService.wakeUpIfDozing(ev.getEventTime(), ev); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 243 | } |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 244 | } |
| 245 | if (!intercept) { |
| 246 | super.onInterceptTouchEvent(ev); |
| 247 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 248 | if (intercept) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 249 | MotionEvent cancellation = MotionEvent.obtain(ev); |
| 250 | cancellation.setAction(MotionEvent.ACTION_CANCEL); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 251 | mStackScrollLayout.onInterceptTouchEvent(cancellation); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 252 | mNotificationPanel.onInterceptTouchEvent(cancellation); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 253 | cancellation.recycle(); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 254 | } |
| 255 | return intercept; |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public boolean onTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 260 | boolean handled = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 261 | if (mService.getBarState() == StatusBarState.KEYGUARD) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 262 | handled = mDragDownHelper.onTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 263 | } |
| 264 | if (!handled) { |
| 265 | handled = super.onTouchEvent(ev); |
| 266 | } |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 267 | final int action = ev.getAction(); |
John Spurlock | d157ca0 | 2013-11-04 10:28:05 -0500 | [diff] [blame] | 268 | if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 269 | mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); |
| 270 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 271 | return handled; |
| 272 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 273 | |
| 274 | @Override |
| 275 | public void onDraw(Canvas canvas) { |
| 276 | super.onDraw(canvas); |
Jorim Jaggi | 0e66439 | 2014-09-27 01:30:22 +0200 | [diff] [blame] | 277 | if (mService.isScrimSrcModeEnabled()) { |
| 278 | // We need to ensure that our window is always drawn fully even when we have paddings, |
| 279 | // since we simulate it to be opaque. |
| 280 | int paddedBottom = getHeight() - getPaddingBottom(); |
| 281 | int paddedRight = getWidth() - getPaddingRight(); |
| 282 | if (getPaddingTop() != 0) { |
| 283 | canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint); |
| 284 | } |
| 285 | if (getPaddingBottom() != 0) { |
| 286 | canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint); |
| 287 | } |
| 288 | if (getPaddingLeft() != 0) { |
| 289 | canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom, |
| 290 | mTransparentSrcPaint); |
| 291 | } |
| 292 | if (getPaddingRight() != 0) { |
| 293 | canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom, |
| 294 | mTransparentSrcPaint); |
| 295 | } |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 296 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 297 | if (DEBUG) { |
| 298 | Paint pt = new Paint(); |
| 299 | pt.setColor(0x80FFFF00); |
| 300 | pt.setStrokeWidth(12.0f); |
| 301 | pt.setStyle(Paint.Style.STROKE); |
| 302 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); |
| 303 | } |
| 304 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 305 | |
| 306 | public void cancelExpandHelper() { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 307 | if (mStackScrollLayout != null) { |
| 308 | mStackScrollLayout.cancelExpandHelper(); |
Daniel Sandler | 1a3bdd5 | 2012-10-23 19:21:20 -0400 | [diff] [blame] | 309 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 310 | } |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 311 | |
| 312 | public class LayoutParams extends FrameLayout.LayoutParams { |
| 313 | |
| 314 | public boolean ignoreRightInset; |
| 315 | |
| 316 | public LayoutParams(int width, int height) { |
| 317 | super(width, height); |
| 318 | } |
| 319 | |
| 320 | public LayoutParams(Context c, AttributeSet attrs) { |
| 321 | super(c, attrs); |
| 322 | |
| 323 | TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout); |
| 324 | ignoreRightInset = a.getBoolean( |
| 325 | R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false); |
| 326 | a.recycle(); |
| 327 | } |
| 328 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 329 | |
| 330 | @Override |
| 331 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, |
| 332 | int type) { |
| 333 | if (type == ActionMode.TYPE_FLOATING) { |
| 334 | return startActionMode(originalView, callback, type); |
| 335 | } |
| 336 | return super.startActionModeForChild(originalView, callback, type); |
| 337 | } |
| 338 | |
| 339 | private ActionMode createFloatingActionMode( |
| 340 | View originatingView, ActionMode.Callback2 callback) { |
| 341 | if (mFloatingActionMode != null) { |
| 342 | mFloatingActionMode.finish(); |
| 343 | } |
| 344 | cleanupFloatingActionModeViews(); |
| 345 | final FloatingActionMode mode = |
| 346 | new FloatingActionMode(mContext, callback, originatingView); |
| 347 | mFloatingActionModeOriginatingView = originatingView; |
| 348 | mFloatingToolbarPreDrawListener = |
| 349 | new ViewTreeObserver.OnPreDrawListener() { |
| 350 | @Override |
| 351 | public boolean onPreDraw() { |
| 352 | mode.updateViewLocationInWindow(); |
| 353 | return true; |
| 354 | } |
| 355 | }; |
| 356 | return mode; |
| 357 | } |
| 358 | |
| 359 | private void setHandledFloatingActionMode(ActionMode mode) { |
| 360 | mFloatingActionMode = mode; |
| 361 | mFloatingToolbar = new FloatingToolbar(mContext, mFakeWindow); |
| 362 | ((FloatingActionMode) mFloatingActionMode).setFloatingToolbar(mFloatingToolbar); |
| 363 | mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary. |
| 364 | mFloatingActionModeOriginatingView.getViewTreeObserver() |
| 365 | .addOnPreDrawListener(mFloatingToolbarPreDrawListener); |
| 366 | } |
| 367 | |
| 368 | private void cleanupFloatingActionModeViews() { |
| 369 | if (mFloatingToolbar != null) { |
| 370 | mFloatingToolbar.dismiss(); |
| 371 | mFloatingToolbar = null; |
| 372 | } |
| 373 | if (mFloatingActionModeOriginatingView != null) { |
| 374 | if (mFloatingToolbarPreDrawListener != null) { |
| 375 | mFloatingActionModeOriginatingView.getViewTreeObserver() |
| 376 | .removeOnPreDrawListener(mFloatingToolbarPreDrawListener); |
| 377 | mFloatingToolbarPreDrawListener = null; |
| 378 | } |
| 379 | mFloatingActionModeOriginatingView = null; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | private ActionMode startActionMode( |
| 384 | View originatingView, ActionMode.Callback callback, int type) { |
| 385 | ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback); |
| 386 | ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback); |
| 387 | if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) { |
| 388 | setHandledFloatingActionMode(mode); |
| 389 | } else { |
| 390 | mode = null; |
| 391 | } |
| 392 | return mode; |
| 393 | } |
| 394 | |
| 395 | private class ActionModeCallback2Wrapper extends ActionMode.Callback2 { |
| 396 | private final ActionMode.Callback mWrapped; |
| 397 | |
| 398 | public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) { |
| 399 | mWrapped = wrapped; |
| 400 | } |
| 401 | |
| 402 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 403 | return mWrapped.onCreateActionMode(mode, menu); |
| 404 | } |
| 405 | |
| 406 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 407 | requestFitSystemWindows(); |
| 408 | return mWrapped.onPrepareActionMode(mode, menu); |
| 409 | } |
| 410 | |
| 411 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 412 | return mWrapped.onActionItemClicked(mode, item); |
| 413 | } |
| 414 | |
| 415 | public void onDestroyActionMode(ActionMode mode) { |
| 416 | mWrapped.onDestroyActionMode(mode); |
| 417 | if (mode == mFloatingActionMode) { |
| 418 | cleanupFloatingActionModeViews(); |
| 419 | mFloatingActionMode = null; |
| 420 | } |
| 421 | requestFitSystemWindows(); |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public void onGetContentRect(ActionMode mode, View view, Rect outRect) { |
| 426 | if (mWrapped instanceof ActionMode.Callback2) { |
| 427 | ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect); |
| 428 | } else { |
| 429 | super.onGetContentRect(mode, view, outRect); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Minimal window to satisfy FloatingToolbar. |
| 436 | */ |
| 437 | private Window mFakeWindow = new Window(mContext) { |
| 438 | @Override |
| 439 | public void takeSurface(SurfaceHolder.Callback2 callback) { |
| 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void takeInputQueue(InputQueue.Callback callback) { |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public boolean isFloating() { |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | @Override |
| 452 | public void alwaysReadCloseOnTouchAttr() { |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void setContentView(@LayoutRes int layoutResID) { |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void setContentView(View view) { |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 469 | } |
| 470 | |
| 471 | @Override |
| 472 | public void clearContentView() { |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public View getCurrentFocus() { |
| 477 | return null; |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public LayoutInflater getLayoutInflater() { |
| 482 | return null; |
| 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public void setTitle(CharSequence title) { |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public void setTitleColor(@ColorInt int textColor) { |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public void openPanel(int featureId, KeyEvent event) { |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public void closePanel(int featureId) { |
| 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public void togglePanel(int featureId, KeyEvent event) { |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void invalidatePanelMenu(int featureId) { |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) { |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | @Override |
| 515 | public boolean performPanelIdentifierAction(int featureId, int id, int flags) { |
| 516 | return false; |
| 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public void closeAllPanels() { |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public boolean performContextMenuIdentifierAction(int id, int flags) { |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | @Override |
| 529 | public void onConfigurationChanged(Configuration newConfig) { |
| 530 | } |
| 531 | |
| 532 | @Override |
| 533 | public void setBackgroundDrawable(Drawable drawable) { |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
| 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public void setFeatureDrawableUri(int featureId, Uri uri) { |
| 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public void setFeatureDrawable(int featureId, Drawable drawable) { |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 550 | } |
| 551 | |
| 552 | @Override |
| 553 | public void setFeatureInt(int featureId, int value) { |
| 554 | } |
| 555 | |
| 556 | @Override |
| 557 | public void takeKeyEvents(boolean get) { |
| 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public boolean superDispatchKeyEvent(KeyEvent event) { |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public boolean superDispatchKeyShortcutEvent(KeyEvent event) { |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | @Override |
| 571 | public boolean superDispatchTouchEvent(MotionEvent event) { |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public boolean superDispatchTrackballEvent(MotionEvent event) { |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public boolean superDispatchGenericMotionEvent(MotionEvent event) { |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public View getDecorView() { |
| 587 | return StatusBarWindowView.this; |
| 588 | } |
| 589 | |
| 590 | @Override |
| 591 | public View peekDecorView() { |
| 592 | return null; |
| 593 | } |
| 594 | |
| 595 | @Override |
| 596 | public Bundle saveHierarchyState() { |
| 597 | return null; |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | public void restoreHierarchyState(Bundle savedInstanceState) { |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | protected void onActive() { |
| 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void setChildDrawable(int featureId, Drawable drawable) { |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public void setChildInt(int featureId, int value) { |
| 614 | } |
| 615 | |
| 616 | @Override |
| 617 | public boolean isShortcutKey(int keyCode, KeyEvent event) { |
| 618 | return false; |
| 619 | } |
| 620 | |
| 621 | @Override |
| 622 | public void setVolumeControlStream(int streamType) { |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public int getVolumeControlStream() { |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | @Override |
| 631 | public int getStatusBarColor() { |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | @Override |
| 636 | public void setStatusBarColor(@ColorInt int color) { |
| 637 | } |
| 638 | |
| 639 | @Override |
| 640 | public int getNavigationBarColor() { |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | public void setNavigationBarColor(@ColorInt int color) { |
| 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public void setDecorCaptionShade(int decorCaptionShade) { |
| 650 | } |
| 651 | |
| 652 | @Override |
| 653 | public void setResizingCaptionDrawable(Drawable drawable) { |
| 654 | } |
| 655 | |
| 656 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 657 | public void onMultiWindowModeChanged() { |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | @Override |
| 661 | public void reportActivityRelaunched() { |
| 662 | } |
| 663 | }; |
| 664 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 665 | } |
| 666 | |