本文整理汇总了Java中android.text.style.ParagraphStyle类的典型用法代码示例。如果您正苦于以下问题:Java ParagraphStyle类的具体用法?Java ParagraphStyle怎么用?Java ParagraphStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParagraphStyle类属于android.text.style包,在下文中一共展示了ParagraphStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSpanForMatchesP
import android.text.style.ParagraphStyle; //导入依赖的package包/类
/**
* Create Span for matches in paragraph's. Note that this will highlight the full matched pattern
* (including optionals) if no group parameters are given.
*
* @param editable Text editable
* @param pattern The pattern to match
* @param creator A ParcelableSpanCreator for ParcelableSpan
* @param groupsToMatch (optional) groups to be matched, indexes start at 1.
*/
protected void createSpanForMatchesP(final Editable editable, final Pattern pattern, final ParagraphStyleCreator creator, int... groupsToMatch) {
if (groupsToMatch == null || groupsToMatch.length < 1) {
groupsToMatch = new int[]{0};
}
int i = 0;
for (Matcher m = pattern.matcher(editable); m.find(); i++) {
ParagraphStyle span = creator.create(m, i);
if (span != null) {
for (int g : groupsToMatch) {
if (g == 0 || g <= m.groupCount()) {
editable.setSpan(span, m.start(g), m.end(g), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
}
示例2: init
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private void init(CharSequence source, int start, int end) {
int initial = 20;
mSpans = new Object[initial];
mSpanData = new int[initial * 3];
if (source instanceof Spanned) {
Spanned sp = (Spanned) source;
for (Object span : sp.getSpans(start, end, Object.class)) {
if (span instanceof CharacterStyle || span instanceof ParagraphStyle) {
int st = sp.getSpanStart(span);
int en = sp.getSpanEnd(span);
int fl = sp.getSpanFlags(span);
if (st < start) st = start;
if (en > end) en = end;
setSpan(span, st - start, en - start, fl);
}
}
}
}
示例3: onSpanAdded
import android.text.style.ParagraphStyle; //导入依赖的package包/类
@Override
/* SpanWatcher */
public void onSpanAdded(Spannable text, Object what, int start, int end) {
mTextChanged = true;
// we need to keep track of ordered list spans
if (what instanceof BulletSpan) {
mIsBulletSpanSelected = true;
// if text was empty then append zero width char
// in order for the bullet to be shown when the span is selected
if (text.toString().isEmpty()) {
this.append("\u200B");
}
} else if (what instanceof NumberSpan) {
mIsNumberSpanSelected = true;
// if text was empty then append zero width char
// in order for the number to be shown when the span is selected
if (text.toString().isEmpty()) {
this.append("\u200B");
}
}
if (what instanceof RTSpan && what instanceof ParagraphStyle) {
setParagraphsAreUp2Date(false);
}
}
示例4: clearParagraphSpanType
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private <T extends ParagraphStyle> void clearParagraphSpanType(Editable editable, Class<T> spanType) {
ParagraphStyle[] spans = editable.getSpans(0, editable.length(), spanType);
for (int n = spans.length; n-- > 0; ) {
editable.removeSpan(spans[n]);
}
}
示例5: encodeTextAlignmentByDiv
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private static void encodeTextAlignmentByDiv(Context context, StringBuilder out, Spanned text, int option) {
int len = text.length();
int next;
for (int i = 0; i < len; i = next) {
next = text.nextSpanTransition(i, len, ParagraphStyle.class);
ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class);
String elements = " ";
boolean needDiv = false;
for (ParagraphStyle style : styles) {
if (style instanceof AlignmentSpan) {
Layout.Alignment align =
((AlignmentSpan) style).getAlignment();
needDiv = true;
if (align == Layout.Alignment.ALIGN_CENTER) {
elements = "align=\"center\" " + elements;
} else if (align == Layout.Alignment.ALIGN_OPPOSITE) {
elements = "align=\"right\" " + elements;
} else {
elements = "align=\"left\" " + elements;
}
}
}
if (needDiv) {
out.append("<div ").append(elements).append(">");
}
withinDiv(context, out, text, i, next, option);
if (needDiv) {
out.append("</div>");
}
}
}
示例6: encodeTextAlignmentByDiv
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) {
int len = text.length();
int next;
for (int i = 0; i < len; i = next) {
next = text.nextSpanTransition(i, len, ParagraphStyle.class);
ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class);
String elements = " ";
boolean needDiv = false;
for (int j = 0; j < style.length; j++) {
if (style[j] instanceof AlignmentSpan) {
Layout.Alignment align =
((AlignmentSpan) style[j]).getAlignment();
needDiv = true;
if (align == Layout.Alignment.ALIGN_CENTER) {
elements = "align=\"center\" " + elements;
} else if (align == Layout.Alignment.ALIGN_OPPOSITE) {
elements = "align=\"right\" " + elements;
} else {
elements = "align=\"left\" " + elements;
}
}
}
if (needDiv) {
out.append("<div ").append(elements).append(">");
}
withinDiv(out, text, i, next, option);
if (needDiv) {
out.append("</div>");
}
}
}
示例7: getParagraphStyles
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private Set<SingleParagraphStyle> getParagraphStyles(final Spanned text, Selection selection) {
Set<SingleParagraphStyle> styles = new HashSet<>();
for (ParagraphStyle style : text.getSpans(selection.start(), selection.end(), ParagraphStyle.class)) {
ParagraphType type = ParagraphType.getInstance(style);
if (type != null) {
styles.add(new SingleParagraphStyle(type, style));
}
}
return styles;
}
示例8: onSpanAdded
import android.text.style.ParagraphStyle; //导入依赖的package包/类
@Override
/* SpanWatcher */
public void onSpanAdded(Spannable text, Object what, int start, int end) {
mTextChanged = true;
if (what instanceof RTSpan && what instanceof ParagraphStyle) {
setParagraphsAreUp2Date(false);
}
}
示例9: onSpanChanged
import android.text.style.ParagraphStyle; //导入依赖的package包/类
@Override
/* SpanWatcher */
public void onSpanChanged(Spannable text, Object what, int ostart, int oend, int nstart, int nend) {
mTextChanged = true;
if (what instanceof RTSpan && what instanceof ParagraphStyle) {
setParagraphsAreUp2Date(false);
}
}
示例10: onSpanRemoved
import android.text.style.ParagraphStyle; //导入依赖的package包/类
@Override
/* SpanWatcher */
public void onSpanRemoved(Spannable text, Object what, int start, int end) {
mTextChanged = true;
if (what instanceof RTSpan && what instanceof ParagraphStyle) {
setParagraphsAreUp2Date(false);
}
}
示例11: getParagraphStyles
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private Set<SingleParagraphStyle> getParagraphStyles(final Spanned text, Selection selection) {
Set<SingleParagraphStyle> styles = new HashSet<SingleParagraphStyle>();
for (ParagraphStyle style : text.getSpans(selection.start(), selection.end(), ParagraphStyle.class)) {
ParagraphType type = ParagraphType.getInstance(style);
if (type != null) {
styles.add(new SingleParagraphStyle(type, style));
}
}
return styles;
}
示例12: convert
import android.text.style.ParagraphStyle; //导入依赖的package包/类
public Spanned convert()
{
mReader.setContentHandler(this);
try {
mReader.parse(new InputSource(new StringReader(text)));
} catch (SAXException | IOException e) {
// We are reading from a string. There should not be IO problems.
throw new RuntimeException(e);
}
// Fix flags and range for paragraph-type markup.
Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class);
for (Object ob : obj) {
int start = mSpannableStringBuilder.getSpanStart(ob);
int end = mSpannableStringBuilder.getSpanEnd(ob);
// If the last line of the range is blank, back off by one.
if (end - 2 >= 0) {
if (mSpannableStringBuilder.charAt(end - 1) == '\n' &&
mSpannableStringBuilder.charAt(end - 2) == '\n') {
end--;
}
}
if (end == start) {
mSpannableStringBuilder.removeSpan(ob);
} else {
mSpannableStringBuilder.setSpan(ob, start, end, Spannable.SPAN_PARAGRAPH);
}
}
return mSpannableStringBuilder;
}
示例13: convert
import android.text.style.ParagraphStyle; //导入依赖的package包/类
public Spanned convert() {
try{
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();//利用获取到的对象创建一个解析器
XMLReader xmlReader =saxFactory.newSAXParser().getXMLReader(); //获取一个XMLReader
xmlReader.setContentHandler(this);
xmlReader.parse(new InputSource(new StringReader(mSource)));
}catch (Exception e){
e.printStackTrace();
}
// Fix flags and range for paragraph-type markup.
Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class);
for (int i = 0; i < obj.length; i++) {
int start = mSpannableStringBuilder.getSpanStart(obj[i]);
int end = mSpannableStringBuilder.getSpanEnd(obj[i]);
// If the last line of the range is blank, back off by one.
if (end - 2 >= 0) {
if (mSpannableStringBuilder.charAt(end - 1) == '\n' &&
mSpannableStringBuilder.charAt(end - 2) == '\n') {
end--;
}
}
if (end == start) {
mSpannableStringBuilder.removeSpan(obj[i]);
} else {
mSpannableStringBuilder.setSpan(obj[i], start, end, Spannable.SPAN_PARAGRAPH);
}
}
return mSpannableStringBuilder;
}
示例14: withinHtml
import android.text.style.ParagraphStyle; //导入依赖的package包/类
private static void withinHtml(StringBuilder out, Spanned text) {
int len = text.length();
int next;
for (int i = 0; i < text.length(); i = next) {
next = text.nextSpanTransition(i, len, ParagraphStyle.class);
ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class);
String elements = " ";
boolean needDiv = false;
for(int j = 0; j < style.length; j++) {
if (style[j] instanceof AlignmentSpan) {
Layout.Alignment align =
((AlignmentSpan) style[j]).getAlignment();
needDiv = true;
if (align == Layout.Alignment.ALIGN_CENTER) {
elements = "align=\"center\" " + elements;
} else if (align == Layout.Alignment.ALIGN_OPPOSITE) {
elements = "align=\"right\" " + elements;
} else {
elements = "align=\"left\" " + elements;
}
}
}
if (needDiv) {
out.append("<div ").append(elements).append(">");
}
withinDiv(out, text, i, next);
if (needDiv) {
out.append("</div>");
}
}
}
示例15: convert
import android.text.style.ParagraphStyle; //导入依赖的package包/类
public SpannableStringBuilder convert() {
mReader.setContentHandler(this);
try {
mReader.parse(new InputSource(new StringReader(mSource)));
} catch (IOException | SAXException e) {
// We are reading from a string. There should not be IO problems.
throw new RuntimeException(e);
}
// Fix flags and range for paragraph-type markup.
Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class);
for (int i = 0; i < obj.length; i++) {
int start = mSpannableStringBuilder.getSpanStart(obj[i]);
int end = mSpannableStringBuilder.getSpanEnd(obj[i]);
// If the last line of the range is blank, back off by one.
if (end - 2 >= 0) {
if (mSpannableStringBuilder.charAt(end - 1) == '\n' &&
mSpannableStringBuilder.charAt(end - 2) == '\n') {
end--;
}
}
if (end == start) {
mSpannableStringBuilder.removeSpan(obj[i]);
} else {
mSpannableStringBuilder.setSpan(obj[i], start, end, Spannable.SPAN_PARAGRAPH);
}
}
return mSpannableStringBuilder;
}