本文整理汇总了Java中android.view.inputmethod.InputConnection.beginBatchEdit方法的典型用法代码示例。如果您正苦于以下问题:Java InputConnection.beginBatchEdit方法的具体用法?Java InputConnection.beginBatchEdit怎么用?Java InputConnection.beginBatchEdit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.inputmethod.InputConnection
的用法示例。
在下文中一共展示了InputConnection.beginBatchEdit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: swapPunctuationAndSpace
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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;
}
}
示例4: reswapPeriodAndSpace
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
private void reswapPeriodAndSpace() {
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
if (lastThree != null && lastThree.length() == 3
&& lastThree.charAt(0) == KEYCODE_PERIOD
&& lastThree.charAt(1) == KEYCODE_SPACE
&& lastThree.charAt(2) == KEYCODE_PERIOD) {
ic.beginBatchEdit();
ic.deleteSurroundingText(3, 0);
ic.commitText(" ..", 1);
ic.endBatchEdit();
updateShiftKeyState(getCurrentInputEditorInfo());
}
}
示例5: setOldSuggestions
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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);
}
}
示例6: onText
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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());
}
示例7: onText
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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());
}
示例8: onText
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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();
}
示例9: onText
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
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());
}
示例10: handleBackspace
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
private void handleBackspace() {
boolean deleteChar = false;
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
ic.beginBatchEdit();
if (mPredicting) {
final int length = mComposing.length();
if (length > 0) {
mComposing.delete(length - 1, length);
mWord.deleteLast();
ic.setComposingText(mComposing, 1);
if (mComposing.length() == 0) {
mPredicting = false;
}
postUpdateSuggestions();
} else {
ic.deleteSurroundingText(1, 0);
}
} else {
deleteChar = true;
}
postUpdateShiftKeyState();
TextEntryState.backspace();
if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) {
revertLastWord(deleteChar);
ic.endBatchEdit();
return;
} else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
ic.deleteSurroundingText(mEnteredText.length(), 0);
} else if (deleteChar) {
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
// Go back to the suggestion mode if the user canceled the
// "Touch again to save".
// NOTE: In gerenal, we don't revert the word when backspacing
// from a manual suggestion pick. We deliberately chose a
// different behavior only in the case of picking the first
// suggestion (typed word). It's intentional to have made this
// inconsistent with backspacing after selecting other suggestions.
revertLastWord(deleteChar);
} else {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
if (mDeleteCount > DELETE_ACCELERATE_AT) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
}
}
}
mJustRevertedSeparator = null;
ic.endBatchEdit();
}
示例11: handleSeparator
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
private void handleSeparator(int primaryCode) {
// Should dismiss the "Touch again to save" message when handling separator
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
postUpdateSuggestions();
}
boolean pickedDefault = false;
// Handle separator
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.beginBatchEdit();
abortCorrection(false);
}
if (mPredicting) {
// In certain languages where single quote is a separator, it's better
// not to auto correct, but accept the typed word. For instance,
// in Italian dov' should not be expanded to dove' because the elision
// requires the last vowel to be removed.
if (mAutoCorrectOn && primaryCode != '\'' &&
(mJustRevertedSeparator == null
|| mJustRevertedSeparator.length() == 0
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
pickedDefault = pickDefaultSuggestion();
// Picked the suggestion by the space key. We consider this
// as "added an auto space".
if (primaryCode == KEYCODE_SPACE) {
mJustAddedAutoSpace = true;
}
} else {
commitTyped(ic);
}
}
if (mJustAddedAutoSpace && primaryCode == KEYCODE_ENTER) {
removeTrailingSpace();
mJustAddedAutoSpace = false;
}
sendKeyChar((char)primaryCode);
// Handle the case of ". ." -> " .." with auto-space if necessary
// before changing the TextEntryState.
if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED
&& primaryCode == KEYCODE_PERIOD) {
reswapPeriodAndSpace();
}
TextEntryState.typedCharacter((char) primaryCode, true);
if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED
&& primaryCode != KEYCODE_ENTER) {
swapPunctuationAndSpace();
} else if (isPredictionOn() && primaryCode == KEYCODE_SPACE) {
doubleSpace();
}
if (pickedDefault) {
TextEntryState.backToAcceptedDefault(mWord.getTypedWord());
}
updateShiftKeyState(getCurrentInputEditorInfo());
if (ic != null) {
ic.endBatchEdit();
}
}
示例12: commitResult
import android.view.inputmethod.InputConnection; //导入方法依赖的package包/类
private void commitResult() {
if (mLastRecognitionResult == null) {
return;
}
String result = mLastRecognitionResult;
InputConnection conn = mInputMethodService.getCurrentInputConnection();
if (conn == null) {
Log.i(TAG, "Unable to commit recognition result, as the current input connection "
+ "is null. Did someone kill the IME?");
return;
}
if (!conn.beginBatchEdit()) {
Log.i(TAG, "Unable to commit recognition result, as a batch edit cannot start");
return;
}
try {
ExtractedTextRequest etr = new ExtractedTextRequest();
etr.flags = InputConnection.GET_TEXT_WITH_STYLES;
ExtractedText et = conn.getExtractedText(etr, 0);
if (et == null) {
Log.i(TAG, "Unable to commit recognition result, as extracted text is null");
return;
}
if (et.text != null) {
if (et.selectionStart != et.selectionEnd) {
conn.deleteSurroundingText(et.selectionStart, et.selectionEnd);
}
result = format(et, result);
}
if (!conn.commitText(result, 0)) {
Log.i(TAG, "Unable to commit recognition result");
return;
}
mLastRecognitionResult = null;
} finally {
conn.endBatchEdit();
}
}