PlayerAndroid/appthemehelper/src/main/java/code/name/monkey/appthemehelper/ATH.kt

104 lines
3.4 KiB
Kotlin
Raw Normal View History

2018-12-26 03:29:12 +00:00
package code.name.monkey.appthemehelper
import android.app.Activity
import android.app.ActivityManager
import android.content.Context
import android.graphics.Color
2018-12-26 03:29:12 +00:00
import android.os.Build
import android.view.View
import androidx.annotation.ColorInt
import androidx.appcompat.widget.Toolbar
import androidx.core.view.WindowInsetsControllerCompat
2018-12-26 03:29:12 +00:00
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object ATH {
fun didThemeValuesChange(context: Context, since: Long): Boolean {
2020-02-22 12:10:12 +00:00
return ThemeStore.isConfigured(context) && ThemeStore.prefs(context).getLong(
ThemeStorePrefKeys.VALUES_CHANGED,
-1
) > since
2018-12-26 03:29:12 +00:00
}
fun setLightStatusBar(activity: Activity, enabled: Boolean) {
activity.window.apply {
WindowInsetsControllerCompat(
this,
decorView
).isAppearanceLightStatusBars = enabled
2018-12-26 03:29:12 +00:00
}
}
fun setLightNavigationbar(activity: Activity, enabled: Boolean) {
activity.window.apply {
WindowInsetsControllerCompat(
this,
decorView
).isAppearanceLightNavigationBars = enabled
navigationBarColor = Color.TRANSPARENT
2018-12-26 03:29:12 +00:00
}
}
fun setLightNavigationBarAuto(activity: Activity, bgColor: Int) {
2018-12-26 03:29:12 +00:00
setLightNavigationbar(activity, ColorUtil.isColorLight(bgColor))
}
fun setNavigationBarColor(activity: Activity, color: Int) {
2018-12-26 03:29:12 +00:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.window.navigationBarColor = color
} else {
activity.window.navigationBarColor = ColorUtil.darkenColor(color)
}
setLightNavigationBarAuto(activity, color)
2018-12-26 03:29:12 +00:00
}
fun setActivityToolbarColorAuto(activity: Activity, toolbar: Toolbar?) {
setActivityToolbarColor(activity, toolbar, ThemeStore.primaryColor(activity))
}
2021-11-27 08:36:49 +00:00
private fun setActivityToolbarColor(
2020-02-22 12:10:12 +00:00
activity: Activity, toolbar: Toolbar?,
color: Int
) {
2018-12-26 03:29:12 +00:00
if (toolbar == null) {
return
}
toolbar.setBackgroundColor(color)
ToolbarContentTintHelper.setToolbarContentColorBasedOnToolbarColor(activity, toolbar, color)
}
fun setTaskDescriptionColorAuto(activity: Activity) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity))
}
fun setTaskDescriptionColor(activity: Activity, @ColorInt color: Int) {
var colorFinal = color
// Task description requires fully opaque color
colorFinal = ColorUtil.stripAlpha(colorFinal)
// Sets color of entry in the system recents page
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
activity.setTaskDescription(
ActivityManager.TaskDescription(
activity.title as String?,
-1,
colorFinal
2020-02-25 14:45:41 +00:00
)
)
} else {
activity.setTaskDescription(ActivityManager.TaskDescription(activity.title as String?))
2018-12-26 03:29:12 +00:00
}
}
fun setTint(view: View, @ColorInt color: Int) {
TintHelper.setTintAuto(view, color, false)
}
fun setBackgroundTint(view: View, @ColorInt color: Int) {
TintHelper.setTintAuto(view, color, true)
}
}