blob: eeae0815ad3efd3ab089dfe917254dead2523324 [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;
Selim Cinek67b22602014-03-10 15:40:16 +010027import android.view.ViewGroup;
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;
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 Cinek67b22602014-03-10 15:40:16 +010043 private ViewGroup latestItems;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070044 private NotificationPanelView mNotificationPanel;
Selim Cinekfab078b2014-03-27 22:45:58 +010045 private View mNotificationScroller;
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
56 protected void onAttachedToWindow () {
57 super.onAttachedToWindow();
Selim Cinek67b22602014-03-10 15:40:16 +010058
Selim Cinekfab078b2014-03-27 22:45:58 +010059 ExpandHelper.ScrollAdapter scrollAdapter;
Selim Cinek67b22602014-03-10 15:40:16 +010060 if (BaseStatusBar.ENABLE_NOTIFICATION_STACK) {
Selim Cinekfab078b2014-03-27 22:45:58 +010061 NotificationStackScrollLayout stackScrollLayout =
62 (NotificationStackScrollLayout) findViewById(R.id.notification_stack_scroller);
63
64 // ScrollView and notification container are unified in a single view now.
65 latestItems = stackScrollLayout;
66 scrollAdapter = stackScrollLayout;
67 mNotificationScroller = stackScrollLayout;
Selim Cinek67b22602014-03-10 15:40:16 +010068 } else {
69 latestItems = (ViewGroup) findViewById(R.id.latestItems);
Selim Cinekfab078b2014-03-27 22:45:58 +010070 mNotificationScroller = findViewById(R.id.scroll);
71 scrollAdapter = new ExpandHelper.ScrollAdapter() {
72 @Override
73 public boolean isScrolledToTop() {
74 return mNotificationScroller.getScrollY() == 0;
75 }
76
77 @Override
78 public View getHostView() {
79 return mNotificationScroller;
80 }
81 };
Selim Cinek67b22602014-03-10 15:40:16 +010082 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070083 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Chris Wren5de6e942012-05-16 14:22:21 -040084 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
85 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
Selim Cinek67b22602014-03-10 15:40:16 +010086 mExpandHelper = new ExpandHelper(getContext(), (ExpandHelper.Callback) latestItems,
87 minHeight, maxHeight);
Chris Wren5de6e942012-05-16 14:22:21 -040088 mExpandHelper.setEventSource(this);
Selim Cinekfab078b2014-03-27 22:45:58 +010089 mExpandHelper.setScrollAdapter(scrollAdapter);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040090
91 // We really need to be able to animate while window animations are going on
92 // so that activities may be started asynchronously from panel animations
93 final ViewRootImpl root = getViewRootImpl();
94 if (root != null) {
95 root.setDrawDuringWindowsAnimating(true);
96 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040097 }
98
99 @Override
100 public boolean dispatchKeyEvent(KeyEvent event) {
101 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
102 switch (event.getKeyCode()) {
103 case KeyEvent.KEYCODE_BACK:
104 if (!down) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400105 mService.animateCollapsePanels();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400106 }
107 return true;
108 }
109 return super.dispatchKeyEvent(event);
110 }
Chris Wren5de6e942012-05-16 14:22:21 -0400111
112 @Override
113 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700114 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100115 if (mNotificationPanel.isFullyExpanded()
116 && mNotificationScroller.getVisibility() == View.VISIBLE) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700117 intercept = mExpandHelper.onInterceptTouchEvent(ev);
118 }
119 if (!intercept) {
120 super.onInterceptTouchEvent(ev);
121 }
Chris Wren5de6e942012-05-16 14:22:21 -0400122 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700123 MotionEvent cancellation = MotionEvent.obtain(ev);
124 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -0400125 latestItems.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;
134 if (mNotificationPanel.isFullyExpanded()) {
135 handled = mExpandHelper.onTouchEvent(ev);
136 }
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() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400160 if (mExpandHelper != null) {
161 mExpandHelper.cancel();
162 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400163 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400164}
165