• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.contacts.widget;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.FrameLayout;
24 
25 /**
26  * A FrameLayout whose contents are kept beneath an {@link AlphaTouchInterceptorOverlay}.
27  * If necessary, you can specify your own alpha-layer and manually manage its z-order.
28  */
29 public class FrameLayoutWithOverlay extends FrameLayout {
30     private final AlphaTouchInterceptorOverlay mOverlay;
31 
FrameLayoutWithOverlay(Context context, AttributeSet attrs)32     public FrameLayoutWithOverlay(Context context, AttributeSet attrs) {
33         super(context, attrs);
34 
35         // Programmatically create touch-interceptor View.
36         mOverlay = new AlphaTouchInterceptorOverlay(context);
37 
38         addView(mOverlay);
39     }
40 
41     /** After adding the View, bring the overlay to the front to ensure it's always on top. */
42     @Override
addView(View child, int index, ViewGroup.LayoutParams params)43     public void addView(View child, int index, ViewGroup.LayoutParams params) {
44         super.addView(child, index, params);
45         mOverlay.bringToFront();
46     }
47 
48     /**
49      * Delegate to overlay:  set the View that it will use as its alpha-layer.
50      * If none is set, the overlay will use its own alpha layer.  Only
51      * necessary to set this if some child views need to appear above the
52      * alpha-layer.
53      */
setAlphaLayer(View layer)54     protected void setAlphaLayer(View layer) {
55         mOverlay.setAlphaLayer(layer);
56     }
57 
58     /** Delegate to overlay: set the alpha value on the alpha layer. */
setAlphaLayerValue(float alpha)59     public void setAlphaLayerValue(float alpha) {
60         mOverlay.setAlphaLayerValue(alpha);
61     }
62 
63     /** Delegate to overlay. */
setOverlayOnClickListener(OnClickListener listener)64     public void setOverlayOnClickListener(OnClickListener listener) {
65         mOverlay.setOverlayOnClickListener(listener);
66     }
67 
68     /** Delegate to overlay. */
setOverlayClickable(boolean clickable)69     public void setOverlayClickable(boolean clickable) {
70         mOverlay.setOverlayClickable(clickable);
71     }
72 }
73