package cn.muchinfo.rma.view.autoWidget

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.view.View
import cn.muchinfo.rma.R
import com.qmuiteam.qmui.util.QMUIResHelper



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

fun createSelectStateColor(normal: String, selectedColor: String): ColorStateList = createSelectStateColor(Color.parseColor(normal), Color.parseColor(selectedColor))
fun createSelectStateColor(normal: Int, selectedColor: Int): ColorStateList {
    return ColorStateList(
            arrayOf(intArrayOf(android.R.attr.state_selected), intArrayOf()),
            intArrayOf(selectedColor, normal)
    )
}

fun View.getColorPrimary(): Int = context.getColorPrimary()
fun Context.getColorPrimary(): Int = QMUIResHelper.getAttrColor(this, R.attr.colorPrimary)
fun Context.getColorPrimaryDark(): Int = QMUIResHelper.getAttrColor(this, R.attr.colorPrimaryDark)