use of android.view.inputmethod.InputConnection in project kdeconnect-android by KDE.
the class RemoteKeyboardPlugin method handleSpecialKey.
private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) {
int keyEvent = specialKeyMap.get(key, 0);
if (keyEvent == 0)
return false;
InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
// special sequences:
if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) {
// Ctrl + right -> next word
ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
if (pos == -1)
pos = currentTextLength(extractedText);
else
pos++;
int startPos = pos;
int endPos = pos;
if (shift) {
// Shift -> select word (otherwise jump)
Pair<Integer, Integer> sel = currentSelection(extractedText);
int cursor = currentCursorPos(extractedText);
// Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor);
startPos = cursor;
if (// active selection from left to right -> grow
sel.first < cursor || // active selection from right to left -> shrink
sel.first > sel.second)
startPos = sel.first;
}
inputConn.setSelection(startPos, endPos);
} else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) {
// Ctrl + left -> previous word
ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
if (pos == -1)
pos = 0;
else
pos++;
int startPos = pos;
int endPos = pos;
if (shift) {
Pair<Integer, Integer> sel = currentSelection(extractedText);
int cursor = currentCursorPos(extractedText);
// Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor);
startPos = cursor;
if (// active selection from right to left -> grow
cursor < sel.first || // active selection from right to left -> shrink
sel.first < sel.second)
startPos = sel.first;
}
inputConn.setSelection(startPos, endPos);
} else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) {
// Shift + up/down/left/right/home/end
long now = SystemClock.uptimeMillis();
inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
} else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) {
// Enter key
EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo();
// Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions);
if (editorInfo != null && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) {
// Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?)
// check for special DONE/GO/etc actions first:
int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_SEARCH, // note: DONE should be last or we might hide the ime instead of "go"
EditorInfo.IME_ACTION_DONE };
for (int i = 0; i < actions.length; i++) {
if ((editorInfo.imeOptions & actions[i]) == actions[i]) {
// Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]);
inputConn.performEditorAction(actions[i]);
return true;
}
}
} else {
// else: fall back to regular Enter-event:
// Log.d("RemoteKeyboardPlugin", "Enter: normal keypress");
inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
}
} else {
// default handling:
inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
}
return true;
}
use of android.view.inputmethod.InputConnection in project speechutils by Kaljurand.
the class InputConnectionCommandEditorTest method before.
@Before
public void before() {
Context context = getInstrumentation().getContext();
EditText view = new EditText(context);
//view.setText("elas metsas mutionu, keset kuuski noori-vanu");
EditorInfo editorInfo = new EditorInfo();
//editorInfo.initialSelStart = 12;
//editorInfo.initialSelEnd = 19;
InputConnection connection = view.onCreateInputConnection(editorInfo);
//InputConnection connection = new BaseInputConnection(view, true);
mEditor = new InputConnectionCommandEditor(context);
mEditor.setInputConnection(connection);
mEditor.setRewriters(URS);
}
use of android.view.inputmethod.InputConnection in project android_frameworks_base by DirtyUnicorns.
the class IInputMethodWrapper method bindInput.
@Override
public void bindInput(InputBinding binding) {
// This IInputContext is guaranteed to implement all the methods.
final int missingMethodFlags = 0;
InputConnection ic = new InputConnectionWrapper(mTarget, IInputContext.Stub.asInterface(binding.getConnectionToken()), missingMethodFlags);
InputBinding nu = new InputBinding(ic, binding);
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_INPUT_CONTEXT, nu));
}
use of android.view.inputmethod.InputConnection in project android_frameworks_base by DirtyUnicorns.
the class InputMethodService method sendDownUpKeyEvents.
/**
* Send the given key event code (as defined by {@link KeyEvent}) to the
* current input connection is a key down + key up event pair. The sent
* events have {@link KeyEvent#FLAG_SOFT_KEYBOARD KeyEvent.FLAG_SOFT_KEYBOARD}
* set, so that the recipient can identify them as coming from a software
* input method, and
* {@link KeyEvent#FLAG_KEEP_TOUCH_MODE KeyEvent.FLAG_KEEP_TOUCH_MODE}, so
* that they don't impact the current touch mode of the UI.
*
* <p>Note that it's discouraged to send such key events in normal operation;
* this is mainly for use with {@link android.text.InputType#TYPE_NULL} type
* text fields, or for non-rich input methods. A reasonably capable software
* input method should use the
* {@link android.view.inputmethod.InputConnection#commitText} family of methods
* to send text to an application, rather than sending key events.</p>
*
* @param keyEventCode The raw key code to send, as defined by
* {@link KeyEvent}.
*/
public void sendDownUpKeyEvents(int keyEventCode) {
InputConnection ic = getCurrentInputConnection();
if (ic == null)
return;
long eventTime = SystemClock.uptimeMillis();
ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
ic.sendKeyEvent(new KeyEvent(eventTime, SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
}
use of android.view.inputmethod.InputConnection in project android_frameworks_base by DirtyUnicorns.
the class InputMethodService method updateFullscreenMode.
/**
* Re-evaluate whether the input method should be running in fullscreen
* mode, and update its UI if this has changed since the last time it
* was evaluated. This will call {@link #onEvaluateFullscreenMode()} to
* determine whether it should currently run in fullscreen mode. You
* can use {@link #isFullscreenMode()} to determine if the input method
* is currently running in fullscreen mode.
*/
public void updateFullscreenMode() {
boolean isFullscreen = mShowInputRequested && onEvaluateFullscreenMode();
boolean changed = mLastShowInputRequested != mShowInputRequested;
if (mIsFullscreen != isFullscreen || !mFullscreenApplied) {
changed = true;
mIsFullscreen = isFullscreen;
InputConnection ic = getCurrentInputConnection();
if (ic != null)
ic.reportFullscreenMode(isFullscreen);
mFullscreenApplied = true;
initialize();
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mFullscreenArea.getLayoutParams();
if (isFullscreen) {
mFullscreenArea.setBackgroundDrawable(mThemeAttrs.getDrawable(com.android.internal.R.styleable.InputMethodService_imeFullscreenBackground));
lp.height = 0;
lp.weight = 1;
} else {
mFullscreenArea.setBackgroundDrawable(null);
lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
lp.weight = 0;
}
((ViewGroup) mFullscreenArea.getParent()).updateViewLayout(mFullscreenArea, lp);
if (isFullscreen) {
if (mExtractView == null) {
View v = onCreateExtractTextView();
if (v != null) {
setExtractView(v);
}
}
startExtractingText(false);
}
updateExtractFrameVisibility();
}
if (changed) {
onConfigureWindow(mWindow.getWindow(), isFullscreen, !mShowInputRequested);
mLastShowInputRequested = mShowInputRequested;
}
}
Aggregations