blob: 6d7106bba9f3c95fe3ea3857c9c158484191d07d [file] [log] [blame]
Josh Gargus7edad9d2012-04-19 18:22:11 -07001/*
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
17package com.android.contacts.widget;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.view.ViewGroup;
23import android.widget.FrameLayout;
24
Josh Gargus7edad9d2012-04-19 18:22:11 -070025/**
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 */
29public class FrameLayoutWithOverlay extends FrameLayout {
30 private final AlphaTouchInterceptorOverlay mOverlay;
31
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
43 public void addView(View child, int index, ViewGroup.LayoutParams params) {
44 super.addView(child, index, params);
45 mOverlay.bringToFront();
46 }
47
48 /**
Josh Gargusfc818922012-04-25 15:08:43 -070049 * 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
Josh Gargus7edad9d2012-04-19 18:22:11 -070051 * necessary to set this if some child views need to appear above the
52 * alpha-layer.
53 */
54 protected void setAlphaLayer(View layer) {
55 mOverlay.setAlphaLayer(layer);
56 }
57
58 /** Delegate to overlay: set the alpha value on the alpha layer. */
59 public void setAlphaLayerValue(float alpha) {
60 mOverlay.setAlphaLayerValue(alpha);
61 }
62
63 /** Delegate to overlay. */
64 public void setOverlayOnClickListener(OnClickListener listener) {
Josh Gargusfc818922012-04-25 15:08:43 -070065 mOverlay.setOverlayOnClickListener(listener);
Josh Gargus7edad9d2012-04-19 18:22:11 -070066 }
67
68 /** Delegate to overlay. */
69 public void setOverlayClickable(boolean clickable) {
Josh Gargusfc818922012-04-25 15:08:43 -070070 mOverlay.setOverlayClickable(clickable);
Josh Gargus7edad9d2012-04-19 18:22:11 -070071 }
72}