Added destauration accent color
This commit is contained in:
parent
694e78e92e
commit
576201bfd5
5 changed files with 20 additions and 20 deletions
|
@ -4,14 +4,9 @@ import android.annotation.SuppressLint
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.CheckResult
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.*
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
|
||||
|
@ -211,7 +206,8 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
@CheckResult
|
||||
@ColorInt
|
||||
fun accentColor(context: Context): Int {
|
||||
return prefs(context).getInt(ThemeStorePrefKeys.KEY_ACCENT_COLOR, ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")))
|
||||
val color = prefs(context).getInt(ThemeStorePrefKeys.KEY_ACCENT_COLOR, ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")))
|
||||
return if (ATHUtil.isWindowBackgroundDark(context)) ColorUtil.desaturateColor(color, 0.4f) else color
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
|
|
|
@ -6,7 +6,14 @@ import androidx.annotation.FloatRange
|
|||
|
||||
|
||||
object ColorUtil {
|
||||
fun desaturateColor(color: Int, ratio: Float): Int {
|
||||
val hsv = FloatArray(3)
|
||||
Color.colorToHSV(color, hsv)
|
||||
|
||||
hsv[1] = hsv[1] / 1 * ratio + 0.2f * (1.0f - ratio)
|
||||
|
||||
return Color.HSVToColor(hsv)
|
||||
}
|
||||
fun stripAlpha(@ColorInt color: Int): Int {
|
||||
return -0x1000000 or color
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue