miha-x64
11/02/2019, 11:06 PM.withStyledAttributes(attr) { getResourceId(it, 0) }
. Should I create a PR? None of the files below look suitable, should I create a new one?
https://github.com/LouisCAD/Splitties/tree/8782cbb5d039a553ed2c5cf795eb53a86146ce91/modules/resources/src/androidMain/kotlin/splitties/resourceslouiscad
11/04/2019, 7:59 AMdevelop
branch and submit a PR.miha-x64
11/04/2019, 11:56 AMresolveThemeAttribute
seems to be what I need.getIndex
necessary here? https://github.com/LouisCAD/Splitties/blob/develop/modules/resources/src/androidMain/kotlin/splitties/resources/StyledAttributes.kt#L50louiscad
11/06/2019, 8:09 AMmiha-x64
11/06/2019, 9:13 AMTypedArray.get*
accepts a @StyleableRes
while styleable res values like R.styleable.ViewClass_attrName
are just a 0-based int indices.int[] attrs { a, b, c }
, obtainStyledAttrubites
will return a TypedArray
which is effectively a SparseIntArray
from attrs.indices
to values. It is 'sparse' when some attributes are not specified and there's index-to-value-mapping.
Hence, there are to way to read styled attributes:
// get values specifying default ones for absent attributes
ta = obtain([a, b, c])
this.a = ta.get*(0, default);
this.b = ta.get*(1, default);
this.c = ta.get*(2, default);
and
// get values only for present attributes
for (i in 0..ta.indexCount) {
idx = ta.getIndex(i)
when (idx) {
0 -> this.a = ta.get*(0, whatever)
1 -> this.b = ta.get*(1, dontMind)
2 -> this.c = ta.get*(2, unused)
}
}