*/
package android.view;
+import android.annotation.NonNull;
import android.content.Context;
import android.graphics.drawable.Drawable;
}
/**
- * 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.
*
* 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);
}
}
package android.view;
import android.animation.LayoutTransition;
+import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
}
/**
- * 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);
}
* 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.
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
}
}
- 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());
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 &&
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);
}