本文整理匯總了Java中android.view.inputmethod.ExtractedText類的典型用法代碼示例。如果您正苦於以下問題:Java ExtractedText類的具體用法?Java ExtractedText怎麽用?Java ExtractedText使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ExtractedText類屬於android.view.inputmethod包,在下文中一共展示了ExtractedText類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkReCorrectionOnStart
import android.view.inputmethod.ExtractedText; //導入依賴的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: format
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/**
* Formats the recognised text by adding white spaces at the beginning or at the end, and
* by making the first char upper case if necessary.
*/
private String format(ExtractedText et, String result) {
int pos = et.selectionStart - 1;
while (pos > 0 && Character.isWhitespace(et.text.charAt(pos))) {
pos--;
}
if (pos == -1 || mUpperCaseChars.contains(et.text.charAt(pos))) {
result = Character.toUpperCase(result.charAt(0)) + result.substring(1);
}
if (et.selectionStart - 1 > 0
&& !Character.isWhitespace(et.text.charAt(et.selectionStart - 1))) {
result = " " + result;
}
if (et.selectionEnd < et.text.length()
&& !Character.isWhitespace(et.text.charAt(et.selectionEnd))) {
result = result + " ";
}
return result;
}
示例3: replace
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
@Override
public boolean replace(String str1, String str2) {
boolean success = false;
mInputConnection.beginBatchEdit();
ExtractedText extractedText = mInputConnection.getExtractedText(new ExtractedTextRequest(), 0);
if (extractedText != null) {
CharSequence beforeCursor = extractedText.text;
//CharSequence beforeCursor = mInputConnection.getTextBeforeCursor(MAX_SELECTABLE_CONTEXT, 0);
Log.i("replace: " + beforeCursor);
int index = beforeCursor.toString().lastIndexOf(str1);
Log.i("replace: " + index);
if (index > 0) {
mInputConnection.setSelection(index, index);
mInputConnection.deleteSurroundingText(0, str1.length());
if (!str2.isEmpty()) {
mInputConnection.commitText(str2, 0);
}
success = true;
}
mInputConnection.endBatchEdit();
}
return success;
}
開發者ID:vaibhavs4424,項目名稱:AI-Powered-Intelligent-Banking-Platform,代碼行數:24,代碼來源:InputConnectionCommandEditor.java
示例4: testSelectionUpdate
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Selection should change after onUpdateSelection. */
public void testSelectionUpdate(){
EditorInfo ei = getSampleEditorInfo();
ei.imeOptions |= EditorInfo.IME_ACTION_NONE;
ExtractedText et = getSampleExtractedText();
et.selectionStart = 3;
et.selectionEnd = 3;
autoStub(mDisplayManager, mInputConnection, ei, et);
createBindAndStart(ei);
// Check selection, update and check again.
verifyDisplayContentMatches("Hello world!", 3, 3);
mIME.onUpdateSelection(3, 3, 3, 6, 0, 0);
verifyDisplayContentMatches("Hello world!", 3, 6);
finishUnbindAndDestroy();
}
示例5: testRouteActionLabel
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** A routing key press on the button should invoke the default action. */
public void testRouteActionLabel() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
ArgumentCaptor<DisplayManager.Content> content =
ArgumentCaptor.forClass(DisplayManager.Content.class);
autoStub(mDisplayManager, mFeedbackManager, mInputConnection, ei, et);
doReturn(true).when(mIME).sendDefaultEditorAction(anyBoolean());
createBindAndStart(ei);
// Grab and verify the populated content.
verify(mDisplayManager).setContent(content.capture());
assertEquals("Hello world! [Execute]",
content.getValue().getText().toString());
// Send a routing event back.
// Default action should be sent, with no feedback from the IME.
Mockito.reset(mFeedbackManager);
mIME.route(16, content.getValue());
verify(mIME).sendDefaultEditorAction(anyBoolean());
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例6: testRouteActionLabelFail
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/**
* If the default action cannot be invoked, the IME should emit failure
* feedback.
*/
public void testRouteActionLabelFail() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
ArgumentCaptor<DisplayManager.Content> content =
ArgumentCaptor.forClass(DisplayManager.Content.class);
autoStub(mDisplayManager, mFeedbackManager, mInputConnection, ei, et);
doReturn(false).when(mIME).sendDefaultEditorAction(anyBoolean());
createBindAndStart(ei);
// Grab and verify the populated content.
verify(mDisplayManager).setContent(content.capture());
assertEquals("Hello world! [Execute]",
content.getValue().getText().toString());
// Send a routing event back.
// Default action should be sent, and feedback should be emitted.
Mockito.reset(mFeedbackManager);
mIME.route(16, content.getValue());
verify(mIME).sendDefaultEditorAction(anyBoolean());
verify(mFeedbackManager).emitFeedback(
FeedbackManager.TYPE_COMMAND_FAILED);
finishUnbindAndDestroy();
}
示例7: testRouteMoveCursor
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** If the routing key is within the text, the cursor should move. */
public void testRouteMoveCursor() {
EditorInfo ei = getSampleEditorInfo();
ei.label = "Label";
ExtractedText et = getSampleExtractedText();
ArgumentCaptor<DisplayManager.Content> content =
ArgumentCaptor.forClass(DisplayManager.Content.class);
autoStub(mDisplayManager, mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.setSelection(3, 3)).thenReturn(true);
createBindAndStart(ei);
// Grab and verify the populated content.
verify(mDisplayManager).setContent(content.capture());
assertEquals("Label: Hello world! [Execute]",
content.getValue().getText().toString());
// Send a routing event back.
// The selection should change, and no feedback should be emitted.
Mockito.reset(mFeedbackManager);
mIME.route(10, content.getValue());
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例8: testRouteMoveCursorFail
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/**
* If the routing key is within the text, but moving fails, feedback
* should be emitted.
*/
public void testRouteMoveCursorFail() {
EditorInfo ei = getSampleEditorInfo();
ei.label = "Label";
ExtractedText et = getSampleExtractedText();
ArgumentCaptor<DisplayManager.Content> content =
ArgumentCaptor.forClass(DisplayManager.Content.class);
autoStub(mDisplayManager, mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.setSelection(3, 3)).thenReturn(false);
createBindAndStart(ei);
// Grab and verify the populated content.
verify(mDisplayManager).setContent(content.capture());
assertEquals("Label: Hello world! [Execute]",
content.getValue().getText().toString());
// Send a routing event back.
// The selection should change, and no feedback should be emitted.
Mockito.reset(mFeedbackManager);
mIME.route(10, content.getValue());
verify(mFeedbackManager).emitFeedback(
FeedbackManager.TYPE_COMMAND_FAILED);
finishUnbindAndDestroy();
}
示例9: testRouteOutOfBounds
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/**
* If a routing key press occurs anywhere else, the IME should emit
* feedback.
*/
public void testRouteOutOfBounds() {
EditorInfo ei = getSampleEditorInfo();
ei.label = "Label";
ExtractedText et = getSampleExtractedText();
ArgumentCaptor<DisplayManager.Content> content =
ArgumentCaptor.forClass(DisplayManager.Content.class);
autoStub(mDisplayManager, mFeedbackManager, mInputConnection, ei, et);
createBindAndStart(ei);
// Grab and verify the populated content.
verify(mDisplayManager).setContent(content.capture());
assertEquals("Label: Hello world! [Execute]",
content.getValue().getText().toString());
// Send a routing event back.
// The selection should change, and no feedback should be emitted.
Mockito.reset(mFeedbackManager);
mIME.route(1, content.getValue());
verify(mFeedbackManager).emitFeedback(
FeedbackManager.TYPE_NAVIGATE_OUT_OF_BOUNDS);
finishUnbindAndDestroy();
}
示例10: testSendDefaultAction
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Default action when no custom action is specified. */
public void testSendDefaultAction() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
doReturn(true).when(mIME).sendDefaultEditorAction(anyBoolean());
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
assertTrue(mIME.sendDefaultAction());
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例11: testSendDefaultActionCustom
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Default action when a custom action is specified. */
public void testSendDefaultActionCustom() {
EditorInfo ei = getSampleEditorInfo();
ei.actionId = 1337;
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.performEditorAction(1337)).thenReturn(true);
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
assertTrue(mIME.sendDefaultAction());
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例12: testSendDefaultActionFail
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/**
* Tests that {@link #sendDefaultAction} returns false on failure.
* At the moment, no feedback is emitted in this method.
*/
public void testSendDefaultActionFail() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
doReturn(false).when(mIME).sendDefaultEditorAction(anyBoolean());
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
assertFalse(mIME.sendDefaultAction());
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例13: testMoveCursorCharacterGranularityFail
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Tests when moving by character granularity fails. */
public void testMoveCursorCharacterGranularityFail() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.sendKeyEvent(isA(KeyEvent.class)))
.thenReturn(false);
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
mIME.moveCursor(BrailleIME.DIRECTION_FORWARD,
AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
verify(mInputConnection).sendKeyEvent(keyEventMatches(
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
verify(mFeedbackManager).emitFeedback(
FeedbackManager.TYPE_COMMAND_FAILED);
finishUnbindAndDestroy();
}
示例14: testSendAndroidKey
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Tests sending an Android key code. */
public void testSendAndroidKey() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.sendKeyEvent(isA(KeyEvent.class)))
.thenReturn(true);
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
mIME.sendAndroidKey(KeyEvent.KEYCODE_ENTER);
verify(mInputConnection).sendKeyEvent(keyEventMatches(
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
verify(mInputConnection).sendKeyEvent(keyEventMatches(
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
verify(mFeedbackManager, never()).emitFeedback(anyInt());
verify(mFeedbackManager, never()).emitOnFailure(eq(false), anyInt());
finishUnbindAndDestroy();
}
示例15: testSendAndroidKeyFail
import android.view.inputmethod.ExtractedText; //導入依賴的package包/類
/** Tests feedback when sending an Android key code fails. */
public void testSendAndroidKeyFail() {
EditorInfo ei = getSampleEditorInfo();
ExtractedText et = getSampleExtractedText();
autoStub(mFeedbackManager, mInputConnection, ei, et);
when(mInputConnection.sendKeyEvent(isA(KeyEvent.class)))
.thenReturn(false);
createBindAndStart(ei);
Mockito.reset(mFeedbackManager);
mIME.sendAndroidKey(KeyEvent.KEYCODE_ENTER);
verify(mInputConnection).sendKeyEvent(keyEventMatches(
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
verify(mFeedbackManager).emitFeedback(
FeedbackManager.TYPE_COMMAND_FAILED);
finishUnbindAndDestroy();
}