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.ExpandHelper; |
| 32 | import com.android.systemui.R; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.BaseStatusBar; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 34 | import com.android.systemui.statusbar.DragDownHelper; |
| 35 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 36 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 37 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 38 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 39 | public class StatusBarWindowView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 40 | public static final String TAG = "StatusBarWindowView"; |
| 41 | public static final boolean DEBUG = BaseStatusBar.DEBUG; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 42 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 43 | private DragDownHelper mDragDownHelper; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 44 | private NotificationStackScrollLayout mStackScrollLayout; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 45 | private NotificationPanelView mNotificationPanel; |
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 | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 58 | setPadding(insets.left, insets.top, insets.right, 0); |
| 59 | insets.left = 0; |
| 60 | insets.top = 0; |
| 61 | insets.right = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 62 | } else { |
| 63 | setPadding(0, 0, 0, 0); |
| 64 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 65 | return false; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 69 | protected void onAttachedToWindow () { |
| 70 | super.onAttachedToWindow(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 71 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 72 | mStackScrollLayout = (NotificationStackScrollLayout) findViewById( |
| 73 | R.id.notification_stack_scroller); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 74 | mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 75 | mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); |
Daniel Sandler | b10d885 | 2013-05-08 15:57:06 -0400 | [diff] [blame] | 76 | |
| 77 | // We really need to be able to animate while window animations are going on |
| 78 | // so that activities may be started asynchronously from panel animations |
| 79 | final ViewRootImpl root = getViewRootImpl(); |
| 80 | if (root != null) { |
| 81 | root.setDrawDuringWindowsAnimating(true); |
| 82 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 87 | boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 88 | switch (event.getKeyCode()) { |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 89 | case KeyEvent.KEYCODE_BACK: |
| 90 | if (!down) { |
| 91 | mService.onBackPressed(); |
| 92 | } |
| 93 | return true; |
| 94 | case KeyEvent.KEYCODE_MENU: |
| 95 | if (!down) { |
| 96 | return mService.onMenuPressed(); |
| 97 | } |
Jorim Jaggi | 3425076 | 2014-07-03 23:51:19 +0200 | [diff] [blame^] | 98 | case KeyEvent.KEYCODE_SPACE: |
| 99 | if (!down) { |
| 100 | return mService.onSpacePressed(); |
| 101 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 102 | } |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 103 | if (mService.interceptMediaKey(event)) { |
| 104 | return true; |
| 105 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 106 | return super.dispatchKeyEvent(event); |
| 107 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 108 | |
| 109 | @Override |
| 110 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 111 | boolean intercept = false; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 112 | if (mNotificationPanel.isFullyExpanded() |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 113 | && mStackScrollLayout.getVisibility() == View.VISIBLE |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 114 | && mService.getBarState() == StatusBarState.KEYGUARD |
| 115 | && !mService.isBouncerShowing()) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 116 | intercept = mDragDownHelper.onInterceptTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 117 | } |
| 118 | if (!intercept) { |
| 119 | super.onInterceptTouchEvent(ev); |
| 120 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 121 | if (intercept) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 122 | MotionEvent cancellation = MotionEvent.obtain(ev); |
| 123 | cancellation.setAction(MotionEvent.ACTION_CANCEL); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 124 | mStackScrollLayout.onInterceptTouchEvent(cancellation); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 125 | cancellation.recycle(); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 126 | } |
| 127 | return intercept; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public boolean onTouchEvent(MotionEvent ev) { |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 132 | boolean handled = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 133 | if (mService.getBarState() == StatusBarState.KEYGUARD) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 134 | handled = mDragDownHelper.onTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 135 | } |
| 136 | if (!handled) { |
| 137 | handled = super.onTouchEvent(ev); |
| 138 | } |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 139 | final int action = ev.getAction(); |
John Spurlock | d157ca0 | 2013-11-04 10:28:05 -0500 | [diff] [blame] | 140 | if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 141 | mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); |
| 142 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 143 | return handled; |
| 144 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 145 | |
| 146 | @Override |
| 147 | public void onDraw(Canvas canvas) { |
| 148 | super.onDraw(canvas); |
| 149 | if (DEBUG) { |
| 150 | Paint pt = new Paint(); |
| 151 | pt.setColor(0x80FFFF00); |
| 152 | pt.setStrokeWidth(12.0f); |
| 153 | pt.setStyle(Paint.Style.STROKE); |
| 154 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); |
| 155 | } |
| 156 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 157 | |
| 158 | public void cancelExpandHelper() { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 159 | if (mStackScrollLayout != null) { |
| 160 | mStackScrollLayout.cancelExpandHelper(); |
Daniel Sandler | 1a3bdd5 | 2012-10-23 19:21:20 -0400 | [diff] [blame] | 161 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 162 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 163 | } |
| 164 | |