From a848897586223b050e87367b48ed2eebd0870d1d Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 18 Jan 2026 17:26:41 +0100 Subject: Refactor: Split DeviceLocales out of Keyboard2 (#1154) * Refactor: Split DeviceLocales out of Keyboard2 This moves the code from Keyboard2 that handles the active IME subtypes and the current one. The goal is to access this information from the dictionary activity while simplifying the code of Keyboard2. * Refresh the candidates view when subtype changes This fixes the status message being inconsistently shown. * Refactor: Load DeviceLocales less often Previously, [DeviceLocales.load()] was called everytime the keyboard was shown on the screen. This operation is moderately costly and only need to be done when the IME subtype changes. * EditorConfig: Fix crash on Android 9--- srcs/juloo.keyboard2/EditorConfig.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'srcs/juloo.keyboard2/EditorConfig.java') diff --git a/srcs/juloo.keyboard2/EditorConfig.java b/srcs/juloo.keyboard2/EditorConfig.java index bdfab3c..2bfbcef 100644 --- a/srcs/juloo.keyboard2/EditorConfig.java +++ b/srcs/juloo.keyboard2/EditorConfig.java @@ -1,9 +1,11 @@ package juloo.keyboard2; import android.content.res.Resources; +import android.os.Build.VERSION; import android.text.InputType; import android.text.TextUtils; import android.view.inputmethod.EditorInfo; +import juloo.keyboard2.CandidatesView; public final class EditorConfig { @@ -27,10 +29,14 @@ public final class EditorConfig public boolean caps_initially_updated = false; /** CurrentlyTypedWord. */ - public CharSequence initial_text_before_cursor = null; + public CharSequence initial_text_before_cursor = null; // Might be [null]. public int initial_sel_start; public int initial_sel_end; + /** Suggestions. */ + // Doesn't override [_config.suggestions_enabled]. + public boolean should_show_candidates_view; + public EditorConfig() {} public void refresh(EditorInfo info, Resources res) @@ -72,9 +78,12 @@ public final class EditorConfig caps_initially_enabled = (info.initialCapsMode != 0); caps_initially_updated = caps_should_update_state(info); /* CurrentlyTypedWord */ - initial_text_before_cursor = info.getInitialTextBeforeCursor(10, 0); + if (VERSION.SDK_INT >= 30) + initial_text_before_cursor = info.getInitialTextBeforeCursor(10, 0); initial_sel_start = info.initialSelStart; initial_sel_end = info.initialSelEnd; + /* Suggestions */ + should_show_candidates_view = CandidatesView.should_show(info); } String actionLabel_of_imeAction(int action, Resources res) -- cgit v1.2.3