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

Commit 76165b2a authored by Alan Viverette's avatar Alan Viverette
Browse files

Return correct intrinsic dimensions for inset colors

Also updates documentation for getIntrinsicWidth/Height to accurately
reflect the behavior of the existing implementations and provide an
explanation of what "intrinsic" means.

Bug: 25646242
Change-Id: I11daf57e598148adfda922cfc1ba31ed48a16bd7
parent 01168521
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -913,16 +913,26 @@ public abstract class Drawable {
    protected void onBoundsChange(Rect bounds) {}

    /**
     * Return the intrinsic width of the underlying drawable object.  Returns
     * -1 if it has no intrinsic width, such as with a solid color.
     * Returns the drawable's intrinsic width.
     * <p>
     * Intrinsic width is the width at which the drawable would like to be laid
     * out, including any inherent padding. If the drawable has no intrinsic
     * width, such as a solid color, this method returns -1.
     *
     * @return the intrinsic width, or -1 if no intrinsic width
     */
    public int getIntrinsicWidth() {
        return -1;
    }

    /**
     * Return the intrinsic height of the underlying drawable object. Returns
     * -1 if it has no intrinsic height, such as with a solid color.
     * Returns the drawable's intrinsic height.
     * <p>
     * Intrinsic height is the height at which the drawable would like to be
     * laid out, including any inherent padding. If the drawable has no
     * intrinsic height, such as a solid color, this method returns -1.
     *
     * @return the intrinsic height, or -1 if no intrinsic height
     */
    public int getIntrinsicHeight() {
        return -1;
+10 −2
Original line number Diff line number Diff line
@@ -222,12 +222,20 @@ public class InsetDrawable extends DrawableWrapper {

    @Override
    public int getIntrinsicWidth() {
        return getDrawable().getIntrinsicWidth() + mState.mInsetLeft + mState.mInsetRight;
        final int childWidth = getDrawable().getIntrinsicWidth();
        if (childWidth < 0) {
            return -1;
        }
        return childWidth + mState.mInsetLeft + mState.mInsetRight;
    }

    @Override
    public int getIntrinsicHeight() {
        return getDrawable().getIntrinsicHeight() + mState.mInsetTop + mState.mInsetBottom;
        final int childHeight = getDrawable().getIntrinsicHeight();
        if (childHeight < 0) {
            return -1;
        }
        return childHeight + mState.mInsetTop + mState.mInsetBottom;
    }

    @Override