本文整理汇总了Java中android.text.style.LeadingMarginSpan类的典型用法代码示例。如果您正苦于以下问题:Java LeadingMarginSpan类的具体用法?Java LeadingMarginSpan怎么用?Java LeadingMarginSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LeadingMarginSpan类属于android.text.style包,在下文中一共展示了LeadingMarginSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleOLTag
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
private void handleOLTag(Editable output) {
if(output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
output.append("\n");
}
int numberMargin = mListIndent * (mLists.size() - 1);
if(mLists.size() > 2) {
// Counter effect of nested spans
numberMargin -= (mLists.size() - 2) * mListIndent;
}
if(mLists.peek().second) {
end(output, Ol.class, false,
new LeadingMarginSpan.Standard(numberMargin),
new ListNumberSpan(mTextPaint, mOlIndices.lastElement().first - 1,
mLists.peek().third
)
);
} else {
end(output, Ol.class, false,
new LeadingMarginSpan.Standard(numberMargin)
);
}
}
示例2: calculateTag2
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
public static void calculateTag2(TextView tag, TextView title, final String text) {
ViewTreeObserver observer = tag.getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
SpannableString spannableString = new SpannableString(text);
LeadingMarginSpan.Standard what = new LeadingMarginSpan.Standard(tag.getWidth() + dip2px(tag.getContext(), 10), 0);
spannableString.setSpan(what, 0, spannableString.length(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
title.setText(spannableString);
tag.getViewTreeObserver().removeOnPreDrawListener(
this);
return false;
}
});
}
示例3: setIndent
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Override
public void setIndent(int indent) {
if(indent < 0)
return;
int currentValue = -1;
if(indentStack.isEmpty() || indent > (currentValue = indentStack.peek().value)){
indentStack.push(new IndentValue(indent));
return;
}
while(indent < currentValue){ // decreasing indent
IndentValue pop = indentStack.pop();
setSpan(new LeadingMarginSpan.Standard(INDENT_SIZE *pop.value), pop.start);
if(indentStack.isEmpty())
break;
currentValue = indentStack.peek().value;
}
}
示例4: getReplaces
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Override
protected Object[] getReplaces(final Editable text, final int indentation) {
// Nested BulletSpans increases distance between BULLET_SPAN and text, so we must prevent it.
int bulletMargin = INDENT_PX;
if (indentation > 1) {
bulletMargin = INDENT_PX - BULLET_SPAN.getLeadingMargin(true);
if (indentation > 2) {
// This get's more complicated when we add a LeadingMarginSpan into the same line:
// we have also counter it's effect to BulletSpan
bulletMargin -= (indentation - 2) * LIST_ITEM_INDENT_PX;
}
}
return new Object[]{
new LeadingMarginSpan.Standard(LIST_ITEM_INDENT_PX * (indentation - 1)),
new BulletSpan(bulletMargin)
};
}
示例5: testSubList
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Test
public void testSubList() throws Exception {
String content = "* item 1\n" +
"* item 2\n" +
" * sublist item 1\n" +
" * sublist item 2\n";
Spanned result = Markdown.fromMarkdown(content);
printSpans(result);
Object[] spans = result.getSpans(0, result.length(), Object.class);
assertEquals(8, spans.length);
assertEquals(LeadingMarginSpan.Standard.class, spans[0].getClass());
assertEquals(BulletSpan.class, spans[1].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[2].getClass());
assertEquals(BulletSpan.class, spans[3].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[4].getClass());
assertEquals(BulletSpan.class, spans[5].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[6].getClass());
assertEquals(BulletSpan.class, spans[7].getClass());
}
示例6: changeSpanBeforeTextChanged
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Override
public void changeSpanBeforeTextChanged(int start, int lengthBefore, int lengthAfter) {
if (changeReplacement) {//add replacement will not change span
return;
}
if (lengthBefore > lengthAfter) {
LeadingMarginSpan richSpan = getAssignSpan(getSpanClass(), start + lengthBefore - 1, start + lengthBefore + 1);
if (richSpan == null) {
return;
}
int sStart = getEditableText().getSpanStart(richSpan);
if (sStart == start && lengthAfter == 0) {
spanDeletedIndex = start;
}
}
}
示例7: handleTag
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
switch (tag) {
case "pre":
case "PRE":
ensureParagraphBoundary(output);
break;
// Unfortunately the following code will be ignored in API 24+ and the native rendering is inferior
case "li":
case "LI":
if (opening) {
liStarts.addLast(ensureParagraphBoundary(output));
} else if (!liStarts.isEmpty()) {
int start = liStarts.popLast();
trimStart(output, start);
int end = ensureParagraphBoundary(output);
// Add leading margin to ensure the bullet is not cut off
output.setSpan(new LeadingMarginSpan.Standard(leadingMargin), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
output.setSpan(new BulletSpan(bulletGapWidth), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
break;
}
}
示例8: LeadingMarginSpanDrawParameters
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
public LeadingMarginSpanDrawParameters(LeadingMarginSpan span,
int x,
int dir,
int top,
int baseline,
int bottom,
int start,
int end,
boolean first) {
this.span = span;
this.x = x;
this.dir = dir;
this.top = top;
this.baseline = baseline;
this.bottom = bottom;
this.start = start;
this.end = end;
this.first = first;
}
示例9: handleULTag
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
private void handleULTag(Editable output) {
if(output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
output.append("\n");
}
if(mLists.peek().second) {
//Check for checkboxes
if(output.length() > 2 &&
((output.charAt(0) >= '\u2610' && output.charAt(0) <= '\u2612')
|| (output.charAt(1) >= '\u2610' && output
.charAt(1) <= '\u2612')
)) {
end(output, Ul.class, false,
new LeadingMarginSpan.Standard(
mListIndent * (mLists.size() - 1))
);
} else {
end(output, Ul.class, false,
new LeadingMarginSpan.Standard(
mListIndent * (mLists.size() - 1)),
new BulletSpan(mSingleIndent)
);
}
} else {
end(output, Ul.class, false,
new LeadingMarginSpan.Standard(mListIndent * (mLists.size() - 1))
);
}
}
示例10: getSpannedTagString
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
/**
* Get a SpannableString suitable for displaying in a TextView using the given {@code book}'s {@link RTag}s.
* @param book Book whose tags to use.
* @param maxLines Maximum number of lines to draw backgrounds for.
* @return A SpannedString.
*/
public static SpannableString getSpannedTagString(RBook book, int maxLines) {
Spanny spanny = new Spanny();
HashMap<String, Integer> colorMap = new HashMap<>(book.tags.size());
for (RTag tag : book.tags) {
spanny.append(tag.name, new ForegroundColorSpan(tag.textColor)).append(TAG_SEP);
colorMap.put(tag.name, tag.bgColor);
}
return Spanny.spanText(spanny,
new LeadingMarginSpan.Standard((int) Minerva.d().TAG_CORNER_RADIUS),
new TagBackgroundSpan(colorMap, maxLines));
}
示例11: testEnumeration
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Test
public void testEnumeration() throws Exception {
String content = " 1. item1\n" +
" 1. item2";
Spanned result = Markdown.fromMarkdown(content);
printSpans(result);
Object[] spans = result.getSpans(0, result.length(), Object.class);
assertEquals(2, spans.length);
assertEquals(LeadingMarginSpan.Standard.class, spans[0].getClass());
assertEquals('1', result.charAt(0));
assertEquals(LeadingMarginSpan.Standard.class, spans[1].getClass());
assertEquals('2', result.charAt(9));
}
示例12: testListAsterisk
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Test
public void testListAsterisk() throws Exception {
String content = " * item1\n" +
" * item2";
Spanned result = Markdown.fromMarkdown(content);
printSpans(result);
Object[] spans = result.getSpans(0, result.length(), Object.class);
assertEquals(4, spans.length);
assertEquals(LeadingMarginSpan.Standard.class, spans[0].getClass());
assertEquals(BulletSpan.class, spans[1].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[2].getClass());
assertEquals(BulletSpan.class, spans[3].getClass());
}
示例13: testListMinus
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Test
public void testListMinus() throws Exception {
String content = " * item1\n" +
" * item2";
Spanned result = Markdown.fromMarkdown(content);
printSpans(result);
Object[] spans = result.getSpans(0, result.length(), Object.class);
assertEquals(4, spans.length);
assertEquals(LeadingMarginSpan.Standard.class, spans[0].getClass());
assertEquals(BulletSpan.class, spans[1].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[2].getClass());
assertEquals(BulletSpan.class, spans[3].getClass());
}
示例14: testListPlus
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
@Test
public void testListPlus() throws Exception {
String content = " * item1\n" +
" * item2";
Spanned result = Markdown.fromMarkdown(content);
printSpans(result);
Object[] spans = result.getSpans(0, result.length(), Object.class);
assertEquals(4, spans.length);
assertEquals(LeadingMarginSpan.Standard.class, spans[0].getClass());
assertEquals(BulletSpan.class, spans[1].getClass());
assertEquals(LeadingMarginSpan.Standard.class, spans[2].getClass());
assertEquals(BulletSpan.class, spans[3].getClass());
}
示例15: setSelectionTextSpan
import android.text.style.LeadingMarginSpan; //导入依赖的package包/类
protected void setSelectionTextSpan(boolean isValid, Class<? extends LeadingMarginSpan> clazz, int start, int end) {
try {
LeadingMarginSpan assignSpan = clazz.newInstance();
setSelectionTextSpan(isValid, assignSpan, start, end);
} catch (Exception e) {
Log.e(TAG, "can not instantiated " + clazz);
e.printStackTrace();
}
}