blob: 3e5ba164912385aa56f576a06f3dacd55bc3870d [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()) {
59 setPadding(insets.left, insets.top, insets.right, insets.bottom);
60 } else {
61 setPadding(0, 0, 0, 0);
62 }
63 return true;
64 }
65
66 @Override
Chris Wren5de6e942012-05-16 14:22:21 -040067 protected void onAttachedToWindow () {
68 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010069
Selim Cinekb6d85eb2014-03-28 20:21:01 +010070 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
71 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070072 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Jorim Jaggife40f7d2014-04-28 15:20:04 +020073 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
74 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010075 mExpandHelper = new ExpandHelper(getContext(), mStackScrollLayout,
Selim Cinek67b22602014-03-10 15:40:16 +010076 minHeight, maxHeight);
Chris Wren5de6e942012-05-16 14:22:21 -040077 mExpandHelper.setEventSource(this);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010078 mExpandHelper.setScrollAdapter(mStackScrollLayout);
Jorim Jaggiecbab362014-04-23 16:13:15 +020079 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040080
81 // We really need to be able to animate while window animations are going on
82 // so that activities may be started asynchronously from panel animations
83 final ViewRootImpl root = getViewRootImpl();
84 if (root != null) {
85 root.setDrawDuringWindowsAnimating(true);
86 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040087 }
88
89 @Override
90 public boolean dispatchKeyEvent(KeyEvent event) {
91 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
92 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +020093 case KeyEvent.KEYCODE_BACK:
94 if (!down) {
95 mService.onBackPressed();
96 }
97 return true;
98 case KeyEvent.KEYCODE_MENU:
99 if (!down) {
100 return mService.onMenuPressed();
101 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400102 }
103 return super.dispatchKeyEvent(event);
104 }
Chris Wren5de6e942012-05-16 14:22:21 -0400105
106 @Override
107 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700108 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100109 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200110 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggiecbab362014-04-23 16:13:15 +0200111 && mService.getBarState() != StatusBarState.KEYGUARD) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700112 intercept = mExpandHelper.onInterceptTouchEvent(ev);
Jorim Jaggiecbab362014-04-23 16:13:15 +0200113 } else if (mNotificationPanel.isFullyExpanded()
114 && mStackScrollLayout.getVisibility() == View.VISIBLE
115 && mService.getBarState() == StatusBarState.KEYGUARD) {
116 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);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700125 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400126 }
127 return intercept;
128 }
129
130 @Override
131 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700132 boolean handled = false;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200133 if (mNotificationPanel.isFullyExpanded()
134 && mService.getBarState() != StatusBarState.KEYGUARD) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700135 handled = mExpandHelper.onTouchEvent(ev);
Jorim Jaggiecbab362014-04-23 16:13:15 +0200136 } else if (mService.getBarState() == StatusBarState.KEYGUARD) {
137 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700138 }
139 if (!handled) {
140 handled = super.onTouchEvent(ev);
141 }
John Spurlock257f2832013-09-21 18:41:53 -0400142 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500143 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400144 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
145 }
Chris Wren5de6e942012-05-16 14:22:21 -0400146 return handled;
147 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400148
149 @Override
150 public void onDraw(Canvas canvas) {
151 super.onDraw(canvas);
152 if (DEBUG) {
153 Paint pt = new Paint();
154 pt.setColor(0x80FFFF00);
155 pt.setStrokeWidth(12.0f);
156 pt.setStyle(Paint.Style.STROKE);
157 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
158 }
159 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400160
161 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400162 if (mExpandHelper != null) {
163 mExpandHelper.cancel();
164 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400165 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400166}
167