Fixed
Status Update
Comments
al...@android.com <al...@android.com>
ch...@google.com <ch...@google.com>
al...@android.com <al...@android.com> #2
We are currently using AGP internal task types to flag memory-intensive tasks to enforce a reduced parallelism at execution time. I've raised this separately (with a lot more detail) as a feature request (
Description
Version used: 24.0.0
Context.obtainStyledAttributes is very picky with its "int[] attrs" parameter, if the numbers inside are unsorted, it will fail to find all attributes. This is usually not an issue as R.styleable.* is automatically sorted on generation of R.java, but if you call with a custom or dynamic array, you must ensure that the values passed in are sorted.
android.support.v7.widget.AppCompatTextHelper declares on line 38
private static final int[] VIEW_ATTRS = {
android.R.attr.textAppearance, // 0x01010034
android.R.attr.drawableLeft, // 0x0101016f
android.R.attr.drawableTop, // 0x0101016d
android.R.attr.drawableRight, // 0x01010170
android.R.attr.drawableBottom // 0x0101016e
};
and uses it on line 62 with
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, VIEW_ATTRS, defStyleAttr, 0);
This will *not* work correctly. The resulting TypedArray will have missing items! Context.obtainStyledAttributes doesn't document this behavior explicitly, but there are tons of threads around the web like
Test case is a single TextView with all four attributes set:
<TextView
android:background="#789abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
android:drawableLeft="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
android:drawableRight="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
android:drawableTop="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
android:text="Hello World" />
This is rendered as missing-tint.png on a LG G4 @ Android M. In a breakpoint on AppCompatTextView:161, inspecting mDrawableLeftTint etc, the top and bottom tint failed to be found and are set to null, left and right are correctly set to a TintInfo object.
The correct rendering would make all 4 copy icons grey (R.attr.colorControlNormal), not leave it white randomly.
Fix request #1:
The correct way add <declare-styleable name="AppCompatTextHelper"> to values.xml and use R.styleable.AppCompatTextHelper instead of that int[]. Please do this to avoid people from pulling out their hair debugging this.
Fix request #2:
Please fix the documentation in Context.obtainStyledAttributes, add a BIG warning that int[] attrs must be sorted or a R.styleable.*.