Skip to content

Instantly share code, notes, and snippets.

@DrewCarlson
Created March 30, 2016 18:38
Show Gist options
  • Save DrewCarlson/f7348cab8ab87cae33adb26173e34dc3 to your computer and use it in GitHub Desktop.
Save DrewCarlson/f7348cab8ab87cae33adb26173e34dc3 to your computer and use it in GitHub Desktop.
Drawable extensions for DrawableCompat helpers.
import android.content.res.ColorStateList
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.support.v4.graphics.drawable.DrawableCompat
fun Drawable.getLayoutDirectionCompat(): Int {
return DrawableCompat.getLayoutDirection(this)
}
fun Drawable.isAutoMirrorCompat(): Boolean {
return DrawableCompat.isAutoMirrored(this)
}
fun Drawable.jumpToCurrentStateCompat() {
DrawableCompat.jumpToCurrentState(this)
}
fun Drawable.setAutoMirrorCompat(mirrored: Boolean) {
DrawableCompat.setAutoMirrored(this, mirrored)
}
fun Drawable.setHotspotCompat(x: Float, y: Float) {
DrawableCompat.setHotspot(this, x, y)
}
fun Drawable.setHotspotBoundsCompat(left: Int, top: Int, right: Int, bottom: Int) {
DrawableCompat.setHotspotBounds(this, left, top, right, bottom)
}
fun Drawable.setLayoutDirectionCompat(layoutDirection: Int) {
DrawableCompat.setLayoutDirection(this, layoutDirection)
}
fun Drawable.setTintCompat(color: Int) {
DrawableCompat.setTint(DrawableCompat.wrap(this).mutate(), color)
}
fun Drawable.setTintListCompat(list: ColorStateList) {
DrawableCompat.setTintList(this, list)
}
fun Drawable.setTintMode(tintMode: PorterDuff.Mode) {
DrawableCompat.setTintMode(this, tintMode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment