mirror of
https://github.com/keymanapp/keyman.git
synced 2026-11-03 09:37:47 +00:00
Merge pull request #12125 from keymanapp/feat/android/enter-mode
feat(android): Enhance how ENTER key is handled in apps
This commit is contained in:
commit
79ebbfa53f
3 changed files with 122 additions and 2 deletions
|
|
@ -175,6 +175,9 @@ public class SystemKeyboard extends InputMethodService implements OnKeyboardEven
|
|||
}
|
||||
}
|
||||
|
||||
// Determine special handling for ENTER key
|
||||
KMManager.setEnterMode(attribute.imeOptions, inputType);
|
||||
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
if (ic != null) {
|
||||
ExtractedText icText = ic.getExtractedText(new ExtractedTextRequest(), 0);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import android.webkit.JavascriptInterface;
|
|||
|
||||
import static android.content.Context.VIBRATOR_SERVICE;
|
||||
|
||||
import com.keyman.engine.KMManager.EnterModeType;
|
||||
import com.keyman.engine.KMManager.KeyboardType;
|
||||
import com.keyman.engine.data.Keyboard;
|
||||
import com.keyman.engine.util.CharSequenceUtil;
|
||||
|
|
@ -153,7 +154,53 @@ public class KMKeyboardJSHandler {
|
|||
}
|
||||
|
||||
if (s.length() > 0 && s.charAt(0) == '\n') {
|
||||
keyDownUp(KeyEvent.KEYCODE_ENTER, 0);
|
||||
if (k.keyboardType == KeyboardType.KEYBOARD_TYPE_SYSTEM) {
|
||||
// Special handling of ENTER key
|
||||
switch (KMManager.enterMode) {
|
||||
// Go action
|
||||
case GO :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_GO);
|
||||
break;
|
||||
|
||||
// Search action
|
||||
case SEARCH :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_SEARCH);
|
||||
break;
|
||||
|
||||
// Send action
|
||||
case SEND :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_SEND);
|
||||
break;
|
||||
|
||||
// Next action
|
||||
case NEXT :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
|
||||
break;
|
||||
|
||||
// Done action
|
||||
case DONE :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_DONE);
|
||||
break;
|
||||
|
||||
// Previous action
|
||||
case PREVIOUS :
|
||||
ic.performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
|
||||
break;
|
||||
|
||||
// Messaging apps
|
||||
case NEWLINE :
|
||||
// Send newline and advance cursor
|
||||
ic.commitText("\n", 1);
|
||||
break;
|
||||
|
||||
// Default ENTER action
|
||||
default:
|
||||
keyDownUp(KeyEvent.KEYCODE_ENTER, 0);
|
||||
}
|
||||
} else {
|
||||
// In-app keyboard uses default ENTER action
|
||||
keyDownUp(KeyEvent.KEYCODE_ENTER, 0);
|
||||
}
|
||||
ic.endBatchEdit();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Typeface;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
|
|
@ -180,6 +179,19 @@ public final class KMManager {
|
|||
}
|
||||
}
|
||||
|
||||
// Enum for how the System Keyboard ENTER key is handled for the EditorInfo action
|
||||
// Reference: https://developer.android.com/reference/android/view/inputmethod/EditorInfo#summary
|
||||
public enum EnterModeType {
|
||||
GO, // Go action
|
||||
SEARCH, // Search action
|
||||
SEND, // Send action
|
||||
NEXT, // Next action
|
||||
DONE, // Done action
|
||||
PREVIOUS, // Previous action
|
||||
NEWLINE, // Send newline character
|
||||
DEFAULT, // Default ENTER action
|
||||
}
|
||||
|
||||
protected static InputMethodService IMService;
|
||||
|
||||
private static boolean debugMode = false;
|
||||
|
|
@ -218,6 +230,9 @@ public final class KMManager {
|
|||
// regardless what the Settings preference is.
|
||||
private static boolean mayPredictOverride = false;
|
||||
|
||||
// Determine how system keyboard handles ENTER key
|
||||
public static EnterModeType enterMode = EnterModeType.DEFAULT;
|
||||
|
||||
// Boolean for whether a keyboard can send embedded KMW crash reports to Sentry
|
||||
// When maySendCrashReport is false, KMW will still attempt to send crash reports, but it
|
||||
// will be blocked.
|
||||
|
|
@ -1251,6 +1266,61 @@ public final class KMManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets enterMode which specifies how the System keyboard ENTER key is handled
|
||||
*
|
||||
* @param imeOptions EditorInfo.imeOptions
|
||||
* @param inputType InputType
|
||||
*/
|
||||
public static void setEnterMode(int imeOptions, int inputType) {
|
||||
if ((inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0) {
|
||||
enterMode = EnterModeType.NEWLINE;
|
||||
return;
|
||||
}
|
||||
|
||||
int imeActions = imeOptions & EditorInfo.IME_MASK_ACTION;
|
||||
EnterModeType value = EnterModeType.DEFAULT;
|
||||
|
||||
switch (imeActions) {
|
||||
case EditorInfo.IME_ACTION_GO:
|
||||
value = EnterModeType.GO;
|
||||
break;
|
||||
|
||||
case EditorInfo.IME_ACTION_SEARCH:
|
||||
value = EnterModeType.SEARCH;
|
||||
break;
|
||||
|
||||
case EditorInfo.IME_ACTION_SEND:
|
||||
value = EnterModeType.SEND;
|
||||
break;
|
||||
|
||||
case EditorInfo.IME_ACTION_NEXT:
|
||||
value = EnterModeType.NEXT;
|
||||
break;
|
||||
|
||||
case EditorInfo.IME_ACTION_DONE:
|
||||
value = EnterModeType.DONE;
|
||||
break;
|
||||
|
||||
case EditorInfo.IME_ACTION_PREVIOUS:
|
||||
value = EnterModeType.PREVIOUS;
|
||||
break;
|
||||
|
||||
default:
|
||||
value = EnterModeType.DEFAULT;
|
||||
}
|
||||
|
||||
enterMode = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of enterMode
|
||||
* @return EnterModeType
|
||||
*/
|
||||
public static EnterModeType getEnterMode() {
|
||||
return enterMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets mayPredictOverride true if the InputType field is a hidden password text field
|
||||
* (either TYPE_TEXT_VARIATION_PASSWORD or TYPE_TEXT_VARIATION_WEB_PASSWORD
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue