Skip to content

Commit

Permalink
Add dynamic colors setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Dec 27, 2023
1 parent 57cd3e7 commit 8e90675
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.kylecorry.trail_sense.settings.ui

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.google.android.material.color.DynamicColors
import com.google.android.material.color.DynamicColorsOptions
import com.google.android.material.color.HarmonizedColors
import com.kylecorry.andromeda.core.system.Intents
import com.kylecorry.andromeda.core.system.Package
import com.kylecorry.andromeda.core.system.Resources
Expand Down Expand Up @@ -46,7 +50,6 @@ class SettingsFragment : AndromedaPreferenceFragment() {
R.string.pref_diagnostics to R.id.action_settings_to_diagnostics
)

private val cache by lazy { PreferencesSubsystem.getInstance(requireContext()).preferences }
private val uriPicker by lazy { ActivityUriPicker(requireMainActivity()) }
private val backupCommand by lazy { BackupCommand(requireContext(), uriPicker) }
private val restoreCommand by lazy { RestoreCommand(requireContext(), uriPicker) }
Expand Down Expand Up @@ -82,6 +85,10 @@ class SettingsFragment : AndromedaPreferenceFragment() {
startActivity(Intent.createChooser(intent, it.title.toString()))
}

val dynamicColorsSwitch = switch(R.string.pref_use_dynamic_colors)
dynamicColorsSwitch?.isVisible = DynamicColors.isDynamicColorAvailable()
reloadThemeOnChange(dynamicColorsSwitch)

val version = Package.getVersionName(requireContext())
preference(R.string.pref_app_version)?.summary = version
setIconColor(preferenceScreen, Resources.androidTextColorSecondary(requireContext()))
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/palette.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- drawable/palette.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M17.5,12A1.5,1.5 0 0,1 16,10.5A1.5,1.5 0 0,1 17.5,9A1.5,1.5 0 0,1 19,10.5A1.5,1.5 0 0,1 17.5,12M14.5,8A1.5,1.5 0 0,1 13,6.5A1.5,1.5 0 0,1 14.5,5A1.5,1.5 0 0,1 16,6.5A1.5,1.5 0 0,1 14.5,8M9.5,8A1.5,1.5 0 0,1 8,6.5A1.5,1.5 0 0,1 9.5,5A1.5,1.5 0 0,1 11,6.5A1.5,1.5 0 0,1 9.5,8M6.5,12A1.5,1.5 0 0,1 5,10.5A1.5,1.5 0 0,1 6.5,9A1.5,1.5 0 0,1 8,10.5A1.5,1.5 0 0,1 6.5,12M12,3A9,9 0 0,0 3,12A9,9 0 0,0 12,21A1.5,1.5 0 0,0 13.5,19.5C13.5,19.11 13.35,18.76 13.11,18.5C12.88,18.23 12.73,17.88 12.73,17.5A1.5,1.5 0 0,1 14.23,16H16A5,5 0 0,0 21,11C21,6.58 16.97,3 12,3Z" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@
<string name="clinometer_augmented_reality">Clinometer augmented reality</string>
<string name="clinometer_augmented_reality_description">Visualize angles with your camera</string>
<string name="pref_use_dynamic_colors" translatable="false">pref_use_dynamic_colors</string>
<string name="dynamic_colors">Dynamic Colors</string>
<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
app:singleLineTitle="false"
app:title="@string/pref_theme_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:icon="@drawable/palette"
app:key="@string/pref_use_dynamic_colors"
app:singleLineTitle="false"
app:title="@string/dynamic_colors" />
<Preference
app:icon="@drawable/ic_tool_battery"
app:key="@string/pref_power_settings"
Expand Down

0 comments on commit 8e90675

Please sign in to comment.