mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-12-25 15:38:48 +01:00
Persist current selected layout
This commit is contained in:
parent
c57d896d8d
commit
15de829138
@ -66,6 +66,7 @@ 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
|
||||||
|
|
||||||
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h)
|
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h)
|
||||||
{
|
{
|
||||||
@ -154,6 +155,15 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set_current_layout(int l)
|
||||||
|
{
|
||||||
|
current_layout = l;
|
||||||
|
SharedPreferences.Editor e = _prefs.edit();
|
||||||
|
e.putInt("current_layout", l);
|
||||||
|
e.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyValue action_key()
|
KeyValue action_key()
|
||||||
|
@ -29,11 +29,9 @@ public class Keyboard2 extends InputMethodService
|
|||||||
{
|
{
|
||||||
private Keyboard2View _keyboardView;
|
private Keyboard2View _keyboardView;
|
||||||
private KeyEventHandler _keyeventhandler;
|
private KeyEventHandler _keyeventhandler;
|
||||||
// If not 'null', the layout to use instead of [_currentTextLayout].
|
/** If not 'null', the layout to use instead of [_config.current_layout]. */
|
||||||
private KeyboardData _currentSpecialLayout;
|
private KeyboardData _currentSpecialLayout;
|
||||||
/** Current layout index in [Config.layouts]. */
|
/** Layout associated with the currently selected locale. Not 'null'. */
|
||||||
private int _currentTextLayout;
|
|
||||||
// Layout associated with the currently selected locale. Not 'null'.
|
|
||||||
private KeyboardData _localeTextLayout;
|
private KeyboardData _localeTextLayout;
|
||||||
private ViewGroup _emojiPane = null;
|
private ViewGroup _emojiPane = null;
|
||||||
public int actionId; // Action performed by the Action key.
|
public int actionId; // Action performed by the Action key.
|
||||||
@ -46,10 +44,11 @@ public class Keyboard2 extends InputMethodService
|
|||||||
if (_currentSpecialLayout != null)
|
if (_currentSpecialLayout != null)
|
||||||
return _currentSpecialLayout;
|
return _currentSpecialLayout;
|
||||||
KeyboardData layout = null;
|
KeyboardData layout = null;
|
||||||
if (_currentTextLayout >= _config.layouts.size())
|
int layout_i = _config.current_layout;
|
||||||
_currentTextLayout = 0;
|
if (layout_i >= _config.layouts.size())
|
||||||
if (_currentTextLayout < _config.layouts.size())
|
layout_i = 0;
|
||||||
layout = _config.layouts.get(_currentTextLayout);
|
if (layout_i < _config.layouts.size())
|
||||||
|
layout = _config.layouts.get(layout_i);
|
||||||
if (layout == null)
|
if (layout == null)
|
||||||
layout = _localeTextLayout;
|
layout = _localeTextLayout;
|
||||||
return layout;
|
return layout;
|
||||||
@ -63,9 +62,9 @@ public class Keyboard2 extends InputMethodService
|
|||||||
|
|
||||||
void setTextLayout(int l)
|
void setTextLayout(int l)
|
||||||
{
|
{
|
||||||
if (l == _currentTextLayout)
|
if (l == _config.current_layout)
|
||||||
return;
|
return;
|
||||||
_currentTextLayout = l;
|
_config.set_current_layout(l);
|
||||||
_currentSpecialLayout = null;
|
_currentSpecialLayout = null;
|
||||||
_keyboardView.setKeyboard(current_layout());
|
_keyboardView.setKeyboard(current_layout());
|
||||||
}
|
}
|
||||||
@ -73,7 +72,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((_currentTextLayout + delta + s) % s);
|
setTextLayout((_config.current_layout + delta + s) % s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSpecialLayout(KeyboardData l)
|
void setSpecialLayout(KeyboardData l)
|
||||||
|
Loading…
Reference in New Issue
Block a user