blob: 1811d8d249528968f5b2d710d16924d7cfdb37ef [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 Jaggid7daab72014-05-06 22:22:20 +020058 setPadding(insets.left, insets.top, insets.right, 0);
59 insets.left = 0;
60 insets.top = 0;
61 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -040062 } else {
63 setPadding(0, 0, 0, 0);
64 }
Jorim Jaggid7daab72014-05-06 22:22:20 +020065 return false;
John Spurlockfba91202014-04-22 12:58:26 -040066 }
67
68 @Override
Chris Wren5de6e942012-05-16 14:22:21 -040069 protected void onAttachedToWindow () {
70 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010071
Selim Cinekb6d85eb2014-03-28 20:21:01 +010072 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
73 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070074 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Jorim Jaggiecbab362014-04-23 16:13:15 +020075 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService);
Adrian Roos9dc32092014-09-02 23:34:10 +020076 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040077
78 // We really need to be able to animate while window animations are going on
79 // so that activities may be started asynchronously from panel animations
80 final ViewRootImpl root = getViewRootImpl();
81 if (root != null) {
82 root.setDrawDuringWindowsAnimating(true);
83 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040084 }
85
86 @Override
87 public boolean dispatchKeyEvent(KeyEvent event) {
88 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
89 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +020090 case KeyEvent.KEYCODE_BACK:
91 if (!down) {
92 mService.onBackPressed();
93 }
94 return true;
95 case KeyEvent.KEYCODE_MENU:
96 if (!down) {
97 return mService.onMenuPressed();
98 }
Jorim Jaggi34250762014-07-03 23:51:19 +020099 case KeyEvent.KEYCODE_SPACE:
100 if (!down) {
101 return mService.onSpacePressed();
102 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400103 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200104 if (mService.interceptMediaKey(event)) {
105 return true;
106 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400107 return super.dispatchKeyEvent(event);
108 }
Chris Wren5de6e942012-05-16 14:22:21 -0400109
110 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200111 public boolean dispatchTouchEvent(MotionEvent ev) {
112 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
113 // Disallow new pointers while the brightness mirror is visible. This is so that you
114 // can't touch anything other than the brightness slider while the mirror is showing
115 // and the rest of the panel is transparent.
116 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
117 return false;
118 }
119 }
120 return super.dispatchTouchEvent(ev);
121 }
122
123 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400124 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700125 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100126 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200127 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200128 && mService.getBarState() == StatusBarState.KEYGUARD
129 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200130 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700131 }
132 if (!intercept) {
133 super.onInterceptTouchEvent(ev);
134 }
Chris Wren5de6e942012-05-16 14:22:21 -0400135 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700136 MotionEvent cancellation = MotionEvent.obtain(ev);
137 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100138 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200139 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700140 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400141 }
142 return intercept;
143 }
144
145 @Override
146 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700147 boolean handled = false;
Jorim Jaggid692dd02014-08-14 20:57:42 +0200148 if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200149 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700150 }
151 if (!handled) {
152 handled = super.onTouchEvent(ev);
153 }
John Spurlock257f2832013-09-21 18:41:53 -0400154 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500155 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400156 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
157 }
Chris Wren5de6e942012-05-16 14:22:21 -0400158 return handled;
159 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400160
161 @Override
162 public void onDraw(Canvas canvas) {
163 super.onDraw(canvas);
164 if (DEBUG) {
165 Paint pt = new Paint();
166 pt.setColor(0x80FFFF00);
167 pt.setStrokeWidth(12.0f);
168 pt.setStyle(Paint.Style.STROKE);
169 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
170 }
171 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400172
173 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200174 if (mStackScrollLayout != null) {
175 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400176 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400177 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400178}
179