OSDN Git Service

071bdeea3375a29136ae748d4bae6781caca1dfa
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / widgets / FrameLayoutWithOverlay.java
1 /*
2  * Copyright (C) 2012 The Android Open Source Project Licensed under the Apache
3  * License, Version 2.0 (the "License"); you may not use this file except in
4  * compliance with the License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6  * or agreed to in writing, software distributed under the License is
7  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the specific language
9  * governing permissions and limitations under the License.
10  */
11
12 package com.cyanogenmod.eleven.widgets;
13
14 import android.content.Context;
15 import android.util.AttributeSet;
16 import android.view.View;
17 import android.view.ViewGroup;
18 import android.widget.FrameLayout;
19
20 /**
21  * A FrameLayout whose contents are kept beneath an
22  * {@link AlphaTouchInterceptorOverlay}. If necessary, you can specify your own
23  * alpha-layer and manually manage its z-order.
24  */
25 public class FrameLayoutWithOverlay extends FrameLayout {
26
27     private final AlphaTouchInterceptorOverlay mOverlay;
28
29     /**
30      * @param context The {@link Context} to use
31      * @param attrs The attributes of the XML tag that is inflating the view.
32      */
33     public FrameLayoutWithOverlay(final Context context, final AttributeSet attrs) {
34         super(context, attrs);
35
36         /* Programmatically create touch-interceptor View. */
37         mOverlay = new AlphaTouchInterceptorOverlay(context);
38
39         addView(mOverlay);
40     }
41
42     /**
43      * After adding the View, bring the overlay to the front to ensure it's
44      * always on top.
45      */
46     @Override
47     public void addView(final View child, final int index, final ViewGroup.LayoutParams params) {
48         super.addView(child, index, params);
49         mOverlay.bringToFront();
50     }
51
52     /**
53      * Delegate to overlay: set the View that it will use as its alpha-layer. If
54      * none is set, the overlay will use its own alpha layer. Only necessary to
55      * set this if some child views need to appear above the alpha-layer.
56      */
57     protected void setAlphaLayer(final View layer) {
58         mOverlay.setAlphaLayer(layer);
59     }
60
61     /** Delegate to overlay: set the alpha value on the alpha layer. */
62     public void setAlphaLayerValue(final float alpha) {
63         mOverlay.setAlphaLayerValue(alpha);
64     }
65
66     /** Delegate to overlay. */
67     public void setOverlayOnClickListener(final OnClickListener listener) {
68         mOverlay.setOverlayOnClickListener(listener);
69     }
70
71     /** Delegate to overlay. */
72     public void setOverlayClickable(final boolean clickable) {
73         mOverlay.setOverlayClickable(clickable);
74     }
75 }