当前位置: 首页>>代码示例>>Java>>正文


Java ExtractedText类代码示例

本文整理汇总了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();
        }
    }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:23,代码来源:KP2AKeyboard.java

示例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;
}
 
开发者ID:MohammadAlBanna,项目名称:Swift-Braille-Soft-keyboard,代码行数:27,代码来源:IntentApiTrigger.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:19,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:27,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:30,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:27,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:30,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:29,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:17,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:18,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:20,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:21,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:22,代码来源:BrailleIMETest.java

示例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();
}
 
开发者ID:google,项目名称:brailleback,代码行数:20,代码来源:BrailleIMETest.java


注:本文中的android.view.inputmethod.ExtractedText类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。