Hide the input switching key if it's not needed

Android has a new way of switching between input methods and this key
need to be hidden in most cases.
This commit is contained in:
Jules Aguillon 2021-04-18 00:55:31 +02:00
parent 1421bccc7b
commit f8bce500ff
4 changed files with 23 additions and 5 deletions

View File

@ -24,6 +24,8 @@ class Config
public float horizontalMargin;
public boolean disableAccentKeys;
public boolean shouldOfferSwitchingToNextInputMethod;
public Config(Keyboard2 context)
{
Resources res = context.getResources();
@ -46,6 +48,8 @@ class Config
disableAccentKeys = false;
// from prefs
refresh();
// initialized later
shouldOfferSwitchingToNextInputMethod = false;
}
/*

View File

@ -100,6 +100,7 @@ public class Keyboard2 extends InputMethodService
public void onStartInputView(EditorInfo info, boolean restarting)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getCurrentInputBinding().getConnectionToken());
refreshSubtype(imm.getCurrentInputMethodSubtype());
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
@ -156,7 +157,7 @@ public class Keyboard2 extends InputMethodService
{
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.switchToNextInputMethod(getWindow().getWindow().getAttributes().token, false);
imm.switchToNextInputMethod(getCurrentInputBinding().getConnectionToken(), false);
}
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
handleMetaKeyUp(key, flags);

View File

@ -83,12 +83,13 @@ public class Keyboard2View extends View
return (paint);
}
public void setKeyboard(KeyboardData keyboard)
public void setKeyboard(KeyboardData kw)
{
if (!_config.shouldOfferSwitchingToNextInputMethod)
kw = kw.removeKeys(new KeyboardData.RemoveKeysByEvent(KeyValue.EVENT_CHANGE_METHOD));
if (_config.disableAccentKeys)
_keyboard = keyboard.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
else
_keyboard = keyboard;
kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
_keyboard = kw;
reset();
}

View File

@ -171,4 +171,16 @@ class KeyboardData
return (k == null || (k.getFlags() & _flags) != 0) ? null : k;
}
}
public static class RemoveKeysByEvent implements MapKeys
{
private final int _eventCode;
public RemoveKeysByEvent(int ev) { _eventCode = ev; }
public KeyValue map(KeyValue k)
{
return (k == null || k.getEventCode() == _eventCode) ? null : k;
}
}
}