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

Commit 0cfb877f authored by Alan Viverette's avatar Alan Viverette
Browse files

Simplify attribute extraction for themed Drawables

Also fixes a bug in GlowPadView that randomly popped up.

Change-Id: Id20508a44ea02b4a14c8f794de36e13a2c06587c
parent a6464b38
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -1475,21 +1475,12 @@ public class Resources {
         *               in length to {@code attrs} or {@code null}. All values
         *               must be of type {@link TypedValue#TYPE_ATTRIBUTE}.
         * @param attrs The desired attributes to be retrieved.
         * @param defStyleAttr An attribute in the current theme that contains a
         *                     reference to a style resource that supplies
         *                     defaults values for the TypedArray.  Can be
         *                     0 to not look for defaults.
         * @param defStyleRes A resource identifier of a style resource that
         *                    supplies default values for the TypedArray,
         *                    used only if defStyleAttr is 0 or can not be found
         *                    in the theme.  Can be 0 to not look for defaults.
         * @return Returns a TypedArray holding an array of the attribute
         *         values. Be sure to call {@link TypedArray#recycle()}
         *         when done with it.
         * @hide
         */
        public TypedArray resolveAttributes(int[] values, int[] attrs,
                int defStyleAttr, int defStyleRes) {
        public TypedArray resolveAttributes(int[] values, int[] attrs) {
            final int len = attrs.length;
            if (values != null && len != values.length) {
                throw new IllegalArgumentException(
@@ -1497,8 +1488,7 @@ public class Resources {
            }

            final TypedArray array = TypedArray.obtain(Resources.this, len);
            AssetManager.resolveAttrs(mTheme, defStyleAttr, defStyleRes,
                    values, attrs, array.mData, array.mIndices);
            AssetManager.resolveAttrs(mTheme, 0, 0, values, attrs, array.mData, array.mIndices);
            array.mTheme = this;
            array.mXml = null;

+23 −11
Original line number Diff line number Diff line
@@ -885,13 +885,13 @@ public class TypedArray {

    /**
     * Extracts theme attributes from a typed array for later resolution using
     * {@link Theme#resolveAttributes(int[], int[], int, int)}.
     * {@link Theme#resolveAttributes(int[], int[])}. Removes the entries from
     * the typed array so that subsequent calls to typed getters will return the
     * default value without crashing.
     *
     * @param array An array to populate with theme attributes. If the array is
     *            null or not large enough, a new array will be returned.
     * @return an array of length {@link #getIndexCount()} populated with theme
     *         attributes, or null if there are no theme attributes in the
     *         typed array
     *         attributes, or null if there are no theme attributes in the typed
     *         array
     * @hide
     */
    public int[] extractThemeAttrs() {
@@ -901,15 +901,27 @@ public class TypedArray {

        int[] attrs = null;

        final int[] data = mData;
        final int N = length();
        for (int i = 0; i < N; i++) {
            final int attrId = getThemeAttributeId(i, 0);
            if (attrId != 0) {
            final int index = i * AssetManager.STYLE_NUM_ENTRIES;
            if (data[index + AssetManager.STYLE_TYPE] != TypedValue.TYPE_ATTRIBUTE) {
                continue;
            }

            // Null the entry so that we can safely call getZzz().
            data[index + AssetManager.STYLE_TYPE] = TypedValue.TYPE_NULL;

            final int attr = data[index + AssetManager.STYLE_DATA];
            if (attr == 0) {
                // This attribute is useless!
                continue;
            }

            if (attrs == null) {
                attrs = new int[N];
            }
                attrs[i] = attrId;
            }
            attrs[i] = attr;
        }

        return attrs;
+4 −4
Original line number Diff line number Diff line
@@ -238,6 +238,10 @@ public class GlowPadView extends View {
        Drawable pointDrawable = pointId != 0 ? context.getDrawable(pointId) : null;
        mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

        mPointCloud = new PointCloud(pointDrawable);
        mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
        mPointCloud.glowManager.setRadius(mGlowRadius);

        TypedValue outValue = new TypedValue();

        // Read array of target drawables
@@ -273,10 +277,6 @@ public class GlowPadView extends View {
        setVibrateEnabled(mVibrationDuration > 0);

        assignDefaultsIfNeeded();

        mPointCloud = new PointCloud(pointDrawable);
        mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
        mPointCloud.glowManager.setRadius(mGlowRadius);
    }

    private int getResourceId(TypedArray a, int id) {
+119 −229

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -199,7 +199,7 @@ public class ColorDrawable extends Drawable {

        final int[] themeAttrs = state.mThemeAttrs;
        if (themeAttrs != null) {
            final TypedArray a = t.resolveAttributes(themeAttrs, R.styleable.ColorDrawable, 0, 0);
            final TypedArray a = t.resolveAttributes(themeAttrs, R.styleable.ColorDrawable);
            updateStateFromTypedArray(a);
            a.recycle();
        }
Loading