blob: a600aae386d9c6966a8916cfd65e5b0c436368fa [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
19import android.content.Context;
Daniel Sandler198a0302012-08-17 16:04:31 -040020import android.graphics.Canvas;
21import android.graphics.Paint;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040022import android.util.AttributeSet;
23import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040024import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070025import android.view.View;
Daniel Sandlerb10d8852013-05-08 15:57:06 -040026import android.view.ViewRootImpl;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040027import android.widget.FrameLayout;
Chris Wren9b2cd152012-06-11 10:39:36 -040028import android.widget.ScrollView;
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;
Chris Wren5de6e942012-05-16 14:22:21 -040033import com.android.systemui.statusbar.policy.NotificationRowLayout;
34
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040035
36public class StatusBarWindowView extends FrameLayout
37{
Daniel Sandler198a0302012-08-17 16:04:31 -040038 public static final String TAG = "StatusBarWindowView";
39 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040040
41 private ExpandHelper mExpandHelper;
42 private NotificationRowLayout latestItems;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070043 private NotificationPanelView mNotificationPanel;
Daniel Sandler101784e2012-10-15 13:39:38 -040044 private ScrollView mScrollView;
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();
57 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
Daniel Sandler101784e2012-10-15 13:39:38 -040058 mScrollView = (ScrollView) findViewById(R.id.scroll);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070059 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Chris Wren5de6e942012-05-16 14:22:21 -040060 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
61 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
62 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
63 mExpandHelper.setEventSource(this);
Daniel Sandler101784e2012-10-15 13:39:38 -040064 mExpandHelper.setScrollView(mScrollView);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040065
66 // We really need to be able to animate while window animations are going on
67 // so that activities may be started asynchronously from panel animations
68 final ViewRootImpl root = getViewRootImpl();
69 if (root != null) {
70 root.setDrawDuringWindowsAnimating(true);
71 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040072 }
73
74 @Override
75 public boolean dispatchKeyEvent(KeyEvent event) {
76 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
77 switch (event.getKeyCode()) {
78 case KeyEvent.KEYCODE_BACK:
79 if (!down) {
Daniel Sandler11cf1782012-09-27 14:03:08 -040080 mService.animateCollapsePanels();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040081 }
82 return true;
83 }
84 return super.dispatchKeyEvent(event);
85 }
Chris Wren5de6e942012-05-16 14:22:21 -040086
87 @Override
88 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070089 boolean intercept = false;
Daniel Sandler101784e2012-10-15 13:39:38 -040090 if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070091 intercept = mExpandHelper.onInterceptTouchEvent(ev);
92 }
93 if (!intercept) {
94 super.onInterceptTouchEvent(ev);
95 }
Chris Wren5de6e942012-05-16 14:22:21 -040096 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070097 MotionEvent cancellation = MotionEvent.obtain(ev);
98 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -040099 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700100 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400101 }
102 return intercept;
103 }
104
105 @Override
106 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700107 boolean handled = false;
108 if (mNotificationPanel.isFullyExpanded()) {
109 handled = mExpandHelper.onTouchEvent(ev);
110 }
111 if (!handled) {
112 handled = super.onTouchEvent(ev);
113 }
Chris Wren5de6e942012-05-16 14:22:21 -0400114 return handled;
115 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400116
117 @Override
118 public void onDraw(Canvas canvas) {
119 super.onDraw(canvas);
120 if (DEBUG) {
121 Paint pt = new Paint();
122 pt.setColor(0x80FFFF00);
123 pt.setStrokeWidth(12.0f);
124 pt.setStyle(Paint.Style.STROKE);
125 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
126 }
127 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400128
129 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400130 if (mExpandHelper != null) {
131 mExpandHelper.cancel();
132 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400133 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400134}
135