Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 633326e2 authored by Chet Haase's avatar Chet Haase
Browse files

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
parent 63f1e2fb
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -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.
+9 −2
Original line number Diff line number Diff line
@@ -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);
+4 −0
Original line number Diff line number Diff line
@@ -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);
        }