blob: 4901823be46eb013459d5f4db18889927ed9da51 [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;
Chris Wren9b2cd152012-06-11 10:39:36 -040029import android.widget.ScrollView;
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;
Chris Wren5de6e942012-05-16 14:22:21 -040034import com.android.systemui.statusbar.policy.NotificationRowLayout;
35
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;
43 private NotificationRowLayout latestItems;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070044 private NotificationPanelView mNotificationPanel;
Daniel Sandler101784e2012-10-15 13:39:38 -040045 private ScrollView mScrollView;
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();
58 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
Daniel Sandler101784e2012-10-15 13:39:38 -040059 mScrollView = (ScrollView) findViewById(R.id.scroll);
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);
63 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
64 mExpandHelper.setEventSource(this);
Daniel Sandler101784e2012-10-15 13:39:38 -040065 mExpandHelper.setScrollView(mScrollView);
Daniel Sandlerb10d8852013-05-08 15:57:06 -040066
67 // We really need to be able to animate while window animations are going on
68 // so that activities may be started asynchronously from panel animations
69 final ViewRootImpl root = getViewRootImpl();
70 if (root != null) {
71 root.setDrawDuringWindowsAnimating(true);
72 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040073 }
74
75 @Override
76 public boolean dispatchKeyEvent(KeyEvent event) {
77 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
78 switch (event.getKeyCode()) {
79 case KeyEvent.KEYCODE_BACK:
80 if (!down) {
Daniel Sandler11cf1782012-09-27 14:03:08 -040081 mService.animateCollapsePanels();
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040082 }
83 return true;
84 }
85 return super.dispatchKeyEvent(event);
86 }
Chris Wren5de6e942012-05-16 14:22:21 -040087
88 @Override
89 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070090 boolean intercept = false;
Daniel Sandler101784e2012-10-15 13:39:38 -040091 if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070092 intercept = mExpandHelper.onInterceptTouchEvent(ev);
93 }
94 if (!intercept) {
95 super.onInterceptTouchEvent(ev);
96 }
Chris Wren5de6e942012-05-16 14:22:21 -040097 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070098 MotionEvent cancellation = MotionEvent.obtain(ev);
99 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -0400100 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700101 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400102 }
103 return intercept;
104 }
105
106 @Override
107 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700108 boolean handled = false;
109 if (mNotificationPanel.isFullyExpanded()) {
110 handled = mExpandHelper.onTouchEvent(ev);
111 }
112 if (!handled) {
113 handled = super.onTouchEvent(ev);
114 }
John Spurlock257f2832013-09-21 18:41:53 -0400115 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500116 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400117 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
118 }
Chris Wren5de6e942012-05-16 14:22:21 -0400119 return handled;
120 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400121
122 @Override
123 public void onDraw(Canvas canvas) {
124 super.onDraw(canvas);
125 if (DEBUG) {
126 Paint pt = new Paint();
127 pt.setColor(0x80FFFF00);
128 pt.setStrokeWidth(12.0f);
129 pt.setStyle(Paint.Style.STROKE);
130 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
131 }
132 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400133
134 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400135 if (mExpandHelper != null) {
136 mExpandHelper.cancel();
137 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400138 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400139}
140