當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。