blob: a7121c4e7d592d57b7ee1a153e456a642c7cf280 [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;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040023import android.util.AttributeSet;
24import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040025import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070026import android.view.View;
Daniel Sandlerb10d8852013-05-08 15:57:06 -040027import android.view.ViewRootImpl;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040028import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040029
Chris Wren5de6e942012-05-16 14:22:21 -040030import com.android.systemui.ExpandHelper;
31import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040032import com.android.systemui.statusbar.BaseStatusBar;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010033import com.android.systemui.statusbar.policy.ScrollAdapter;
Selim Cinekfab078b2014-03-27 22:45:58 +010034import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040035
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040036
37public class StatusBarWindowView extends FrameLayout
38{
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
42 private ExpandHelper mExpandHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010043 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070044 private NotificationPanelView mNotificationPanel;
Chris Wren5de6e942012-05-16 14:22:21 -040045
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040046 PhoneStatusBar mService;
47
48 public StatusBarWindowView(Context context, AttributeSet attrs) {
49 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040050 setMotionEventSplittingEnabled(false);
Daniel Sandler198a0302012-08-17 16:04:31 -040051 setWillNotDraw(!DEBUG);
Chris Wren5de6e942012-05-16 14:22:21 -040052 }
53
54 @Override
55 protected void onAttachedToWindow () {
56 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010057
Selim Cinekb6d85eb2014-03-28 20:21:01 +010058 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
59 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070060 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Chris Wren5de6e942012-05-16 14:22:21 -040061 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
62 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010063 mExpandHelper = new ExpandHelper(getContext(), mStackScrollLayout,
Selim Cinek67b22602014-03-10 15:40:16 +010064 minHeight, maxHeight);
Chris Wren5de6e942012-05-16 14:22:21 -040065 mExpandHelper.setEventSource(this);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010066 mExpandHelper.setScrollAdapter(mStackScrollLayout);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040067
68 // We really need to be able to animate while window animations are going on
69 // so that activities may be started asynchronously from panel animations
70 final ViewRootImpl root = getViewRootImpl();
71 if (root != null) {
72 root.setDrawDuringWindowsAnimating(true);
73 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040074 }
75
76 @Override
77 public boolean dispatchKeyEvent(KeyEvent event) {
78 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
79 switch (event.getKeyCode()) {
80 case KeyEvent.KEYCODE_BACK:
81 if (!down) {
Daniel Sandler11cf1782012-09-27 14:03:08 -040082 mService.animateCollapsePanels();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040083 }
84 return true;
85 }
86 return super.dispatchKeyEvent(event);
87 }
Chris Wren5de6e942012-05-16 14:22:21 -040088
89 @Override
90 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070091 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +010092 if (mNotificationPanel.isFullyExpanded()
Selim Cinekb6d85eb2014-03-28 20:21:01 +010093 && mStackScrollLayout.getVisibility() == View.VISIBLE) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070094 intercept = mExpandHelper.onInterceptTouchEvent(ev);
95 }
96 if (!intercept) {
97 super.onInterceptTouchEvent(ev);
98 }
Chris Wren5de6e942012-05-16 14:22:21 -040099 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700100 MotionEvent cancellation = MotionEvent.obtain(ev);
101 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100102 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700103 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400104 }
105 return intercept;
106 }
107
108 @Override
109 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700110 boolean handled = false;
111 if (mNotificationPanel.isFullyExpanded()) {
112 handled = mExpandHelper.onTouchEvent(ev);
113 }
114 if (!handled) {
115 handled = super.onTouchEvent(ev);
116 }
John Spurlock257f2832013-09-21 18:41:53 -0400117 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500118 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400119 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
120 }
Chris Wren5de6e942012-05-16 14:22:21 -0400121 return handled;
122 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400123
124 @Override
125 public void onDraw(Canvas canvas) {
126 super.onDraw(canvas);
127 if (DEBUG) {
128 Paint pt = new Paint();
129 pt.setColor(0x80FFFF00);
130 pt.setStrokeWidth(12.0f);
131 pt.setStyle(Paint.Style.STROKE);
132 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
133 }
134 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400135
136 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400137 if (mExpandHelper != null) {
138 mExpandHelper.cancel();
139 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400140 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400141}
142