...
 
Commits (2)
......@@ -73,6 +73,15 @@ fun Context.getDrawableForAttributeId(attributeResourceId: Int): Drawable {
return drawable
}
fun Context.isAttributeSet(attributeResourceId: Int): Boolean {
val defaultValue = 0
val actualValue = getResourceIdForAttributeId(attributeResourceId, defaultValue)
return actualValue != defaultValue
}
fun Context.getResourceIdForAttributeId(attributeResourceId: Int): Int {
return getResourceIdForAttributeId(attributeResourceId, 0)
}
......
......@@ -16,6 +16,15 @@ fun TextView.setTextColorToColorResource(colorResourceId: Int) {
}
}
/**
* If attribute with [attributeResourceId] (a value of R.attrib.xyz) is set, its resolved value is used.
*
* If not, resolved value of [fallbackResourceId] (a value of R.color.xyz or R.drawable.xyz) is used.
*/
fun TextView.setTextColorToAttribute(attributeResourceId: Int, fallbackResourceId: Int) {
this.setTextColorToColorResource(context.getResourceIdForAttributeId(attributeResourceId, fallbackResourceId))
}
fun TextView.setCustomTypeface(context: Context?, typefaceName: String) {
var filename = typefaceName
......
......@@ -109,6 +109,16 @@ fun View.getResourceIdentifier(identifierName: String, resourceType: String): In
}
/**
* If attribute with [attributeResourceId] (a value of R.attrib.xyz) is set, its resolved value is used.
*
* If not, resolved value of [fallbackResourceId] (a value of R.color.xyz or R.drawable.xyz) is used.
*/
fun View.setBackgroundToAttribute(attributeResourceId: Int, fallbackResourceId: Int) {
this.setBackgroundResource(context.getResourceIdForAttributeId(attributeResourceId, fallbackResourceId))
}
fun View.setPadding(paddingTopBottomLeftRight: Int) {
this.setPadding(paddingTopBottomLeftRight, paddingTopBottomLeftRight, paddingTopBottomLeftRight, paddingTopBottomLeftRight)
}
......