From a38665d2ca2d13beb6f8b43dc6e3fe2de97a5d4e Mon Sep 17 00:00:00 2001 From: chr56 Date: Mon, 3 Apr 2023 19:21:15 +0800 Subject: [PATCH] [Theme] support to use Monet colors automatically --- .../java/lib/phonograph/activity/ThemeActivity.kt | 11 +++++++++++ app/src/main/java/player/phonograph/App.kt | 5 +++++ .../player/phonograph/util/PhonographColorUtil.kt | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/app/src/main/java/lib/phonograph/activity/ThemeActivity.kt b/app/src/main/java/lib/phonograph/activity/ThemeActivity.kt index 582ff890a..ead7e4e3a 100644 --- a/app/src/main/java/lib/phonograph/activity/ThemeActivity.kt +++ b/app/src/main/java/lib/phonograph/activity/ThemeActivity.kt @@ -13,10 +13,12 @@ import mt.util.color.darkenColor import mt.util.color.primaryTextColor import mt.util.color.secondaryTextColor import player.phonograph.R +import player.phonograph.util.PhonographColorUtil.applyMonet import player.phonograph.util.PhonographColorUtil.nightMode import player.phonograph.util.preferences.StyleConfig import androidx.appcompat.app.AppCompatDelegate import android.animation.ValueAnimator +import android.content.res.Configuration import android.os.Bundle import android.os.Handler import android.os.Looper @@ -178,4 +180,13 @@ abstract class ThemeActivity : MultiLanguageActivity() { colorChangeAnimator?.cancel() colorChangeAnimator = null } + + // + // Material You Dynamic COlor + // + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + // Theme + applyMonet(this) + } } diff --git a/app/src/main/java/player/phonograph/App.kt b/app/src/main/java/player/phonograph/App.kt index 84f6ec288..8368c6a28 100644 --- a/app/src/main/java/player/phonograph/App.kt +++ b/app/src/main/java/player/phonograph/App.kt @@ -12,6 +12,7 @@ import player.phonograph.notification.ErrorNotification import player.phonograph.notification.ErrorNotification.KEY_STACK_TRACE import player.phonograph.service.queue.QueueManager import player.phonograph.ui.activities.CrashActivity +import player.phonograph.util.PhonographColorUtil.applyMonet import android.app.Application import android.content.Context import android.content.Intent @@ -57,6 +58,8 @@ class App : Application(), ImageLoaderFactory { super.onConfigurationChanged( ContextLocaleDelegate.onConfigurationChanged(this, newConfig) ) + // Theme + applyMonet(this) } override fun onCreate() { @@ -91,6 +94,8 @@ class App : Application(), ImageLoaderFactory { .commit() } + applyMonet(this) + // Set up dynamic shortcuts if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { DynamicShortcutManager(this).initDynamicShortcuts() diff --git a/app/src/main/java/player/phonograph/util/PhonographColorUtil.kt b/app/src/main/java/player/phonograph/util/PhonographColorUtil.kt index c8fa2f8e1..d84f41df0 100644 --- a/app/src/main/java/player/phonograph/util/PhonographColorUtil.kt +++ b/app/src/main/java/player/phonograph/util/PhonographColorUtil.kt @@ -1,5 +1,6 @@ package player.phonograph.util +import mt.pref.ThemeColor import android.content.Context import android.content.res.Configuration import android.content.res.Resources @@ -12,7 +13,9 @@ import mt.util.color.isColorLight import mt.util.color.lightenColor import player.phonograph.App import player.phonograph.R +import player.phonograph.settings.Setting import player.phonograph.util.preferences.StyleConfig +import android.os.Build import java.util.* @@ -51,6 +54,18 @@ object PhonographColorUtil { theme ) + /** + * adjust color settings from Dynamic Color of Material You if available + */ + fun applyMonet(context: Context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && Setting.instance.enableMonet) { + ThemeColor.editTheme(context) + .primaryColor(context.getColor(android.R.color.system_accent1_300)) + .accentColor(context.getColor(android.R.color.system_accent1_600)) + .commit() + } + } + @JvmStatic @ColorInt fun shiftBackgroundColorForLightText(@ColorInt backgroundColor: Int): Int {