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

Commit 72146433 authored by Alan Viverette's avatar Alan Viverette
Browse files

Deprecate DrawableStateList.getChildren() and add getChild().

Moves from exposing the internal structure of a drawable state list
to only exposing the data. Adds getCapacity() and mutate() as
package-private APIs to support various drawable subclasses.

Change-Id: Id08743f979287e1a305f069ccc3c0085a7da6f7b
parent 83ad439c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9858,7 +9858,9 @@ package android.graphics.drawable {
    method public final int addChild(android.graphics.drawable.Drawable);
    method public synchronized boolean canConstantState();
    method protected void computeConstantSize();
    method public final int getCapacity();
    method public int getChangingConfigurations();
    method public final android.graphics.drawable.Drawable getChild(int);
    method public final int getChildCount();
    method public final android.graphics.drawable.Drawable[] getChildren();
    method public final int getConstantHeight();
@@ -9872,6 +9874,7 @@ package android.graphics.drawable {
    method public void growArray(int, int);
    method public final boolean isConstantSize();
    method public final boolean isStateful();
    method public final void mutate();
    method public final void setConstantSize(boolean);
    method public final void setEnterFadeDuration(int);
    method public final void setExitFadeDuration(int);
+2 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
     * @return The Drawable at the specified frame index
     */
    public Drawable getFrame(int index) {
        return mAnimationState.getChildren()[index];
        return mAnimationState.getChild(index);
    }
    
    /**
@@ -322,7 +322,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
                mDurations = orig.mDurations;
                mOneShot = orig.mOneShot;
            } else {
                mDurations = new int[getChildren().length];
                mDurations = new int[getCapacity()];
                mOneShot = true;
            }
        }
+23 −5
Original line number Diff line number Diff line
@@ -250,18 +250,21 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
        return mCurrDrawable != null ? mCurrDrawable.getMinimumHeight() : 0;
    }

    @Override
    public void invalidateDrawable(Drawable who) {
        if (who == mCurrDrawable && getCallback() != null) {
            getCallback().invalidateDrawable(this);
        }
    }

    @Override
    public void scheduleDrawable(Drawable who, Runnable what, long when) {
        if (who == mCurrDrawable && getCallback() != null) {
            getCallback().scheduleDrawable(this, what, when);
        }
    }

    @Override
    public void unscheduleDrawable(Drawable who, Runnable what) {
        if (who == mCurrDrawable && getCallback() != null) {
            getCallback().unscheduleDrawable(this, what);
@@ -415,11 +418,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
    @Override
    public Drawable mutate() {
        if (!mMutated && super.mutate() == this) {
            final int N = mDrawableContainerState.getChildCount();
            final Drawable[] drawables = mDrawableContainerState.getChildren();
            for (int i = 0; i < N; i++) {
                if (drawables[i] != null) drawables[i].mutate();
            }
            mDrawableContainerState.mutate();
            mMutated = true;
        }
        return this;
@@ -544,14 +543,33 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
            return pos;
        }

        final int getCapacity() {
            return mDrawables.length;
        }

        public final int getChildCount() {
            return mNumChildren;
        }

        /*
         * @deprecated Use {@link #getChild} instead.
         */
        public final Drawable[] getChildren() {
            return mDrawables;
        }

        public final Drawable getChild(int index) {
            return mDrawables[index];
        }

        final void mutate() {
            final int N = getChildCount();
            final Drawable[] drawables = mDrawables;
            for (int i = 0; i < N; i++) {
                if (drawables[i] != null) drawables[i].mutate();
            }
        }

        /** A boolean value indicating whether to use the maximum padding value of 
          * all frames in the set (false), or to use the padding value of the frame 
          * being shown (true). Default value is false. 
+2 −2
Original line number Diff line number Diff line
@@ -164,8 +164,8 @@ public class LevelListDrawable extends DrawableContainer {
                mLows = orig.mLows;
                mHighs = orig.mHighs;
            } else {
                mLows = new int[getChildren().length];
                mHighs = new int[getChildren().length];
                mLows = new int[getCapacity()];
                mHighs = new int[getCapacity()];
            }
        }

+3 −3
Original line number Diff line number Diff line
@@ -228,7 +228,7 @@ public class StateListDrawable extends DrawableContainer {
     * @see #getStateSet(int)
     */
    public Drawable getStateDrawable(int index) {
        return mStateListState.getChildren()[index];
        return mStateListState.getChild(index);
    }
    
    /**
@@ -278,9 +278,9 @@ public class StateListDrawable extends DrawableContainer {
            super(orig, owner, res);

            if (orig != null) {
                mStateSets = orig.mStateSets;
                mStateSets = Arrays.copyOf(orig.mStateSets, orig.mStateSets.length);
            } else {
                mStateSets = new int[getChildren().length][];
                mStateSets = new int[getCapacity()][];
            }
        }