diff options
| author | Jules Aguillon | 2026-02-02 00:20:00 +0100 |
|---|---|---|
| committer | GitHub | 2026-02-02 00:20:00 +0100 |
| commit | 77c4a27c4c37b3620defcab94ffd1b2f536c88cb (patch) | |
| tree | 1bf2c5b723e1f86b0904257e7e57f4fda15378e9 /srcs/juloo.keyboard2/Keyboard2.java | |
| parent | 2ecf93d9904544ee73159e9f0ee74b49057bca6c (diff) | |
| download | unexpected-keyboard-77c4a27c4c37b3620defcab94ffd1b2f536c88cb.tar.gz unexpected-keyboard-77c4a27c4c37b3620defcab94ffd1b2f536c88cb.zip | |
Spell checking (#1137)
This adds dictionary-based spell checking to the keyboard. The keyboard looks at the word being typed and matches it against a dictionary to either complete the rest of the word or find alternative spellings.
The core of this feature is implemented in cdict, which is included as a
submodule in vendor/cidct.
Cdict is developped at https://github.com/Julow/cdict
The dictionaries are hosted at https://github.com/Julow/Unexpected-Keyboard-dictionaries/
The wordlists used to build the dictionaries are the same ones used by
HeliBoard from https://codeberg.org/Helium314/aosp-dictionaries
- Add an activity accessible from the launcher app that lists available
dictionaries with a download button.
The DictionaryListView view shows the list of available dictionaries and
handles downloading and installing them.
- The Dictionaries class manages installed dictionaries. Dictionaries are
installed as individual files into the app's private directory.
- Available dictionaries are listed in dictionaries.xml, which is generated
when building Unexpected-Keyboard-dictionaries.
method.xml mentions the dictionary name for each locales.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 25af0d0..ffe99ac 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -23,8 +23,11 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import juloo.keyboard2.dict.Dictionaries; +import juloo.keyboard2.dict.DictionariesActivity; import juloo.keyboard2.prefs.LayoutsPreference; import juloo.keyboard2.suggestions.CandidatesView; +import juloo.cdict.Cdict; public class Keyboard2 extends InputMethodService implements SharedPreferences.OnSharedPreferenceChangeListener @@ -40,6 +43,7 @@ public class Keyboard2 extends InputMethodService private KeyboardData _localeTextLayout; /** Installed and current locales. */ private DeviceLocales _device_locales; + private Dictionaries _dictionaries; private ViewGroup _emojiPane = null; private ViewGroup _clipboard_pane = null; private Handler _handler; @@ -115,11 +119,14 @@ public class Keyboard2 extends InputMethodService super.onCreate(); SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this); _handler = new Handler(getMainLooper()); - _keyeventhandler = new KeyEventHandler(this.new Receiver()); _foldStateTracker = new FoldStateTracker(this); - Config.initGlobalConfig(prefs, getResources(), _keyeventhandler, _foldStateTracker.isUnfolded()); - prefs.registerOnSharedPreferenceChangeListener(this); + _dictionaries = Dictionaries.instance(this); + Config.initGlobalConfig(prefs, getResources(), + _foldStateTracker.isUnfolded(), _dictionaries); _config = Config.globalConfig(); + _keyeventhandler = new KeyEventHandler(this.new Receiver(), _config); + _config.handler = _keyeventhandler; + prefs.registerOnSharedPreferenceChangeListener(this); Logs.set_debug_logs(getResources().getBoolean(R.bool.debug_logs)); refreshSubtypeImm(); create_keyboard_view(); @@ -163,6 +170,18 @@ public class Keyboard2 extends InputMethodService _localeTextLayout = default_layout; } + private void refresh_current_dictionary() + { + _config.current_dictionary = null; + String current = _device_locales.default_.dictionary; + if (current == null) + return; + Cdict[] dicts = _dictionaries.load(current); + if (dicts == null) + return; + _config.current_dictionary = Dictionaries.find_by_name(dicts, "main"); + } + private void refresh_candidates_view() { boolean should_show = @@ -178,7 +197,8 @@ public class Keyboard2 extends InputMethodService private void refresh_config() { int prev_theme = _config.theme; - _config.refresh(getResources(), _foldStateTracker.isUnfolded()); + _config.refresh(getResources(), _foldStateTracker.isUnfolded(), _dictionaries); + refresh_current_dictionary(); // Refreshing the theme config requires re-creating the views if (prev_theme != _config.theme) { @@ -331,6 +351,19 @@ public class Keyboard2 extends InputMethodService return false; } + /** Called from [onClick] attributes. */ + public void launch_dictionaries_activity(View v) + { + start_activity(DictionariesActivity.class); + } + + void start_activity(Class cls) + { + Intent intent = new Intent(this, cls); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + /** Not static */ public class Receiver implements KeyEventHandler.IReceiver { @@ -339,9 +372,7 @@ public class Keyboard2 extends InputMethodService switch (ev) { case CONFIG: - Intent intent = new Intent(Keyboard2.this, SettingsActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + start_activity(SettingsActivity.class); break; case SWITCH_TEXT: |
