Switch to TYPE_NULL as input type

This fixes #126 where the previous input type put some keyboards into
word mode (no direct echo). The workaround for Google Pinyin does not
seem to be necessary no more.

Also fix backspace after entering emojis on some keyboards (Swype).
This commit is contained in:
Fredrik Fornwall
2016-08-04 23:56:17 +02:00
parent dfdc9b37e1
commit c0a5e5f57a

View File

@@ -228,18 +228,13 @@ public final class TerminalView extends View {
@Override @Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) { public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
// Using InputType.TYPE_TEXT_VARIATION_URI avoids having an extra row of numbers on the // Using InputType.NULL is the most correct input type and avoids issues with other hacks.
// Google keyboard. https://github.com/termux/termux-app/issues/87.
// It also makes the '/' keyboard more accessible, and makes some sense.
// //
// If using just "TYPE_NULL", there is a problem with the "Google Pinyin Input" being in // Previous keyboard issues:
// word mode when used with the "En" tab available when the "Show English keyboard" option // https://github.com/termux/termux-packages/issues/25
// is enabled - see https://github.com/termux/termux-packages/issues/25. // https://github.com/termux/termux-app/issues/87.
// Adding TYPE_TEXT_FLAG_NO_SUGGESTIONS fixes Pinyin Input and removes the row of numbers // https://github.com/termux/termux-app/issues/126 for breakage from that.
// on the Google keyboard. . It also causes Swype to be put in outAttrs.inputType = InputType.TYPE_NULL;
// word mode, but using TYPE_TEXT_VARIATION_VISIBLE_PASSWORD would fix that. But for now
// use InputType.TYPE_TEXT_VARIATION_URI as it makes more sense.
outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_URI;
// Let part of the application show behind when in landscape: // Let part of the application show behind when in landscape:
outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
@@ -310,17 +305,18 @@ public final class TerminalView extends View {
public boolean deleteSurroundingText(int leftLength, int rightLength) { public boolean deleteSurroundingText(int leftLength, int rightLength) {
if (LOG_KEY_EVENTS) if (LOG_KEY_EVENTS)
Log.i(EmulatorDebug.LOG_TAG, "IME: deleteSurroundingText(" + leftLength + ", " + rightLength + ")"); Log.i(EmulatorDebug.LOG_TAG, "IME: deleteSurroundingText(" + leftLength + ", " + rightLength + ")");
// If leftLength=2 it may be due to a UTF-16 surrogate pair. So we cannot send
// Swype keyboard sometimes(?) sends this on backspace: // multiple key events for that. Let's just hope that keyboards don't use
if (leftLength == 0 && rightLength == 0) leftLength = 1; // leftLength > 1 for other purposes (such as holding down backspace for repeat).
for (int i = 0; i < leftLength; i++)
sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
return true; return true;
} }
@Override @Override
public boolean setComposingText(CharSequence text, int newCursorPosition) { public boolean setComposingText(CharSequence text, int newCursorPosition) {
if (LOG_KEY_EVENTS)
Log.i(EmulatorDebug.LOG_TAG, "IME: setComposingText(\"" + text + "\", " + newCursorPosition + ")");
if (text.length() == 0) { if (text.length() == 0) {
// Avoid log spam "SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot // Avoid log spam "SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot
// have a zero length" when backspacing with the Google keyboard. // have a zero length" when backspacing with the Google keyboard.