TabletStatusBarView.java revision ec51a82bd6e7a33fe6ed84ba252b82625629eaac
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 View[] mIgnoreChildren = new View[3];
31    private View[] mPanels = new View[3];
32    private int[] mPos = new int[2];
33
34    public TabletStatusBarView(Context context) {
35        super(context);
36    }
37
38    public TabletStatusBarView(Context context, AttributeSet attrs) {
39        super(context, attrs);
40    }
41
42    public boolean onInterceptTouchEvent(MotionEvent ev) {
43        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
44            if (TabletStatusBar.DEBUG) {
45                Slog.d(TabletStatusBar.TAG, "TabletStatusBarView intercepting touch event: " + ev);
46            }
47            mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
48            mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_NOTIFICATION_PANEL);
49            mHandler.removeMessages(TabletStatusBar.MSG_CLOSE_RECENTS_PANEL);
50            mHandler.sendEmptyMessage(TabletStatusBar.MSG_CLOSE_RECENTS_PANEL);
51
52            for (int i=0; i < mPanels.length; i++) {
53                if (mPanels[i] != null && mPanels[i].getVisibility() == View.VISIBLE) {
54                    if (eventInside(mIgnoreChildren[i], ev)) {
55                        if (TabletStatusBar.DEBUG) {
56                            Slog.d(TabletStatusBar.TAG, "TabletStatusBarView eating event for view: " + mIgnoreChildren[i]);
57                        }
58                        return true;
59                    }
60                }
61            }
62        }
63        Slog.d(TabletStatusBar.TAG, "TabletStatusBarView not intercepting event");
64        return super.onInterceptTouchEvent(ev);
65    }
66
67    private boolean eventInside(View v, MotionEvent ev) {
68        // assume that x and y are window coords because we are.
69        final int x = (int)ev.getX();
70        final int y = (int)ev.getY();
71
72        final int[] p = mPos;
73        v.getLocationInWindow(p);
74
75        final int l = p[0];
76        final int t = p[1];
77        final int r = p[0] + v.getWidth();
78        final int b = p[1] + v.getHeight();
79
80        return x >= l && x < r && y >= t && y < b;
81    }
82
83    public void setHandler(Handler h) {
84        mHandler = h;
85    }
86
87    public void setIgnoreChildren(int index, View ignore, View panel) {
88        mIgnoreChildren[index] = ignore;
89        mPanels[index] = panel;
90    }
91}
92