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