use of android.text.Spanned in project android_frameworks_base by DirtyUnicorns.
the class MetaKeyKeyListener method getActive.
private static int getActive(CharSequence text, Object meta, int on, int lock) {
if (!(text instanceof Spanned)) {
return 0;
}
Spanned sp = (Spanned) text;
int flag = sp.getSpanFlags(meta);
if (flag == LOCKED) {
return lock;
} else if (flag != 0) {
return on;
} else {
return 0;
}
}
use of android.text.Spanned in project android_frameworks_base by DirtyUnicorns.
the class Editor method extractTextInternal.
private boolean extractTextInternal(@Nullable ExtractedTextRequest request, int partialStartOffset, int partialEndOffset, int delta, @Nullable ExtractedText outText) {
if (request == null || outText == null) {
return false;
}
final CharSequence content = mTextView.getText();
if (content == null) {
return false;
}
if (partialStartOffset != EXTRACT_NOTHING) {
final int N = content.length();
if (partialStartOffset < 0) {
outText.partialStartOffset = outText.partialEndOffset = -1;
partialStartOffset = 0;
partialEndOffset = N;
} else {
// Now use the delta to determine the actual amount of text
// we need.
partialEndOffset += delta;
// Adjust offsets to ensure we contain full spans.
if (content instanceof Spanned) {
Spanned spanned = (Spanned) content;
Object[] spans = spanned.getSpans(partialStartOffset, partialEndOffset, ParcelableSpan.class);
int i = spans.length;
while (i > 0) {
i--;
int j = spanned.getSpanStart(spans[i]);
if (j < partialStartOffset)
partialStartOffset = j;
j = spanned.getSpanEnd(spans[i]);
if (j > partialEndOffset)
partialEndOffset = j;
}
}
outText.partialStartOffset = partialStartOffset;
outText.partialEndOffset = partialEndOffset - delta;
if (partialStartOffset > N) {
partialStartOffset = N;
} else if (partialStartOffset < 0) {
partialStartOffset = 0;
}
if (partialEndOffset > N) {
partialEndOffset = N;
} else if (partialEndOffset < 0) {
partialEndOffset = 0;
}
}
if ((request.flags & InputConnection.GET_TEXT_WITH_STYLES) != 0) {
outText.text = content.subSequence(partialStartOffset, partialEndOffset);
} else {
outText.text = TextUtils.substring(content, partialStartOffset, partialEndOffset);
}
} else {
outText.partialStartOffset = 0;
outText.partialEndOffset = 0;
outText.text = "";
}
outText.flags = 0;
if (MetaKeyKeyListener.getMetaState(content, MetaKeyKeyListener.META_SELECTING) != 0) {
outText.flags |= ExtractedText.FLAG_SELECTING;
}
if (mTextView.isSingleLine()) {
outText.flags |= ExtractedText.FLAG_SINGLE_LINE;
}
outText.startOffset = 0;
outText.selectionStart = mTextView.getSelectionStart();
outText.selectionEnd = mTextView.getSelectionEnd();
return true;
}
use of android.text.Spanned in project android_frameworks_base by AOSPA.
the class Notification method removeTextSizeSpans.
private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
if (charSequence instanceof Spanned) {
Spanned ss = (Spanned) charSequence;
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
for (Object span : spans) {
Object resultSpan = span;
if (resultSpan instanceof CharacterStyle) {
resultSpan = ((CharacterStyle) span).getUnderlying();
}
if (resultSpan instanceof TextAppearanceSpan) {
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
resultSpan = new TextAppearanceSpan(originalSpan.getFamily(), originalSpan.getTextStyle(), -1, originalSpan.getTextColor(), originalSpan.getLinkTextColor());
} else if (resultSpan instanceof RelativeSizeSpan || resultSpan instanceof AbsoluteSizeSpan) {
continue;
} else {
resultSpan = span;
}
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
}
return builder;
}
return charSequence;
}
use of android.text.Spanned in project android_frameworks_base by AOSPA.
the class DrawableMarginSpan method drawLeadingMargin.
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {
int st = ((Spanned) text).getSpanStart(this);
int ix = (int) x;
int itop = (int) layout.getLineTop(layout.getLineForOffset(st));
int dw = mDrawable.getIntrinsicWidth();
int dh = mDrawable.getIntrinsicHeight();
// XXX What to do about Paint?
mDrawable.setBounds(ix, itop, ix + dw, itop + dh);
mDrawable.draw(c);
}
use of android.text.Spanned in project android_frameworks_base by AOSPA.
the class MetaKeyKeyListener method getActive.
private static int getActive(CharSequence text, Object meta, int on, int lock) {
if (!(text instanceof Spanned)) {
return 0;
}
Spanned sp = (Spanned) text;
int flag = sp.getSpanFlags(meta);
if (flag == LOCKED) {
return lock;
} else if (flag != 0) {
return on;
} else {
return 0;
}
}
Aggregations