本文整理匯總了Java中android.view.inputmethod.InputConnection.getExtractedText方法的典型用法代碼示例。如果您正苦於以下問題:Java InputConnection.getExtractedText方法的具體用法?Java InputConnection.getExtractedText怎麽用?Java InputConnection.getExtractedText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.inputmethod.InputConnection
的用法示例。
在下文中一共展示了InputConnection.getExtractedText方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkReCorrectionOnStart
import android.view.inputmethod.InputConnection; //導入方法依賴的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: getCursorPosition
import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private static int getCursorPosition(InputConnection connection) {
ExtractedText extracted = connection.getExtractedText(
new ExtractedTextRequest(), 0);
if (extracted == null) {
return -1;
}
return extracted.startOffset + extracted.selectionStart;
}
示例3: getAllInputText
import android.view.inputmethod.InputConnection; //導入方法依賴的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;
}
示例4: tryKp2aAutoFill
import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private boolean tryKp2aAutoFill(final EditorInfo editorInfo) {
if (!mKp2aAutoFillOn)
return false;
//auto fill in?
InputConnection ic = getCurrentInputConnection();
if (ic == null) return false;
ExtractedTextRequest etr = new ExtractedTextRequest();
etr.token = 0; // anything is fine here
ExtractedText et = ic.getExtractedText(etr, 0);
boolean hasTextInField = (et != null) && (!TextUtils.isEmpty(et.text));
if (!hasTextInField) //only auto-fill if target field is empty
{
//try to look up saved field hint:
if (!TextUtils.isEmpty(editorInfo.hintText))
{
SharedPreferences prefs = getApplicationContext().getSharedPreferences(KP2A_SAVED_FIELD_HINTS, MODE_PRIVATE);
String key = editorInfo.packageName+"/"+keepass2android.kbbridge.KeyboardData.entryId+"/"+editorInfo.hintText;
Log.d("KP2AK", "looking up saved field hint for "+key);
String savedKey = prefs.getString(key, "");
if ("".equals(savedKey) == false)
{
Log.d("KP2AK","Found field "+savedKey);
if (commitTextForKey(editorInfo, savedKey))
return true;
}
}
//try to look up by hint
if ((editorInfo.hintText != null) && (editorInfo.hintText.length() > 0))
{
if (commitTextForKey(editorInfo, editorInfo.hintText.toString()))
return true;
}
}
return false;
}
示例5: 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();
}
}