Separately persisted current layout in landscape mode

Remember the selected layout in portrait and landscape mode
independently.
This allows to define a layout specific to landscape without having to
switch manually.
This commit is contained in:
Jules Aguillon 2023-11-19 20:10:45 +01:00
parent 15de829138
commit 44adb55544
2 changed files with 20 additions and 8 deletions

View File

@ -66,7 +66,10 @@ final class Config
public final IKeyEventHandler handler; public final IKeyEventHandler handler;
public boolean orientation_landscape = false; public boolean orientation_landscape = false;
public int current_layout; // Index in 'layouts' of the currently used layout /** Index in 'layouts' of the currently used layout. See
[get_current_layout()] and [set_current_layout()]. */
int current_layout_portrait;
int current_layout_landscape;
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h) private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h)
{ {
@ -155,14 +158,25 @@ final class Config
extra_keys_param = ExtraKeysPreference.get_extra_keys(_prefs); extra_keys_param = ExtraKeysPreference.get_extra_keys(_prefs);
extra_keys_custom = CustomExtraKeysPreference.get(_prefs); extra_keys_custom = CustomExtraKeysPreference.get(_prefs);
pin_entry_enabled = _prefs.getBoolean("pin_entry_enabled", true); pin_entry_enabled = _prefs.getBoolean("pin_entry_enabled", true);
current_layout = _prefs.getInt("current_layout", 0); current_layout_portrait = _prefs.getInt("current_layout_portrait", 0);
current_layout_landscape = _prefs.getInt("current_layout_landscape", 0);
}
public int get_current_layout()
{
return (orientation_landscape)
? current_layout_landscape : current_layout_portrait;
} }
public void set_current_layout(int l) public void set_current_layout(int l)
{ {
current_layout = l; if (orientation_landscape)
current_layout_landscape = l;
else
current_layout_portrait = l;
SharedPreferences.Editor e = _prefs.edit(); SharedPreferences.Editor e = _prefs.edit();
e.putInt("current_layout", l); e.putInt("current_layout_portrait", current_layout_portrait);
e.putInt("current_layout_landscape", current_layout_landscape);
e.apply(); e.apply();
} }

View File

@ -44,7 +44,7 @@ public class Keyboard2 extends InputMethodService
if (_currentSpecialLayout != null) if (_currentSpecialLayout != null)
return _currentSpecialLayout; return _currentSpecialLayout;
KeyboardData layout = null; KeyboardData layout = null;
int layout_i = _config.current_layout; int layout_i = _config.get_current_layout();
if (layout_i >= _config.layouts.size()) if (layout_i >= _config.layouts.size())
layout_i = 0; layout_i = 0;
if (layout_i < _config.layouts.size()) if (layout_i < _config.layouts.size())
@ -62,8 +62,6 @@ public class Keyboard2 extends InputMethodService
void setTextLayout(int l) void setTextLayout(int l)
{ {
if (l == _config.current_layout)
return;
_config.set_current_layout(l); _config.set_current_layout(l);
_currentSpecialLayout = null; _currentSpecialLayout = null;
_keyboardView.setKeyboard(current_layout()); _keyboardView.setKeyboard(current_layout());
@ -72,7 +70,7 @@ public class Keyboard2 extends InputMethodService
void incrTextLayout(int delta) void incrTextLayout(int delta)
{ {
int s = _config.layouts.size(); int s = _config.layouts.size();
setTextLayout((_config.current_layout + delta + s) % s); setTextLayout((_config.get_current_layout() + delta + s) % s);
} }
void setSpecialLayout(KeyboardData l) void setSpecialLayout(KeyboardData l)