use of android.text.Spanned in project Jota-Text-Editor-old by jiro-aqua.
the class TextUtils method getOffsetAfter.
public static int getOffsetAfter(CharSequence text, int offset) {
int len = text.length();
if (offset == len)
return len;
if (offset == len - 1)
return len;
char c = text.charAt(offset);
if (c >= '�' && c <= '�') {
char c1 = text.charAt(offset + 1);
if (c1 >= '�' && c1 <= '�')
offset += 2;
else
offset += 1;
} else {
offset += 1;
}
if (text instanceof Spanned) {
ReplacementSpan[] spans = ((Spanned) text).getSpans(offset, offset, ReplacementSpan.class);
for (int i = 0; i < spans.length; i++) {
int start = ((Spanned) text).getSpanStart(spans[i]);
int end = ((Spanned) text).getSpanEnd(spans[i]);
if (start < offset && end > offset)
offset = end;
}
}
return offset;
}
use of android.text.Spanned in project Jota-Text-Editor-old by jiro-aqua.
the class TextUtils method concat.
/**
* Returns a CharSequence concatenating the specified CharSequences,
* retaining their spans if any.
*/
public static CharSequence concat(CharSequence... text) {
if (text.length == 0) {
return "";
}
if (text.length == 1) {
return text[0];
}
boolean spanned = false;
for (int i = 0; i < text.length; i++) {
if (text[i] instanceof Spanned) {
spanned = true;
break;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length; i++) {
sb.append(text[i]);
}
if (!spanned) {
return sb.toString();
}
SpannableString ss = new SpannableString(sb);
int off = 0;
for (int i = 0; i < text.length; i++) {
int len = text[i].length();
if (text[i] instanceof Spanned) {
copySpansFrom((Spanned) text[i], 0, len, Object.class, ss, off);
}
off += len;
}
return new SpannedString(ss);
}
use of android.text.Spanned in project Jota-Text-Editor-old by jiro-aqua.
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();
if (dir < 0)
x -= dw;
// XXX What to do about Paint?
mDrawable.setBounds(ix, itop, ix + dw, itop + dh);
mDrawable.draw(c);
}
use of android.text.Spanned in project Jota-Text-Editor-old by jiro-aqua.
the class TextView method onSaveInstanceState.
@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
// Save state if we are forced to
boolean save = mFreezesText;
int start = 0;
int end = 0;
if (mText != null) {
start = getSelectionStart();
end = getSelectionEnd();
if (start >= 0 || end >= 0) {
// Or save state if there is a selection
save = true;
}
}
if (save) {
SavedState ss = new SavedState(superState);
// XXX Should also save the current scroll position!
ss.selStart = start;
ss.selEnd = end;
if (mText instanceof Spanned) {
/*
* Calling setText() strips off any ChangeWatchers;
* strip them now to avoid leaking references.
* But do it to a copy so that if there are any
* further changes to the text of this view, it
* won't get into an inconsistent state.
*/
Spannable sp = new SpannableString(mText);
for (ChangeWatcher cw : sp.getSpans(0, sp.length(), ChangeWatcher.class)) {
sp.removeSpan(cw);
}
ss.text = sp;
} else {
ss.text = mText.toString();
}
if (isFocused() && start >= 0 && end >= 0) {
ss.frozenWithFocus = true;
}
ss.error = mError;
// Jota Text Editor
ss.undoBuffer = mUndoBuffer;
// Jota Text Editor
ss.redoBuffer = mRedoBuffer;
// Jota Text Editor
ss.imeShown = isImeShown();
return ss;
}
return superState;
}
use of android.text.Spanned in project Jota-Text-Editor-old by jiro-aqua.
the class IconMarginSpan 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 itop = layout.getLineTop(layout.getLineForOffset(st));
if (dir < 0)
x -= mBitmap.getWidth();
c.drawBitmap(mBitmap, x, itop, p);
}
Aggregations