17edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus/*
27edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * Copyright (C) 2012 The Android Open Source Project
37edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus *
47edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * Licensed under the Apache License, Version 2.0 (the "License");
57edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * you may not use this file except in compliance with the License.
67edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * You may obtain a copy of the License at
77edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus *
87edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus *      http://www.apache.org/licenses/LICENSE-2.0
97edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus *
107edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * Unless required by applicable law or agreed to in writing, software
117edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * distributed under the License is distributed on an "AS IS" BASIS,
127edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * See the License for the specific language governing permissions and
147edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * limitations under the License.
157edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus */
167edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
177edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Garguspackage com.android.contacts.widget;
187edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
197edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargusimport android.content.Context;
207edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargusimport android.util.AttributeSet;
217edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargusimport android.view.View;
227edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargusimport android.view.ViewGroup;
237edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargusimport android.widget.FrameLayout;
247edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
257edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus/**
267edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * A FrameLayout whose contents are kept beneath an {@link AlphaTouchInterceptorOverlay}.
277edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus * If necessary, you can specify your own alpha-layer and manually manage its z-order.
287edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus */
297edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Garguspublic class FrameLayoutWithOverlay extends FrameLayout {
307edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    private final AlphaTouchInterceptorOverlay mOverlay;
317edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
327edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    public FrameLayoutWithOverlay(Context context, AttributeSet attrs) {
337edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        super(context, attrs);
347edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
357edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        // Programmatically create touch-interceptor View.
367edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        mOverlay = new AlphaTouchInterceptorOverlay(context);
377edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
387edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        addView(mOverlay);
397edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
407edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
417edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    /** After adding the View, bring the overlay to the front to ensure it's always on top. */
427edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    @Override
437edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    public void addView(View child, int index, ViewGroup.LayoutParams params) {
447edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        super.addView(child, index, params);
457edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        mOverlay.bringToFront();
467edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
477edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
487edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    /**
49fc81892e4081f46a54a68498e96d89864c77348eJosh Gargus     * Delegate to overlay:  set the View that it will use as its alpha-layer.
50fc81892e4081f46a54a68498e96d89864c77348eJosh Gargus     * If none is set, the overlay will use its own alpha layer.  Only
517edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus     * necessary to set this if some child views need to appear above the
527edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus     * alpha-layer.
537edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus     */
547edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    protected void setAlphaLayer(View layer) {
557edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        mOverlay.setAlphaLayer(layer);
567edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
577edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
587edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    /** Delegate to overlay: set the alpha value on the alpha layer. */
597edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    public void setAlphaLayerValue(float alpha) {
607edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus        mOverlay.setAlphaLayerValue(alpha);
617edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
627edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
637edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    /** Delegate to overlay. */
647edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    public void setOverlayOnClickListener(OnClickListener listener) {
65fc81892e4081f46a54a68498e96d89864c77348eJosh Gargus        mOverlay.setOverlayOnClickListener(listener);
667edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
677edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus
687edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    /** Delegate to overlay. */
697edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    public void setOverlayClickable(boolean clickable) {
70fc81892e4081f46a54a68498e96d89864c77348eJosh Gargus        mOverlay.setOverlayClickable(clickable);
717edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus    }
727edad9dd95a411cc5ed69815e5f0be8a5d1e8b19Josh Gargus}
73