Merge "Tweaks to ViewOverlay." into nyc-dev
am: 04c659299f
* commit '04c659299f3ef9ca82a40e068695473add350ea4':
Tweaks to ViewOverlay.
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package android.view;
|
package android.view;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ public class ViewGroupOverlay extends ViewOverlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a View to the overlay. The bounds of the added view should be
|
* Adds a {@code View} to the overlay. The bounds of the added view should be
|
||||||
* relative to the host view. Any view added to the overlay should be
|
* relative to the host view. Any view added to the overlay should be
|
||||||
* removed when it is no longer needed or no longer visible.
|
* removed when it is no longer needed or no longer visible.
|
||||||
*
|
*
|
||||||
@@ -54,23 +55,32 @@ public class ViewGroupOverlay extends ViewOverlay {
|
|||||||
* and 200 pixels down from the origin of the overlay's
|
* and 200 pixels down from the origin of the overlay's
|
||||||
* host view, then the view will be offset by (100, 200).</p>
|
* host view, then the view will be offset by (100, 200).</p>
|
||||||
*
|
*
|
||||||
* @param view The View to be added to the overlay. The added view will be
|
* <p>{@code View}s added with this API will be drawn in the order they were
|
||||||
|
* added. Drawing of the overlay views will happen before drawing of any of the
|
||||||
|
* {@code Drawable}s added with {@link #add(Drawable)} API even if a call to
|
||||||
|
* this API happened after the call to {@link #add(Drawable)}.</p>
|
||||||
|
*
|
||||||
|
* <p>Passing <code>null</code> parameter will result in an
|
||||||
|
* {@link IllegalArgumentException} being thrown.</p>
|
||||||
|
*
|
||||||
|
* @param view The {@code View} to be added to the overlay. The added view will be
|
||||||
* drawn when the overlay is drawn.
|
* drawn when the overlay is drawn.
|
||||||
* @see #remove(View)
|
* @see #remove(View)
|
||||||
* @see ViewOverlay#add(Drawable)
|
* @see ViewOverlay#add(Drawable)
|
||||||
*/
|
*/
|
||||||
public void add(View view) {
|
public void add(@NonNull View view) {
|
||||||
mOverlayViewGroup.add(view);
|
mOverlayViewGroup.add(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified View from the overlay.
|
* Removes the specified {@code View} from the overlay. Passing <code>null</code> parameter
|
||||||
|
* will result in an {@link IllegalArgumentException} being thrown.
|
||||||
*
|
*
|
||||||
* @param view The View to be removed from the overlay.
|
* @param view The {@code View} to be removed from the overlay.
|
||||||
* @see #add(View)
|
* @see #add(View)
|
||||||
* @see ViewOverlay#remove(Drawable)
|
* @see ViewOverlay#remove(Drawable)
|
||||||
*/
|
*/
|
||||||
public void remove(View view) {
|
public void remove(@NonNull View view) {
|
||||||
mOverlayViewGroup.remove(view);
|
mOverlayViewGroup.remove(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package android.view;
|
package android.view;
|
||||||
|
|
||||||
import android.animation.LayoutTransition;
|
import android.animation.LayoutTransition;
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
@@ -59,25 +60,30 @@ public class ViewOverlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a Drawable to the overlay. The bounds of the drawable should be relative to
|
* Adds a {@link Drawable} to the overlay. The bounds of the drawable should be relative to
|
||||||
* the host view. Any drawable added to the overlay should be removed when it is no longer
|
* the host view. Any drawable added to the overlay should be removed when it is no longer
|
||||||
* needed or no longer visible.
|
* needed or no longer visible. Adding an already existing {@link Drawable}
|
||||||
|
* is a no-op. Passing <code>null</code> parameter will result in an
|
||||||
|
* {@link IllegalArgumentException} being thrown.
|
||||||
*
|
*
|
||||||
* @param drawable The Drawable to be added to the overlay. This drawable will be
|
* @param drawable The {@link Drawable} to be added to the overlay. This drawable will be
|
||||||
* drawn when the view redraws its overlay.
|
* drawn when the view redraws its overlay. {@link Drawable}s will be drawn in the order that
|
||||||
|
* they were added.
|
||||||
* @see #remove(Drawable)
|
* @see #remove(Drawable)
|
||||||
*/
|
*/
|
||||||
public void add(Drawable drawable) {
|
public void add(@NonNull Drawable drawable) {
|
||||||
mOverlayViewGroup.add(drawable);
|
mOverlayViewGroup.add(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified Drawable from the overlay.
|
* Removes the specified {@link Drawable} from the overlay. Removing a {@link Drawable} that was
|
||||||
|
* not added with {@link #add(Drawable)} is a no-op. Passing <code>null</code> parameter will
|
||||||
|
* result in an {@link IllegalArgumentException} being thrown.
|
||||||
*
|
*
|
||||||
* @param drawable The Drawable to be removed from the overlay.
|
* @param drawable The {@link Drawable} to be removed from the overlay.
|
||||||
* @see #add(Drawable)
|
* @see #add(Drawable)
|
||||||
*/
|
*/
|
||||||
public void remove(Drawable drawable) {
|
public void remove(@NonNull Drawable drawable) {
|
||||||
mOverlayViewGroup.remove(drawable);
|
mOverlayViewGroup.remove(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +125,7 @@ public class ViewOverlay {
|
|||||||
* The View for which this is an overlay. Invalidations of the overlay are redirected to
|
* The View for which this is an overlay. Invalidations of the overlay are redirected to
|
||||||
* this host view.
|
* this host view.
|
||||||
*/
|
*/
|
||||||
View mHostView;
|
final View mHostView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The set of drawables to draw when the overlay is rendered.
|
* The set of drawables to draw when the overlay is rendered.
|
||||||
@@ -137,10 +143,12 @@ public class ViewOverlay {
|
|||||||
mRenderNode.setLeftTopRightBottom(0, 0, mRight, mBottom);
|
mRenderNode.setLeftTopRightBottom(0, 0, mRight, mBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Drawable drawable) {
|
public void add(@NonNull Drawable drawable) {
|
||||||
|
if (drawable == null) {
|
||||||
|
throw new IllegalArgumentException("drawable must be non-null");
|
||||||
|
}
|
||||||
if (mDrawables == null) {
|
if (mDrawables == null) {
|
||||||
|
mDrawables = new ArrayList<>();
|
||||||
mDrawables = new ArrayList<Drawable>();
|
|
||||||
}
|
}
|
||||||
if (!mDrawables.contains(drawable)) {
|
if (!mDrawables.contains(drawable)) {
|
||||||
// Make each drawable unique in the overlay; can't add it more than once
|
// Make each drawable unique in the overlay; can't add it more than once
|
||||||
@@ -150,7 +158,10 @@ public class ViewOverlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Drawable drawable) {
|
public void remove(@NonNull Drawable drawable) {
|
||||||
|
if (drawable == null) {
|
||||||
|
throw new IllegalArgumentException("drawable must be non-null");
|
||||||
|
}
|
||||||
if (mDrawables != null) {
|
if (mDrawables != null) {
|
||||||
mDrawables.remove(drawable);
|
mDrawables.remove(drawable);
|
||||||
invalidate(drawable.getBounds());
|
invalidate(drawable.getBounds());
|
||||||
@@ -163,7 +174,11 @@ public class ViewOverlay {
|
|||||||
return super.verifyDrawable(who) || (mDrawables != null && mDrawables.contains(who));
|
return super.verifyDrawable(who) || (mDrawables != null && mDrawables.contains(who));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(View child) {
|
public void add(@NonNull View child) {
|
||||||
|
if (child == null) {
|
||||||
|
throw new IllegalArgumentException("view must be non-null");
|
||||||
|
}
|
||||||
|
|
||||||
if (child.getParent() instanceof ViewGroup) {
|
if (child.getParent() instanceof ViewGroup) {
|
||||||
ViewGroup parent = (ViewGroup) child.getParent();
|
ViewGroup parent = (ViewGroup) child.getParent();
|
||||||
if (parent != mHostView && parent.getParent() != null &&
|
if (parent != mHostView && parent.getParent() != null &&
|
||||||
@@ -190,7 +205,11 @@ public class ViewOverlay {
|
|||||||
super.addView(child);
|
super.addView(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(View view) {
|
public void remove(@NonNull View view) {
|
||||||
|
if (view == null) {
|
||||||
|
throw new IllegalArgumentException("view must be non-null");
|
||||||
|
}
|
||||||
|
|
||||||
super.removeView(view);
|
super.removeView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user