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