blob: f0c599d044e32927ce55ed6e7d38f62221eef589 [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;
Selim Cineka0fad3b2014-09-19 17:20:05 +020023import android.graphics.PorterDuff;
24import android.graphics.PorterDuffXfermode;
John Spurlockfba91202014-04-22 12:58:26 -040025import android.graphics.Rect;
John Spurlock0b99ea92014-10-01 15:32:22 -040026import android.media.session.MediaSessionLegacyHelper;
Selim Cineka0fad3b2014-09-19 17:20:05 +020027import android.os.IBinder;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040028import android.util.AttributeSet;
29import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040030import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070031import android.view.View;
Daniel Sandlerb10d8852013-05-08 15:57:06 -040032import android.view.ViewRootImpl;
Selim Cineka0fad3b2014-09-19 17:20:05 +020033import android.view.WindowManager;
34import android.view.WindowManagerGlobal;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040035import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040036
Chris Wren5de6e942012-05-16 14:22:21 -040037import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040038import com.android.systemui.statusbar.BaseStatusBar;
Jorim Jaggiecbab362014-04-23 16:13:15 +020039import com.android.systemui.statusbar.DragDownHelper;
40import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010041import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040042
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040043
Jorim Jaggiecbab362014-04-23 16:13:15 +020044public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040045 public static final String TAG = "StatusBarWindowView";
46 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040047
Jorim Jaggiecbab362014-04-23 16:13:15 +020048 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010049 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070050 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020051 private View mBrightnessMirror;
Chris Wren5de6e942012-05-16 14:22:21 -040052
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040053 PhoneStatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +020054 private final Paint mTransparentSrcPaint = new Paint();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040055
56 public StatusBarWindowView(Context context, AttributeSet attrs) {
57 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040058 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +020059 mTransparentSrcPaint.setColor(0);
60 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Chris Wren5de6e942012-05-16 14:22:21 -040061 }
62
63 @Override
John Spurlockfba91202014-04-22 12:58:26 -040064 protected boolean fitSystemWindows(Rect insets) {
65 if (getFitsSystemWindows()) {
Jorim Jaggi416493b2014-09-13 03:57:32 +020066 boolean changed = insets.left != getPaddingLeft()
67 || insets.top != getPaddingTop()
68 || insets.right != getPaddingRight()
69 || insets.bottom != getPaddingBottom();
70 if (changed) {
71 setPadding(insets.left, insets.top, insets.right, 0);
72 }
Jorim Jaggid7daab72014-05-06 22:22:20 +020073 insets.left = 0;
74 insets.top = 0;
75 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -040076 } else {
Jorim Jaggi416493b2014-09-13 03:57:32 +020077 boolean changed = getPaddingLeft() != 0
78 || getPaddingRight() != 0
79 || getPaddingTop() != 0
80 || getPaddingBottom() != 0;
81 if (changed) {
82 setPadding(0, 0, 0, 0);
83 }
John Spurlockfba91202014-04-22 12:58:26 -040084 }
Jorim Jaggid7daab72014-05-06 22:22:20 +020085 return false;
John Spurlockfba91202014-04-22 12:58:26 -040086 }
87
88 @Override
Chris Wren5de6e942012-05-16 14:22:21 -040089 protected void onAttachedToWindow () {
90 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010091
Selim Cinekb6d85eb2014-03-28 20:21:01 +010092 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
93 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070094 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Jorim Jaggiecbab362014-04-23 16:13:15 +020095 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService);
Adrian Roos9dc32092014-09-02 23:34:10 +020096 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040097
98 // We really need to be able to animate while window animations are going on
99 // so that activities may be started asynchronously from panel animations
100 final ViewRootImpl root = getViewRootImpl();
101 if (root != null) {
102 root.setDrawDuringWindowsAnimating(true);
103 }
Selim Cineka0fad3b2014-09-19 17:20:05 +0200104
105 // We need to ensure that our window doesn't suffer from overdraw which would normally
106 // occur if our window is translucent. Since we are drawing the whole window anyway with
107 // the scrim, we don't need the window to be cleared in the beginning.
Jorim Jaggi0e664392014-09-27 01:30:22 +0200108 if (mService.isScrimSrcModeEnabled()) {
109 IBinder windowToken = getWindowToken();
110 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
111 lp.token = windowToken;
112 setLayoutParams(lp);
113 WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
114 setWillNotDraw(false);
115 } else {
116 setWillNotDraw(!DEBUG);
117 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400118 }
119
120 @Override
121 public boolean dispatchKeyEvent(KeyEvent event) {
122 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
123 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200124 case KeyEvent.KEYCODE_BACK:
125 if (!down) {
126 mService.onBackPressed();
127 }
128 return true;
129 case KeyEvent.KEYCODE_MENU:
130 if (!down) {
131 return mService.onMenuPressed();
132 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200133 case KeyEvent.KEYCODE_SPACE:
134 if (!down) {
135 return mService.onSpacePressed();
136 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400137 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400138 case KeyEvent.KEYCODE_VOLUME_DOWN:
139 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400140 if (mService.isDozing()) {
141 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, true);
142 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400143 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400144 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400145 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200146 if (mService.interceptMediaKey(event)) {
147 return true;
148 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400149 return super.dispatchKeyEvent(event);
150 }
Chris Wren5de6e942012-05-16 14:22:21 -0400151
152 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200153 public boolean dispatchTouchEvent(MotionEvent ev) {
154 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
155 // Disallow new pointers while the brightness mirror is visible. This is so that you
156 // can't touch anything other than the brightness slider while the mirror is showing
157 // and the rest of the panel is transparent.
158 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
159 return false;
160 }
161 }
162 return super.dispatchTouchEvent(ev);
163 }
164
165 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400166 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700167 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100168 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200169 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200170 && mService.getBarState() == StatusBarState.KEYGUARD
171 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200172 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
John Spurlock8b12f222014-09-09 11:54:11 -0400173 // wake up on a touch down event, if dozing
174 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
Selim Cinek29ed3c92014-09-23 20:44:35 +0200175 mService.wakeUpIfDozing(ev.getEventTime(), true);
John Spurlock8b12f222014-09-09 11:54:11 -0400176 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700177 }
178 if (!intercept) {
179 super.onInterceptTouchEvent(ev);
180 }
Chris Wren5de6e942012-05-16 14:22:21 -0400181 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700182 MotionEvent cancellation = MotionEvent.obtain(ev);
183 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100184 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200185 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700186 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400187 }
188 return intercept;
189 }
190
191 @Override
192 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700193 boolean handled = false;
Jorim Jaggid692dd02014-08-14 20:57:42 +0200194 if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200195 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700196 }
197 if (!handled) {
198 handled = super.onTouchEvent(ev);
199 }
John Spurlock257f2832013-09-21 18:41:53 -0400200 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500201 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400202 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
203 }
Chris Wren5de6e942012-05-16 14:22:21 -0400204 return handled;
205 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400206
207 @Override
208 public void onDraw(Canvas canvas) {
209 super.onDraw(canvas);
Jorim Jaggi0e664392014-09-27 01:30:22 +0200210 if (mService.isScrimSrcModeEnabled()) {
211 // We need to ensure that our window is always drawn fully even when we have paddings,
212 // since we simulate it to be opaque.
213 int paddedBottom = getHeight() - getPaddingBottom();
214 int paddedRight = getWidth() - getPaddingRight();
215 if (getPaddingTop() != 0) {
216 canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
217 }
218 if (getPaddingBottom() != 0) {
219 canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
220 }
221 if (getPaddingLeft() != 0) {
222 canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
223 mTransparentSrcPaint);
224 }
225 if (getPaddingRight() != 0) {
226 canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
227 mTransparentSrcPaint);
228 }
Selim Cineka0fad3b2014-09-19 17:20:05 +0200229 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400230 if (DEBUG) {
231 Paint pt = new Paint();
232 pt.setColor(0x80FFFF00);
233 pt.setStrokeWidth(12.0f);
234 pt.setStyle(Paint.Style.STROKE);
235 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
236 }
237 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400238
239 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200240 if (mStackScrollLayout != null) {
241 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400242 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400243 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400244}
245