TabletStatusBarView.java revision b62ac127824e9723534a197189eca58d30f15d3d
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.view.View; 23import android.view.MotionEvent; 24import android.widget.FrameLayout; 25 26public class TabletStatusBarView extends FrameLayout { 27 private Handler mHandler; 28 29 private View[] mIgnoreChildren = new View[2]; 30 private View[] mPanels = new View[2]; 31 private int[] mPos = new int[2]; 32 33 public TabletStatusBarView(Context context) { 34 super(context); 35 } 36 37 public TabletStatusBarView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 } 40 41 public boolean onInterceptTouchEvent(MotionEvent ev) { 42 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 43 mHandler.removeMessages(TabletStatusBarService.MSG_CLOSE_NOTIFICATION_PANEL); 44 mHandler.sendEmptyMessage(TabletStatusBarService.MSG_CLOSE_NOTIFICATION_PANEL); 45 mHandler.removeMessages(TabletStatusBarService.MSG_CLOSE_SYSTEM_PANEL); 46 mHandler.sendEmptyMessage(TabletStatusBarService.MSG_CLOSE_SYSTEM_PANEL); 47 48 for (int i=0; i<mPanels.length; i++) { 49 if (mPanels[i].getVisibility() == View.VISIBLE) { 50 if (eventInside(mIgnoreChildren[i], ev)) { 51 return true; 52 } 53 } 54 } 55 } 56 return super.onInterceptTouchEvent(ev); 57 } 58 59 private boolean eventInside(View v, MotionEvent ev) { 60 // assume that x and y are window coords because we are. 61 final int x = (int)ev.getX(); 62 final int y = (int)ev.getY(); 63 64 final int[] p = mPos; 65 v.getLocationInWindow(p); 66 67 final int l = p[0]; 68 final int t = p[1]; 69 final int r = p[0] + v.getWidth(); 70 final int b = p[1] + v.getHeight(); 71 72 return x >= l && x < r && y >= t && y < b; 73 } 74 75 public void setHandler(Handler h) { 76 mHandler = h; 77 } 78 79 public void setIgnoreChildren(int index, View ignore, View panel) { 80 mIgnoreChildren[index] = ignore; 81 mPanels[index] = panel; 82 } 83} 84