2016-03-12 08:22:40 -05:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
|
|
|
import android.content.res.Resources
|
|
|
|
import android.graphics.drawable.Drawable
|
2016-09-29 13:53:59 -04:00
|
|
|
import android.support.annotation.AttrRes
|
2016-03-12 08:22:40 -05:00
|
|
|
import android.support.annotation.StringRes
|
|
|
|
|
2016-09-29 13:53:59 -04:00
|
|
|
fun Resources.Theme.getResourceColor(@StringRes resource: Int): Int {
|
|
|
|
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
2016-03-12 08:22:40 -05:00
|
|
|
val attrValue = typedArray.getColor(0, 0)
|
|
|
|
typedArray.recycle()
|
|
|
|
return attrValue
|
|
|
|
}
|
|
|
|
|
2016-09-29 13:53:59 -04:00
|
|
|
fun Resources.Theme.getResourceDrawable(@StringRes resource: Int): Drawable {
|
|
|
|
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
2016-03-12 08:22:40 -05:00
|
|
|
val attrValue = typedArray.getDrawable(0)
|
|
|
|
typedArray.recycle()
|
|
|
|
return attrValue
|
2016-09-29 13:53:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fun Resources.Theme.getResourceId(@AttrRes resource: Int, fallback: Int): Int {
|
|
|
|
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
|
|
|
val attrValue = typedArray.getResourceId(0, fallback)
|
|
|
|
typedArray.recycle()
|
|
|
|
return attrValue
|
2016-03-12 08:22:40 -05:00
|
|
|
}
|