android.view.inputmethod.InputConnection Java Examples

The following examples show how to use android.view.inputmethod.InputConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
    if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
    }
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }

    outAttrs.actionId = EditorInfo.IME_ACTION_DONE;
    outAttrs.actionLabel = getContext().getString(R.string.done);
    return connection;
}
 
Example #2
Source File: KCommands.java    From kboard with GNU General Public License v3.0 6 votes vote down vote up
public KCommands(
        KboardIME ime,
        InputConnection ic,
        EditorInfo ei,
        List<String> keys,
        boolean autoSpace,
        boolean passiveAggressive) {
    inputConnection = ic;
    inputEditor = ei;
    mAutoSpace = autoSpace;
    mPassiveAggressive = passiveAggressive;
    List<String> mKeys = keys;
    mIme = ime;
    for (String key: mKeys) {
        if (!(key.startsWith("/") && key.contains("!"))) {
            mTextKeys.add(key);
        } else {
            mCommandKeys.put(key.split("!", 2)[0].substring(1), key.split("!", 2)[1]);
        }
    }
    mEmoji = EmojiManager.getAll();
}
 
Example #3
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
    if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
    }
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }

    outAttrs.actionId = EditorInfo.IME_ACTION_DONE;
    outAttrs.actionLabel = getContext().getString(R.string.done);
    return connection;
}
 
Example #4
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void doStartInput(InputConnection ic, EditorInfo attribute, boolean restarting) {
    if (!restarting) {
        doFinishInput();
    }
    mInputStarted = true;
    mStartedInputConnection = ic;
    mInputEditorInfo = attribute;
    initialize();
    if (DEBUG) Log.v(TAG, "CALL: onStartInput");
    onStartInput(attribute, restarting);
    if (mWindowVisible) {
        if (mShowInputRequested) {
            if (DEBUG) Log.v(TAG, "CALL: onStartInputView");
            mInputViewStarted = true;
            onStartInputView(mInputEditorInfo, restarting);
            startExtractingText(true);
        } else if (mCandidatesVisibility == View.VISIBLE) {
            if (DEBUG) Log.v(TAG, "CALL: onStartCandidatesView");
            mCandidatesViewStarted = true;
            onStartCandidatesView(mInputEditorInfo, restarting);
        }
    }
}
 
Example #5
Source File: ImeContainer.java    From mongol-library with MIT License 6 votes vote down vote up
/**
 * Keyboard.OnKeyboardListener method
 * <p>
 * Delete back one visible character before cursor. Extra control
 * characters like FVS, MVS, ZWJ, etc. may also be deleted.
 */
@Override
public void onBackspace() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;

    if (!TextUtils.isEmpty(mComposing)) {
        ic.commitText(mComposing, 1);
        mComposing = "";
    }

    if (hasSelection()) {
        doBackspace();
        return;
    }

    CharSequence previousFourChars = getTextBeforeCursor(4);
    backspaceFromEndOf(previousFourChars);

    clearCandidates();
}
 
Example #6
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 6 votes vote down vote up
private boolean isCursorTouchingWord() {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return false;
    CharSequence toLeft = ic.getTextBeforeCursor(1, 0);
    CharSequence toRight = ic.getTextAfterCursor(1, 0);
    if (!TextUtils.isEmpty(toLeft) && !isWordSeparator(toLeft.charAt(0))
            && !isSuggestedPunctuation(toLeft.charAt(0))) {
        return true;
    }
    if (!TextUtils.isEmpty(toRight) && !isWordSeparator(toRight.charAt(0))
            && !isSuggestedPunctuation(toRight.charAt(0))) {
        return true;
    }
    return false;
}
 
Example #7
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Commits the chosen word to the text field and saves it for later
 * retrieval.
 *
 * @param suggestion
 *            the suggestion picked by the user to be committed to the text
 *            field
 * @param correcting
 *            whether this is due to a correction of an existing word.
 */
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
    LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
    int shiftState = getShiftState();
    if (shiftState == Keyboard.SHIFT_LOCKED || shiftState == Keyboard.SHIFT_CAPS_LOCKED) {
        suggestion = suggestion.toString().toUpperCase(); // all UPPERCASE
    }
    InputConnection ic = getCurrentInputConnection();
    if (ic != null) {
        rememberReplacedWord(suggestion);
        ic.commitText(suggestion, 1);
    }
    saveWordInHistory(suggestion);
    mPredicting = false;
    mCommittedLength = suggestion.length();
    ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null);
    // If we just corrected a word, then don't show punctuations
    if (!correcting) {
        setNextSuggestions();
    }
    updateShiftKeyState(getCurrentInputEditorInfo());
}
 
Example #8
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 6 votes vote down vote up
private void setOldSuggestions() {
    if (mCandidateView != null
            && mCandidateView.isShowingAddToDictionaryHint()) {
        return;
    }
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;
    if (!mPredicting) {
        // Extract the selected or touching text
        EditingUtil.SelectedWord touching = EditingUtil
                .getWordAtCursorOrSelection(ic, mLastSelectionStart,
                        mLastSelectionEnd, mWordSeparators);

        abortCorrection(true);
        setNextSuggestions(); // Show the punctuation suggestions list
    } else {
        abortCorrection(true);
    }
}
 
Example #9
Source File: TextInputAutoCompleteTextView.java    From EosCommander with MIT License 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    final InputConnection ic = super.onCreateInputConnection(outAttrs);
    if ( ic == null ) {
        return null;
    }

    if ( outAttrs.hintText == null ) {
        // If we don't have a hint and our parent is a TextInputLayout, use it's hint for the
        // EditorInfo. This allows us to display a hint in 'extract mode'.
        final ViewParent parent = getParent();
        if (parent instanceof TextInputLayout) {
            outAttrs.hintText = ((TextInputLayout) parent).getHint();
        }
    }
    return ic;
}
 
Example #10
Source File: RichEditText.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
    final InputConnection ic = super.onCreateInputConnection(editorInfo);
    EditorInfoCompat.setContentMimeTypes(editorInfo, mSupportedMimeTypes);

    final InputConnectionCompat.OnCommitContentListener callback =
            new InputConnectionCompat.OnCommitContentListener() {
                @Override
                public boolean onCommitContent(
                        InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
                    if (mListener != null) {
                        return mListener.onCommitContent(
                                inputContentInfo, flags, opts, mSupportedMimeTypes);
                    }
                    return false;
                }
            };

    if (ic != null) {
        return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
    }
    return null;
}
 
Example #11
Source File: InputConnectionTest.java    From TokenAutoComplete with Apache License 2.0 6 votes vote down vote up
public static ViewAction forceCommitText(final String text) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ContactsCompletionView.class);
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public void perform(UiController uiController, View view) {
            ContactsCompletionView completionView = (ContactsCompletionView)view;
            InputConnection connection = completionView.testAccessibleInputConnection;
            connection.commitText(text, 1);
        }
    };
}
 
Example #12
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
private boolean shouldDoMvsShortcut(InputConnection ic, String text) {
    if (!text.equals(String.valueOf(MongolCode.Uni.A))
            && !text.equals(String.valueOf(MongolCode.Uni.E)))
        return false;
    CharSequence previousTwo = ic.getTextBeforeCursor(2, 0);
    return previousTwo != null
            && previousTwo.length() >= 2
            && MongolCode.isMvsPrecedingChar(previousTwo.charAt(0))
            && previousTwo.charAt(1) == text.charAt(0);
}
 
Example #13
Source File: BrailleIME.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Cancels the text composition by leaving the already-composed text there
 * and clearing the composition state. Use this when the user tries to
 * interact with the edit field before composition has finished.
 */
private boolean cancelComposingText() {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null) {
        LogUtils.log(this, Log.WARN, "missing IC %s", ic);
        return false;
    }

    mComposingBraille.clear();
    return ic.finishComposingText();
}
 
Example #14
Source File: Utf7ImeService.java    From android-unicode with MIT License 5 votes vote down vote up
private void toUnshifted() {
    // Log.d(TAG, "toUnshifted()");
    mIsShifted = false;
    mComposing.append(UTF7_UNSHIFT);
    String decoded = decodeUtf7(mComposing.toString());
    InputConnection ic = getCurrentInputConnection();
    ic.commitText(decoded, 1);
    mComposing = null;
}
 
Example #15
Source File: ReactEditTextInputConnectionWrapper.java    From react-native-GPay with MIT License 5 votes vote down vote up
public ReactEditTextInputConnectionWrapper(
    InputConnection target,
    final ReactContext reactContext,
    final ReactEditText editText
) {
  super(target, false);
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mEditText = editText;
}
 
Example #16
Source File: CtrlInputAction.java    From remotekeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Place the cursor on the last occusrance of a symbol
 * 
 * @param con
 *          driver
 * @param symbol
 *          the symbol to jump to
 */
private void jumpBackward(InputConnection con, int symbol) {
	ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
	if (txt != null) {
		int pos = txt.text.toString().lastIndexOf(symbol, txt.selectionEnd - 2);
		pos++;

		con.setSelection(pos, pos);
	}

}
 
Example #17
Source File: KeyboardSelectorWidget.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
private void updateStatus() {
    InputConnection ic = getCurrentIC();
    if (ic == null) {
        return;
    }
    CharSequence cs = ic.getSelectedText(0);
    boolean hasSelection = !TextUtils.isEmpty(cs);
    boolean hasClipData = ClipManager.getInstance().hasClipData();
    updateSelectAllStatus(hasSelection);
    updateCopyStatus(hasSelection);
    updatePasteStatus(hasClipData);
    updateDeleteStatus(hasSelection || !TextUtils.isEmpty(ic.getTextBeforeCursor(1, 0)));
}
 
Example #18
Source File: InputConnectionCompatUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static boolean requestCursorUpdatesImpl(final InputConnection inputConnection,
        final int cursorUpdateMode) {
    if (!isRequestCursorUpdatesAvailable()) {
         return false;
    }
    return sRequestCursorUpdatesMethod.invoke(inputConnection, cursorUpdateMode);
}
 
Example #19
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
    int caps = 0;
    EditorInfo ei = getCurrentInputEditorInfo();
    if (mAutoCapActive && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
        caps = ic.getCursorCapsMode(attr.inputType);
    }
    return caps;
}
 
Example #20
Source File: KeyboardWidget.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
private String getTextBeforeCursor(InputConnection aConnection) {
    if (aConnection == null) {
        return "";
    }

    ExtractedText extracted = aConnection.getExtractedText(new ExtractedTextRequest(),0);
    if ((extracted == null) || extracted.text == null) {
        return "";
    }

    String fullText = extracted.text.toString();
    return aConnection.getTextBeforeCursor(fullText.length(),0).toString();
}
 
Example #21
Source File: EditingUtil.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the word surrounding the cursor. Parameters are identical to
 * getWordAtCursor.
 */
public static void deleteWordAtCursor(
    InputConnection connection, String separators) {

    Range range = getWordRangeAtCursor(connection, separators, null);
    if (range == null) return;

    connection.finishComposingText();
    // Move cursor to beginning of word, to avoid crash when cursor is outside
    // of valid range after deleting text.
    int newCursor = getCursorPosition(connection) - range.charsBefore;
    connection.setSelection(newCursor, newCursor);
    connection.deleteSurroundingText(0, range.charsBefore + range.charsAfter);
}
 
Example #22
Source File: SDLActivity.java    From android-port with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    ic = new SDLInputConnection(this, true);

    outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
    outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
            | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;

    return ic;
}
 
Example #23
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private void sendAltKey(InputConnection ic, boolean isDown, boolean chording) {
    if (chording && delayChordingAltModifier()) return;

    int key = sKeyboardSettings.chordingAltKey;
    if (key == 0) key = KeyEvent.KEYCODE_ALT_LEFT;
    int meta = KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    if (isDown) {
        sendKeyDown(ic, key, meta);
    } else {
        sendKeyUp(ic, key, meta);
    }
}
 
Example #24
Source File: Utf7ImeService.java    From uiautomator-unicode-input-helper with Apache License 2.0 5 votes vote down vote up
private void toUnshifted() {
    // Log.d(TAG, "toUnshifted()");
    mIsShifted = false;
    mComposing.append(MODIFIED_UTF7_UNSHIFT);
    String decoded = decodeUtf7(mComposing.toString());
    InputConnection ic = getCurrentInputConnection();
    ic.commitText(decoded, 1);
    mComposing = null;
}
 
Example #25
Source File: TextInputEditText.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
  final InputConnection ic = super.onCreateInputConnection(outAttrs);
  if (ic != null && outAttrs.hintText == null) {
    // If we don't have a hint and our parent is a TextInputLayout, use its hint for the
    // EditorInfo. This allows us to display a hint in 'extract mode'.
    outAttrs.hintText = getHintFromLayout();
  }
  return ic;
}
 
Example #26
Source File: Pathfinder.java    From sinovoice-pathfinder with MIT License 5 votes vote down vote up
/**
 * Helper function to commit any text being composed in to the editor.
 */
private void commitTyped(InputConnection inputConnection) {
    if (mComposing.length() > 0) {
        inputConnection.commitText(mComposing, mComposing.length());
        mComposing.setLength(0);
        updateCandidates();
    }
}
 
Example #27
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
@Override
public void selectWordBack() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ExtractedText extractedText = ic.getExtractedText(new ExtractedTextRequest(), 0);
    int previousWordBoundary = getPreviousWordBoundary(extractedText.text, extractedText.selectionStart);
    int start = extractedText.startOffset + previousWordBoundary;
    int end = extractedText.startOffset + extractedText.selectionEnd;
    ic.setSelection(start, end);
}
 
Example #28
Source File: TerminalKeyboard.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void onText(CharSequence text) {
//        Log.v("SpartacusRex","SOFT : onText "+text.toString());

        InputConnection ic = getCurrentInputConnection();
        if (ic == null) return;
        ic.beginBatchEdit();
        if (mComposing.length() > 0) {
            commitTyped(ic);
        }
        ic.commitText(text, 0);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
    }
 
Example #29
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
public void onText(CharSequence text) {
    //mDeadAccentBuffer.clear();  // FIXME
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;
    if (mPredicting && text.length() == 1) {
        // If adding a single letter, treat it as a regular keystroke so
        // that completion works as expected.
        int c = text.charAt(0);
        if (!isWordSeparator(c)) {
            int[] codes = {c};
            handleCharacter(c, codes);
            return;
        }
    }
    abortCorrection(false);
    ic.beginBatchEdit();
    if (mPredicting) {
        commitTyped(ic, true);
    }
    maybeRemovePreviousPeriod(text);
    ic.commitText(text, 1);
    ic.endBatchEdit();
    updateShiftKeyState(getCurrentInputEditorInfo());
    mKeyboardSwitcher.onKey(0); // dummy key code.
    mJustRevertedSeparator = null;
    mJustAddedAutoSpace = false;
    mEnteredText = text;
}
 
Example #30
Source File: InputTestsBase.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    mEditText = new MyEditText(getContext());
    final int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    mEditText.setInputType(inputType);
    mEditText.setEnabled(true);
    mLastCursorPos = 0;
    if (null == Looper.myLooper()) {
        Looper.prepare();
    }
    setupService();
    mLatinIME = getService();
    setDebugMode(true);
    mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS,
            true, true /* defaultValue */);
    mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION,
            DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION);
    mLatinIME.onCreate();
    EditorInfo ei = new EditorInfo();
    final InputConnection ic = mEditText.onCreateInputConnection(ei);
    final LayoutInflater inflater =
            (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ViewGroup vg = new FrameLayout(getContext());
    mInputView = inflater.inflate(R.layout.input_view, vg);
    ei = enrichEditorInfo(ei);
    mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
    mLatinIME.setInputView(mInputView);
    mLatinIME.onBindInput();
    mLatinIME.onCreateInputView();
    mLatinIME.onStartInputView(ei, false);
    mInputConnection = ic;
    changeLanguage("en_US");
    // Run messages to avoid the messages enqueued by startInputView() and its friends
    // to run on a later call and ruin things. We need to wait first because some of them
    // can be posted with a delay (notably,  MSG_RESUME_SUGGESTIONS)
    sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
    runMessages();
}