blob: f381b055f45d5549a9fc267c2eedeef5a132214b [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.ExpandHelper;
32import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040033import com.android.systemui.statusbar.BaseStatusBar;
Jorim Jaggiecbab362014-04-23 16:13:15 +020034import com.android.systemui.statusbar.DragDownHelper;
35import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010036import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040037
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040038
Jorim Jaggiecbab362014-04-23 16:13:15 +020039public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040040 public static final String TAG = "StatusBarWindowView";
41 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040042
Jorim Jaggiecbab362014-04-23 16:13:15 +020043 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010044 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070045 private NotificationPanelView mNotificationPanel;
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);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040076
77 // We really need to be able to animate while window animations are going on
78 // so that activities may be started asynchronously from panel animations
79 final ViewRootImpl root = getViewRootImpl();
80 if (root != null) {
81 root.setDrawDuringWindowsAnimating(true);
82 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040083 }
84
85 @Override
86 public boolean dispatchKeyEvent(KeyEvent event) {
87 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
88 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +020089 case KeyEvent.KEYCODE_BACK:
90 if (!down) {
91 mService.onBackPressed();
92 }
93 return true;
94 case KeyEvent.KEYCODE_MENU:
95 if (!down) {
96 return mService.onMenuPressed();
97 }
Jorim Jaggi34250762014-07-03 23:51:19 +020098 case KeyEvent.KEYCODE_SPACE:
99 if (!down) {
100 return mService.onSpacePressed();
101 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400102 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200103 if (mService.interceptMediaKey(event)) {
104 return true;
105 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400106 return super.dispatchKeyEvent(event);
107 }
Chris Wren5de6e942012-05-16 14:22:21 -0400108
109 @Override
110 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700111 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100112 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200113 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200114 && mService.getBarState() == StatusBarState.KEYGUARD
115 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200116 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700117 }
118 if (!intercept) {
119 super.onInterceptTouchEvent(ev);
120 }
Chris Wren5de6e942012-05-16 14:22:21 -0400121 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700122 MotionEvent cancellation = MotionEvent.obtain(ev);
123 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100124 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200125 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700126 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400127 }
128 return intercept;
129 }
130
131 @Override
132 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700133 boolean handled = false;
Selim Cinek1408eb52014-06-02 14:45:38 +0200134 if (mService.getBarState() == StatusBarState.KEYGUARD) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200135 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700136 }
137 if (!handled) {
138 handled = super.onTouchEvent(ev);
139 }
John Spurlock257f2832013-09-21 18:41:53 -0400140 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500141 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400142 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
143 }
Chris Wren5de6e942012-05-16 14:22:21 -0400144 return handled;
145 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400146
147 @Override
148 public void onDraw(Canvas canvas) {
149 super.onDraw(canvas);
150 if (DEBUG) {
151 Paint pt = new Paint();
152 pt.setColor(0x80FFFF00);
153 pt.setStrokeWidth(12.0f);
154 pt.setStyle(Paint.Style.STROKE);
155 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
156 }
157 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400158
159 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200160 if (mStackScrollLayout != null) {
161 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400162 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400163 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400164}
165