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

Commit bbd51f1e authored by Philip Milne's avatar Philip Milne
Browse files

Share Insets instances between views that have the same background (Drawable)

Change-Id: I47d93ccca6f553b678d25966d10d7a0a97cfa5ea
parent f341e554
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -13846,13 +13846,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     */
    public Insets getLayoutInsets() {
        if (mLayoutInsets == null) {
            if (mBackground == null) {
                mLayoutInsets = Insets.NONE;
            } else {
                Rect insetRect = new Rect();
                boolean hasInsets = mBackground.getLayoutInsets(insetRect);
                mLayoutInsets = hasInsets ? Insets.of(insetRect) : Insets.NONE;
            }
            mLayoutInsets = (mBackground == null) ? Insets.NONE : mBackground.getLayoutInsets();
        }
        return mLayoutInsets;
    }
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class Insets {
     * @return an Insets instance with the appropriate values
     */
    public static Insets of(Rect r) {
        return of(r.left, r.top, r.right, r.bottom);
        return (r == null) ? NONE : of(r.left, r.top, r.right, r.bottom);
    }

    /**
+4 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.graphics.drawable;

import android.graphics.Insets;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -706,16 +707,12 @@ public abstract class Drawable {

    /**
     * Return in insets the layout insets suggested by this Drawable for use with alignment
     * operations during layout. Positive values move toward the
     * center of the Drawable. Returns true if this drawable
     * actually has a layout insets, else false. When false is returned, the padding
     * is always set to 0.
     * operations during layout.
     *
     * @hide
     */
    public boolean getLayoutInsets(Rect insets) {
        insets.set(0, 0, 0, 0);
        return false;
    public Insets getLayoutInsets() {
        return Insets.NONE;
    }

    /**
+3 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.graphics.drawable;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.SystemClock;
@@ -94,12 +95,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
     * @hide
     */
    @Override
    public boolean getLayoutInsets(Rect insets) {
        if (mCurrDrawable != null) {
            return mCurrDrawable.getLayoutInsets(insets);
        } else {
            return super.getLayoutInsets(insets);
        }
    public Insets getLayoutInsets() {
        return (mCurrDrawable == null) ? Insets.NONE : mCurrDrawable.getLayoutInsets();
    }

    @Override
+5 −9
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Insets;
import android.graphics.NinePatch;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@@ -224,13 +225,8 @@ public class NinePatchDrawable extends Drawable {
     * @hide
     */
    @Override
    public boolean getLayoutInsets(Rect insets) {
        Rect layoutInsets = mNinePatchState.mLayoutInsets;
        if (layoutInsets == null) {
            return super.getLayoutInsets(insets);
        }
        insets.set(layoutInsets);
        return true;
    public Insets getLayoutInsets() {
        return mNinePatchState.mLayoutInsets;
    }

    @Override
@@ -390,7 +386,7 @@ public class NinePatchDrawable extends Drawable {
    private final static class NinePatchState extends ConstantState {
        final NinePatch mNinePatch;
        final Rect mPadding;
        final Rect mLayoutInsets;
        final Insets mLayoutInsets;
        final boolean mDither;
        int mChangingConfigurations;
        int mTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
@@ -406,7 +402,7 @@ public class NinePatchDrawable extends Drawable {
        NinePatchState(NinePatch ninePatch, Rect rect, Rect layoutInsets, boolean dither) {
            mNinePatch = ninePatch;
            mPadding = rect;
            mLayoutInsets = layoutInsets;
            mLayoutInsets = Insets.of(layoutInsets);
            mDither = dither;
        }

Loading