use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.
the class Editor method sendUpdateSelection.
private void sendUpdateSelection() {
if (null != mInputMethodState && mInputMethodState.mBatchEditNesting <= 0) {
final InputMethodManager imm = InputMethodManager.peekInstance();
if (null != imm) {
final int selectionStart = mTextView.getSelectionStart();
final int selectionEnd = mTextView.getSelectionEnd();
int candStart = -1;
int candEnd = -1;
if (mTextView.getText() instanceof Spannable) {
final Spannable sp = (Spannable) mTextView.getText();
candStart = EditableInputConnection.getComposingSpanStart(sp);
candEnd = EditableInputConnection.getComposingSpanEnd(sp);
}
// InputMethodManager#updateSelection skips sending the message if
// none of the parameters have changed since the last time we called it.
imm.updateSelection(mTextView, selectionStart, selectionEnd, candStart, candEnd);
}
}
}
use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.
the class DialerFilter method removeFilterWatcher.
public void removeFilterWatcher(TextWatcher watcher) {
Spannable text;
if (mMode != DIGITS_ONLY) {
text = mLetters.getText();
} else {
text = mDigits.getText();
}
text.removeSpan(watcher);
}
use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.
the class Editor method shouldOfferToShowSuggestions.
/**
* @return <code>true</code> if it's reasonable to offer to show suggestions depending on
* the current cursor position or selection range. This method is consistent with the
* method to show suggestions {@link SuggestionsPopupWindow#updateSuggestions}.
*/
private boolean shouldOfferToShowSuggestions() {
CharSequence text = mTextView.getText();
if (!(text instanceof Spannable))
return false;
final Spannable spannable = (Spannable) text;
final int selectionStart = mTextView.getSelectionStart();
final int selectionEnd = mTextView.getSelectionEnd();
final SuggestionSpan[] suggestionSpans = spannable.getSpans(selectionStart, selectionEnd, SuggestionSpan.class);
if (suggestionSpans.length == 0) {
return false;
}
if (selectionStart == selectionEnd) {
// Spans overlap the cursor.
for (int i = 0; i < suggestionSpans.length; i++) {
if (suggestionSpans[i].getSuggestions().length > 0) {
return true;
}
}
return false;
}
int minSpanStart = mTextView.getText().length();
int maxSpanEnd = 0;
int unionOfSpansCoveringSelectionStartStart = mTextView.getText().length();
int unionOfSpansCoveringSelectionStartEnd = 0;
boolean hasValidSuggestions = false;
for (int i = 0; i < suggestionSpans.length; i++) {
final int spanStart = spannable.getSpanStart(suggestionSpans[i]);
final int spanEnd = spannable.getSpanEnd(suggestionSpans[i]);
minSpanStart = Math.min(minSpanStart, spanStart);
maxSpanEnd = Math.max(maxSpanEnd, spanEnd);
if (selectionStart < spanStart || selectionStart > spanEnd) {
// The span doesn't cover the current selection start point.
continue;
}
hasValidSuggestions = hasValidSuggestions || suggestionSpans[i].getSuggestions().length > 0;
unionOfSpansCoveringSelectionStartStart = Math.min(unionOfSpansCoveringSelectionStartStart, spanStart);
unionOfSpansCoveringSelectionStartEnd = Math.max(unionOfSpansCoveringSelectionStartEnd, spanEnd);
}
if (!hasValidSuggestions) {
return false;
}
if (unionOfSpansCoveringSelectionStartStart >= unionOfSpansCoveringSelectionStartEnd) {
// No spans cover the selection start point.
return false;
}
if (minSpanStart < unionOfSpansCoveringSelectionStartStart || maxSpanEnd > unionOfSpansCoveringSelectionStartEnd) {
// to show suggestions as it's confusing.
return false;
}
return true;
}
use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.
the class DialerFilter method setDigitsWatcher.
public void setDigitsWatcher(TextWatcher watcher) {
CharSequence text = mDigits.getText();
Spannable span = (Spannable) text;
span.setSpan(watcher, 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.
the class DialerFilter method setLettersWatcher.
public void setLettersWatcher(TextWatcher watcher) {
CharSequence text = mLetters.getText();
Spannable span = (Spannable) text;
span.setSpan(watcher, 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
Aggregations