blob: f83517b8ff4f06e8799312c0c8992e3033908673 [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 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 -040029import android.widget.TextSwitcher;
30
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;
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);
Chris Wren9b2cd152012-06-11 10:39:36 -040058 ScrollView scroller = (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);
Chris Wrenb4e2c48b2012-06-15 16:51:54 -040064 mExpandHelper.setScrollView(scroller);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040065 }
66
67 @Override
68 public boolean dispatchKeyEvent(KeyEvent event) {
69 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
70 switch (event.getKeyCode()) {
71 case KeyEvent.KEYCODE_BACK:
72 if (!down) {
73 mService.animateCollapse();
74 }
75 return true;
76 }
77 return super.dispatchKeyEvent(event);
78 }
Chris Wren5de6e942012-05-16 14:22:21 -040079
80 @Override
81 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070082 boolean intercept = false;
83 if (mNotificationPanel.isFullyExpanded()) {
84 intercept = mExpandHelper.onInterceptTouchEvent(ev);
85 }
86 if (!intercept) {
87 super.onInterceptTouchEvent(ev);
88 }
Chris Wren5de6e942012-05-16 14:22:21 -040089 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070090 MotionEvent cancellation = MotionEvent.obtain(ev);
91 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -040092 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070093 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -040094 }
95 return intercept;
96 }
97
98 @Override
99 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700100 boolean handled = false;
101 if (mNotificationPanel.isFullyExpanded()) {
102 handled = mExpandHelper.onTouchEvent(ev);
103 }
104 if (!handled) {
105 handled = super.onTouchEvent(ev);
106 }
Chris Wren5de6e942012-05-16 14:22:21 -0400107 return handled;
108 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400109
110 @Override
111 public void onDraw(Canvas canvas) {
112 super.onDraw(canvas);
113 if (DEBUG) {
114 Paint pt = new Paint();
115 pt.setColor(0x80FFFF00);
116 pt.setStrokeWidth(12.0f);
117 pt.setStyle(Paint.Style.STROKE);
118 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
119 }
120 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400121}
122