Merge "Tweaks to ViewOverlay." into nyc-dev

This commit is contained in:
Kirill Grouchnikov
2016-03-09 21:35:44 +00:00
committed by Android (Google) Code Review
2 changed files with 50 additions and 21 deletions

View File

@@ -15,6 +15,7 @@
*/
package android.view;
import android.annotation.NonNull;
import android.content.Context;
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
* 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
* 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.
* @see #remove(View)
* @see ViewOverlay#add(Drawable)
*/
public void add(View view) {
public void add(@NonNull View 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 ViewOverlay#remove(Drawable)
*/
public void remove(View view) {
public void remove(@NonNull View view) {
mOverlayViewGroup.remove(view);
}
}

View File

@@ -16,6 +16,7 @@
package android.view;
import android.animation.LayoutTransition;
import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Canvas;
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
* 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
* drawn when the view redraws its overlay.
* @param drawable The {@link Drawable} to be added to the overlay. This drawable will be
* drawn when the view redraws its overlay. {@link Drawable}s will be drawn in the order that
* they were added.
* @see #remove(Drawable)
*/
public void add(Drawable drawable) {
public void add(@NonNull Drawable 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)
*/
public void remove(Drawable drawable) {
public void remove(@NonNull Drawable 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
* this host view.
*/
View mHostView;
final View mHostView;
/**
* The set of drawables to draw when the overlay is rendered.
@@ -137,10 +143,12 @@ public class ViewOverlay {
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) {
mDrawables = new ArrayList<Drawable>();
mDrawables = new ArrayList<>();
}
if (!mDrawables.contains(drawable)) {
// 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) {
mDrawables.remove(drawable);
invalidate(drawable.getBounds());
@@ -163,7 +174,11 @@ public class ViewOverlay {
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) {
ViewGroup parent = (ViewGroup) child.getParent();
if (parent != mHostView && parent.getParent() != null &&
@@ -190,7 +205,11 @@ public class ViewOverlay {
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);
}