diff options
| author | Jules Aguillon | 2022-01-30 23:29:50 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2022-01-30 23:29:50 +0100 |
| commit | 8631dfb723716e3273e92b2dfd02008d733b86a9 (patch) | |
| tree | 9c05a311c2554f11f2184198e40de3fa24807fa9 /srcs/juloo.keyboard2/Config.java | |
| parent | c9f7f2cfc8c08254d9a2c7edd9d290759c63b9b6 (diff) | |
| download | unexpected-keyboard-8631dfb723716e3273e92b2dfd02008d733b86a9.tar.gz unexpected-keyboard-8631dfb723716e3273e92b2dfd02008d733b86a9.zip | |
Select theme depending on system settings
Automatically choose between the Dark and Light themes.
Diffstat (limited to 'srcs/juloo.keyboard2/Config.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 42f983e..fb55955 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -2,7 +2,9 @@ package juloo.keyboard2; import android.content.Context; import android.content.res.Resources; +import android.content.res.Configuration; import android.content.SharedPreferences; +import android.os.Build; import android.preference.PreferenceManager; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -77,7 +79,8 @@ final class Config public void refresh(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - DisplayMetrics dm = context.getResources().getDisplayMetrics(); + Resources res = context.getResources(); + DisplayMetrics dm = res.getDisplayMetrics(); layout = layoutId_of_string(prefs.getString("layout", "system")); swipe_dist_dp = Float.valueOf(prefs.getString("swipe_dist", "15")); swipe_dist_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, swipe_dist_dp, dm); @@ -93,7 +96,7 @@ final class Config preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat); characterSize = prefs.getFloat("character_size", characterSize); accents = Integer.valueOf(prefs.getString("accents", "1")); - theme = themeId_of_string(prefs.getString("theme", "")); + theme = getThemeId(res, prefs.getString("theme", "")); } private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) @@ -104,6 +107,25 @@ final class Config return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, dm)); } + private int getThemeId(Resources res, String theme_name) + { + switch (theme_name) + { + case "light": return R.style.Light; + case "black": return R.style.Black; + case "dark": return R.style.Dark; + default: + case "system": + if (Build.VERSION.SDK_INT >= 8) + { + int night_mode = res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + if ((night_mode & Configuration.UI_MODE_NIGHT_NO) != 0) + return R.style.Light; + } + return R.style.Dark; + } + } + public static int layoutId_of_string(String name) { switch (name) |
