abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorJules Aguillon2022-01-30 23:29:50 +0100
committerJules Aguillon2022-01-30 23:29:50 +0100
commit8631dfb723716e3273e92b2dfd02008d733b86a9 (patch)
tree9c05a311c2554f11f2184198e40de3fa24807fa9
parentc9f7f2cfc8c08254d9a2c7edd9d290759c63b9b6 (diff)
downloadunexpected-keyboard-8631dfb723716e3273e92b2dfd02008d733b86a9.tar.gz
unexpected-keyboard-8631dfb723716e3273e92b2dfd02008d733b86a9.zip
Select theme depending on system settings
Automatically choose between the Dark and Light themes.
-rw-r--r--res/values-fr/strings.xml1
-rw-r--r--res/values-lv/strings.xml1
-rw-r--r--res/values/arrays.xml2
-rw-r--r--res/values/strings.xml1
-rw-r--r--res/xml/settings.xml2
-rw-r--r--srcs/juloo.keyboard2/Config.java26
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java32
7 files changed, 47 insertions, 18 deletions
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 3da3bf4..6650119 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -28,6 +28,7 @@
<string name="pref_character_size_title">Taille des labels</string>
<string name="pref_character_size_summary">Taille des caractères affichés sur les touches (%.2fx)</string>
<string name="pref_theme">Thème</string>
+ <string name="pref_theme_e_system">Paramètre système</string>
<string name="pref_theme_e_dark">Sombre</string>
<string name="pref_theme_e_light">Clair</string>
<string name="pref_theme_e_black">Noir</string>
diff --git a/res/values-lv/strings.xml b/res/values-lv/strings.xml
index 312f2b9..48fccda 100644
--- a/res/values-lv/strings.xml
+++ b/res/values-lv/strings.xml
@@ -28,6 +28,7 @@
<string name="pref_character_size_title">Iezīmes izmērs</string>
<string name="pref_character_size_summary">Tastatūrā attēloto rakstzīmju izmērs (%.2fx)</string>
<string name="pref_theme">Izskats</string>
+ <string name="pref_theme_e_system">Ierīces iestatījumi</string>
<string name="pref_theme_e_dark">Tumšs</string>
<string name="pref_theme_e_light">Gaišs</string>
<string name="pref_theme_e_black">Melns</string>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index bcc8576..62d791c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -29,11 +29,13 @@
<item>4</item>
</string-array>
<string-array name="pref_theme_entries">
+ <item>@string/pref_theme_e_system</item>
<item>@string/pref_theme_e_dark</item>
<item>@string/pref_theme_e_light</item>
<item>@string/pref_theme_e_black</item>
</string-array>
<string-array name="pref_theme_values">
+ <item>system</item>
<item>dark</item>
<item>light</item>
<item>black</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1ff286a..199fbd2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -28,6 +28,7 @@
<string name="pref_character_size_title">Label size</string>
<string name="pref_character_size_summary">Size of characters displayed on the keyboard (%.2fx)</string>
<string name="pref_theme">Theme</string>
+ <string name="pref_theme_e_system">System settings</string>
<string name="pref_theme_e_dark">Dark</string>
<string name="pref_theme_e_light">Light</string>
<string name="pref_theme_e_black">Black</string>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index c882f00..df5f201 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -15,7 +15,7 @@
<juloo.common.IntSlideBarPreference android:key="vibrate_duration" android:title="@string/pref_vibrate_duration_title" android:summary="%sms" android:defaultValue="20" min="5" max="50"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_style">
- <ListPreference android:key="theme" android:title="@string/pref_theme" android:summary="%s" android:defaultValue="dark" android:entries="@array/pref_theme_entries" android:entryValues="@array/pref_theme_values"/>
+ <ListPreference android:key="theme" android:title="@string/pref_theme" android:summary="%s" android:defaultValue="system" android:entries="@array/pref_theme_entries" android:entryValues="@array/pref_theme_values"/>
<juloo.common.IntSlideBarPreference android:key="margin_bottom" android:title="@string/pref_margin_bottom_title" android:summary="%sdp" android:defaultValue="5" min="0" max="100"/>
<juloo.common.IntSlideBarPreference android:key="key_height" android:title="@string/pref_key_height_title" android:summary="%sdp" android:defaultValue="50" min="30" max="90"/>
<juloo.common.IntSlideBarPreference android:key="horizontal_margin" android:title="@string/pref_horizontal_margin_title" android:summary="%sdp" android:defaultValue="3" min="0" max="20"/>
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)
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index fa4b494..54fe587 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -57,6 +57,7 @@ public class Keyboard2 extends InputMethodService
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
Config.initGlobalConfig(this, new KeyEventHandler(this.new Receiver()));
_config = Config.globalConfig();
+ _config.refresh(this);
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
_keyboardView.reset();
}
@@ -177,17 +178,27 @@ public class Keyboard2 extends InputMethodService
}
}
+ private void refreshConfig()
+ {
+ int prev_theme = _config.theme;
+ _config.refresh(this);
+ refreshSubtypeImm();
+ // Refreshing the theme config requires re-creating the views
+ if (prev_theme != _config.theme)
+ {
+ _keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
+ _emojiPane = null;
+ }
+ _keyboardView.setKeyboard(getLayout(_currentTextLayout));
+ }
+
@Override
public void onStartInputView(EditorInfo info, boolean restarting)
{
- // Update '_config' before calling 'KeyboardView.setKeyboard'
- refreshSubtypeImm();
+ refreshConfig();
refreshEditorInfo(info);
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
- else
- _keyboardView.setKeyboard(getLayout(_currentTextLayout));
- _keyboardView.reset(); // Layout might need to change due to rotation
setInputView(_keyboardView);
}
@@ -217,16 +228,7 @@ public class Keyboard2 extends InputMethodService
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
- int prev_theme = _config.theme;
- _config.refresh(this);
- refreshSubtypeImm();
- _keyboardView.setKeyboard(getLayout(_currentTextLayout));
- // Refreshing the theme config requires re-creating the views
- if (prev_theme != _config.theme)
- {
- _keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
- _emojiPane = null;
- }
+ refreshConfig();
}
/** Not static */