use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class PasswordTransformationMethod method onFocusChanged.
public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect) {
if (!focused) {
if (sourceText instanceof Spannable) {
Spannable sp = (Spannable) sourceText;
removeVisibleSpans(sp);
}
}
}
use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class TextView method onResolvePointerIcon.
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
if (mText instanceof Spannable && mLinksClickable) {
final float x = event.getX(pointerIndex);
final float y = event.getY(pointerIndex);
final int offset = getOffsetForPosition(x, y);
final ClickableSpan[] clickables = ((Spannable) mText).getSpans(offset, offset, ClickableSpan.class);
if (clickables.length > 0) {
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HAND);
}
}
if (isTextSelectable() || isTextEditable()) {
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_TEXT);
}
return super.onResolvePointerIcon(event, pointerIndex);
}
use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class TextView method onKeyMultiple.
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
final int which = doKeyDown(keyCode, down, event);
if (which == KEY_EVENT_NOT_HANDLED) {
// Go through default dispatching.
return super.onKeyMultiple(keyCode, repeatCount, event);
}
if (which == KEY_EVENT_HANDLED) {
// Consumed the whole thing.
return true;
}
repeatCount--;
// We are going to dispatch the remaining events to either the input
// or movement method. To do this, we will just send a repeated stream
// of down and up events until we have done the complete repeatCount.
// It would be nice if those interfaces had an onKeyMultiple() method,
// but adding that is a more complicated change.
KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
if (which == KEY_DOWN_HANDLED_BY_KEY_LISTENER) {
// mEditor and mEditor.mInput are not null from doKeyDown
mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
while (--repeatCount > 0) {
mEditor.mKeyListener.onKeyDown(this, (Editable) mText, keyCode, down);
mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
}
hideErrorIfUnchanged();
} else if (which == KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD) {
// mMovement is not null from doKeyDown
mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
while (--repeatCount > 0) {
mMovement.onKeyDown(this, (Spannable) mText, keyCode, down);
mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
}
}
return true;
}
use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class TextView method removeSuggestionSpans.
/**
* Removes the suggestion spans.
*/
CharSequence removeSuggestionSpans(CharSequence text) {
if (text instanceof Spanned) {
Spannable spannable;
if (text instanceof Spannable) {
spannable = (Spannable) text;
} else {
spannable = new SpannableString(text);
text = spannable;
}
SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
for (int i = 0; i < spans.length; i++) {
spannable.removeSpan(spans[i]);
}
}
return text;
}
use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class SuggestionsPopupWindowTest method setSuggestionSpan.
private void setSuggestionSpan(SuggestionSpan span, int start, int end) {
final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
textView.post(() -> {
final Spannable text = (Spannable) textView.getText();
text.setSpan(span, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
Selection.setSelection(text, (start + end) / 2);
});
getInstrumentation().waitForIdleSync();
}
Aggregations