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