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