blob: e0b7fe6f9c2861bf80a37c6635623aa57efb4274 [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;
20import android.util.AttributeSet;
Chris Wren5de6e942012-05-16 14:22:21 -040021import android.util.Log;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040022import android.view.KeyEvent;
Chris Wren5de6e942012-05-16 14:22:21 -040023import android.view.MotionEvent;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070024import android.view.View;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040025import android.widget.FrameLayout;
Chris Wren9b2cd152012-06-11 10:39:36 -040026import android.widget.ScrollView;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040027import android.widget.TextSwitcher;
28
Chris Wren5de6e942012-05-16 14:22:21 -040029import com.android.systemui.ExpandHelper;
30import com.android.systemui.R;
31import com.android.systemui.statusbar.policy.NotificationRowLayout;
32
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040033
34public class StatusBarWindowView extends FrameLayout
35{
Chris Wren5de6e942012-05-16 14:22:21 -040036 private static final String TAG = "StatusBarWindowView";
37
38 private ExpandHelper mExpandHelper;
39 private NotificationRowLayout latestItems;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070040 private NotificationPanelView mNotificationPanel;
Chris Wren5de6e942012-05-16 14:22:21 -040041
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040042 PhoneStatusBar mService;
43
44 public StatusBarWindowView(Context context, AttributeSet attrs) {
45 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -040046 setMotionEventSplittingEnabled(false);
47 }
48
49 @Override
50 protected void onAttachedToWindow () {
51 super.onAttachedToWindow();
52 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
Chris Wren9b2cd152012-06-11 10:39:36 -040053 ScrollView scroller = (ScrollView) findViewById(R.id.scroll);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070054 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Chris Wren5de6e942012-05-16 14:22:21 -040055 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
56 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
57 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
58 mExpandHelper.setEventSource(this);
Chris Wrenb4e2c48b2012-06-15 16:51:54 -040059 mExpandHelper.setScrollView(scroller);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040060 }
61
62 @Override
63 public boolean dispatchKeyEvent(KeyEvent event) {
64 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
65 switch (event.getKeyCode()) {
66 case KeyEvent.KEYCODE_BACK:
67 if (!down) {
68 mService.animateCollapse();
69 }
70 return true;
71 }
72 return super.dispatchKeyEvent(event);
73 }
Chris Wren5de6e942012-05-16 14:22:21 -040074
75 @Override
76 public boolean onInterceptTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070077 boolean intercept = false;
78 if (mNotificationPanel.isFullyExpanded()) {
79 intercept = mExpandHelper.onInterceptTouchEvent(ev);
80 }
81 if (!intercept) {
82 super.onInterceptTouchEvent(ev);
83 }
Chris Wren5de6e942012-05-16 14:22:21 -040084 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070085 MotionEvent cancellation = MotionEvent.obtain(ev);
86 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -040087 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070088 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -040089 }
90 return intercept;
91 }
92
93 @Override
94 public boolean onTouchEvent(MotionEvent ev) {
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070095 boolean handled = false;
96 if (mNotificationPanel.isFullyExpanded()) {
97 handled = mExpandHelper.onTouchEvent(ev);
98 }
99 if (!handled) {
100 handled = super.onTouchEvent(ev);
101 }
Chris Wren5de6e942012-05-16 14:22:21 -0400102 return handled;
103 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400104}
105