TabletStatusBarView.java revision 06a0d4b5c36b3353a89ec31e097bf0b54b5f2549
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
17package com.android.systemui.statusbar.tablet;
18
19import android.content.Context;
20import android.os.Handler;
21import android.util.AttributeSet;
22import android.util.Slog;
23import android.view.View;
24import android.view.MotionEvent;
25import android.widget.FrameLayout;
26
27public class TabletStatusBarView extends FrameLayout {
28    private Handler mHandler;
29
30    private final int MAX_PANELS = 5;
31    private final View[] mIgnoreChildren = new View[MAX_PANELS];
32    private final View[] mPanels = new View[MAX_PANELS];
33    private final int[] mPos = new int[2];
34
35    public TabletStatusBarView(Context context) {
36        super(context);
37    }
38
39    public TabletStatusBarView(Context context, AttributeSet attrs) {
40        super(context, attrs);
41    }
42
43    @Override
44    public boolean onInterceptTouchEvent(MotionEvent ev) {
45        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
46            if (TabletStatusBar.DEBUG) {
47                Slog.d(TabletStatusBar.TAG, "TabletStatusBarView intercepting touch event: " + ev);
48            }
49            mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
50            mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
51            mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_RECENTS_PANEL);
52            mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_RECENTS_PANEL);
53            mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL);
54            mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_INPUT_METHODS_PANEL);
55            mHandler.removeMessages(TabletStatusBar.MSG_STOP_TICKER);
56            mHandler.sendEmptyMessage(TabletStatusBar.MSG_STOP_TICKER);
57
58            for (int i=0; i < mPanels.length; i++) {
59                if (mPanels[i] != null && mPanels[i].getVisibility() == View.VISIBLE) {
60                    if (eventInside(mIgnoreChildren[i], ev)) {
61                        if (TabletStatusBar.DEBUG) {
62                            Slog.d(TabletStatusBar.TAG,
63                                    "TabletStatusBarView eating event for view: "
64                                    + mIgnoreChildren[i]);
65                        }
66                        return true;
67                    }
68                }
69            }
70        }
71        if (TabletStatusBar.DEBUG) {
72            Slog.d(TabletStatusBar.TAG, "TabletStatusBarView not intercepting event");
73        }
74        return super.onInterceptTouchEvent(ev);
75    }
76
77    private boolean eventInside(View v, MotionEvent ev) {
78        // assume that x and y are window coords because we are.
79        final int x = (int)ev.getX();
80        final int y = (int)ev.getY();
81
82        final int[] p = mPos;
83        v.getLocationInWindow(p);
84
85        final int l = p[0];
86        final int t = p[1];
87        final int r = p[0] + v.getWidth();
88        final int b = p[1] + v.getHeight();
89
90        return x >= l && x < r && y >= t && y < b;
91    }
92
93    public void setHandler(Handler h) {
94        mHandler = h;
95    }
96
97    /**
98     * Let the status bar know that if you tap on ignore while panel is showing, don't do anything.
99     *
100     * Debounces taps on, say, a popup's trigger when the popup is already showing.
101     */
102    public void setIgnoreChildren(int index, View ignore, View panel) {
103        mIgnoreChildren[index] = ignore;
104        mPanels[index] = panel;
105    }
106}
107