Skip to content

Add support for language switching for autocorrect#1315

Open
firefox97 wants to merge 13 commits into
Julow:masterfrom
firefox97:multi-dict
Open

Add support for language switching for autocorrect#1315
firefox97 wants to merge 13 commits into
Julow:masterfrom
firefox97:multi-dict

Conversation

@firefox97

Copy link
Copy Markdown

Added keyboard symbol for switching language, switch_dictionary
Added ability to download multiple languages at once
Added personal dictionary to check first
Added capture of backspace undo of autocorrect, to pre-populate add to personal dictionary

This does have my Dvorak layouts, which are also on another pull request with comments, so those can be left out if merged...

firefox97 and others added 13 commits April 18, 2026 10:51
left layout add language key.
DictionaryListView.java now shows all 56 supported languages instead of only those matching your device locale. Any language can be downloaded and installed.

2. Quick dictionary switcher in Settings
DictionaryPickerPreference.java — a new ListPreference under Settings → Suggestions → "Active dictionary". Options: Auto (based on language) + any installed dictionary by display name. Stored as pref key selected_dictionary.

3. Personal dictionary
PersonalDictionary.java — singleton that stores word/replacement pairs in SharedPreferences. Each entry is either:

A plain word (recognized for completions)
A trigger → replacement pair (autocorrect)
Personal dictionary suggestions appear before main-dictionary suggestions.

4. Personal dictionary manager
PersonalDictionaryActivity.java — accessible from Settings → Suggestions → "Personal dictionary". Shows all entries; tap any to edit (word field + replacement field + Delete button).

5. "+" button while typing
A + button appears in the suggestions bar while you're typing a word. Tapping it opens the personal dictionary manager with the current word pre-filled in the add-word dialog. You can then modify both the word (trigger) and the replacement before saving.

The button is wired via CandidatesView.java → set_current_word() which is called by Suggestions.java on every keystroke.
1. Settings crash — The <intent> elements used android:targetPackage="juloo.keyboard2" but the debug build appends .debug to the app ID, so the intent couldn't resolve. Fixed by giving both preferences an android:key and wiring up OnPreferenceClickListener in SettingsActivity.java via wire_activity_pref(), which calls startActivity directly using the class reference (no package string involved).

2. Manage dictionaries language list — The DictionaryListView.java change was already correct; the issue was just that the settings link crashed before you could reach it. After reinstalling the updated build, all 56 languages will appear.

3. "+" button always visible while typing — Fixed in CandidatesView.java: the "No dictionary installed" status view is now inserted before the "+" button in the layout (using addView(view, indexOfChild(_add_word_btn))), so the "+" always sits at the right edge. The "no dict" message also now hides if the personal dictionary has entries (so it won't keep saying "no dictionary" when personal words are in use).
Add it to any keyboard layout XML like this:

<key key0="switch_dictionary"/>
It displays as "¿" (upside-down question mark) — distinctive, small, no font glyphs to add.

How it works
Tapping the key opens a full-width dictionary picker pane that replaces the keyboard view (same pattern as the emoji/clipboard panes). It lists:

Auto (based on language) — the existing locale-derived behavior
One row per installed dictionary, by display name
The currently active dictionary is marked with a ✓ checkmark. Tapping any row immediately:

Writes selected_dictionary to SharedPreferences
Updates _config.selected_dictionary
Calls refresh_current_dictionary() and refreshes suggestions
Returns to the keyboard
The bottom of the pane has a standard keyboard row with an "ABC" key to close and return without changing anything.
…ng.personal_dict_title))

"Add word" is now a clearly visible button in the ActionBar, always accessible at the top right
Back arrow added via setDisplayHomeAsUpEnabled(true) so the user can navigate back
The redundant custom header row is gone — the layout is now just a scrollable list
…he list starts below the ActionBar instead of sliding under it

Single-line entries — word takes the left side (with weight=1), replacement text sits to the right with an ellipsis if it's too long
Narrow left column: Auto/Correct labels + Switch toggle at top, ABC button at bottom
Full-height right column: scrollable dictionary list
Height locked to keyboard height via OnPreDrawListener (no flash)
Dictionary item rows: padding halved, 14sp text
Autocorrect toggle

Switch in the dict picker left column persists to SharedPreferences
Wired to KeyEventHandler.set_space_bar_auto_complete() without resetting other state
switch_dictionary key glyph

New glyph at 0xE01D — ¿ inside a square outline with evenodd cutaway where they intersect
Built via FontForge from srcs/special_font/01D.svg
Key uses FLAG_KEY_FONT | FLAG_SMALLER_FONT
Always-visible + button

+ button stays visible at all times in the candidates bar (not just while typing)
Backspace undo → + button pre-population

Backspace undoing an autocorrect highlights the + button and stores the original/corrected words
_pending_word (original) and _pending_replacement (correction) stored separately from _current_word so they survive the word-tracking reset that fires when cursor lands after the restored space
Both fields persist until the user taps + (which opens PersonalDictionaryActivity pre-filled) or a new autocorrect fires
PersonalDictionaryActivity

Title set correctly; Add word moved to ActionBar options menu
Back navigation via ActionBar home button
Accepts EXTRA_WORD and EXTRA_REPLACEMENT intents for pre-filling both fields
Entry rows: compact single-line horizontal layout (word + → replacement)

@Julow Julow left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way too big. Here are some comments but to make progress, you really need to split this into separate PRs that implement a single feature at a time.

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dictionary picker is way too complex. What about a key (maybe on the right side of the suggestion bar) that cycles through dictionaries ?

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea about the personal dictionary (that is maybe bad) is to present it as a text file with one word per line. Like the popup for entering a custom dictionary.
That way, people can copy and paste entire lists of words or they can add many words quickly without clicking on buttons.
What do you think ?

DownloadBtnListener listener = this.new DownloadBtnListener();
_dict_views = new ArrayList<DictView>();
for (DeviceLocales.Loc loc : locales.installed)
for (int i = 0; i < ds.length(); i++)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list is way too long. At least, the dictionaries for installed languages should be at the top. Maybe even in a different list view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants