blob: f53ed0c5c1c0f2b001524e32f6dc7ef5410d63be [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 Sandlerc4f2a562012-05-04 11:55:46 -040024import android.widget.FrameLayout;
Chris Wren9b2cd152012-06-11 10:39:36 -040025import android.widget.ScrollView;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040026import android.widget.TextSwitcher;
27
Chris Wren5de6e942012-05-16 14:22:21 -040028import com.android.systemui.ExpandHelper;
29import com.android.systemui.R;
30import com.android.systemui.statusbar.policy.NotificationRowLayout;
31
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040032
33public class StatusBarWindowView extends FrameLayout
34{
Chris Wren5de6e942012-05-16 14:22:21 -040035 private static final String TAG = "StatusBarWindowView";
36
37 private ExpandHelper mExpandHelper;
38 private NotificationRowLayout latestItems;
39
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070040 private boolean mUniverseHandling = false;
41
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);
Chris Wren5de6e942012-05-16 14:22:21 -040054 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
55 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
56 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
57 mExpandHelper.setEventSource(this);
Chris Wrenb4e2c48b2012-06-15 16:51:54 -040058 mExpandHelper.setScrollView(scroller);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040059 }
60
61 @Override
62 public boolean dispatchKeyEvent(KeyEvent event) {
63 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
64 switch (event.getKeyCode()) {
65 case KeyEvent.KEYCODE_BACK:
66 if (!down) {
67 mService.animateCollapse();
68 }
69 return true;
70 }
71 return super.dispatchKeyEvent(event);
72 }
Chris Wren5de6e942012-05-16 14:22:21 -040073
74 @Override
75 public boolean onInterceptTouchEvent(MotionEvent ev) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070076 if (mService.handleUniverseEvent(ev)) {
77 mUniverseHandling = true;
78 MotionEvent cancellation = MotionEvent.obtain(ev);
79 cancellation.setAction(MotionEvent.ACTION_CANCEL);
80 mExpandHelper.onInterceptTouchEvent(cancellation);
81 latestItems.onInterceptTouchEvent(cancellation);
82 cancellation.recycle();
83 return true;
84 }
Chris Wren5de6e942012-05-16 14:22:21 -040085
86 boolean intercept = mExpandHelper.onInterceptTouchEvent(ev) ||
87 super.onInterceptTouchEvent(ev);
88 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070089 MotionEvent cancellation = MotionEvent.obtain(ev);
90 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Chris Wren5de6e942012-05-16 14:22:21 -040091 latestItems.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070092 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -040093 }
94 return intercept;
95 }
96
97 @Override
98 public boolean onTouchEvent(MotionEvent ev) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070099 if (mUniverseHandling) {
100 if (!mService.handleUniverseEvent(ev)) {
101 mUniverseHandling = false;
102 }
103 return true;
104 }
Chris Wren5de6e942012-05-16 14:22:21 -0400105 boolean handled = mExpandHelper.onTouchEvent(ev) ||
106 super.onTouchEvent(ev);
107 return handled;
108 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400109}
110