Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/ktextension/ColorExtensions.kt

15 lines
420 B
Kotlin

package org.mariotaku.ktextension
import android.support.annotation.ColorInt
import java.util.*
/**
* Created by mariotaku on 2017/1/2.
*/
fun toHexColor(@ColorInt color: Int, format: HexColorFormat = HexColorFormat.ARGB) = format.transform(color)
enum class HexColorFormat(val transform: (Int) -> String) {
ARGB({ "#%08X".format(Locale.ROOT, it) }),
RGB({ "#%06X".format(Locale.ROOT, 0xFFFFFF and it) })
}