Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Jim Miller | 1615389 | 2012-05-17 19:47:55 -0700 | [diff] [blame] | 19 | import com.android.systemui.R; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 20 | import com.android.systemui.statusbar.BaseStatusBar; |
| 21 | import com.android.systemui.statusbar.DelegateViewHelper; |
| 22 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.os.Handler; |
| 25 | import android.util.AttributeSet; |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 26 | import android.util.Slog; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 27 | import android.view.View; |
| 28 | import android.view.MotionEvent; |
| 29 | import android.widget.FrameLayout; |
| 30 | |
| 31 | public class TabletStatusBarView extends FrameLayout { |
| 32 | private Handler mHandler; |
| 33 | |
Daniel Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 34 | private final int MAX_PANELS = 5; |
| 35 | private final View[] mIgnoreChildren = new View[MAX_PANELS]; |
| 36 | private final View[] mPanels = new View[MAX_PANELS]; |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 37 | private final int[] mPos = new int[2]; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 38 | private DelegateViewHelper mDelegateHelper; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 39 | |
| 40 | public TabletStatusBarView(Context context) { |
Jim Miller | 1615389 | 2012-05-17 19:47:55 -0700 | [diff] [blame] | 41 | this(context, null); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | public TabletStatusBarView(Context context, AttributeSet attrs) { |
| 45 | super(context, attrs); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 46 | 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 Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 55 | } |
| 56 | |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 57 | @Override |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 58 | 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 Miller | 1615389 | 2012-05-17 19:47:55 -0700 | [diff] [blame] | 68 | // 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 Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 71 | View view = findViewById(R.id.navigationArea); |
| 72 | if (view == null) { |
| 73 | view = findViewById(R.id.nav_buttons); |
Jim Miller | 1615389 | 2012-05-17 19:47:55 -0700 | [diff] [blame] | 74 | } |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 75 | mDelegateHelper.setSourceView(view); |
| 76 | mDelegateHelper.setInitialTouchRegion(view); |
Jim Miller | 1615389 | 2012-05-17 19:47:55 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @Override |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 80 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 81 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 82 | if (TabletStatusBar.DEBUG) { |
| 83 | Slog.d(TabletStatusBar.TAG, "TabletStatusBarView intercepting touch event: " + ev); |
| 84 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 85 | // 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 Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 88 | mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL); |
| 89 | mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL); |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 90 | mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL); |
| 91 | mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL); |
Daniel Sandler | 2ed08d2 | 2011-01-30 16:07:28 -0500 | [diff] [blame] | 92 | mHandler.removeMessages(TabletStatusBar.MSG_STOP_TICKER); |
| 93 | mHandler.sendEmptyMessage(TabletStatusBar.MSG_STOP_TICKER); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 94 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 95 | for (int i=0; i < mPanels.length; i++) { |
| 96 | if (mPanels[i] != null && mPanels[i].getVisibility() == View.VISIBLE) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 97 | if (eventInside(mIgnoreChildren[i], ev)) { |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 98 | if (TabletStatusBar.DEBUG) { |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 99 | Slog.d(TabletStatusBar.TAG, |
| 100 | "TabletStatusBarView eating event for view: " |
| 101 | + mIgnoreChildren[i]); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 102 | } |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
Joe Onorato | f68b500 | 2011-01-16 17:00:34 -0800 | [diff] [blame] | 108 | if (TabletStatusBar.DEBUG) { |
| 109 | Slog.d(TabletStatusBar.TAG, "TabletStatusBarView not intercepting event"); |
| 110 | } |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 111 | if (mDelegateHelper != null && mDelegateHelper.onInterceptTouchEvent(ev)) { |
| 112 | return true; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 113 | } |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 114 | 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 Sandler | 06a0d4b | 2011-08-05 00:19:21 -0400 | [diff] [blame] | 137 | /** |
| 138 | * Let the status bar know that if you tap on ignore while panel is showing, don't do anything. |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 139 | * |
Daniel Sandler | 06a0d4b | 2011-08-05 00:19:21 -0400 | [diff] [blame] | 140 | * Debounces taps on, say, a popup's trigger when the popup is already showing. |
| 141 | */ |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 142 | public void setIgnoreChildren(int index, View ignore, View panel) { |
| 143 | mIgnoreChildren[index] = ignore; |
| 144 | mPanels[index] = panel; |
| 145 | } |
| 146 | } |