java类android.view.inputmethod.InputConnection的实例源码

KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 39 收藏 0 点赞 0 评论 0
private void checkReCorrectionOnStart() {
    if (mReCorrectionEnabled && isPredictionOn()) {
        // First get the cursor position. This is required by setOldSuggestions(), so that
        // it can pass the correct range to setComposingRegion(). At this point, we don't
        // have valid values for mLastSelectionStart/Stop because onUpdateSelection() has
        // not been called yet.
        InputConnection ic = getCurrentInputConnection();
        if (ic == null) return;
        ExtractedTextRequest etr = new ExtractedTextRequest();
        etr.token = 0; // anything is fine here
        ExtractedText et = ic.getExtractedText(etr, 0);
        if (et == null) return;

        mLastSelectionStart = et.startOffset + et.selectionStart;
        mLastSelectionEnd = et.startOffset + et.selectionEnd;

        // Then look for possible corrections in a delayed fashion
        if (!TextUtils.isEmpty(et.text) && isCursorTouchingWord()) {
            postUpdateOldSuggestions();
        }
    }
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 30 收藏 0 点赞 0 评论 0
private void doubleSpace() {
    //if (!mAutoPunctuate) return;
    if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
    if (lastThree != null && lastThree.length() == 3
            && Character.isLetterOrDigit(lastThree.charAt(0))
            && lastThree.charAt(1) == KEYCODE_SPACE && lastThree.charAt(2) == KEYCODE_SPACE) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);
        ic.commitText(". ", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
        mJustAddedAutoSpace = true;
    }
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 40 收藏 0 点赞 0 评论 0
public void onText(CharSequence text) {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    if (text == null)
    {
        Log.e("KP2AK", "text = null!");
        return;
    }
    abortCorrection(false);
    ic.beginBatchEdit();
    if (mPredicting) {
        commitTyped(ic);
    }
    maybeRemovePreviousPeriod(text);
    ic.commitText(text, 1);
    ic.endBatchEdit();
    updateShiftKeyState(getCurrentInputEditorInfo());
    mKeyboardSwitcher.onKey(0); // dummy key code.
    mJustRevertedSeparator = null;
    mJustAddedAutoSpace = false;
    mEnteredText = text;
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 34 收藏 0 点赞 0 评论 0
public void revertLastWord(boolean deleteChar) {
    final int length = mComposing.length();
    if (!mPredicting && length > 0) {
        final InputConnection ic = getCurrentInputConnection();
        mPredicting = true;
        mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
        if (deleteChar) ic.deleteSurroundingText(1, 0);
        int toDelete = mCommittedLength;
        CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
        if (toTheLeft != null && toTheLeft.length() > 0
                && isWordSeparator(toTheLeft.charAt(0))) {
            toDelete--;
        }
        ic.deleteSurroundingText(toDelete, 0);
        ic.setComposingText(mComposing, 1);
        TextEntryState.backspace();
        postUpdateSuggestions();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
        mJustRevertedSeparator = null;
    }
}
EditingUtil.java 文件源码 项目:keepass2android 阅读 31 收藏 0 点赞 0 评论 0
public static CharSequence getPreviousWord(InputConnection connection,
        String sentenceSeperators) {
    //TODO: Should fix this. This could be slow!
    CharSequence prev = connection.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
    if (prev == null) {
        return null;
    }
    String[] w = spaceRegex.split(prev);
    if (w.length >= 2 && w[w.length-2].length() > 0) {
        char lastChar = w[w.length-2].charAt(w[w.length-2].length() -1);
        if (sentenceSeperators.contains(String.valueOf(lastChar))) {
            return null;
        }
        return w[w.length-2];
    } else {
        return null;
    }
}
ImeContainer.java 文件源码 项目:mongol-library 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void onRequestNewKeyboard(String keyboardDisplayName) {

    Keyboard newKeyboard = null;
    for (Keyboard keyboard : mKeyboardCandidates) {
        if (keyboard.getDisplayName().equals(keyboardDisplayName)) {
            newKeyboard = keyboard;
        }
    }

    if (newKeyboard == null) return;

    this.removeView(mCurrentKeyboard);
    newKeyboard.setKeyboardListener(this);
    this.addView(newKeyboard);
    mCurrentKeyboard = newKeyboard;
    InputConnection ic = getInputConnection();
    mCurrentKeyboard.setInputConnection(ic);
}
KeyboardService.java 文件源码 项目:ROKOmoji.Emoji.Keyboard.App-Android 阅读 32 收藏 0 点赞 0 评论 0
private boolean isCommitContentSupported(@Nullable EditorInfo editorInfo, @NonNull String mimeType) {
    if (editorInfo == null) {
        return false;
    }

    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) {
        return false;
    }

    if (!validatePackageName(editorInfo)) {
        return false;
    }

    final String[] supportedMimeTypes = EditorInfoCompat.getContentMimeTypes(editorInfo);
    for (String supportedMimeType : supportedMimeTypes) {
        if (ClipDescription.compareMimeTypes(mimeType, supportedMimeType)) {
            return true;
        }
    }
    return false;
}
PCKeyboard.java 文件源码 项目:behe-keyboard 阅读 43 收藏 0 点赞 0 评论 0
/**
 * Deal with the editor reporting movement of its cursor.
 */
@Override public void onUpdateSelection(int oldSelStart, int oldSelEnd,
                                        int newSelStart, int newSelEnd,
                                        int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
            candidatesStart, candidatesEnd);

    // If the current selection in the text view changes, we should
    // clear whatever candidate text we have.
    if (mComposing.length() > 0 && (newSelStart != candidatesEnd
            || newSelEnd != candidatesEnd)) {
        mComposing.setLength(0);
        updateCandidates();
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            ic.finishComposingText();
        }
    }
}
AirBoard.java 文件源码 项目:airboard 阅读 34 收藏 0 点赞 0 评论 0
@Override
  public void onKey(int primaryCode, int[] keyCodes) {
      InputConnection ic = getCurrentInputConnection() ;
      playclick(primaryCode);
      switch (primaryCode) {
          case Keyboard.KEYCODE_DELETE:
              ic.deleteSurroundingText(1, 0);
              break;
          case Keyboard.KEYCODE_SHIFT:
              caps = !caps;
              keyboard.setShifted(caps);
              kv.invalidateAllKeys();
              break;
          case Keyboard.KEYCODE_DONE:
              ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
              break;
          default:
              char code = (char) primaryCode;
              if(Character.isLetter(code) && caps) {
                  code = Character.toUpperCase(code);
              }

              ic.commitText(String.valueOf(code), 1);
break;
      }
  }
TextInputAutoCompleteTextView.java 文件源码 项目:CouponsTracker 阅读 27 收藏 0 点赞 0 评论 0
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    /*
    Taken from:
    https://android.googlesource.com/platform/frameworks/support.git/+/master/design/src/android/support/design/widget/TextInputEditText.java
    to extend TextInputEditText functionality to AppCompatAutoCompleteTextView.
     */

    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 it's hint for the
        // EditorInfo. This allows us to display a hint in 'extract mode'.
        ViewParent parent = getParent();
        while (parent instanceof View) {
            if (parent instanceof TextInputLayout) {
                outAttrs.hintText = ((TextInputLayout) parent).getHint();
                break;
            }
            parent = parent.getParent();
        }
    }
    return ic;
}
SDLActivity.java 文件源码 项目:cdep-android-studio-freetype-sample 阅读 34 收藏 0 点赞 0 评论 0
@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
            | 33554432 /* API 11: EditorInfo.IME_FLAG_NO_FULLSCREEN */;

    return ic;
}
TerminalKeyboard.java 文件源码 项目:javaide 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Deal with the editor reporting movement of its cursor.
 */
@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
                              int newSelStart, int newSelEnd,
                              int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
            candidatesStart, candidatesEnd);

    // If the current selection in the text view changes, we should
    // clear whatever candidate text we have.
    if (mComposing.length() > 0 && (newSelStart != candidatesEnd
            || newSelEnd != candidatesEnd)) {
        mComposing.setLength(0);
        updateCandidates();
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            ic.finishComposingText();
        }
    }
}
InputConnectionCompatUtils.java 文件源码 项目:AOSP-Kayboard-7.1.2 阅读 30 收藏 0 点赞 0 评论 0
private static boolean requestCursorUpdatesImpl(final InputConnection inputConnection,
        final int cursorUpdateMode) {
    if (!isRequestCursorUpdatesAvailable()) {
         return false;
    }
    return sRequestCursorUpdatesMethod.invoke(inputConnection, cursorUpdateMode);
}
SDLActivity.java 文件源码 项目:sdl2-cross-platform-vs2017 阅读 38 收藏 0 点赞 0 评论 0
@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
            | 33554432 /* API 11: EditorInfo.IME_FLAG_NO_FULLSCREEN */;

    return ic;
}
SDLActivity.java 文件源码 项目:SDL2_gradle_template 阅读 38 收藏 0 点赞 0 评论 0
@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
            | 33554432 /* API 11: EditorInfo.IME_FLAG_NO_FULLSCREEN */;

    return ic;
}
ThumbkeyboardView.java 文件源码 项目:Thumbkeyboard 阅读 29 收藏 0 点赞 0 评论 0
String readBackwardsUntil(String p, boolean eof) {
    final InputConnection ic = Ime.getCurrentInputConnection();
    if(ic == null) return null;
    int size = 32;
    String c = null;
    while(size < 4096) {
        c = ic.getTextBeforeCursor(size, 0).toString();
        int idx = c.lastIndexOf(p);
        if(idx >= 0) { return c.substring(idx + 1); }
        size *= 2;
    }
    return eof ? c : null;
}
ThumbkeyboardView.java 文件源码 项目:Thumbkeyboard 阅读 33 收藏 0 点赞 0 评论 0
private boolean deleteSurroundingText(int before, int after) {
    final InputConnection ic = Ime.getCurrentInputConnection();
    if(ic != null) {
        ic.deleteSurroundingText(before, after);
        return true;
    }
    return false;
}
Limit.java 文件源码 项目:stynico 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 输入法
 * @param outAttrs
 * @return
 */
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs)
{
    return new mInputConnecttion(super.onCreateInputConnection(outAttrs),
     false);
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 35 收藏 0 点赞 0 评论 0
@Override
public void onConfigurationChanged(Configuration conf) {
    // If the system locale changes and is different from the saved
    // locale (mSystemLocale), then reload the input locale list from the
    // latin ime settings (shared prefs) and reset the input locale
    // to the first one.
    final String systemLocale = conf.locale.toString();
    if (!TextUtils.equals(systemLocale, mSystemLocale)) {
        mSystemLocale = systemLocale;
        if (mLanguageSwitcher != null) {
            mLanguageSwitcher.loadLocales(
                    PreferenceManager.getDefaultSharedPreferences(this));
            mLanguageSwitcher.setSystemLocale(conf.locale);
            toggleLanguage(true, true);
        } else {
            reloadKeyboards();
        }
    }
    // If orientation changed while predicting, commit the change
    if (conf.orientation != mOrientation) {
        InputConnection ic = getCurrentInputConnection();
        commitTyped(ic);
        if (ic != null) ic.finishComposingText(); // For voice input
        mOrientation = conf.orientation;
        reloadKeyboards();
    }
    mConfigurationChanging = true;
    super.onConfigurationChanged(conf);
    mConfigurationChanging = false;
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 33 收藏 0 点赞 0 评论 0
private void commitTyped(InputConnection inputConnection) {
    if (mPredicting) {
        mPredicting = false;
        if (mComposing.length() > 0) {
            if (inputConnection != null) {
                inputConnection.commitText(mComposing, 1);
            }
            mCommittedLength = mComposing.length();
            TextEntryState.acceptedTyped(mComposing);
            addToDictionaries(mComposing, AutoDictionary.FREQUENCY_FOR_TYPED);
        }
        updateSuggestions();
    }
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 37 收藏 0 点赞 0 评论 0
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
    int caps = 0;
    EditorInfo ei = getCurrentInputEditorInfo();
    if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
        caps = ic.getCursorCapsMode(attr.inputType);
    }
    return caps;
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 30 收藏 0 点赞 0 评论 0
private void swapPunctuationAndSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    CharSequence lastTwo = ic.getTextBeforeCursor(2, 0);
    if (lastTwo != null && lastTwo.length() == 2
            && lastTwo.charAt(0) == KEYCODE_SPACE && isSentenceSeparator(lastTwo.charAt(1))) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);
        ic.commitText(lastTwo.charAt(1) + " ", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
        mJustAddedAutoSpace = true;
    }
}
RTextEditorView.java 文件源码 项目:RTextEditorView 阅读 39 收藏 0 点赞 0 评论 0
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
    if (isIncognitoModeEnabled) {
        outAttrs.imeOptions = outAttrs.imeOptions
                | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING;
    }
    return inputConnection;
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 33 收藏 0 点赞 0 评论 0
private void removeTrailingSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;

    CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
    if (lastOne != null && lastOne.length() == 1
            && lastOne.charAt(0) == KEYCODE_SPACE) {
        ic.deleteSurroundingText(1, 0);
    }
}
TerminalKeyboard.java 文件源码 项目:javaide 阅读 32 收藏 0 点赞 0 评论 0
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());
    }
ComposeText.java 文件源码 项目:Cable-Android 阅读 38 收藏 0 点赞 0 评论 0
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
  InputConnection inputConnection = super.onCreateInputConnection(editorInfo);

  if(TextSecurePreferences.isEnterSendsEnabled(getContext())) {
    editorInfo.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
  }

  if (Build.VERSION.SDK_INT < 21) return inputConnection;
  if (mediaListener == null)      return inputConnection;
  if (inputConnection == null)    return null;

  EditorInfoCompat.setContentMimeTypes(editorInfo, new String[] {"image/jpeg", "image/png", "image/gif"});
  return InputConnectionCompat.createWrapper(inputConnection, editorInfo, new CommitContentListener(mediaListener));
}
SmartMyan.java 文件源码 项目:myan 阅读 33 收藏 0 点赞 0 评论 0
public void onText(CharSequence text) {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    ic.beginBatchEdit();
    if (mComposing.length() > 0) {
        commitTyped(ic);
    }
    ic.commitText(text, 0);
    ic.endBatchEdit();
    updateShiftKeyState(getCurrentInputEditorInfo());
}
KP2AKeyboard.java 文件源码 项目:keepass2android 阅读 28 收藏 0 点赞 0 评论 0
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);

        if (touching != null && touching.word.length() > 1) {
            ic.beginBatchEdit();

            if (!applyTypedAlternatives(touching)) {
                abortCorrection(true);
            } else {
                TextEntryState.selectedForCorrection();
                EditingUtil.underlineWord(ic, touching);
            }

            ic.endBatchEdit();
        } else {
            abortCorrection(true);
            setNextSuggestions();  // Show the punctuation suggestions list
        }
    } else {
        abortCorrection(true);
    }
}
Hints.java 文件源码 项目:keepass2android 阅读 30 收藏 0 点赞 0 评论 0
public boolean showPunctuationHintIfNecessary(InputConnection ic) {
    if (!mVoiceResultContainedPunctuation
            && ic != null
            && getAndIncrementPref(PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT)
                    < mPunctuationHintMaxDisplays) {
        CharSequence charBeforeCursor = ic.getTextBeforeCursor(1, 0);
        if (SPEAKABLE_PUNCTUATION.containsKey(charBeforeCursor)) {
            showHint(R.layout.voice_punctuation_hint);
            return true;
        }
    }

    return false;
}
EditingUtil.java 文件源码 项目:keepass2android 阅读 30 收藏 0 点赞 0 评论 0
private static int getCursorPosition(InputConnection connection) {
    ExtractedText extracted = connection.getExtractedText(
        new ExtractedTextRequest(), 0);
    if (extracted == null) {
      return -1;
    }
    return extracted.startOffset + extracted.selectionStart;
}


问题


面经


文章

微信
公众号

扫码关注公众号