forked from upstream-mirrors/OpenTracks
Android12+: use user-defined DynamicColors.
This commit is contained in:
@@ -7,6 +7,8 @@ import android.os.Build;
|
|||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.google.android.material.color.DynamicColors;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
@@ -28,6 +30,11 @@ public class Startup extends Application {
|
|||||||
|
|
||||||
// Include version information into stack traces.
|
// 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);
|
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());
|
PreferencesUtils.initPreferences(this, getResources());
|
||||||
// Set default values of preferences on first start.
|
// Set default values of preferences on first start.
|
||||||
@@ -35,11 +42,8 @@ public class Startup extends Application {
|
|||||||
PreferencesUtils.applyDefaultUnit();
|
PreferencesUtils.applyDefaultUnit();
|
||||||
PreferencesUtils.applyNightMode();
|
PreferencesUtils.applyNightMode();
|
||||||
|
|
||||||
|
if (PreferencesUtils.shouldUseDynamicColors()) {
|
||||||
// In debug builds: show thread and VM warnings.
|
DynamicColors.applyToActivitiesIfAvailable(this);
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
Log.d(TAG, "Enabling strict mode");
|
|
||||||
StrictMode.enableDefaults();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -307,6 +307,11 @@ public class PreferencesUtils {
|
|||||||
return getBoolean(R.string.stats_fullscreen_while_recording_key, DEFAULT);
|
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() {
|
public static boolean shouldVoiceAnnouncementOnDeviceSpeaker() {
|
||||||
final boolean DEFAULT = resources.getBoolean(R.bool.voice_on_device_speaker_default);
|
final boolean DEFAULT = resources.getBoolean(R.bool.voice_on_device_speaker_default);
|
||||||
return getBoolean(R.string.voice_on_device_speaker_key, DEFAULT);
|
return getBoolean(R.string.voice_on_device_speaker_key, DEFAULT);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.dennisguse.opentracks.settings;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
@@ -34,6 +35,9 @@ public class UserInterfaceSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Preference dynamicColors = findPreference(getString(R.string.settings_ui_dynamic_colors_key));
|
||||||
|
dynamicColors.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU);
|
||||||
|
|
||||||
setShowOnMapFormatOptions();
|
setShowOnMapFormatOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -271,6 +271,9 @@
|
|||||||
<string name="show_introduction_screen_key" translatable="false">showIntroduction</string>
|
<string name="show_introduction_screen_key" translatable="false">showIntroduction</string>
|
||||||
<bool name="show_introduction_screen_default">true</bool>
|
<bool name="show_introduction_screen_default">true</bool>
|
||||||
|
|
||||||
|
<string name="settings_ui_dynamic_colors_key" translatable="false">uiDynamicColors</string>
|
||||||
|
<bool name="settings_ui_dynamic_colors_default" translatable="false">false</bool>
|
||||||
|
|
||||||
<!-- androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode() -->
|
<!-- androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode() -->
|
||||||
<string name="night_mode_key" translatable="false">nightMode</string>
|
<string name="night_mode_key" translatable="false">nightMode</string>
|
||||||
<string name="night_mode_default" translatable="false">@string/night_mode_system_value</string>
|
<string name="night_mode_default" translatable="false">@string/night_mode_system_value</string>
|
||||||
|
|||||||
@@ -374,6 +374,8 @@ limitations under the License.
|
|||||||
<string name="settings_chart_by_time">By time</string>
|
<string name="settings_chart_by_time">By time</string>
|
||||||
<!-- Settings Recording -->
|
<!-- Settings Recording -->
|
||||||
<string name="settings_recording_title">Recording</string>
|
<string name="settings_recording_title">Recording</string>
|
||||||
|
<string name="settings_ui_dynamic_colors_title">Dynamic Colors</string>
|
||||||
|
<string name="settings_ui_dynamic_colors_summary">Use user-defined Dynamic Colors (requires Android 12+)</string>
|
||||||
<string name="settings_recording_customize_layout_title">Customize your recording layout</string>
|
<string name="settings_recording_customize_layout_title">Customize your recording layout</string>
|
||||||
<string name="settings_recording_customize_layout_select_columns">Data fields per row</string>
|
<string name="settings_recording_customize_layout_select_columns">Data fields per row</string>
|
||||||
<string name="settings_recording_show_on_lockscreen_while_recording_title">Show statistics on lockscreen</string>
|
<string name="settings_recording_show_on_lockscreen_while_recording_title">Show statistics on lockscreen</string>
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
android:title="@string/settings_night_mode_title"
|
android:title="@string/settings_night_mode_title"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="@bool/settings_ui_dynamic_colors_default"
|
||||||
|
android:key="@string/settings_ui_dynamic_colors_key"
|
||||||
|
android:summary="@string/settings_ui_dynamic_colors_summary"
|
||||||
|
android:title="@string/settings_ui_dynamic_colors_title" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="@string/show_on_map_format_ask"
|
android:defaultValue="@string/show_on_map_format_ask"
|
||||||
android:key="@string/show_on_map_format_key"
|
android:key="@string/show_on_map_format_key"
|
||||||
|
|||||||
Reference in New Issue
Block a user