blob: c2807babdff2fc90fb92cb4ce78412545afe347c [file] [log] [blame]
Chet Haaseedf6f4b2013-03-26 07:55:30 -07001/*
2 * Copyright (C) 2013 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 */
16package android.view;
17
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050018import android.annotation.NonNull;
Chet Haaseedf6f4b2013-03-26 07:55:30 -070019import android.content.Context;
20import android.graphics.drawable.Drawable;
21
22/**
23 * A group overlay is an extra layer that sits on top of a ViewGroup
24 * (the "host view") which is drawn after all other content in that view
25 * (including the view group's children). Interaction with the overlay
26 * layer is done by adding and removing views and drawables.
27 *
28 * <p>ViewGroupOverlay is a subclass of {@link ViewOverlay}, adding the ability to
29 * manage views for overlays on ViewGroups, in addition to the drawable
30 * support in ViewOverlay.</p>
31 *
32 * @see ViewGroup#getOverlay()
33 */
34public class ViewGroupOverlay extends ViewOverlay {
35
36 ViewGroupOverlay(Context context, View hostView) {
37 super(context, hostView);
38 }
39
40 /**
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050041 * Adds a {@code View} to the overlay. The bounds of the added view should be
Chet Haaseedf6f4b2013-03-26 07:55:30 -070042 * relative to the host view. Any view added to the overlay should be
43 * removed when it is no longer needed or no longer visible.
44 *
45 * <p>Views in the overlay are visual-only; they do not receive input
46 * events and do not participate in focus traversal. Overlay views
47 * are intended to be transient, such as might be needed by a temporary
48 * animation effect.</p>
49 *
50 * <p>If the view has a parent, the view will be removed from that parent
Chet Haaseface7422013-04-15 15:15:59 -070051 * before being added to the overlay. Also, if that parent is attached
52 * in the current view hierarchy, the view will be repositioned
Chet Haaseedf6f4b2013-03-26 07:55:30 -070053 * such that it is in the same relative location inside the activity. For
54 * example, if the view's current parent lies 100 pixels to the right
55 * and 200 pixels down from the origin of the overlay's
56 * host view, then the view will be offset by (100, 200).</p>
57 *
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050058 * <p>{@code View}s added with this API will be drawn in the order they were
59 * added. Drawing of the overlay views will happen before drawing of any of the
60 * {@code Drawable}s added with {@link #add(Drawable)} API even if a call to
61 * this API happened after the call to {@link #add(Drawable)}.</p>
62 *
63 * <p>Passing <code>null</code> parameter will result in an
64 * {@link IllegalArgumentException} being thrown.</p>
65 *
66 * @param view The {@code View} to be added to the overlay. The added view will be
Chet Haaseedf6f4b2013-03-26 07:55:30 -070067 * drawn when the overlay is drawn.
68 * @see #remove(View)
69 * @see ViewOverlay#add(Drawable)
70 */
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050071 public void add(@NonNull View view) {
Chet Haaseedf6f4b2013-03-26 07:55:30 -070072 mOverlayViewGroup.add(view);
73 }
74
75 /**
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050076 * Removes the specified {@code View} from the overlay. Passing <code>null</code> parameter
77 * will result in an {@link IllegalArgumentException} being thrown.
Chet Haaseedf6f4b2013-03-26 07:55:30 -070078 *
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050079 * @param view The {@code View} to be removed from the overlay.
Chet Haaseedf6f4b2013-03-26 07:55:30 -070080 * @see #add(View)
81 * @see ViewOverlay#remove(Drawable)
82 */
Kirill Grouchnikovb4b939c2016-03-08 10:37:06 -050083 public void remove(@NonNull View view) {
Chet Haaseedf6f4b2013-03-26 07:55:30 -070084 mOverlayViewGroup.remove(view);
85 }
86}