Merge "Manage drawable invalidation automatically for Overlays" into jb-mr2-dev
This commit is contained in:
@@ -20,11 +20,7 @@ import android.graphics.drawable.Drawable;
|
||||
/**
|
||||
* An overlay is an extra layer that sits on top of a View (the "host view") which is drawn after
|
||||
* all other content in that view (including children, if the view is a ViewGroup). Interaction
|
||||
* with the overlay layer is done in terms of adding/removing views and drawables. Invalidation and
|
||||
* redrawing of the overlay layer (and its host view) is handled differently for views versus
|
||||
* drawables in the overlay. Views invalidate themselves as usual, causing appropriate redrawing
|
||||
* to occur automatically. Drawables, on the other hand, do not manage invalidation, so changes to
|
||||
* drawable objects should be accompanied by appropriate calls to invalidate() on the host view.
|
||||
* with the overlay layer is done in terms of adding/removing views and drawables.
|
||||
*
|
||||
* @see android.view.View#getOverlay()
|
||||
*/
|
||||
@@ -33,9 +29,7 @@ public interface Overlay {
|
||||
/**
|
||||
* Adds a 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. There is no automatic invalidation of the host view; changes to
|
||||
* the drawable should be accompanied by appropriate invalidation calls to the host view
|
||||
* to cause the proper area of the view, and the overlay, to be redrawn.
|
||||
* needed or no longer visible.
|
||||
*
|
||||
* @param drawable The Drawable to be added to the overlay. This drawable will be
|
||||
* drawn when the view redraws its overlay.
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.ArrayList;
|
||||
* ViewOverlay is a container that View uses to host all objects (views and drawables) that
|
||||
* are added to its "overlay", gotten through {@link View#getOverlay()}. Views and drawables are
|
||||
* added to the overlay via the add/remove methods in this class. These views and drawables are
|
||||
* then drawn whenever the view itself is drawn, after which it will draw its overlay (if it
|
||||
* exists).
|
||||
* drawn whenever the view itself is drawn; first the view draws its own content (and children,
|
||||
* if it is a ViewGroup), then it draws its overlay (if it has one).
|
||||
*
|
||||
* Besides managing and drawing the list of drawables, this class serves two purposes:
|
||||
* (1) it noops layout calls because children are absolutely positioned and
|
||||
@@ -65,6 +65,7 @@ class ViewOverlay extends ViewGroup implements Overlay {
|
||||
// Make each drawable unique in the overlay; can't add it more than once
|
||||
mDrawables.add(drawable);
|
||||
invalidate(drawable.getBounds());
|
||||
drawable.setCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +74,15 @@ class ViewOverlay extends ViewGroup implements Overlay {
|
||||
if (mDrawables != null) {
|
||||
mDrawables.remove(drawable);
|
||||
invalidate(drawable.getBounds());
|
||||
drawable.setCallback(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateDrawable(Drawable drawable) {
|
||||
invalidate(drawable.getBounds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(View child) {
|
||||
super.addView(child);
|
||||
|
||||
@@ -146,6 +146,10 @@ public abstract class Drawable {
|
||||
|
||||
if (oldBounds.left != left || oldBounds.top != top ||
|
||||
oldBounds.right != right || oldBounds.bottom != bottom) {
|
||||
if (!oldBounds.isEmpty()) {
|
||||
// first invalidate the previous bounds
|
||||
invalidateSelf();
|
||||
}
|
||||
mBounds.set(left, top, right, bottom);
|
||||
onBoundsChange(mBounds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user