use of android.view.inputmethod.ExtractedText in project platform_frameworks_base by android.
the class InputConnectionWrapper method getExtractedText.
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
ExtractedText value = null;
try {
InputContextCallback callback = InputContextCallback.getInstance();
mIInputContext.getExtractedText(request, flags, callback.mSeq, callback);
synchronized (callback) {
callback.waitForResultLocked();
if (callback.mHaveValue) {
value = callback.mExtractedText;
}
}
callback.dispose();
} catch (RemoteException e) {
return null;
}
return value;
}
use of android.view.inputmethod.ExtractedText in project XobotOS by xamarin.
the class InputConnectionWrapper method getExtractedText.
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
ExtractedText value = null;
try {
InputContextCallback callback = InputContextCallback.getInstance();
mIInputContext.getExtractedText(request, flags, callback.mSeq, callback);
synchronized (callback) {
callback.waitForResultLocked();
if (callback.mHaveValue) {
value = callback.mExtractedText;
}
}
callback.dispose();
} catch (RemoteException e) {
return null;
}
return value;
}
use of android.view.inputmethod.ExtractedText in project speechutils by Kaljurand.
the class InputConnectionCommandEditor method getCommitTextOp.
/**
* Op that commits a text at the cursor. If successful then an undo is returned which deletes
* the text and restores the old selection.
*/
private Op getCommitTextOp(final CharSequence oldText, final CharSequence newText) {
return new Op("commitText") {
@Override
public Op run() {
Op undo = null;
// TODO: use getSelection
final ExtractedText et = getExtractedText();
if (mInputConnection.commitText(newText, 1)) {
undo = new Op("deleteSurroundingText+commitText") {
@Override
public Op run() {
mInputConnection.beginBatchEdit();
boolean success = mInputConnection.deleteSurroundingText(newText.length(), 0);
if (success && oldText != null) {
success = mInputConnection.commitText(oldText, 1);
}
if (et != null && success) {
success = mInputConnection.setSelection(et.selectionStart, et.selectionEnd);
}
mInputConnection.endBatchEdit();
if (success) {
return NO_OP;
}
return null;
}
};
}
return undo;
}
};
}
use of android.view.inputmethod.ExtractedText in project speechutils by Kaljurand.
the class InputConnectionCommandEditor method getCommitWithOverwriteOp.
/**
* TODO: review
* we should be able to review the last N ops and undo then if they can be interpreted as
* a combined op.
*/
private Op getCommitWithOverwriteOp(final String text) {
return new Op("add " + text) {
@Override
public Op run() {
// Calculate the length of the text that has changed
String commonPrefix = greatestCommonPrefix(mPrevText, text);
int commonPrefixLength = commonPrefix.length();
mInputConnection.beginBatchEdit();
final ExtractedText et = getExtractedText();
final String selectedText = getSelectedText();
// Delete the part that changed compared to the partial text added earlier.
int deletableLength = mPrevText.length() - commonPrefixLength;
if (deletableLength > 0) {
mInputConnection.deleteSurroundingText(deletableLength, 0);
}
// Finish if there is nothing to add
if (text.isEmpty() || commonPrefixLength == text.length()) {
mAddedLength -= deletableLength;
} else {
CharSequence leftContext = "";
String glue = "";
String text1 = text;
// If the prev text and the current text share no prefix then recalculate the glue.
if (commonPrefixLength == 0) {
// We look at the left context of the cursor
// to decide which glue symbol to use and whether to capitalize the text.
CharSequence textBeforeCursor = mInputConnection.getTextBeforeCursor(MAX_DELETABLE_CONTEXT, 0);
// In some error situations, null is returned
if (textBeforeCursor != null) {
leftContext = textBeforeCursor;
}
glue = getGlue(text, leftContext);
mAddedLength = glue.length() + text.length();
} else {
text1 = text.substring(commonPrefixLength);
leftContext = commonPrefix;
mAddedLength = mAddedLength - deletableLength + text1.length();
}
text1 = capitalizeIfNeeded(text1, leftContext);
mInputConnection.commitText(glue + text1, 1);
}
mInputConnection.endBatchEdit();
return new Op("delete " + mAddedLength) {
@Override
public Op run() {
mInputConnection.beginBatchEdit();
boolean success = mInputConnection.deleteSurroundingText(mAddedLength, 0);
if (et != null && selectedText.length() > 0) {
success = mInputConnection.commitText(selectedText, 1) && mInputConnection.setSelection(et.selectionStart, et.selectionEnd);
}
mInputConnection.endBatchEdit();
if (success) {
return NO_OP;
}
return null;
}
};
}
};
}
use of android.view.inputmethod.ExtractedText in project speechutils by Kaljurand.
the class InputConnectionCommandEditor method selectReAfter.
@Override
public Op selectReAfter(final String regex, final int n) {
return new Op("selectReAfter") {
@Override
public Op run() {
Op undo = null;
mInputConnection.beginBatchEdit();
final ExtractedText et = getExtractedText();
if (et != null) {
CharSequence input = et.text.subSequence(et.selectionEnd, et.text.length());
Pair<Integer, Integer> pos = matchNth(Pattern.compile(regex), input, n);
if (pos != null) {
undo = getOpSetSelection(et.selectionEnd + pos.first, et.selectionEnd + pos.second, et.selectionStart, et.selectionEnd).run();
}
}
mInputConnection.endBatchEdit();
return undo;
}
};
}
Aggregations