summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chet Haase <chet@google.com> 2013-03-20 16:14:56 -0700
committer Chet Haase <chet@google.com> 2013-03-20 16:23:33 -0700
commit633326e29f008d2b86e523cfeedcbb2a0883181f (patch)
treea409f9b189e442d95c297d146942d0f5df5136b6
parent63f1e2fb6b7102490b11523589b82c2101d3c079 (diff)
Manage drawable invalidation automatically for Overlays
Drawables added to a view's Overlay will now cause the Overlay to be invalidated via the normal drawable-invalidation mechanism. That is, changes to any of the drawables in the overlay should cause invalidation of the proper area of the overlay and thus the hostView, causing the appropriate area to be redrawn. Also, fixed a bug in drawable invalidation so that bounds changes will now correctly invalidate both the old and new bounds areas. Issue #8350510 Add APIs needed for future animation capabilities Change-Id: Icae5fa0e420232ee17dc39be10084345bae8dbd8
-rw-r--r--core/java/android/view/Overlay.java10
-rw-r--r--core/java/android/view/ViewOverlay.java11
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java4
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);
}