blob: 5620e1b35ab4ae14de51626fc85de6c306f91ca1 [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;
Chris Wren5de6e942012-05-16 14:22:21 -040023import android.util.Log;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040024import 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 -040030import android.widget.TextSwitcher;
31
Chris Wren5de6e942012-05-16 14:22:21 -040032import com.android.systemui.ExpandHelper;
33import com.android.systemui.R;
Daniel Sandler198a0302012-08-17 16:04:31 -040034import com.android.systemui.statusbar.BaseStatusBar;
Chris Wren5de6e942012-05-16 14:22:21 -040035import com.android.systemui.statusbar.policy.NotificationRowLayout;
36
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040037
38public class StatusBarWindowView extends FrameLayout
39{
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;
44 private NotificationRowLayout latestItems;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070045 private NotificationPanelView mNotificationPanel;
Daniel Sandler101784e2012-10-15 13:39:38 -040046 private ScrollView mScrollView;
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
57 protected void onAttachedToWindow () {
58 super.onAttachedToWindow();
59 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
Daniel Sandler101784e2012-10-15 13:39:38 -040060 mScrollView = (ScrollView) findViewById(R.id.scroll);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070061 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Chris Wren5de6e942012-05-16 14:22:21 -040062 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
63 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
64 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
65 mExpandHelper.setEventSource(this);
Daniel Sandler101784e2012-10-15 13:39:38 -040066 mExpandHelper.setScrollView(mScrollView);
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;
Daniel Sandler101784e2012-10-15 13:39:38 -040092 if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070093 intercept = mExpandHelper.onInterceptTouchEvent(ev);
94 }
95 if (!intercept) {
96 super.onInterceptTouchEvent(ev);
97 }
Chris Wren5de6e942012-05-16 14:22:21 -040098 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070099 MotionEvent cancellation = MotionEvent.obtain(ev);
100 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -0400101 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700102 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400103 }
104 return intercept;
105 }
106
107 @Override
108 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700109 boolean handled = false;
110 if (mNotificationPanel.isFullyExpanded()) {
111 handled = mExpandHelper.onTouchEvent(ev);
112 }
113 if (!handled) {
114 handled = super.onTouchEvent(ev);
115 }
Chris Wren5de6e942012-05-16 14:22:21 -0400116 return handled;
117 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400118
119 @Override
120 public void onDraw(Canvas canvas) {
121 super.onDraw(canvas);
122 if (DEBUG) {
123 Paint pt = new Paint();
124 pt.setColor(0x80FFFF00);
125 pt.setStrokeWidth(12.0f);
126 pt.setStyle(Paint.Style.STROKE);
127 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
128 }
129 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400130
131 public void cancelExpandHelper() {
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400132 if (mExpandHelper != null) {
133 mExpandHelper.cancel();
134 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400135 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400136}
137