blob: 78554525e720ce682e2c8088c5eceb09954a0e21 [file] [log] [blame]
Daniel Sandlerc4f2a562012-05-04 11:55:46 -04001/*
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
17package com.android.systemui.statusbar.phone;
18
John Spurlock257f2832013-09-21 18:41:53 -040019import android.app.StatusBarManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040020import android.content.Context;
Daniel Sandler198a0302012-08-17 16:04:31 -040021import android.graphics.Canvas;
22import android.graphics.Paint;
John Spurlockfba91202014-04-22 12:58:26 -040023import android.graphics.Rect;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040024import android.util.AttributeSet;
25import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040026import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070027import android.view.View;
Daniel Sandlerb10d8852013-05-08 15:57:06 -040028import android.view.ViewRootImpl;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040029import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040030
Chris Wren5de6e942012-05-16 14:22:21 -040031import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040032import com.android.systemui.statusbar.BaseStatusBar;
Jorim Jaggiecbab362014-04-23 16:13:15 +020033import com.android.systemui.statusbar.DragDownHelper;
34import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010035import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040036
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040037
Jorim Jaggiecbab362014-04-23 16:13:15 +020038public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040039 public static final String TAG = "StatusBarWindowView";
40 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040041
Jorim Jaggiecbab362014-04-23 16:13:15 +020042 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010043 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070044 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020045 private View mBrightnessMirror;
Chris Wren5de6e942012-05-16 14:22:21 -040046
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040047 PhoneStatusBar mService;
48
49 public StatusBarWindowView(Context context, AttributeSet attrs) {
50 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040051 setMotionEventSplittingEnabled(false);
Daniel Sandler198a0302012-08-17 16:04:31 -040052 setWillNotDraw(!DEBUG);
Chris Wren5de6e942012-05-16 14:22:21 -040053 }
54
55 @Override
John Spurlockfba91202014-04-22 12:58:26 -040056 protected boolean fitSystemWindows(Rect insets) {
57 if (getFitsSystemWindows()) {
Jorim Jaggi416493b2014-09-13 03:57:32 +020058 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 Jaggid7daab72014-05-06 22:22:20 +020065 insets.left = 0;
66 insets.top = 0;
67 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -040068 } else {
Jorim Jaggi416493b2014-09-13 03:57:32 +020069 boolean changed = getPaddingLeft() != 0
70 || getPaddingRight() != 0
71 || getPaddingTop() != 0
72 || getPaddingBottom() != 0;
73 if (changed) {
74 setPadding(0, 0, 0, 0);
75 }
John Spurlockfba91202014-04-22 12:58:26 -040076 }
Jorim Jaggid7daab72014-05-06 22:22:20 +020077 return false;
John Spurlockfba91202014-04-22 12:58:26 -040078 }
79
80 @Override
Chris Wren5de6e942012-05-16 14:22:21 -040081 protected void onAttachedToWindow () {
82 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010083
Selim Cinekb6d85eb2014-03-28 20:21:01 +010084 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
85 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070086 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Jorim Jaggiecbab362014-04-23 16:13:15 +020087 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService);
Adrian Roos9dc32092014-09-02 23:34:10 +020088 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040089
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 Sandlerc4f2a562012-05-04 11:55:46 -040096 }
97
98 @Override
99 public boolean dispatchKeyEvent(KeyEvent event) {
100 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
101 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200102 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 Jaggi34250762014-07-03 23:51:19 +0200111 case KeyEvent.KEYCODE_SPACE:
112 if (!down) {
113 return mService.onSpacePressed();
114 }
John Spurlockd06aa572014-09-10 10:40:49 -0400115 case KeyEvent.KEYCODE_VOLUME_DOWN:
116 case KeyEvent.KEYCODE_VOLUME_UP:
117 if (down) {
118 mService.wakeUpIfDozing(event.getEventTime());
119 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400120 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200121 if (mService.interceptMediaKey(event)) {
122 return true;
123 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400124 return super.dispatchKeyEvent(event);
125 }
Chris Wren5de6e942012-05-16 14:22:21 -0400126
127 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200128 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 Wren5de6e942012-05-16 14:22:21 -0400141 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700142 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100143 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200144 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200145 && mService.getBarState() == StatusBarState.KEYGUARD
146 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200147 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
John Spurlock8b12f222014-09-09 11:54:11 -0400148 // wake up on a touch down event, if dozing
149 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
150 mService.wakeUpIfDozing(ev.getEventTime());
151 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700152 }
153 if (!intercept) {
154 super.onInterceptTouchEvent(ev);
155 }
Chris Wren5de6e942012-05-16 14:22:21 -0400156 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700157 MotionEvent cancellation = MotionEvent.obtain(ev);
158 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100159 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200160 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700161 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400162 }
163 return intercept;
164 }
165
166 @Override
167 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700168 boolean handled = false;
Jorim Jaggid692dd02014-08-14 20:57:42 +0200169 if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200170 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700171 }
172 if (!handled) {
173 handled = super.onTouchEvent(ev);
174 }
John Spurlock257f2832013-09-21 18:41:53 -0400175 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500176 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400177 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
178 }
Chris Wren5de6e942012-05-16 14:22:21 -0400179 return handled;
180 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400181
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 Sandlerac47ff72012-10-23 10:41:44 -0400193
194 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200195 if (mStackScrollLayout != null) {
196 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400197 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400198 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400199}
200