diff options
| author | 2013-03-20 23:30:52 +0000 | |
|---|---|---|
| committer | 2013-03-20 23:30:53 +0000 | |
| commit | 10c4d99f04a399c78529d0ae66c1785b26a125c3 (patch) | |
| tree | 37d4980a49b7a466e49b6c773a9f8b3d89763ca3 | |
| parent | afd10322f598abfda973ad78117dd297e09de212 (diff) | |
| parent | 633326e29f008d2b86e523cfeedcbb2a0883181f (diff) | |
Merge "Manage drawable invalidation automatically for Overlays" into jb-mr2-dev
| -rw-r--r-- | core/java/android/view/Overlay.java | 10 | ||||
| -rw-r--r-- | core/java/android/view/ViewOverlay.java | 11 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/Drawable.java | 4 |
3 files changed, 15 insertions, 10 deletions
diff --git a/core/java/android/view/Overlay.java b/core/java/android/view/Overlay.java index f15d4d2b57dd..210bc3177b4e 100644 --- a/core/java/android/view/Overlay.java +++ b/core/java/android/view/Overlay.java @@ -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. diff --git a/core/java/android/view/ViewOverlay.java b/core/java/android/view/ViewOverlay.java index 8c2ab9da77a2..939377d7af18 100644 --- a/core/java/android/view/ViewOverlay.java +++ b/core/java/android/view/ViewOverlay.java @@ -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,10 +74,16 @@ 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); } diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 37f2250658f6..c90f400b6b26 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -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); } |