Added ability to extract accent color from wallpaper on 8.1+ devices
This commit is contained in:
parent
09ad243a14
commit
9d1018c03c
16 changed files with 117 additions and 6 deletions
|
@ -59,6 +59,11 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
return this
|
||||
}
|
||||
|
||||
override fun wallpaperColor(color: Int): ThemeStore {
|
||||
mEditor.putInt(ThemeStorePrefKeys.KEY_WALLPAPER_COLOR, color)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun accentColorRes(@ColorRes colorRes: Int): ThemeStore {
|
||||
return accentColor(ContextCompat.getColor(mContext, colorRes))
|
||||
}
|
||||
|
@ -211,16 +216,30 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
return ContextCompat.getColor(context, R.color.m3_accent_color)
|
||||
}
|
||||
val desaturatedColor = prefs(context).getBoolean("desaturated_color", false)
|
||||
val color = prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_ACCENT_COLOR,
|
||||
resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
|
||||
)
|
||||
println(isWallpaperAccentEnabled(context))
|
||||
val color = if (isWallpaperAccentEnabled(context)) {
|
||||
wallpaperColor(context)
|
||||
} else {
|
||||
prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_ACCENT_COLOR,
|
||||
resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
|
||||
)
|
||||
}
|
||||
return if (isWindowBackgroundDark(context) && desaturatedColor) ColorUtil.desaturateColor(
|
||||
color,
|
||||
0.4f
|
||||
) else color
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun wallpaperColor(context: Context): Int {
|
||||
return prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_WALLPAPER_COLOR,
|
||||
resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun navigationBarColor(context: Context): Int {
|
||||
|
@ -307,7 +326,13 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
}
|
||||
|
||||
private fun isMD3Enabled(context: Context): Boolean {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ThemeStorePrefKeys.KEY_MATERIAL_YOU, VersionUtils.hasS())
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(ThemeStorePrefKeys.KEY_MATERIAL_YOU, VersionUtils.hasS())
|
||||
}
|
||||
|
||||
private fun isWallpaperAccentEnabled(context: Context): Boolean {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean("wallpaper_accent", VersionUtils.hasOreoMR1() && !VersionUtils.hasS())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,8 @@ internal interface ThemeStoreInterface {
|
|||
|
||||
fun accentColor(@ColorInt color: Int): ThemeStore
|
||||
|
||||
fun wallpaperColor(@ColorInt color: Int): ThemeStore
|
||||
|
||||
fun accentColorRes(@ColorRes colorRes: Int): ThemeStore
|
||||
|
||||
fun accentColorAttr(@AttrRes colorAttr: Int): ThemeStore
|
||||
|
|
|
@ -29,5 +29,6 @@ internal interface ThemeStorePrefKeys {
|
|||
const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
|
||||
|
||||
const val KEY_MATERIAL_YOU = "material_you"
|
||||
const val KEY_WALLPAPER_COLOR = "wallpaper_color"
|
||||
}
|
||||
}
|
|
@ -35,6 +35,13 @@ object VersionUtils {
|
|||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if device is running API >= 27
|
||||
*/
|
||||
fun hasOreoMR1(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if device is running API >= 28
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue