]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Add "system theme" to theme options
authorMatthew Hague <matthewhague@zoho.com>
Tue, 26 May 2020 08:45:40 +0000 (09:45 +0100)
committerReimar Döffinger <rdoeffinger@users.noreply.github.com>
Tue, 2 Jun 2020 15:36:07 +0000 (17:36 +0200)
Dark mode if system is dark, light if it's light.

res/values/arrays.xml
src/com/hughes/android/dictionary/DictionaryApplication.java

index 9a8b0a8b866e5ae85bc6fed8bdbd857aa6748506..1cac2f67d86968321a7dd03c798c50cddfc69cb6 100644 (file)
   <string-array name="themeKeys" translatable="false">
     <item>themeLight</item>
     <item>themeDefault</item>
+    <item>themeSystem</item>
   </string-array>
 
   <string-array name="themes">
     <item>Light theme</item>
     <item>Dark theme (default)</item>
+    <item>System theme</item>
   </string-array>
 
 </resources>
index 1e3788be869e7d830511705e391282e1af33c0ca..fa4571c6483773b73ec6c2454c11295432b6e740 100644 (file)
@@ -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;
         }