use of android.text.style.SpellCheckSpan in project platform_frameworks_base by android.
the class SpellChecker method addSpellCheckSpan.
private void addSpellCheckSpan(Editable editable, int start, int end) {
final int index = nextSpellCheckSpanIndex();
SpellCheckSpan spellCheckSpan = mSpellCheckSpans[index];
editable.setSpan(spellCheckSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spellCheckSpan.setSpellCheckInProgress(false);
mIds[index] = mSpanSequenceCounter++;
}
use of android.text.style.SpellCheckSpan in project XobotOS by xamarin.
the class TextView method spanChange.
/**
* Not private so it can be called from an inner class without going
* through a thunk.
*/
void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd, int newEnd) {
// XXX Make the start and end move together if this ends up
// spending too much time invalidating.
boolean selChanged = false;
int newSelStart = -1, newSelEnd = -1;
final InputMethodState ims = mInputMethodState;
if (what == Selection.SELECTION_END) {
mHighlightPathBogus = true;
selChanged = true;
newSelEnd = newStart;
if (!isFocused()) {
mSelectionMoved = true;
}
if (oldStart >= 0 || newStart >= 0) {
invalidateCursor(Selection.getSelectionStart(buf), oldStart, newStart);
registerForPreDraw();
makeBlink();
}
}
if (what == Selection.SELECTION_START) {
mHighlightPathBogus = true;
selChanged = true;
newSelStart = newStart;
if (!isFocused()) {
mSelectionMoved = true;
}
if (oldStart >= 0 || newStart >= 0) {
int end = Selection.getSelectionEnd(buf);
invalidateCursor(end, oldStart, newStart);
}
}
if (selChanged) {
if ((buf.getSpanFlags(what) & Spanned.SPAN_INTERMEDIATE) == 0) {
if (newSelStart < 0) {
newSelStart = Selection.getSelectionStart(buf);
}
if (newSelEnd < 0) {
newSelEnd = Selection.getSelectionEnd(buf);
}
onSelectionChanged(newSelStart, newSelEnd);
}
}
if (what instanceof UpdateAppearance || what instanceof ParagraphStyle || (what instanceof SuggestionSpan && (((SuggestionSpan) what).getFlags() & SuggestionSpan.FLAG_AUTO_CORRECTION) != 0)) {
if (ims == null || ims.mBatchEditNesting == 0) {
invalidate();
mHighlightPathBogus = true;
checkForResize();
} else {
ims.mContentChanged = true;
}
}
if (MetaKeyKeyListener.isMetaTracker(buf, what)) {
mHighlightPathBogus = true;
if (ims != null && MetaKeyKeyListener.isSelectingMetaTracker(buf, what)) {
ims.mSelectionModeChanged = true;
}
if (Selection.getSelectionStart(buf) >= 0) {
if (ims == null || ims.mBatchEditNesting == 0) {
invalidateCursor();
} else {
ims.mCursorChanged = true;
}
}
}
if (what instanceof ParcelableSpan) {
// the current extract editor would be interested in it.
if (ims != null && ims.mExtracting != null) {
if (ims.mBatchEditNesting != 0) {
if (oldStart >= 0) {
if (ims.mChangedStart > oldStart) {
ims.mChangedStart = oldStart;
}
if (ims.mChangedStart > oldEnd) {
ims.mChangedStart = oldEnd;
}
}
if (newStart >= 0) {
if (ims.mChangedStart > newStart) {
ims.mChangedStart = newStart;
}
if (ims.mChangedStart > newEnd) {
ims.mChangedStart = newEnd;
}
}
} else {
if (DEBUG_EXTRACT)
Log.v(LOG_TAG, "Span change outside of batch: " + oldStart + "-" + oldEnd + "," + newStart + "-" + newEnd + what);
ims.mContentChanged = true;
}
}
}
if (newStart < 0 && what instanceof SpellCheckSpan) {
getSpellChecker().removeSpellCheckSpan((SpellCheckSpan) what);
}
}
use of android.text.style.SpellCheckSpan in project XobotOS by xamarin.
the class SpellChecker method onGetSuggestions.
@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
Editable editable = (Editable) mTextView.getText();
for (int i = 0; i < results.length; i++) {
SuggestionsInfo suggestionsInfo = results[i];
if (suggestionsInfo.getCookie() != mCookie)
continue;
final int sequenceNumber = suggestionsInfo.getSequence();
for (int j = 0; j < mLength; j++) {
if (sequenceNumber == mIds[j]) {
final int attributes = suggestionsInfo.getSuggestionsAttributes();
boolean isInDictionary = ((attributes & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) > 0);
boolean looksLikeTypo = ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0);
SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j];
if (!isInDictionary && looksLikeTypo) {
createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan);
}
editable.removeSpan(spellCheckSpan);
break;
}
}
}
final int length = mSpellParsers.length;
for (int i = 0; i < length; i++) {
final SpellParser spellParser = mSpellParsers[i];
if (!spellParser.isDone()) {
spellParser.parse();
}
}
}
use of android.text.style.SpellCheckSpan in project XobotOS by xamarin.
the class SpellChecker method nextSpellCheckSpanIndex.
private int nextSpellCheckSpanIndex() {
for (int i = 0; i < mLength; i++) {
if (mIds[i] < 0)
return i;
}
if (mLength == mSpellCheckSpans.length) {
final int newSize = mLength * 2;
int[] newIds = new int[newSize];
SpellCheckSpan[] newSpellCheckSpans = new SpellCheckSpan[newSize];
System.arraycopy(mIds, 0, newIds, 0, mLength);
System.arraycopy(mSpellCheckSpans, 0, newSpellCheckSpans, 0, mLength);
mIds = newIds;
mSpellCheckSpans = newSpellCheckSpans;
}
mSpellCheckSpans[mLength] = new SpellCheckSpan();
mLength++;
return mLength - 1;
}
use of android.text.style.SpellCheckSpan in project XobotOS by xamarin.
the class SpellChecker method spellCheck.
private void spellCheck() {
if (mSpellCheckerSession == null)
return;
Editable editable = (Editable) mTextView.getText();
final int selectionStart = Selection.getSelectionStart(editable);
final int selectionEnd = Selection.getSelectionEnd(editable);
TextInfo[] textInfos = new TextInfo[mLength];
int textInfosCount = 0;
for (int i = 0; i < mLength; i++) {
final SpellCheckSpan spellCheckSpan = mSpellCheckSpans[i];
if (spellCheckSpan.isSpellCheckInProgress())
continue;
final int start = editable.getSpanStart(spellCheckSpan);
final int end = editable.getSpanEnd(spellCheckSpan);
// Do not check this word if the user is currently editing it
if (start >= 0 && end > start && (selectionEnd < start || selectionStart > end)) {
final String word = editable.subSequence(start, end).toString();
spellCheckSpan.setSpellCheckInProgress(true);
textInfos[textInfosCount++] = new TextInfo(word, mCookie, mIds[i]);
}
}
if (textInfosCount > 0) {
if (textInfosCount < textInfos.length) {
TextInfo[] textInfosCopy = new TextInfo[textInfosCount];
System.arraycopy(textInfos, 0, textInfosCopy, 0, textInfosCount);
textInfos = textInfosCopy;
}
mSpellCheckerSession.getSuggestions(textInfos, SuggestionSpan.SUGGESTIONS_MAX_SIZE, false);
}
}
Aggregations