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


Java ExtractedTextRequest类代码示例

本文整理汇总了Java中android.view.inputmethod.ExtractedTextRequest的典型用法代码示例。如果您正苦于以下问题:Java ExtractedTextRequest类的具体用法?Java ExtractedTextRequest怎么用?Java ExtractedTextRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExtractedTextRequest类属于android.view.inputmethod包,在下文中一共展示了ExtractedTextRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkReCorrectionOnStart

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的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: replace

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的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

示例3: onStartInput

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
@Override
public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);
    LogUtils.log(this, Log.VERBOSE,
            "onStartInput: inputType: %x, imeOption: %x, " +
            ", label: %s, hint: %s, package: %s, ",
            attribute.inputType, attribute.imeOptions, attribute.label,
            attribute.hintText, attribute.packageName);
    InputConnection ic = getCurrentInputConnection();
    if (ic != null) {
        ExtractedTextRequest req = new ExtractedTextRequest();
        req.token = ++mExtractedTextToken;
        req.hintMaxChars = MAX_REQUEST_CHARS;
        mExtractedText = getCurrentInputConnection().getExtractedText(req,
                InputConnection.GET_EXTRACTED_TEXT_MONITOR);
    } else {
        mExtractedText = null;
    }
    updateCurrentText();
    updateDisplay();

    Host host = getHost();
    if (host != null) {
        host.onStartInput(attribute, restarting);
    }
}
 
开发者ID:google,项目名称:brailleback,代码行数:27,代码来源:BrailleIME.java

示例4: autoStub

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
/**
 * Injects objects into their usual places in the mocks and stubs.
 * Simplifies boilerplate stubbing.
 */
private void autoStub(Object... objects) {
    for (Object o : objects) {
        if (o == mBrailleTranslator) {
            when(mHost.getBrailleTranslator())
                .thenReturn(mBrailleTranslator);
        } else if (o == mDisplayManager) {
            when(mHost.getDisplayManager()).thenReturn(mDisplayManager);
        } else if (o == mFeedbackManager) {
            when(mHost.getFeedbackManager()).thenReturn(mFeedbackManager);
        } else if (o == mInputConnection) {
            when(mIME.getCurrentInputConnection())
                .thenReturn(mInputConnection);
        } else if (o instanceof EditorInfo) {
            when(mIME.getCurrentInputEditorInfo())
                .thenReturn((EditorInfo) o);
        } else if (o instanceof ExtractedText) {
            when(mInputConnection.getExtractedText(
                    isA(ExtractedTextRequest.class), anyInt()))
                .thenReturn((ExtractedText) o);
        } else {
            throw new UnsupportedOperationException(
                    "can't auto-stub " + o.toString());
        }
    }
}
 
开发者ID:google,项目名称:brailleback,代码行数:30,代码来源:BrailleIMETest.java

示例5: replaceText

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
/**
 * Try to replace the current word with its substitution.
 */
private void replaceText(InputConnection con) {
	ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
	if (txt != null) {
		int end = txt.text.toString().indexOf(" ", txt.selectionEnd);
		if (end == -1) {
			end = txt.text.length();
		}
		int start = txt.text.toString().lastIndexOf(" ", txt.selectionEnd - 1);
		start++;
		String sel = txt.text.subSequence(start, end).toString();
		String rep = myService.replacements.get(sel);
		if (rep != null) {
			con.setComposingRegion(start, end);
			con.setComposingText(rep, 1);
			con.finishComposingText();
		}
		else {
			String err = myService.getResources().getString(
					R.string.err_no_replacement, sel);
			Toast.makeText(myService, err, Toast.LENGTH_SHORT).show();
		}
	}
}
 
开发者ID:onyxbits,项目名称:remotekeyboard,代码行数:27,代码来源:CtrlInputAction.java

示例6: getCursorPosition

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
private static int getCursorPosition(InputConnection connection) {
    ExtractedText extracted = connection.getExtractedText(
        new ExtractedTextRequest(), 0);
    if (extracted == null) {
      return -1;
    }
    return extracted.startOffset + extracted.selectionStart;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:9,代码来源:EditingUtil.java

示例7: checkConsistencyForDebug

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:32,代码来源:RichInputConnection.java

示例8: getAllInputText

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
public static String getAllInputText(InputConnection inputConnection) {
    String allText = "";
    try {
        ExtractedText extractedText = inputConnection.getExtractedText(new ExtractedTextRequest(), 0);
        if (extractedText != null) {
            allText = extractedText.text.toString();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return allText;
}
 
开发者ID:MohammadAlBanna,项目名称:Swift-Braille-Soft-keyboard,代码行数:13,代码来源:Common.java

示例9: select

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
@Override
public boolean select(String str) {
    boolean success = false;
    mInputConnection.beginBatchEdit();
    ExtractedText extractedText = mInputConnection.getExtractedText(new ExtractedTextRequest(), 0);
    CharSequence beforeCursor = extractedText.text;
    int index = beforeCursor.toString().lastIndexOf(str);
    if (index > 0) {
        mInputConnection.setSelection(index, index + str.length());
        success = true;
    }
    mInputConnection.endBatchEdit();
    return success;
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:15,代码来源:InputConnectionCommandEditor.java

示例10: testLifecycle

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
/** Tests that lifecycle events are passed to the host. */
public void testLifecycle() {
    EditorInfo editorInfo = getSampleEditorInfo();

    doReturn(null).when(mIME).getCurrentInputConnection();
    mIME.onCreate();
    verify(mHost).onCreateIME();

    doReturn(mInputConnection).when(mIME).getCurrentInputConnection();
    mIME.onBindInput();
    verify(mHost).onBindInput();

    doReturn(getSampleExtractedText()).when(mInputConnection)
        .getExtractedText(isA(ExtractedTextRequest.class), anyInt());
    mIME.onStartInput(editorInfo, false);
    verify(mHost).onStartInput(editorInfo, false);

    mIME.onStartInputView(editorInfo, false);
    verify(mHost).onStartInputView(editorInfo, false);

    mIME.onFinishInputView(true);
    verify(mHost).onFinishInputView(true);

    doReturn(null).when(mInputConnection)
        .getExtractedText(isA(ExtractedTextRequest.class), anyInt());
    mIME.onFinishInput();
    verify(mHost).onFinishInput();

    doReturn(null).when(mIME).getCurrentInputConnection();
    mIME.onUnbindInput();
    verify(mHost).onUnbindInput();

    mIME.onDestroy();
    verify(mHost).onDestroyIME();
}
 
开发者ID:google,项目名称:brailleback,代码行数:36,代码来源:BrailleIMETest.java

示例11: testMonitorsExtractedText

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
/** Tests that the IME monitors the extracted text. */
public void testMonitorsExtractedText() {
    EditorInfo editorInfo = getSampleEditorInfo();
    ExtractedText et = getSampleExtractedText();
    ArgumentCaptor<ExtractedTextRequest> etr =
        ArgumentCaptor.forClass(ExtractedTextRequest.class);
    ArgumentCaptor<Integer> etFlags =
        ArgumentCaptor.forClass(Integer.class);

    autoStub(mDisplayManager, mInputConnection, editorInfo);
    when(mInputConnection.getExtractedText(
                etr.capture(), etFlags.capture())).thenReturn(et);
    createBindAndStart(editorInfo);

    // Check the extracted text request.
    assertNotNull(etr.getValue());
    assertEquals(InputConnection.GET_EXTRACTED_TEXT_MONITOR,
            etFlags.getValue().intValue());
    int etToken = etr.getValue().token;

    // Check the provided display content.
    verifyDisplayContentMatches("Hello world! [Execute]");

    // Change the content and verify that the display manager is updated.
    et.text = "Hello Canada!";
    mIME.onUpdateExtractedText(etToken, et);
    verifyDisplayContentMatches("Hello Canada! [Execute]");

    finishUnbindAndDestroy();
}
 
开发者ID:google,项目名称:brailleback,代码行数:31,代码来源:BrailleIMETest.java

示例12: getExtractedText

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
@Override
    public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
//        return ic.getExtractedText(request, flags);
        String text = editAreaView.getSelectedText();
        if (text == null) text = "";
        ExtractedText et = new ExtractedText();
        et.text = text;
        et.partialEndOffset = text.length();
        et.selectionStart = 0;
        et.selectionEnd = text.length();
        et.flags = 0;
        return et;
    }
 
开发者ID:jecelyin,项目名称:920-text-editor-v2,代码行数:14,代码来源:InputConnectionHacker.java

示例13: checkReCorrectionOnStart

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的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:klausw,项目名称:hackerskeyboard,代码行数:28,代码来源:LatinIME.java

示例14: getText

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
String getText() {
  String text = "";
  try {
    InputConnection conn = getCurrentInputConnection();
    ExtractedTextRequest req = new ExtractedTextRequest();
    req.hintMaxChars = 1000000;
    req.hintMaxLines = 10000;
    req.flags = 0;
    req.token = 1;
    text = conn.getExtractedText(req, 0).text.toString();
  } catch (Throwable t) {
  }
  return text;
}
 
开发者ID:wildeyes,项目名称:wifikeyboard,代码行数:15,代码来源:WiFiInputMethod.java

示例15: setExtracting

import android.view.inputmethod.ExtractedTextRequest; //导入依赖的package包/类
/**
 * @hide
 */
public void setExtracting(ExtractedTextRequest req) {
    if (mEditor.mInputMethodState != null) {
        mEditor.mInputMethodState.mExtractedTextRequest = req;
    }
    // This would stop a possible selection mode, but no such mode is started in case
    // extracted mode will start. Some text is selected though, and will trigger an action mode
    // in the extracted view.
    mEditor.hideControllers();
}
 
开发者ID:AungThiha,项目名称:Tada,代码行数:13,代码来源:TextView.java


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