blob: e802d185cc5bca102a3896cdc3d9fc83671fa178 [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
43 private ExpandHelper mExpandHelper;
Jorim Jaggiecbab362014-04-23 16:13:15 +020044 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010045 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070046 private NotificationPanelView mNotificationPanel;
Chris Wren5de6e942012-05-16 14:22:21 -040047
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040048 PhoneStatusBar mService;
49
50 public StatusBarWindowView(Context context, AttributeSet attrs) {
51 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040052 setMotionEventSplittingEnabled(false);
Daniel Sandler198a0302012-08-17 16:04:31 -040053 setWillNotDraw(!DEBUG);
Chris Wren5de6e942012-05-16 14:22:21 -040054 }
55
56 @Override
John Spurlockfba91202014-04-22 12:58:26 -040057 protected boolean fitSystemWindows(Rect insets) {
58 if (getFitsSystemWindows()) {
Jorim Jaggid7daab72014-05-06 22:22:20 +020059 setPadding(insets.left, insets.top, insets.right, 0);
60 insets.left = 0;
61 insets.top = 0;
62 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -040063 } else {
64 setPadding(0, 0, 0, 0);
65 }
Jorim Jaggid7daab72014-05-06 22:22:20 +020066 return false;
John Spurlockfba91202014-04-22 12:58:26 -040067 }
68
69 @Override
Chris Wren5de6e942012-05-16 14:22:21 -040070 protected void onAttachedToWindow () {
71 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010072
Selim Cinekb6d85eb2014-03-28 20:21:01 +010073 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
74 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070075 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Jorim Jaggife40f7d2014-04-28 15:20:04 +020076 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
77 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010078 mExpandHelper = new ExpandHelper(getContext(), mStackScrollLayout,
Selim Cinek67b22602014-03-10 15:40:16 +010079 minHeight, maxHeight);
Chris Wren5de6e942012-05-16 14:22:21 -040080 mExpandHelper.setEventSource(this);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010081 mExpandHelper.setScrollAdapter(mStackScrollLayout);
Jorim Jaggiecbab362014-04-23 16:13:15 +020082 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040083
84 // We really need to be able to animate while window animations are going on
85 // so that activities may be started asynchronously from panel animations
86 final ViewRootImpl root = getViewRootImpl();
87 if (root != null) {
88 root.setDrawDuringWindowsAnimating(true);
89 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040090 }
91
92 @Override
93 public boolean dispatchKeyEvent(KeyEvent event) {
94 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
95 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +020096 case KeyEvent.KEYCODE_BACK:
97 if (!down) {
98 mService.onBackPressed();
99 }
100 return true;
101 case KeyEvent.KEYCODE_MENU:
102 if (!down) {
103 return mService.onMenuPressed();
104 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400105 }
106 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 Jaggic1cf1ae2014-05-02 21:19:17 +0200114 && (mService.getBarState() == StatusBarState.SHADE
115 || (mService.getBarState() == StatusBarState.SHADE_LOCKED
116 && !mService.isBouncerShowing()))) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700117 intercept = mExpandHelper.onInterceptTouchEvent(ev);
Jorim Jaggiecbab362014-04-23 16:13:15 +0200118 } else if (mNotificationPanel.isFullyExpanded()
119 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200120 && mService.getBarState() == StatusBarState.KEYGUARD
121 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200122 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700123 }
124 if (!intercept) {
125 super.onInterceptTouchEvent(ev);
126 }
Chris Wren5de6e942012-05-16 14:22:21 -0400127 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700128 MotionEvent cancellation = MotionEvent.obtain(ev);
129 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100130 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700131 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400132 }
133 return intercept;
134 }
135
136 @Override
137 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700138 boolean handled = false;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200139 if (mNotificationPanel.isFullyExpanded()
140 && mService.getBarState() != StatusBarState.KEYGUARD) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700141 handled = mExpandHelper.onTouchEvent(ev);
Jorim Jaggiecbab362014-04-23 16:13:15 +0200142 } else if (mService.getBarState() == StatusBarState.KEYGUARD) {
143 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700144 }
145 if (!handled) {
146 handled = super.onTouchEvent(ev);
147 }
John Spurlock257f2832013-09-21 18:41:53 -0400148 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500149 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400150 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
151 }
Chris Wren5de6e942012-05-16 14:22:21 -0400152 return handled;
153 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400154
155 @Override
156 public void onDraw(Canvas canvas) {
157 super.onDraw(canvas);
158 if (DEBUG) {
159 Paint pt = new Paint();
160 pt.setColor(0x80FFFF00);
161 pt.setStrokeWidth(12.0f);
162 pt.setStyle(Paint.Style.STROKE);
163 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
164 }
165 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400166
167 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400168 if (mExpandHelper != null) {
169 mExpandHelper.cancel();
170 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400171 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400172}
173