Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package android.view; |
| 17 | |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 18 | import android.annotation.NonNull; |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import 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 | */ |
| 34 | public class ViewGroupOverlay extends ViewOverlay { |
| 35 | |
| 36 | ViewGroupOverlay(Context context, View hostView) { |
| 37 | super(context, hostView); |
| 38 | } |
| 39 | |
| 40 | /** |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 41 | * Adds a {@code View} to the overlay. The bounds of the added view should be |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 42 | * 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 Haase | face742 | 2013-04-15 15:15:59 -0700 | [diff] [blame] | 51 | * before being added to the overlay. Also, if that parent is attached |
| 52 | * in the current view hierarchy, the view will be repositioned |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 53 | * 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 Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 58 | * <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 Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 67 | * drawn when the overlay is drawn. |
| 68 | * @see #remove(View) |
| 69 | * @see ViewOverlay#add(Drawable) |
| 70 | */ |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 71 | public void add(@NonNull View view) { |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 72 | mOverlayViewGroup.add(view); |
| 73 | } |
| 74 | |
| 75 | /** |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 76 | * Removes the specified {@code View} from the overlay. Passing <code>null</code> parameter |
| 77 | * will result in an {@link IllegalArgumentException} being thrown. |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 78 | * |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 79 | * @param view The {@code View} to be removed from the overlay. |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 80 | * @see #add(View) |
| 81 | * @see ViewOverlay#remove(Drawable) |
| 82 | */ |
Kirill Grouchnikov | b4b939c | 2016-03-08 10:37:06 -0500 | [diff] [blame] | 83 | public void remove(@NonNull View view) { |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 84 | mOverlayViewGroup.remove(view); |
| 85 | } |
| 86 | } |