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 | |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 19 | import android.app.StatusBarManager; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 21 | import android.graphics.Canvas; |
| 22 | import android.graphics.Paint; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 23 | import android.graphics.Rect; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.view.KeyEvent; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 26 | import android.view.MotionEvent; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 27 | import android.view.View; |
Daniel Sandler | b10d885 | 2013-05-08 15:57:06 -0400 | [diff] [blame] | 28 | import android.view.ViewRootImpl; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 29 | import android.widget.FrameLayout; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 30 | |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 31 | import com.android.systemui.R; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 32 | import com.android.systemui.statusbar.BaseStatusBar; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 33 | import com.android.systemui.statusbar.DragDownHelper; |
| 34 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 35 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 36 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 37 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 38 | public class StatusBarWindowView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 39 | public static final String TAG = "StatusBarWindowView"; |
| 40 | public static final boolean DEBUG = BaseStatusBar.DEBUG; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 41 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 42 | private DragDownHelper mDragDownHelper; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 43 | private NotificationStackScrollLayout mStackScrollLayout; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 44 | private NotificationPanelView mNotificationPanel; |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 45 | private View mBrightnessMirror; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 46 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 47 | PhoneStatusBar mService; |
| 48 | |
| 49 | public StatusBarWindowView(Context context, AttributeSet attrs) { |
| 50 | super(context, attrs); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 51 | setMotionEventSplittingEnabled(false); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 52 | setWillNotDraw(!DEBUG); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 56 | protected boolean fitSystemWindows(Rect insets) { |
| 57 | if (getFitsSystemWindows()) { |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame^] | 58 | boolean changed = insets.left != getPaddingLeft() |
| 59 | || insets.top != getPaddingTop() |
| 60 | || insets.right != getPaddingRight() |
| 61 | || insets.bottom != getPaddingBottom(); |
| 62 | if (changed) { |
| 63 | setPadding(insets.left, insets.top, insets.right, 0); |
| 64 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 65 | insets.left = 0; |
| 66 | insets.top = 0; |
| 67 | insets.right = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 68 | } else { |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame^] | 69 | boolean changed = getPaddingLeft() != 0 |
| 70 | || getPaddingRight() != 0 |
| 71 | || getPaddingTop() != 0 |
| 72 | || getPaddingBottom() != 0; |
| 73 | if (changed) { |
| 74 | setPadding(0, 0, 0, 0); |
| 75 | } |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 76 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 77 | return false; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 81 | protected void onAttachedToWindow () { |
| 82 | super.onAttachedToWindow(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 83 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 84 | mStackScrollLayout = (NotificationStackScrollLayout) findViewById( |
| 85 | R.id.notification_stack_scroller); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 86 | mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 87 | mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 88 | mBrightnessMirror = findViewById(R.id.brightness_mirror); |
Daniel Sandler | b10d885 | 2013-05-08 15:57:06 -0400 | [diff] [blame] | 89 | |
| 90 | // We really need to be able to animate while window animations are going on |
| 91 | // so that activities may be started asynchronously from panel animations |
| 92 | final ViewRootImpl root = getViewRootImpl(); |
| 93 | if (root != null) { |
| 94 | root.setDrawDuringWindowsAnimating(true); |
| 95 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 100 | boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 101 | switch (event.getKeyCode()) { |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 102 | case KeyEvent.KEYCODE_BACK: |
| 103 | if (!down) { |
| 104 | mService.onBackPressed(); |
| 105 | } |
| 106 | return true; |
| 107 | case KeyEvent.KEYCODE_MENU: |
| 108 | if (!down) { |
| 109 | return mService.onMenuPressed(); |
| 110 | } |
Jorim Jaggi | 3425076 | 2014-07-03 23:51:19 +0200 | [diff] [blame] | 111 | case KeyEvent.KEYCODE_SPACE: |
| 112 | if (!down) { |
| 113 | return mService.onSpacePressed(); |
| 114 | } |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 115 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 116 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 117 | if (down) { |
| 118 | mService.wakeUpIfDozing(event.getEventTime()); |
| 119 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 120 | } |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 121 | if (mService.interceptMediaKey(event)) { |
| 122 | return true; |
| 123 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 124 | return super.dispatchKeyEvent(event); |
| 125 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 126 | |
| 127 | @Override |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 128 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 129 | if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) { |
| 130 | // Disallow new pointers while the brightness mirror is visible. This is so that you |
| 131 | // can't touch anything other than the brightness slider while the mirror is showing |
| 132 | // and the rest of the panel is transparent. |
| 133 | if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | return super.dispatchTouchEvent(ev); |
| 138 | } |
| 139 | |
| 140 | @Override |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 141 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 142 | boolean intercept = false; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 143 | if (mNotificationPanel.isFullyExpanded() |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 144 | && mStackScrollLayout.getVisibility() == View.VISIBLE |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 145 | && mService.getBarState() == StatusBarState.KEYGUARD |
| 146 | && !mService.isBouncerShowing()) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 147 | intercept = mDragDownHelper.onInterceptTouchEvent(ev); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 148 | // wake up on a touch down event, if dozing |
| 149 | if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 150 | mService.wakeUpIfDozing(ev.getEventTime()); |
| 151 | } |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 152 | } |
| 153 | if (!intercept) { |
| 154 | super.onInterceptTouchEvent(ev); |
| 155 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 156 | if (intercept) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 157 | MotionEvent cancellation = MotionEvent.obtain(ev); |
| 158 | cancellation.setAction(MotionEvent.ACTION_CANCEL); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 159 | mStackScrollLayout.onInterceptTouchEvent(cancellation); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 160 | mNotificationPanel.onInterceptTouchEvent(cancellation); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 161 | cancellation.recycle(); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 162 | } |
| 163 | return intercept; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public boolean onTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 168 | boolean handled = false; |
Jorim Jaggi | d692dd0 | 2014-08-14 20:57:42 +0200 | [diff] [blame] | 169 | if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 170 | handled = mDragDownHelper.onTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 171 | } |
| 172 | if (!handled) { |
| 173 | handled = super.onTouchEvent(ev); |
| 174 | } |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 175 | final int action = ev.getAction(); |
John Spurlock | d157ca0 | 2013-11-04 10:28:05 -0500 | [diff] [blame] | 176 | if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 177 | mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); |
| 178 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 179 | return handled; |
| 180 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 181 | |
| 182 | @Override |
| 183 | public void onDraw(Canvas canvas) { |
| 184 | super.onDraw(canvas); |
| 185 | if (DEBUG) { |
| 186 | Paint pt = new Paint(); |
| 187 | pt.setColor(0x80FFFF00); |
| 188 | pt.setStrokeWidth(12.0f); |
| 189 | pt.setStyle(Paint.Style.STROKE); |
| 190 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); |
| 191 | } |
| 192 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 193 | |
| 194 | public void cancelExpandHelper() { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 195 | if (mStackScrollLayout != null) { |
| 196 | mStackScrollLayout.cancelExpandHelper(); |
Daniel Sandler | 1a3bdd5 | 2012-10-23 19:21:20 -0400 | [diff] [blame] | 197 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 198 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 199 | } |
| 200 | |