From 099a2b5ae0ec99b9aba69642c53a66c613268c57 Mon Sep 17 00:00:00 2001 From: Matthew Hague Date: Tue, 26 May 2020 09:45:40 +0100 Subject: [PATCH] Add "system theme" to theme options Dark mode if system is dark, light if it's light. --- res/values/arrays.xml | 2 ++ .../hughes/android/dictionary/DictionaryApplication.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 9a8b0a8..1cac2f6 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -20,11 +20,13 @@ themeLight themeDefault + themeSystem Light theme Dark theme (default) + System theme diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index 1e3788b..fa4571c 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -18,6 +18,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Environment; @@ -313,6 +314,12 @@ public enum DictionaryApplication { final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeLight"); if (theme.equals("themeLight")) { return Theme.LIGHT; + } else if (theme.equals("themeSystem")) { + int mode = (appContext.getResources().getConfiguration().uiMode & + Configuration.UI_MODE_NIGHT_MASK); + return ((mode == Configuration.UI_MODE_NIGHT_YES) ? + Theme.DEFAULT : + Theme.LIGHT); } else { return Theme.DEFAULT; } -- 2.43.0