191cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase/* 291cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * Copyright (C) 2013 The Android Open Source Project 391cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 491cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * Licensed under the Apache License, Version 2.0 (the "License"); 591cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * you may not use this file except in compliance with the License. 691cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * You may obtain a copy of the License at 791cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 891cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * http://www.apache.org/licenses/LICENSE-2.0 991cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 1091cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * Unless required by applicable law or agreed to in writing, software 1191cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * distributed under the License is distributed on an "AS IS" BASIS, 1291cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1391cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * See the License for the specific language governing permissions and 1491cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * limitations under the License. 1591cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase */ 1691cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haasepackage android.view; 1791cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase 18b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikovimport android.annotation.NonNull; 19edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haaseimport android.content.Context; 2091cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haaseimport android.graphics.drawable.Drawable; 2191cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase 2291cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase/** 23edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * A group overlay is an extra layer that sits on top of a ViewGroup 24edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * (the "host view") which is drawn after all other content in that view 25edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * (including the view group's children). Interaction with the overlay 26edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * layer is done by adding and removing views and drawables. 2791cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 28edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * <p>ViewGroupOverlay is a subclass of {@link ViewOverlay}, adding the ability to 29edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * manage views for overlays on ViewGroups, in addition to the drawable 30edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * support in ViewOverlay.</p> 31edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * 32edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * @see ViewGroup#getOverlay() 3391cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase */ 34edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haasepublic class ViewGroupOverlay extends ViewOverlay { 3591cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase 36edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase ViewGroupOverlay(Context context, View hostView) { 37edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase super(context, hostView); 38edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase } 3991cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase 4091cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase /** 41b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * Adds a {@code View} to the overlay. The bounds of the added view should be 429c17fe693deb0cc84099b619185472f192c2b52dChet Haase * relative to the host view. Any view added to the overlay should be 439c17fe693deb0cc84099b619185472f192c2b52dChet Haase * removed when it is no longer needed or no longer visible. 449c17fe693deb0cc84099b619185472f192c2b52dChet Haase * 45edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * <p>Views in the overlay are visual-only; they do not receive input 46edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * events and do not participate in focus traversal. Overlay views 47edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * are intended to be transient, such as might be needed by a temporary 48edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * animation effect.</p> 49edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * 509c17fe693deb0cc84099b619185472f192c2b52dChet Haase * <p>If the view has a parent, the view will be removed from that parent 51face742d31a7a72a4bdced5594e00e51ecee6c84Chet Haase * before being added to the overlay. Also, if that parent is attached 52face742d31a7a72a4bdced5594e00e51ecee6c84Chet Haase * in the current view hierarchy, the view will be repositioned 539c17fe693deb0cc84099b619185472f192c2b52dChet Haase * such that it is in the same relative location inside the activity. For 549c17fe693deb0cc84099b619185472f192c2b52dChet Haase * example, if the view's current parent lies 100 pixels to the right 559c17fe693deb0cc84099b619185472f192c2b52dChet Haase * and 200 pixels down from the origin of the overlay's 569c17fe693deb0cc84099b619185472f192c2b52dChet Haase * host view, then the view will be offset by (100, 200).</p> 5791cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 58b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * <p>{@code View}s added with this API will be drawn in the order they were 59b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * added. Drawing of the overlay views will happen before drawing of any of the 60b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * {@code Drawable}s added with {@link #add(Drawable)} API even if a call to 61b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * this API happened after the call to {@link #add(Drawable)}.</p> 62b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * 63b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * <p>Passing <code>null</code> parameter will result in an 64b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * {@link IllegalArgumentException} being thrown.</p> 65b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * 66b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * @param view The {@code View} to be added to the overlay. The added view will be 6791cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * drawn when the overlay is drawn. 6891cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * @see #remove(View) 69edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * @see ViewOverlay#add(Drawable) 7091cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase */ 71b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov public void add(@NonNull View view) { 72edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase mOverlayViewGroup.add(view); 73edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase } 7491cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase 7591cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase /** 76b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * Removes the specified {@code View} from the overlay. Passing <code>null</code> parameter 77b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * will result in an {@link IllegalArgumentException} being thrown. 7891cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * 79b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov * @param view The {@code View} to be removed from the overlay. 8091cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase * @see #add(View) 81edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * @see ViewOverlay#remove(Drawable) 8291cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase */ 83b4b939cf1af397cd223ac7ebb12e1d2d61e2a83eKirill Grouchnikov public void remove(@NonNull View view) { 84edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase mOverlayViewGroup.remove(view); 85edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase } 8691cedf1c3dbf7a52c2892294b2e5ba3e40ef3583Chet Haase} 87