blob: 89ce257cec08e3f6037403ca6902384d834b044c [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;
Selim Cineka0fad3b2014-09-19 17:20:05 +020026import android.os.IBinder;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040027import android.util.AttributeSet;
28import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040029import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070030import android.view.View;
Daniel Sandlerb10d8852013-05-08 15:57:06 -040031import android.view.ViewRootImpl;
Selim Cineka0fad3b2014-09-19 17:20:05 +020032import android.view.WindowManager;
33import android.view.WindowManagerGlobal;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040034import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040035
Chris Wren5de6e942012-05-16 14:22:21 -040036import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040037import com.android.systemui.statusbar.BaseStatusBar;
Jorim Jaggiecbab362014-04-23 16:13:15 +020038import com.android.systemui.statusbar.DragDownHelper;
39import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010040import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040041
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040042
Jorim Jaggiecbab362014-04-23 16:13:15 +020043public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040044 public static final String TAG = "StatusBarWindowView";
45 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040046
Jorim Jaggiecbab362014-04-23 16:13:15 +020047 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010048 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070049 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020050 private View mBrightnessMirror;
Chris Wren5de6e942012-05-16 14:22:21 -040051
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040052 PhoneStatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +020053 private final Paint mTransparentSrcPaint = new Paint();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040054
55 public StatusBarWindowView(Context context, AttributeSet attrs) {
56 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040057 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +020058 setWillNotDraw(false);
59 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.
108 IBinder windowToken = getWindowToken();
109 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
110 lp.token = windowToken;
111 setLayoutParams(lp);
112 WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400113 }
114
115 @Override
116 public boolean dispatchKeyEvent(KeyEvent event) {
117 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
118 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200119 case KeyEvent.KEYCODE_BACK:
120 if (!down) {
121 mService.onBackPressed();
122 }
123 return true;
124 case KeyEvent.KEYCODE_MENU:
125 if (!down) {
126 return mService.onMenuPressed();
127 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200128 case KeyEvent.KEYCODE_SPACE:
129 if (!down) {
130 return mService.onSpacePressed();
131 }
John Spurlockd06aa572014-09-10 10:40:49 -0400132 case KeyEvent.KEYCODE_VOLUME_DOWN:
133 case KeyEvent.KEYCODE_VOLUME_UP:
134 if (down) {
135 mService.wakeUpIfDozing(event.getEventTime());
136 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400137 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200138 if (mService.interceptMediaKey(event)) {
139 return true;
140 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400141 return super.dispatchKeyEvent(event);
142 }
Chris Wren5de6e942012-05-16 14:22:21 -0400143
144 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200145 public boolean dispatchTouchEvent(MotionEvent ev) {
146 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
147 // Disallow new pointers while the brightness mirror is visible. This is so that you
148 // can't touch anything other than the brightness slider while the mirror is showing
149 // and the rest of the panel is transparent.
150 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
151 return false;
152 }
153 }
154 return super.dispatchTouchEvent(ev);
155 }
156
157 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400158 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700159 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100160 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200161 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200162 && mService.getBarState() == StatusBarState.KEYGUARD
163 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200164 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
John Spurlock8b12f222014-09-09 11:54:11 -0400165 // wake up on a touch down event, if dozing
166 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
167 mService.wakeUpIfDozing(ev.getEventTime());
168 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700169 }
170 if (!intercept) {
171 super.onInterceptTouchEvent(ev);
172 }
Chris Wren5de6e942012-05-16 14:22:21 -0400173 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700174 MotionEvent cancellation = MotionEvent.obtain(ev);
175 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100176 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200177 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700178 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400179 }
180 return intercept;
181 }
182
183 @Override
184 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700185 boolean handled = false;
Jorim Jaggid692dd02014-08-14 20:57:42 +0200186 if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200187 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700188 }
189 if (!handled) {
190 handled = super.onTouchEvent(ev);
191 }
John Spurlock257f2832013-09-21 18:41:53 -0400192 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500193 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400194 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
195 }
Chris Wren5de6e942012-05-16 14:22:21 -0400196 return handled;
197 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400198
199 @Override
200 public void onDraw(Canvas canvas) {
201 super.onDraw(canvas);
Selim Cineka0fad3b2014-09-19 17:20:05 +0200202 // We need to ensure that our window is always drawn fully even when we have paddings,
203 // since we simulate it to be opaque.
204 int paddedBottom = getHeight() - getPaddingBottom();
205 int paddedRight = getWidth() - getPaddingRight();
206 if (getPaddingTop() != 0) {
207 canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
208 }
209 if (getPaddingBottom() != 0) {
210 canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
211 }
212 if (getPaddingLeft() != 0) {
213 canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
214 mTransparentSrcPaint);
215 }
216 if (getPaddingRight() != 0) {
217 canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
218 mTransparentSrcPaint);
219 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400220 if (DEBUG) {
221 Paint pt = new Paint();
222 pt.setColor(0x80FFFF00);
223 pt.setStrokeWidth(12.0f);
224 pt.setStyle(Paint.Style.STROKE);
225 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
226 }
227 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400228
229 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200230 if (mStackScrollLayout != null) {
231 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400232 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400233 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400234}
235