本文整理汇总了Java中android.view.inputmethod.InputConnection类的典型用法代码示例。如果您正苦于以下问题:Java InputConnection类的具体用法?Java InputConnection怎么用?Java InputConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputConnection类属于android.view.inputmethod包,在下文中一共展示了InputConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkReCorrectionOnStart
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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();
}
}
}
示例2: doubleSpace
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
}
示例3: onText
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
示例4: revertLastWord
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
}
示例5: getPreviousWord
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
}
示例6: onRequestNewKeyboard
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
@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);
}
示例7: isCommitContentSupported
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
示例8: onUpdateSelection
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
/**
* 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();
}
}
}
示例9: onKey
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
@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;
}
}
示例10: onCreateInputConnection
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
@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;
}
示例11: onCreateInputConnection
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
@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;
}
示例12: onUpdateSelection
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
/**
* 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();
}
}
}
示例13: requestCursorUpdatesImpl
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
private static boolean requestCursorUpdatesImpl(final InputConnection inputConnection,
final int cursorUpdateMode) {
if (!isRequestCursorUpdatesAvailable()) {
return false;
}
return sRequestCursorUpdatesMethod.invoke(inputConnection, cursorUpdateMode);
}
示例14: readBackwardsUntil
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
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;
}
示例15: deleteSurroundingText
import android.view.inputmethod.InputConnection; //导入依赖的package包/类
private boolean deleteSurroundingText(int before, int after) {
final InputConnection ic = Ime.getCurrentInputConnection();
if(ic != null) {
ic.deleteSurroundingText(before, after);
return true;
}
return false;
}