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

Commit e2112310 authored by Aurimas Liutikas's avatar Aurimas Liutikas
Browse files

Update View#getAttributeResolutionStack to take @AttrRes

getAttributeResolutionStack was not enough for cases where View
subclasses called obtainstyledattributes with different defStyle values.

Bug: 111439551
Test: updated CTS tests
Change-Id: I81403bdfd5e6f6b34ce34824689d0cef9c32ae44
parent 26ebfe89
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -50792,7 +50792,7 @@ package android.view {
    method @android.view.ViewDebug.ExportedProperty(category="drawing") public float getAlpha();
    method public android.view.animation.Animation getAnimation();
    method public android.os.IBinder getApplicationWindowToken();
    method @NonNull public java.util.List<java.lang.Integer> getAttributeResolutionStack();
    method @NonNull public java.util.List<java.lang.Integer> getAttributeResolutionStack(@AttrRes int);
    method @NonNull public java.util.Map<java.lang.Integer,java.lang.Integer> getAttributeSourceResourceMap();
    method @android.view.ViewDebug.ExportedProperty @Nullable public String[] getAutofillHints();
    method public final android.view.autofill.AutofillId getAutofillId();
+16 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static java.lang.Math.max;
import android.animation.AnimatorInflater;
import android.animation.StateListAnimator;
import android.annotation.AttrRes;
import android.annotation.CallSuper;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
@@ -5108,7 +5109,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private SparseIntArray mAttributeSourceResId;
    @Nullable
    private int[] mAttributeResolutionStack;
    private SparseArray<int[]> mAttributeResolutionStacks;
    @StyleRes
    private int mExplicitStyle;
@@ -5963,11 +5964,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * <b>Note:</b> this method will only return actual values if the view attribute debugging
     * is enabled in Android developer options.
     *
     * @param attribute Attribute resource ID for which the resolution stack should be returned.
     * @return ordered list of resource ID that are considered when resolving attribute values for
     * this {@link View}.
     */
    @NonNull
    public List<Integer> getAttributeResolutionStack() {
    public List<Integer> getAttributeResolutionStack(@AttrRes int attribute) {
        ArrayList<Integer> stack = new ArrayList<>();
        if (!sDebugViewAttributes) {
            return stack;
@@ -5975,8 +5977,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (mSourceLayoutId != ID_NULL) {
            stack.add(mSourceLayoutId);
        }
        for (int i = 0; i < mAttributeResolutionStack.length; i++) {
            stack.add(mAttributeResolutionStack[i]);
        int[] attributeResolutionStack = mAttributeResolutionStacks.get(attribute);
        if (attributeResolutionStack == null) {
            return stack;
        }
        for (int i = 0; i < attributeResolutionStack.length; i++) {
            stack.add(attributeResolutionStack[i]);
        }
        return stack;
    }
@@ -6143,9 +6149,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            return;
        }
        mAttributeResolutionStack = context.getTheme().getAttributeResolutionStack(
        int[] attributeResolutionStack = context.getTheme().getAttributeResolutionStack(
                defStyleAttr, defStyleRes, mExplicitStyle);
        if (mAttributeResolutionStacks == null) {
            mAttributeResolutionStacks = new SparseArray<>();
        }
        if (mAttributeSourceResId == null) {
            mAttributeSourceResId = new SparseIntArray();
        }
@@ -6154,6 +6164,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        for (int j = 0; j < indexCount; ++j) {
            final int index = t.getIndex(j);
            mAttributeSourceResId.append(styleable[index], t.getSourceResourceId(index, 0));
            mAttributeResolutionStacks.append(styleable[index], attributeResolutionStack);
        }
    }