removed light theme; added dynamic theme (cf. #75)

This commit is contained in:
Josia Pietsch 2024-12-06 00:27:26 +01:00
parent 06777a4d34
commit 3c59ad4c41
Signed by: jrpie
GPG key ID: E70B571D66986A2D
6 changed files with 63 additions and 6 deletions

View file

@ -19,6 +19,9 @@ class Application : android.app.Application() {
override fun onCreate() {
super.onCreate()
// TODO Error: Invalid resource ID 0x00000000.
// DynamicColors.applyToActivitiesIfAvailable(this)
if (Build.VERSION.SDK_INT >= VERSION_CODES.M) {
torchManager = TorchManager(this)

View file

@ -1,20 +1,49 @@
package de.jrpie.android.launcher.preferences.theme
import android.content.Context
import android.content.res.Resources
import de.jrpie.android.launcher.R
import com.google.android.material.color.DynamicColors
@Suppress("unused")
enum class ColorTheme(private val id: Int, private val shadowId: Int) {
DEFAULT(R.style.colorThemeDefault, R.style.textShadow),
DARK(R.style.colorThemeDark, R.style.textShadow),
LIGHT(R.style.colorThemeLight, R.style.textShadowLight),
enum class ColorTheme(
private val id: Int,
private val labelResource: Int,
private val shadowId: Int,
val isAvailable: () -> Boolean
) {
DEFAULT(
R.style.colorThemeDefault,
R.string.settings_theme_color_theme_item_default,
R.style.textShadow,
{ true }),
DARK(
R.style.colorThemeDark,
R.string.settings_theme_color_theme_item_dark,
R.style.textShadow,
{ true }),
LIGHT(
R.style.colorThemeLight,
R.string.settings_theme_color_theme_item_light,
R.style.textShadowLight,
{ false }),
DYNAMIC(
R.style.colorThemeDynamic,
R.string.settings_theme_color_theme_item_dynamic,
R.style.textShadow,
{ DynamicColors.isDynamicColorAvailable() }),
;
fun applyToTheme(theme: Resources.Theme, shadow: Boolean) {
theme.applyStyle(id, true)
val colorTheme = if (this.isAvailable()) this else DEFAULT
theme.applyStyle(colorTheme.id, true)
if (shadow) {
theme.applyStyle(shadowId, true)
theme.applyStyle(colorTheme.shadowId, true)
}
}
fun getLabel(context: Context): String {
return context.getString(labelResource)
}
}

View file

@ -9,6 +9,7 @@ import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.actions.lock.LockMethod
import de.jrpie.android.launcher.actions.openAppsList
import de.jrpie.android.launcher.preferences.LauncherPreferences
import de.jrpie.android.launcher.preferences.theme.ColorTheme
import de.jrpie.android.launcher.setDefaultHomeScreen
@ -86,6 +87,16 @@ class SettingsFragmentLauncher : PreferenceFragmentCompat() {
true
}
findPreference<androidx.preference.DropDownPreference>(
LauncherPreferences.theme().keys().colorTheme()
)?.apply {
entries = ColorTheme.entries.filter { x -> x.isAvailable() }
.map { x -> x.getLabel(requireContext()) }.toTypedArray()
entryValues = ColorTheme.entries.filter { x -> x.isAvailable() }
.map { x -> x.name }.toTypedArray()
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
lockMethod?.isVisible = false
}

View file

@ -66,11 +66,13 @@
<item>DEFAULT</item>
<item>DARK</item>
<item>LIGHT</item>
<item>DYNAMIC</item>
</string-array>
<string-array name="settings_theme_color_theme_items" translatable="false">
<item>@string/settings_theme_color_theme_item_default</item>
<item>@string/settings_theme_color_theme_item_dark</item>
<item>@string/settings_theme_color_theme_item_light</item>
<item>@string/settings_theme_color_theme_item_dynamic</item>
</string-array>
<string name="settings_theme_text_shadow_key" translatable="false">theme.text_shadow</string>

View file

@ -90,6 +90,7 @@
<string name="settings_theme_color_theme_item_default">Default</string>
<string name="settings_theme_color_theme_item_dark">Dark</string>
<string name="settings_theme_color_theme_item_light">Light</string>
<string name="settings_theme_color_theme_item_dynamic">Dynamic</string>
<string name="settings_theme_text_shadow">Text shadow</string>
<string name="settings_theme_background">Background (app list and setting)</string>

View file

@ -51,6 +51,15 @@
<item name="android:textColor">@color/lightTheme_text_color</item>
</style>
<style name="colorThemeDynamic">
<!--parent="Theme.Material3.Dark.NoActionBar"-->
<item name="colorPrimary">@color/material_dynamic_primary70</item>
<item name="colorPrimaryDark">@color/material_dynamic_primary50</item>
<item name="colorAccent">@color/material_dynamic_tertiary50</item>
<item name="android:colorBackground">@color/material_dynamic_neutral10</item>
<item name="android:textColor">@color/material_dynamic_neutral_variant90</item>
</style>
<style name="textShadow">
<item name="android:shadowColor">#000</item>
<item name="android:shadowDx">0</item>
@ -118,6 +127,8 @@
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">#000000</item>
<item name="android:background">#ffffff</item>
<item name="android:color">#000000</item>
</style>
<!-- Set the fade in animation on all activities by default -->