package com.example.base.extensions

import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.OvalShape


/**
 * 返回圆形 drawable
 * *
 * @return
 */
fun Int.createOvalDrawable(): ShapeDrawable {

    val drawable = ShapeDrawable(OvalShape())
    drawable.paint.color = this

    return drawable
}

fun Int.isLightColor(): Boolean {
    val r = 0.299 * Color.red(this)
    val g = 0.587 * Color.green(this)
    val b = 0.114 * Color.blue(this)
    val darkness = 1 - (r + g + b) / 255
    return darkness < 0.4
}

fun Int.toColorStateList(): ColorStateList {
    val states = arrayOfNulls<IntArray>(2)
    states[0] = intArrayOf()
    states[1] = intArrayOf()

    val colors = intArrayOf(this, this)
    return ColorStateList(states, colors)
}
