diff --git a/src/main/java/de/dennisguse/opentracks/Startup.java b/src/main/java/de/dennisguse/opentracks/Startup.java
index 052b752f0a..a1c1b623d3 100644
--- a/src/main/java/de/dennisguse/opentracks/Startup.java
+++ b/src/main/java/de/dennisguse/opentracks/Startup.java
@@ -7,6 +7,8 @@
import android.os.StrictMode;
import android.util.Log;
+import com.google.android.material.color.DynamicColors;
+
import java.lang.reflect.Method;
import de.dennisguse.opentracks.settings.PreferencesUtils;
@@ -28,6 +30,11 @@ public void onCreate() {
// Include version information into stack traces.
Log.i(TAG, BuildConfig.APPLICATION_ID + "; BuildType: " + BuildConfig.BUILD_TYPE + "; VersionName: " + BuildConfig.VERSION_NAME + "/" + BuildConfig.VERSION_NAME_FULL + " VersionCode: " + BuildConfig.VERSION_CODE);
+ // In debug builds: show thread and VM warnings.
+ if (BuildConfig.DEBUG) {
+ Log.d(TAG, "Enabling strict mode");
+ StrictMode.enableDefaults();
+ }
PreferencesUtils.initPreferences(this, getResources());
// Set default values of preferences on first start.
@@ -35,11 +42,8 @@ public void onCreate() {
PreferencesUtils.applyDefaultUnit();
PreferencesUtils.applyNightMode();
-
- // In debug builds: show thread and VM warnings.
- if (BuildConfig.DEBUG) {
- Log.d(TAG, "Enabling strict mode");
- StrictMode.enableDefaults();
+ if (PreferencesUtils.shouldUseDynamicColors()) {
+ DynamicColors.applyToActivitiesIfAvailable(this);
}
}
diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java
index 9c40c4805a..6f5c5affbe 100644
--- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java
+++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java
@@ -307,6 +307,11 @@ public static boolean shouldUseFullscreen() {
return getBoolean(R.string.stats_fullscreen_while_recording_key, DEFAULT);
}
+ public static boolean shouldUseDynamicColors() {
+ final boolean DEFAULT = resources.getBoolean(R.bool.settings_ui_dynamic_colors_default);
+ return getBoolean(R.string.settings_ui_dynamic_colors_key, DEFAULT);
+ }
+
public static boolean shouldVoiceAnnouncementOnDeviceSpeaker() {
final boolean DEFAULT = resources.getBoolean(R.bool.voice_on_device_speaker_default);
return getBoolean(R.string.voice_on_device_speaker_key, DEFAULT);
diff --git a/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java
index 1a6e4ae69a..ca122b43d0 100644
--- a/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java
+++ b/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java
@@ -2,6 +2,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
@@ -34,6 +35,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
return true;
});
+ Preference dynamicColors = findPreference(getString(R.string.settings_ui_dynamic_colors_key));
+ dynamicColors.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU);
+
setShowOnMapFormatOptions();
}
diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml
index 16a6c40423..f66ad622a1 100644
--- a/src/main/res/values/settings.xml
+++ b/src/main/res/values/settings.xml
@@ -271,6 +271,9 @@
showIntroduction
true
+ uiDynamicColors
+ false
+
nightMode
@string/night_mode_system_value
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 2d2e01645f..81cae2f320 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -374,6 +374,8 @@ limitations under the License.
By time
Recording
+ Dynamic Colors
+ Use user-defined Dynamic Colors (requires Android 12+)
Customize your recording layout
Data fields per row
Show statistics on lockscreen
diff --git a/src/main/res/xml/settings_user_interface.xml b/src/main/res/xml/settings_user_interface.xml
index 080e8f8ed0..8c34c1c11f 100644
--- a/src/main/res/xml/settings_user_interface.xml
+++ b/src/main/res/xml/settings_user_interface.xml
@@ -12,6 +12,12 @@
android:title="@string/settings_night_mode_title"
app:useSimpleSummaryProvider="true" />
+
+