From 98c1b8db82c0da8f49eb12d18c9001a57009eca5 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 27 Jul 2025 22:09:45 +0200 Subject: Candidates view The `CandidatesView` is implemented as a `LinearLayout` that is divided horizontally with up to 3 `TextView`. It might in the future contain buttons on the sides. The candidate view is nested into the input view rather than using Android's `setCandidatesView` and callbacks as the API is unreliable and complicated. The first suggestion goes in the middle to be more accessible. The second suggestion goes on the right to be more accessible to the right-handed, because it must go somewhere. --- srcs/juloo.keyboard2/Keyboard2.java | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'srcs/juloo.keyboard2/Keyboard2.java') diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 1efe0f5..c7d7e3d 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -29,7 +29,10 @@ import juloo.keyboard2.prefs.LayoutsPreference; public class Keyboard2 extends InputMethodService implements SharedPreferences.OnSharedPreferenceChangeListener { + /** The view containing the keyboard and candidates view. */ + private ViewGroup _container_view; private Keyboard2View _keyboardView; + private CandidatesView _candidates_view; private KeyEventHandler _keyeventhandler; /** If not 'null', the layout to use instead of [_config.current_layout]. */ private KeyboardData _currentSpecialLayout; @@ -115,9 +118,8 @@ public class Keyboard2 extends InputMethodService Config.initGlobalConfig(prefs, getResources(), _keyeventhandler, _foldStateTracker.isUnfolded()); prefs.registerOnSharedPreferenceChangeListener(this); _config = Config.globalConfig(); - _keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard); - _keyboardView.reset(); Logs.set_debug_logs(getResources().getBoolean(R.bool.debug_logs)); + create_keyboard_view(); ClipboardHistoryService.on_startup(this, _keyeventhandler); _foldStateTracker.setChangedCallback(() -> { refresh_config(); }); } @@ -129,6 +131,13 @@ public class Keyboard2 extends InputMethodService _foldStateTracker.close(); } + private void create_keyboard_view() + { + _container_view = (ViewGroup)inflate_view(R.layout.keyboard); + _keyboardView = (Keyboard2View)_container_view.findViewById(R.id.keyboard_view); + _candidates_view = (CandidatesView)_container_view.findViewById(R.id.candidates_view); + } + private List getEnabledSubtypes(InputMethodManager imm) { String pkg = getPackageName(); @@ -198,6 +207,13 @@ public class Keyboard2 extends InputMethodService _localeTextLayout = default_layout; } + private void refresh_candidates_view(EditorInfo info) + { + boolean should_show = CandidatesView.should_show(info); + _config.should_show_candidates_view = should_show; + _candidates_view.setVisibility(should_show ? View.VISIBLE : View.GONE); + } + /** Might re-create the keyboard view. [_keyboardView.setKeyboard()] and [setInputView()] must be called soon after. */ private void refresh_config() @@ -208,11 +224,13 @@ public class Keyboard2 extends InputMethodService // Refreshing the theme config requires re-creating the views if (prev_theme != _config.theme) { - _keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard); + create_keyboard_view(); _emojiPane = null; _clipboard_pane = null; - setInputView(_keyboardView); + setInputView(_container_view); } + // Set keyboard background opacity + _container_view.getBackground().setAlpha(_config.keyboardOpacity); _keyboardView.reset(); } @@ -234,10 +252,11 @@ public class Keyboard2 extends InputMethodService { _config.editor_config.refresh(info, getResources()); refresh_config(); + refresh_candidates_view(info); _currentSpecialLayout = refresh_special_layout(); _keyboardView.setKeyboard(current_layout()); _keyeventhandler.started(_config); - setInputView(_keyboardView); + setInputView(_container_view); Logs.debug_startup_input_view(info, _config); } @@ -252,7 +271,6 @@ public class Keyboard2 extends InputMethodService v.requestApplyInsets(); } - @Override public void updateFullscreenMode() { super.updateFullscreenMode(); -- cgit v1.2.3