blob: 30d49ca86d84c4d02a3c7617fd6d2fdb57f030d6 [file] [log] [blame]
Joe Onoratob62ac122010-09-20 16:16:32 -04001/*
2 * Copyright (C) 2010 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.tablet;
18
Jim Miller16153892012-05-17 19:47:55 -070019import com.android.systemui.R;
Jim Millere898ac52012-04-06 17:10:57 -070020import com.android.systemui.statusbar.BaseStatusBar;
21import com.android.systemui.statusbar.DelegateViewHelper;
22
Joe Onoratob62ac122010-09-20 16:16:32 -040023import android.content.Context;
24import android.os.Handler;
25import android.util.AttributeSet;
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -050026import android.util.Slog;
Joe Onoratob62ac122010-09-20 16:16:32 -040027import android.view.View;
28import android.view.MotionEvent;
29import android.widget.FrameLayout;
30
31public class TabletStatusBarView extends FrameLayout {
32 private Handler mHandler;
33
Daniel Sandler3b0543a2011-06-14 11:30:28 -040034 private final int MAX_PANELS = 5;
35 private final View[] mIgnoreChildren = new View[MAX_PANELS];
36 private final View[] mPanels = new View[MAX_PANELS];
satok82beadf2010-12-27 19:03:06 +090037 private final int[] mPos = new int[2];
Jim Millere898ac52012-04-06 17:10:57 -070038 private DelegateViewHelper mDelegateHelper;
Joe Onoratob62ac122010-09-20 16:16:32 -040039
40 public TabletStatusBarView(Context context) {
Jim Miller16153892012-05-17 19:47:55 -070041 this(context, null);
Joe Onoratob62ac122010-09-20 16:16:32 -040042 }
43
44 public TabletStatusBarView(Context context, AttributeSet attrs) {
45 super(context, attrs);
Jim Millere898ac52012-04-06 17:10:57 -070046 mDelegateHelper = new DelegateViewHelper(this);
47 }
48
49 public void setDelegateView(View view) {
50 mDelegateHelper.setDelegateView(view);
51 }
52
53 public void setBar(BaseStatusBar phoneStatusBar) {
54 mDelegateHelper.setBar(phoneStatusBar);
Joe Onoratob62ac122010-09-20 16:16:32 -040055 }
56
satok82beadf2010-12-27 19:03:06 +090057 @Override
Jim Miller960892c2012-05-23 15:50:04 -070058 public boolean onTouchEvent(MotionEvent event) {
59 if (mDelegateHelper != null) {
60 mDelegateHelper.onInterceptTouchEvent(event);
61 }
62 return true;
63 }
64
65 @Override
66 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
67 super.onLayout(changed, left, top, right, bottom);
Jim Miller16153892012-05-17 19:47:55 -070068 // Find the view we wish to grab events from in order to detect search gesture.
69 // Depending on the device, this will be one of the id's listed below.
70 // If we don't find one, we'll use the view provided in the constructor above (this view).
Jim Miller960892c2012-05-23 15:50:04 -070071 View view = findViewById(R.id.navigationArea);
72 if (view == null) {
73 view = findViewById(R.id.nav_buttons);
Jim Miller16153892012-05-17 19:47:55 -070074 }
Jim Miller960892c2012-05-23 15:50:04 -070075 mDelegateHelper.setSourceView(view);
76 mDelegateHelper.setInitialTouchRegion(view);
Jim Miller16153892012-05-17 19:47:55 -070077 }
78
79 @Override
Joe Onoratob62ac122010-09-20 16:16:32 -040080 public boolean onInterceptTouchEvent(MotionEvent ev) {
81 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -050082 if (TabletStatusBar.DEBUG) {
83 Slog.d(TabletStatusBar.TAG, "TabletStatusBarView intercepting touch event: " + ev);
84 }
Daniel Sandler328310c2011-09-23 15:56:52 -040085 // do not close the recents panel here- the intended behavior is that recents is dismissed
86 // on touch up when clicking on status bar buttons
87 // TODO: should we be closing the notification panel and input methods panel?
Joe Onoratofd52b182010-11-10 18:00:52 -080088 mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
89 mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
satok82beadf2010-12-27 19:03:06 +090090 mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL);
91 mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL);
Daniel Sandler2ed08d22011-01-30 16:07:28 -050092 mHandler.removeMessages(TabletStatusBar.MSG_STOP_TICKER);
93 mHandler.sendEmptyMessage(TabletStatusBar.MSG_STOP_TICKER);
Joe Onoratob62ac122010-09-20 16:16:32 -040094
Jim Miller44c66fe2010-10-20 18:32:52 -070095 for (int i=0; i < mPanels.length; i++) {
96 if (mPanels[i] != null && mPanels[i].getVisibility() == View.VISIBLE) {
Joe Onoratob62ac122010-09-20 16:16:32 -040097 if (eventInside(mIgnoreChildren[i], ev)) {
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -050098 if (TabletStatusBar.DEBUG) {
satok82beadf2010-12-27 19:03:06 +090099 Slog.d(TabletStatusBar.TAG,
100 "TabletStatusBarView eating event for view: "
101 + mIgnoreChildren[i]);
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500102 }
Joe Onoratob62ac122010-09-20 16:16:32 -0400103 return true;
104 }
105 }
106 }
107 }
Joe Onoratof68b5002011-01-16 17:00:34 -0800108 if (TabletStatusBar.DEBUG) {
109 Slog.d(TabletStatusBar.TAG, "TabletStatusBarView not intercepting event");
110 }
Jim Miller960892c2012-05-23 15:50:04 -0700111 if (mDelegateHelper != null && mDelegateHelper.onInterceptTouchEvent(ev)) {
112 return true;
Jim Millere898ac52012-04-06 17:10:57 -0700113 }
Joe Onoratob62ac122010-09-20 16:16:32 -0400114 return super.onInterceptTouchEvent(ev);
115 }
116
117 private boolean eventInside(View v, MotionEvent ev) {
118 // assume that x and y are window coords because we are.
119 final int x = (int)ev.getX();
120 final int y = (int)ev.getY();
121
122 final int[] p = mPos;
123 v.getLocationInWindow(p);
124
125 final int l = p[0];
126 final int t = p[1];
127 final int r = p[0] + v.getWidth();
128 final int b = p[1] + v.getHeight();
129
130 return x >= l && x < r && y >= t && y < b;
131 }
132
133 public void setHandler(Handler h) {
134 mHandler = h;
135 }
136
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400137 /**
138 * Let the status bar know that if you tap on ignore while panel is showing, don't do anything.
Jim Millere898ac52012-04-06 17:10:57 -0700139 *
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400140 * Debounces taps on, say, a popup's trigger when the popup is already showing.
141 */
Joe Onoratob62ac122010-09-20 16:16:32 -0400142 public void setIgnoreChildren(int index, View ignore, View panel) {
143 mIgnoreChildren[index] = ignore;
144 mPanels[index] = panel;
145 }
146}