Home | History | Annotate | Download | only in policy
      1 /*
      2  * Copyright (C) 2008 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.policy;
     18 
     19 import android.content.Context;
     20 import android.content.res.TypedArray;
     21 import android.graphics.Region;
     22 import android.graphics.drawable.AnimationDrawable;
     23 import android.graphics.drawable.Drawable;
     24 import android.os.RemoteException;
     25 import android.os.SystemClock;
     26 import android.os.ServiceManager;
     27 import android.util.AttributeSet;
     28 import android.util.Slog;
     29 import android.view.HapticFeedbackConstants;
     30 import android.view.IWindowManager;
     31 import android.view.InputDevice;
     32 import android.view.KeyCharacterMap;
     33 import android.view.KeyEvent;
     34 import android.view.MotionEvent;
     35 import android.view.View;
     36 import android.view.ViewConfiguration;
     37 import android.view.ViewTreeObserver;
     38 import android.widget.RemoteViews.RemoteView;
     39 
     40 import com.android.systemui.R;
     41 
     42 public class EventHole extends View implements ViewTreeObserver.OnComputeInternalInsetsListener {
     43     private static final String TAG = "StatusBar.EventHole";
     44 
     45     private boolean mWindowVis;
     46     private int[] mLoc = new int[2];
     47 
     48     public EventHole(Context context, AttributeSet attrs) {
     49         this(context, attrs, 0);
     50     }
     51 
     52     public EventHole(Context context, AttributeSet attrs, int defStyle) {
     53         super(context, attrs);
     54     }
     55 
     56     @Override
     57     protected void onWindowVisibilityChanged(int visibility) {
     58         super.onWindowVisibilityChanged(visibility);
     59         mWindowVis = visibility == View.VISIBLE;
     60     }
     61 
     62     @Override
     63     protected void onAttachedToWindow() {
     64         super.onAttachedToWindow();
     65         getViewTreeObserver().addOnComputeInternalInsetsListener(this);
     66     }
     67 
     68     @Override
     69     protected void onDetachedFromWindow() {
     70         super.onDetachedFromWindow();
     71         getViewTreeObserver().removeOnComputeInternalInsetsListener(this);
     72     }
     73 
     74     public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo info) {
     75         final boolean visible = isShown() && mWindowVis && getWidth() > 0 && getHeight() > 0;
     76         final int[] loc = mLoc;
     77         getLocationInWindow(loc);
     78         final int l = loc[0];
     79         final int r = l + getWidth();
     80         final int t = loc[1];
     81         final int b = t + getHeight();
     82 
     83         View top = this;
     84         while (top.getParent() instanceof View) {
     85             top = (View)top.getParent();
     86         }
     87 
     88         if (visible) {
     89             info.setTouchableInsets(
     90                     ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
     91             info.touchableRegion.set(0, 0, top.getWidth(), top.getHeight());
     92             info.touchableRegion.op(l, t, r, b, Region.Op.DIFFERENCE);
     93         } else {
     94             info.setTouchableInsets(
     95                     ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
     96         }
     97     }
     98 }
     99 
    100