Java Examples for android.text.style.LeadingMarginSpan
The following java examples will help you to understand the usage of android.text.style.LeadingMarginSpan. These source code samples are taken from different open source projects.
Example 1
Project: BioWiki-master File: BWHtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 2
Project: hpbpad-Android-master File: WPHtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 3
Project: WordPress-Android-master File: WPHtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
int size = mListParents.size();
if (size > 0 && output != null) {
if ("ul".equals(mListParents.get(size - 1))) {
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.setSpan(new BulletSpan(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
} else if ("ol".equals(mListParents.get(size - 1))) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
}
}
}
Example 4
Project: WordPress-Networking-Android-master File: WPHtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 5
Project: training-content-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 6
Project: android-discourse-master File: HtmlTagHandler.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); // TODO: add support for lists starting other index than 1 olNextIndex.push(Integer.valueOf(1)).toString(); } else { lists.pop(); olNextIndex.pop().toString(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else if (tag.equalsIgnoreCase("code")) { if (opening) { output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK); } else { L.d("Code tag encountered"); Object obj = getLast(output, TypefaceSpan.class); int where = output.getSpanStart(obj); output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0); output.setSpan(new BackgroundColorSpan(Color.parseColor("#f1f1ff")), where, output.length(), 0); } } else { if (opening) L.d("Found an unsupported tag " + tag); } }
Example 7
Project: JNote-master File: MDFormatter.java View source code |
protected void format(MDLine line) {
int start = mBuilder.length();
for (MDWord word : line.mMDWords) {
int index = mBuilder.length();
mBuilder.append(word.mRawContent);
mBuilder.setSpan(getSpan(word.mFormat), index, mBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mBuilder.append("\n");
if (line.mFormat == Markdown.MD_FMT_ORDER_LIST || line.mFormat == Markdown.MD_FMT_UNORDER_LIST || line.mFormat == Markdown.MD_FMT_QUOTE) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(40), start, mBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
if (line.mFormat != Markdown.MD_FMT_TEXT) {
mBuilder.setSpan(getSpan(line.mFormat), start, mBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
Example 8
Project: iven-feed-reader-master File: ArticleFragment.java View source code |
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//set the view
rootView = (ViewGroup) inflater.inflate(R.layout.article_fragment, container, false);
//article title and subtitle
//title
title = (TextView) rootView.findViewById(R.id.title);
//subtitle
subtitle = (TextView) rootView.findViewById(R.id.subtitle);
//action Buttons
//read more button
button_continue_reading = (ImageButton) rootView.findViewById(R.id.button_continue);
//this is the method to handle the continue reading button click
View.OnClickListener listener_forward = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Preferences.WebViewEnabled(getContext())) {
ArticleUtils.openFeedPage(getActivity(), feedLink);
} else {
ArticleUtils.continueReading(getActivity(), feedLink);
}
}
};
//set Read more listener
button_continue_reading.setOnClickListener(listener_forward);
if (Preferences.WebViewEnabled(getContext())) {
//this is the method to handle the continue reading long button click
View.OnLongClickListener listener_external = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//open the url using external browser if webview is enabled
ArticleUtils.continueReading(getActivity(), feedLink);
return true;
}
};
//set the long click listener
button_continue_reading.setOnLongClickListener(listener_external);
}
//share button
button_share = (ImageButton) rootView.findViewById(R.id.button_share);
//this is the method to handle the share button click
View.OnClickListener listener_share = new View.OnClickListener() {
@Override
public void onClick(View v) {
ArticleUtils.share(getActivity(), feedLink, feedTitle);
}
};
//set Share listener
button_share.setOnClickListener(listener_share);
//back button
button_back = (ImageButton) rootView.findViewById(R.id.button_back);
//this is the click listener to provide back navigation
View.OnClickListener listener_back = new View.OnClickListener() {
@Override
public void onClick(View v) {
AppCompatActivity appCompatActivity = (AppCompatActivity) getActivity();
ArticleUtils.goBack(appCompatActivity);
}
};
//set back button on click listener
button_back.setOnClickListener(listener_back);
titleSpan = new SpannableString(feedTitle.toUpperCase());
titleSpan.setSpan(new StyleSpan(Typeface.BOLD), 0, titleSpan.length(), 0);
//dynamically set title and subtitle according to the feed data
//set title of the article
title.setText(titleSpan);
subtitleSpan = new SpannableString(feedDate);
subtitleSpan.setSpan(new StyleSpan(Typeface.BOLD), 0, subtitleSpan.length(), 0);
//set the date of the article to subtitle
subtitle.setText(subtitleSpan);
//set the articles text size from preferences
//get the chosen article's text size from preferences
size = Preferences.resolveTextSizeResId(getContext());
//set it in SP unit
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, size + 4);
subtitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, size - 5);
//if the preference is enabled remove the imageview from the linear layout
//ImageView
imageView = (ImageView) rootView.findViewById(R.id.img);
//initialize the article view linear layout
article_default_linearLayout = (LinearLayout) rootView.findViewById(R.id.article_linearlayout);
if (Preferences.imagesRemoved(getContext())) {
article_default_linearLayout.removeView(imageView);
} else //if getImage() method fails (i.e when img is in content:encoded) load image2
if (imageLink.isEmpty()) {
GlideUtils.loadImage(getActivity(), imageLink2, imageView);
//else use image
} else {
GlideUtils.loadImage(getActivity(), imageLink, imageView);
}
//we can open the image on web browser on long click on the image
imageView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
final Intent intent;
//open imageview links
if (imageLink.isEmpty()) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(imageLink2));
} else //else use image
{
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(imageLink));
}
//open the image
ArticleUtils.openImageLink(getActivity(), intent);
return true;
}
});
//use complete description by default, but sometimes the method returns null
if (feedCompleteDescription.contains("no desc")) {
datDescription = Jsoup.parse(feedDescription).text().replace("Continua a leggere...", "");
// else, use complete description
} else {
datDescription = Jsoup.parse(feedCompleteDescription).text().replace("Continua a leggere...", "");
}
//replace some items since this is a simple TextView
datDescriptionFirstformat = datDescription.replace("Continue reading...", "");
datDescriptionSecondformat = datDescriptionFirstformat.replace("Read More", "");
datDescriptionThirdformat = datDescriptionSecondformat.replace("(read more)", "");
//load the article inside a TextView
articletext = (TextView) rootView.findViewById(R.id.webv);
storySpan = new SpannableString(datDescriptionThirdformat);
storySpan.setSpan(new StyleSpan(Typeface.ITALIC), 0, storySpan.length(), 0);
leadingMarginSpan = new android.text.style.LeadingMarginSpan.Standard(10);
quoteSpan = new QuoteSpan();
storySpan.setSpan(quoteSpan, 0, 0, 0);
storySpan.setSpan(leadingMarginSpan, 0, storySpan.length(), 0);
//set the articles text
articletext.setText(storySpan);
//set the article text size according to preferences
articletext.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
return rootView;
}
Example 9
Project: Android-RTEditor-master File: RTEditorMovementMethod.java View source code |
// TODO finding links doesn't work with right alignment and potentially other formatting options private int getCharIndexAt(TextView textView, MotionEvent event) { // get coordinates int x = (int) event.getX(); int y = (int) event.getY(); x -= textView.getTotalPaddingLeft(); y -= textView.getTotalPaddingTop(); x += textView.getScrollX(); y += textView.getScrollY(); /* * Fail-fast check of the line bound. * If we're not within the line bound no character was touched */ Layout layout = textView.getLayout(); int line = layout.getLineForVertical(y); synchronized (sLineBounds) { layout.getLineBounds(line, sLineBounds); if (!sLineBounds.contains(x, y)) { return -1; } } // retrieve line text Spanned text = (Spanned) textView.getText(); int lineStart = layout.getLineStart(line); int lineEnd = layout.getLineEnd(line); int lineLength = lineEnd - lineStart; if (lineLength == 0) { return -1; } Spanned lineText = (Spanned) text.subSequence(lineStart, lineEnd); // compute leading margin and subtract it from the x coordinate int margin = 0; LeadingMarginSpan[] marginSpans = lineText.getSpans(0, lineLength, LeadingMarginSpan.class); if (marginSpans != null) { for (LeadingMarginSpan span : marginSpans) { margin += span.getLeadingMargin(true); } } x -= margin; // retrieve text widths float[] widths = new float[lineLength]; TextPaint paint = textView.getPaint(); paint.getTextWidths(lineText, 0, lineLength, widths); // scale text widths by relative font size (absolute size / default size) final float defaultSize = textView.getTextSize(); float scaleFactor = 1f; AbsoluteSizeSpan[] absSpans = lineText.getSpans(0, lineLength, AbsoluteSizeSpan.class); if (absSpans != null) { for (AbsoluteSizeSpan span : absSpans) { int spanStart = lineText.getSpanStart(span); int spanEnd = lineText.getSpanEnd(span); scaleFactor = span.getSize() / defaultSize; int start = Math.max(lineStart, spanStart); int end = Math.min(lineEnd, spanEnd); for (int i = start; i < end; i++) { widths[i] *= scaleFactor; } } } // find index of touched character float startChar = 0; float endChar = 0; for (int i = 0; i < lineLength; i++) { startChar = endChar; endChar += widths[i]; if (endChar >= x) { // which "end" is closer to x, the start or the end of the character? int index = lineStart + (x - startChar < endChar - x ? i : i + 1); //Logger.e(Logger.LOG_TAG, "Found character: " + (text.length()>index ? text.charAt(index) : "")); return index; } } return -1; }
Example 10
Project: androidbible-master File: SyncLogActivity.java View source code |
@Override
public void bindView(final View view, final int position, final ViewGroup parent) {
final SyncLog log = logs.get(position);
final SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append(dateFormat.get().format(log.createTime));
sb.append("\n");
{
final SyncRecorder.EventKind kind = SyncRecorder.EventKind.fromCode(log.kind_code);
final int sb_len = sb.length();
if (kind == null) {
sb.append(String.valueOf(log.kind_code));
sb.setSpan(new BackgroundColorSpan(0xff222222), sb_len, sb.length(), 0);
} else {
sb.append(kind.toString());
sb.setSpan(new BackgroundColorSpan(kind.backgroundColor), sb_len, sb.length(), 0);
}
if (log.syncSetName != null) {
sb.append(" ");
sb.append(log.syncSetName);
}
}
if (log.params != null) {
final int sb_len0 = sb.length();
for (final Map.Entry<String, Object> entry : log.params.entrySet()) {
sb.append("\n");
final int sb_len = sb.length();
sb.append(entry.getKey());
sb.setSpan(new StyleSpan(Typeface.BOLD), sb_len, sb.length(), 0);
sb.append(" ");
final Object value = entry.getValue();
if (value instanceof Number) {
final double doubleValue = ((Number) value).doubleValue();
final double floored = Math.floor(doubleValue);
if (floored == doubleValue) {
sb.append(String.valueOf((long) floored));
} else {
sb.append(String.valueOf(doubleValue));
}
} else {
sb.append(String.valueOf(value));
}
}
sb.setSpan(new RelativeSizeSpan(0.8f), sb_len0, sb.length(), 0);
sb.setSpan(new LeadingMarginSpan.Standard(((int) (8 * density))), sb_len0, sb.length(), 0);
}
final TextView text = (TextView) view;
text.setTextSize(14.f);
text.setText(sb);
text.setPadding((int) (4 * density), (int) (4 * density), (int) (4 * density), (int) (4 * density));
}
Example 11
Project: armatus-master File: ConsoleInputEditText.java View source code |
@Override public void afterTextChanged(Editable s) { int cursorPos = getSelectionStart(); removeTextChangedListener(this); //Remove additional spans that might be introduced through pasting for (LeadingMarginSpan span : s.getSpans(0, s.length(), LeadingMarginSpan.class)) { s.removeSpan(span); } s.setSpan(mIndent, 0, 0, 0); for (; mChangedStartIndex < mChangedEndIndex; mChangedStartIndex++) { switch(s.charAt(mChangedStartIndex)) { case ' ': //Prevent TextView's default word-wrapping behavior (wrap by character instead) s.replace(mChangedStartIndex, mChangedStartIndex + 1, StringUtils.NBSP); break; case '\n': /* A strange bug exists where pasting multiple lines will seemingly indent all * newlines--until the text is changed via typing. Therefore, this will initiate * the typing on each newline to prevent weirdness. */ setSelection(mChangedStartIndex); dispatchKeyEvent(Q); dispatchKeyEvent(DEL); break; } } addTextChangedListener(this); setSelection(cursorPos); }
Example 12
Project: boardgamegeek4android-master File: ListTagHandler.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tagIsTypeOf(tag, UL)) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tagIsTypeOf(tag, OL)) { if (opening) { lists.push(tag); nextOrderedIndex.push(1); } else { lists.pop(); nextOrderedIndex.pop(); } } else if (tagIsTypeOf(tag, LI)) { String currentListTag = lists.peek(); ensureTrailingNewLine(output); if (opening) { if (tagIsTypeOf(currentListTag, UL)) { startListItem(output, new Ul()); } else if (tagIsTypeOf(currentListTag, OL)) { startListItem(output, new Ol()); output.append(nextOrderedIndex.peek().toString()).append(". "); nextOrderedIndex.push(nextOrderedIndex.pop() + 1); } } else { if (tagIsTypeOf(currentListTag, UL)) { // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int margin = INDENTATION_IN_PIXELS; if (lists.size() > 1) { margin = INDENTATION_IN_PIXELS - BULLET_SPAN.getLeadingMargin(true); if (lists.size() > 2) { // This gets more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan margin -= (lists.size() - 2) * LIST_ITEM_INDENTATION_IN_PIXELS; } } BulletSpan newBullet = new BulletSpan(margin); endListItem(output, Ul.class, new LeadingMarginSpan.Standard(LIST_ITEM_INDENTATION_IN_PIXELS * (lists.size() - 1)), newBullet); } else if (tagIsTypeOf(currentListTag, OL)) { int margin = LIST_ITEM_INDENTATION_IN_PIXELS * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans margin -= (lists.size() - 2) * LIST_ITEM_INDENTATION_IN_PIXELS; } endListItem(output, Ol.class, new LeadingMarginSpan.Standard(margin)); } } } else { if (opening) { Timber.d("Found an unsupported tag: %s", tag); } } }
Example 13
Project: GSoC-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 14
Project: i2p.i2p-bote.android-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 15
Project: MozuAndroidInStoreAssistant-master File: HTMLTagHandler.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); //TODO: add support for lists starting other index than 1 olNextIndex.push(Integer.valueOf(1)).toString(); } else { lists.pop(); olNextIndex.pop().toString(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else { if (opening) Log.d("TagHandler", "Found an unsupported tag " + tag); } }
Example 16
Project: PanicButton-master File: MyTagHandler.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); //TODO: add support for lists starting other index than 1 olNextIndex.push(Integer.valueOf(1)).toString(); } else { lists.pop(); olNextIndex.pop().toString(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else { if (opening) Log.d("TagHandler", "Found an unsupported tag " + tag); } }
Example 17
Project: PrepayCredit-master File: CustomTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.get(mListParents.size() - 1).equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.get(mListParents.size() - 1).equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 18
Project: project_open-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 19
Project: QuickNews-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 20
Project: RealTextView-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 21
Project: ts-android-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 22
Project: v2ex-master File: HtmlTagHandler.java View source code |
private void handleListTag(Editable output) {
if (mListParents.lastElement().equals("ul")) {
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
} else if (mListParents.lastElement().equals("ol")) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int lastIndex = split.length - 1;
int start = output.length() - split[lastIndex].length() - 1;
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
}
}
Example 23
Project: WhatAndroid-master File: HTMLListTagHandler.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); olNextIndex.push(1); } else { lists.pop(); olNextIndex.pop(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString()).append(". "); olNextIndex.push(olNextIndex.pop() + 1); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 2) { // This gets more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan bulletMargin -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else { if (opening) { Log.d("TagHandler", "Found an unsupported tag " + tag); } } }
Example 24
Project: zulip-android-master File: ListTagHandler.java View source code |
@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) }; }
Example 25
Project: AndroidCommon-master File: SpannableStringUtils.java View source code |
private void setSpan() {
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new QuoteSpan(quoteColor), start, end, 0);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new BulletSpan(gapWidth, bulletColor), start, end, 0);
isBullet = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (align != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(align), start, end, flag);
align = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new ImageSpan(mContext, bitmap), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new ImageSpan(drawable), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new ImageSpan(mContext, uri), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new ImageSpan(mContext, resourceId), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 26
Project: kaif-android-master File: DefaultDecorator.java View source code |
@Override
public void closeOrderedListItem(SpannableStringBuilder out) {
OrderedList orderedList = getLast(out, OrderedList.class);
if (orderedList != null) {
int number = orderedList.getAndIncrement();
int where = out.getSpanStart(getLast(out, OrderedListItem.class));
out.insert(where, Integer.toString(number) + ". ");
}
//check BulletSpan2
end(out, OrderedListItem.class, new LeadingMarginSpan.LeadingMarginSpan2.Standard(leading));
}
Example 27
Project: POI-Android-master File: TextPainter.java View source code |
public SpannableStringBuilder getAttributedString(TextRun txrun) {
String text = txrun.getText();
//TODO: properly process tabs
text = text.replace('\t', ' ');
text = text.replace((char) 160, ' ');
System.out.println("text: " + text);
SpannableStringBuilder at = new SpannableStringBuilder(text);
RichTextRun[] rt = txrun.getRichTextRuns();
for (int i = 0; i < rt.length; i++) {
int start = rt[i].getStartIndex();
int end = rt[i].getEndIndex();
if (start == end) {
logger.log(POILogger.INFO, "Skipping RichTextRun with zero length");
continue;
}
if (end > at.length() || start > at.length()) {
continue;
}
int style = Typeface.NORMAL;
if (rt[i].isBold() && rt[i].isItalic()) {
style = Typeface.BOLD_ITALIC;
} else if (rt[i].isItalic()) {
style = Typeface.ITALIC;
} else if (rt[i].isBold()) {
style = Typeface.BOLD;
}
ColorStateList color = ColorStateList.valueOf(rt[i].getFontColor().getRGB());
at.setSpan(new TextAppearanceSpan(rt[i].getFontName(), style, rt[i].getFontSize(), color, color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (rt[i].isUnderlined()) {
at.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (rt[i].isStrikethrough()) {
at.setSpan(new StrikethroughSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
int superScript = rt[i].getSuperscript();
if (superScript > 0) {
at.setSpan(new SuperscriptSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (superScript < 0) {
at.setSpan(new SubscriptSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Alignment alignment;
switch(rt[i].getAlignment()) {
case TextShape.AlignLeft:
alignment = Alignment.ALIGN_NORMAL;
break;
case TextShape.AlignRight:
alignment = Alignment.ALIGN_OPPOSITE;
break;
case TextShape.AlignCenter:
alignment = Alignment.ALIGN_CENTER;
break;
default:
alignment = Alignment.ALIGN_NORMAL;
break;
}
at.setSpan(new AlignmentSpan.Standard(alignment), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
System.out.println("start: " + start + ", end: " + end + ", offset: " + rt[i].getTextOffset() + ", getBulletOffset: " + rt[i].getBulletOffset() + ", getSpaceBefore: " + rt[i].getSpaceBefore() + ", getSpaceAfter: " + rt[i].getSpaceAfter() + ", getIndentLevel: " + rt[i].getIndentLevel() + ", getIndentLevel: " + rt[i].getAlignment() + ", text: " + rt[i].getText());
at.setSpan(new LeadingMarginSpan.Standard(rt[i].getTextOffset()), start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
return at;
}
Example 28
Project: weechat-android-master File: Line.java View source code |
/** * process the message and create a spannable object according to settings * * TODO: reuse span objects (how? would that do any good?) * * the problem is that one has to use distinct spans on the same string * * TODO: allow variable width font (should be simple enough */ public void processMessage() { if (DEBUG) logger.debug("processMessage()"); String timestamp = (P.dateFormat == null) ? null : P.dateFormat.format(date); boolean encloseNick = P.encloseNick && privmsg && !action; Color.parse(timestamp, prefix, message, encloseNick, highlighted, P.maxWidth, P.align); Spannable spannable = new SpannableString(Color.cleanMessage); if (this.type == LINE_OTHER && P.dimDownNonHumanLines) { spannable.setSpan(new ForegroundColorSpan(ColorScheme.get().chat_inactive_buffer[0] | 0xFF000000), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { CharacterStyle droidSpan; for (Color.Span span : Color.finalSpanList) { switch(span.type) { case Color.Span.FGCOLOR: droidSpan = new ForegroundColorSpan(span.color | 0xFF000000); break; case Color.Span.BGCOLOR: droidSpan = new BackgroundColorSpan(span.color | 0xFF000000); break; case Color.Span.ITALIC: droidSpan = new StyleSpan(Typeface.ITALIC); break; case Color.Span.BOLD: droidSpan = new StyleSpan(Typeface.BOLD); break; case Color.Span.UNDERLINE: droidSpan = new UnderlineSpan(); break; default: continue; } spannable.setSpan(droidSpan, span.start, span.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (P.align != Color.ALIGN_NONE) { LeadingMarginSpan margin_span = new LeadingMarginSpan.Standard(0, (int) (P.letterWidth * Color.margin)); spannable.setSpan(margin_span, 0, spannable.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); } // what a nice little custom linkifier we've got us here Linkify.linkify(spannable); this.spannable = spannable; }
Example 29
Project: Eng-Chi-Dictionary-master File: DictionaryFragment.java View source code |
private void buildHtmlFromDictionary(String query, Word word) { mWord = word; updateFavFab(word); if (word != null) { Analytics.trackFoundWord(getActivity(), word.mWord); mWordTextView.setText(word.mWord); if (!TextUtils.isEmpty(mWord.mPhoneticString)) { mPhoneticTextView.setText(mWord.mPhoneticString); } if (mWord.mDifficulty > 0) { mCommonnessBar.setVisibility(View.VISIBLE); mCommonnessBar.setLevel((5 - mWord.mDifficulty)); } else { mCommonnessBar.setVisibility(View.GONE); } List<Word.TypeEntry> typeEntries = word.mTypeEntry; SpannableStringBuilder builder = new SpannableStringBuilder(); int prevType = -1; boolean firstEntry = true; for (Word.TypeEntry typeEntry : typeEntries) { if (prevType != typeEntry.mType) { if (!firstEntry) { builder.append("\n"); } firstEntry = false; appendStyled(builder, typeEntry.getTypeDescription() + "\n", new ForegroundColorSpan(mAccentColor)); prevType = typeEntry.mType; } appendStyled(builder, "• " + typeEntry.mMeaning + "\n", new LeadingMarginSpan.Standard(INDENTATION_MEANING_LEFT, INDENTATION_EXAMPLE_LEFT)); if (!TextUtils.isEmpty(typeEntry.mEngExample)) { appendStyled(builder, typeEntry.mEngExample + "\n", new LeadingMarginSpan.Standard(INDENTATION_EXAMPLE_LEFT)); boldKeyWord(builder, typeEntry.mEngExample + "\n", word.mWord); } if (!TextUtils.isEmpty(typeEntry.mChiExample)) { appendStyled(builder, typeEntry.mChiExample + "\n", new LeadingMarginSpan.Standard(INDENTATION_EXAMPLE_LEFT)); } } mDetailTextView.setText(builder); mPronounceButton.setVisibility(View.VISIBLE); mPhoneticTextView.setVisibility(View.VISIBLE); AppPreference.saveLastWord(mContext, word.mWord); } else { Analytics.trackNotFoundWord(getActivity(), query); mWordTextView.setText("No such word :("); mCommonnessBar.setVisibility(View.GONE); mDetailTextView.setText(""); mPronounceButton.setVisibility(View.GONE); mPhoneticTextView.setVisibility(View.GONE); } }
Example 30
Project: matrix-android-sdk-master File: ConsoleHtmlTagHandler.java View source code |
@Override public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) { if (opening) { if (tag.equalsIgnoreCase("ul")) { lists.push(tag); } else if (tag.equalsIgnoreCase("ol")) { lists.push(tag); olNextIndex.push(1); } else if (tag.equalsIgnoreCase("li")) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString()).append(". "); olNextIndex.push(olNextIndex.pop() + 1); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else if (tag.equalsIgnoreCase("code")) { start(output, new Code()); } else if (tag.equalsIgnoreCase("center")) { start(output, new Center()); } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) { start(output, new Strike()); } else if (tag.equalsIgnoreCase("table")) { start(output, new Table()); if (tableTagLevel == 0) { tableHtmlBuilder = new StringBuilder(); // We need some text for the table to be replaced by the span because // the other tags will remove their text when their text is extracted output.append("table placeholder"); } tableTagLevel++; } else if (tag.equalsIgnoreCase("tr")) { start(output, new Tr()); } else if (tag.equalsIgnoreCase("th")) { start(output, new Th()); } else if (tag.equalsIgnoreCase("td")) { start(output, new Td()); } } else { if (tag.equalsIgnoreCase("ul")) { lists.pop(); } else if (tag.equalsIgnoreCase("ol")) { lists.pop(); olNextIndex.pop(); } else if (tag.equalsIgnoreCase("li")) { if (lists.peek().equalsIgnoreCase("ul")) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, false, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, false, new LeadingMarginSpan.Standard(numberMargin)); } } else if (tag.equalsIgnoreCase("code")) { end(output, Code.class, false, new BackgroundColorSpan(mContext.getResources().getColor(R.color.markdown_code_background)), new TypefaceSpan("monospace")); } else if (tag.equalsIgnoreCase("center")) { end(output, Center.class, true, new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER)); } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) { end(output, Strike.class, false, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("table")) { tableTagLevel--; // When we're back at the root-level table end(output, Table.class, false); } else if (tag.equalsIgnoreCase("tr")) { end(output, Tr.class, false); } else if (tag.equalsIgnoreCase("th")) { end(output, Th.class, false); } else if (tag.equalsIgnoreCase("td")) { end(output, Td.class, false); } } storeTableTags(opening, tag); }
Example 31
Project: android-proguards-master File: Bypass.java View source code |
// The 'numberOfSiblings' parameters refers to the number of siblings within the parent, including // the 'element' parameter, as in "How many siblings are you?" rather than "How many siblings do // you have?". private CharSequence recurseElement(Element element, int indexWithinParent, int numberOfSiblings, TextView textView, LoadImageCallback loadImageCallback) { Type type = element.getType(); boolean isOrderedList = false; if (type == Type.LIST) { String flagsStr = element.getAttribute("flags"); if (flagsStr != null) { int flags = Integer.parseInt(flagsStr); isOrderedList = (flags & Element.F_LIST_ORDERED) != 0; if (isOrderedList) { mOrderedListNumber.put(element, 1); } } } int size = element.size(); CharSequence[] spans = new CharSequence[size]; for (int i = 0; i < size; i++) { spans[i] = recurseElement(element.children[i], i, size, textView, loadImageCallback); } // Clean up after we're done if (isOrderedList) { mOrderedListNumber.remove(this); } CharSequence concat = TextUtils.concat(spans); SpannableStringBuilder builder = new ReverseSpannableStringBuilder(); String text = element.getText(); if (element.size() == 0 && element.getParent() != null && element.getParent().getType() != Type.BLOCK_CODE) { text = text.replace('\n', ' '); } switch(type) { case LIST: if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { builder.append("\n"); } break; case LINEBREAK: builder.append("\n"); break; case LIST_ITEM: builder.append(" "); if (mOrderedListNumber.containsKey(element.getParent())) { int number = mOrderedListNumber.get(element.getParent()); builder.append(Integer.toString(number) + "."); mOrderedListNumber.put(element.getParent(), number + 1); } else { builder.append(mOptions.mUnorderedListItem); } builder.append(" "); break; case AUTOLINK: builder.append(element.getAttribute("link")); break; case HRULE: // This ultimately gets drawn over by the line span, but // we need something here or the span isn't even drawn. builder.append("-"); break; case IMAGE: if (loadImageCallback != null && !TextUtils.isEmpty(element.getAttribute("link"))) { // prepend a new line so that images are always on a new line builder.append("\n"); // Display alt text (or title text) if there is no image String alt = element.getAttribute("alt"); if (TextUtils.isEmpty(alt)) { alt = element.getAttribute("title"); } if (!TextUtils.isEmpty(alt)) { alt = "[" + alt + "]"; builder.append(alt); } else { // Character to be replaced builder.append(""); } } else { // Character to be replaced builder.append(""); } break; } builder.append(text); builder.append(concat); // of the last child within the parent. if (element.getParent() != null || indexWithinParent < (numberOfSiblings - 1)) { if (type == Type.LIST_ITEM) { if (element.size() == 0 || !element.children[element.size() - 1].isBlockElement()) { builder.append("\n"); } } else if (element.isBlockElement() && type != Type.BLOCK_QUOTE) { if (type == Type.LIST) { // If this is a nested list, don't include newlines if (element.getParent() == null || element.getParent().getType() != Type.LIST_ITEM) { builder.append("\n"); } } else if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { // List items should never double-space their entries builder.append("\n"); } else { builder.append("\n\n"); } } } switch(type) { case HEADER: String levelStr = element.getAttribute("level"); int level = Integer.parseInt(levelStr); setSpan(builder, new RelativeSizeSpan(mOptions.mHeaderSizes[level - 1])); setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case LIST: setBlockSpan(builder, new LeadingMarginSpan.Standard(mListItemIndent)); break; case EMPHASIS: setSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case DOUBLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case TRIPLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD_ITALIC)); break; case BLOCK_CODE: setSpan(builder, new LeadingMarginSpan.Standard(mCodeBlockIndent)); setSpan(builder, new TypefaceSpan("monospace")); break; case CODE_SPAN: setSpan(builder, new TypefaceSpan("monospace")); break; case LINK: case AUTOLINK: String link = element.getAttribute("link"); if (!TextUtils.isEmpty(link) && Patterns.EMAIL_ADDRESS.matcher(link).matches()) { link = "mailto:" + link; } setSpan(builder, new TouchableUrlSpan(link, textView.getLinkTextColors(), textView.getHighlightColor())); break; case BLOCK_QUOTE: // We add two leading margin spans so that when the order is reversed, // the QuoteSpan will always be in the same spot. setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); //setBlockSpan(builder, new QuoteSpan(mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new FancyQuoteSpan(mBlockQuoteLineWidth, mBlockQuoteLineIndent, mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new ForegroundColorSpan(mOptions.mBlockQuoteTextColor)); setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); setBlockSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case STRIKETHROUGH: setSpan(builder, new StrikethroughSpan()); break; case HRULE: setSpan(builder, new HorizontalLineSpan(mOptions.mHruleColor, mHruleSize, mHruleTopBottomPadding)); break; case IMAGE: String url = element.getAttribute("link"); if (loadImageCallback != null && !TextUtils.isEmpty(url)) { setPrependedNewlineSpan(builder, mOptions.mPreImageLinebreakHeight); ImageLoadingSpan loadingSpan = new ImageLoadingSpan(); setSpanWithPrependedNewline(builder, loadingSpan); // make the (eventually loaded) image span clickable to open in browser setSpanWithPrependedNewline(builder, new TouchableUrlSpan(url, textView.getLinkTextColors(), textView.getHighlightColor())); loadImageCallback.loadImage(url, loadingSpan); } break; } return builder; }
Example 32
Project: BaseRecyclerViewAdapterHelper-master File: SpannableStringUtils.java View source code |
/**
* è®¾ç½®æ ·å¼?
*/
private void setSpan() {
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new QuoteSpan(quoteColor), start, end, 0);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new BulletSpan(gapWidth, bulletColor), start, end, 0);
isBullet = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (align != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(align), start, end, flag);
align = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), bitmap), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new ImageSpan(drawable), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), uri), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), resourceId), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 33
Project: bypasses-master File: Bypass.java View source code |
// The 'numberOfSiblings' parameters refers to the number of siblings within the parent, including // the 'element' parameter, as in "How many siblings are you?" rather than "How many siblings do // you have?". private CharSequence recurseElement(Element element, int indexWithinParent, int numberOfSiblings, ImageGetter imageGetter) { Type type = element.getType(); boolean isOrderedList = false; if (type == Type.LIST) { String flagsStr = element.getAttribute("flags"); if (flagsStr != null) { int flags = Integer.parseInt(flagsStr); isOrderedList = (flags & Element.F_LIST_ORDERED) != 0; if (isOrderedList) { mOrderedListNumber.put(element, 1); } } } int size = element.size(); CharSequence[] spans = new CharSequence[size]; for (int i = 0; i < size; i++) { spans[i] = recurseElement(element.children[i], i, size, imageGetter); } // Clean up after we're done if (isOrderedList) { mOrderedListNumber.remove(this); } CharSequence concat = TextUtils.concat(spans); SpannableStringBuilder builder = new ReverseSpannableStringBuilder(); String text = element.getText(); if (element.size() == 0 && element.getParent() != null && element.getParent().getType() != Type.BLOCK_CODE) { text = text.replace('\n', ' '); } // Retrieve the image now so we know whether we're going to have something to display later // If we don't, then show the alt text instead (if available). Drawable imageDrawable = null; String imageLink = element.getAttribute("link"); if (type == Type.IMAGE && imageGetter != null && !TextUtils.isEmpty(imageLink)) { imageDrawable = imageGetter.getDrawable(imageLink); } switch(type) { case LIST: if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { builder.append("\n"); } break; case LINEBREAK: builder.append("\n"); break; case LIST_ITEM: builder.append(" "); if (mOrderedListNumber.containsKey(element.getParent())) { int number = mOrderedListNumber.get(element.getParent()); builder.append(Integer.toString(number) + "."); mOrderedListNumber.put(element.getParent(), number + 1); } else { builder.append(mOptions.mUnorderedListItem); } builder.append(" "); break; case AUTOLINK: builder.append(element.getAttribute("link")); break; case HRULE: // This ultimately gets drawn over by the line span, but // we need something here or the span isn't even drawn. builder.append("-"); break; case IMAGE: // Display alt text (or title text) if there is no image if (imageDrawable == null) { String show = element.getAttribute("alt"); if (TextUtils.isEmpty(show)) { show = element.getAttribute("title"); } if (!TextUtils.isEmpty(show)) { show = "[" + show + "]"; builder.append(show); } } else { // Character to be replaced builder.append(""); } break; } builder.append(text); builder.append(concat); // of the last child within the parent. if (element.getParent() != null || indexWithinParent < (numberOfSiblings - 1)) { if (type == Type.LIST_ITEM) { if (element.size() == 0 || !element.children[element.size() - 1].isBlockElement()) { builder.append("\n"); } } else if (element.isBlockElement() && type != Type.BLOCK_QUOTE) { if (type == Type.LIST) { // If this is a nested list, don't include newlines if (element.getParent() == null || element.getParent().getType() != Type.LIST_ITEM) { builder.append("\n"); } } else if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { // List items should never double-space their entries builder.append("\n"); } else { builder.append("\n\n"); } } } switch(type) { case HEADER: String levelStr = element.getAttribute("level"); int level = Integer.parseInt(levelStr); setSpan(builder, new RelativeSizeSpan(mOptions.mHeaderSizes[level - 1])); setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case LIST: setBlockSpan(builder, new LeadingMarginSpan.Standard(mListItemIndent)); break; case EMPHASIS: setSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case DOUBLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case TRIPLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD_ITALIC)); break; case BLOCK_CODE: setSpan(builder, new LeadingMarginSpan.Standard(mCodeBlockIndent)); setSpan(builder, new TypefaceSpan("monospace")); break; case CODE_SPAN: setSpan(builder, new TypefaceSpan("monospace")); break; case LINK: case AUTOLINK: String link = element.getAttribute("link"); if (!TextUtils.isEmpty(link) && Patterns.EMAIL_ADDRESS.matcher(link).matches()) { link = "mailto:" + link; } setSpan(builder, new URLSpan(link)); break; case BLOCK_QUOTE: // We add two leading margin spans so that when the order is reversed, // the QuoteSpan will always be in the same spot. setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); setBlockSpan(builder, new QuoteSpan(mOptions.mBlockQuoteColor)); setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); setBlockSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case STRIKETHROUGH: setSpan(builder, new StrikethroughSpan()); break; case HRULE: setSpan(builder, new HorizontalLineSpan(mOptions.mHruleColor, mHruleSize, mHruleTopBottomPadding)); break; case IMAGE: if (imageDrawable != null) { setClickableImageSpan(builder, new ImageSpan(imageDrawable), imageLink); } break; } return builder; }
Example 34
Project: html-textview-master File: HtmlTagHandler.java View source code |
@Override public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) { if (opening) { // opening tag if (HtmlTextView.DEBUG) { Log.d(HtmlTextView.TAG, "opening, output: " + output.toString()); } if (tag.equalsIgnoreCase(UNORDERED_LIST)) { lists.push(tag); } else if (tag.equalsIgnoreCase(ORDERED_LIST)) { lists.push(tag); olNextIndex.push(1); } else if (tag.equalsIgnoreCase(LIST_ITEM)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } if (!lists.isEmpty()) { String parentList = lists.peek(); if (parentList.equalsIgnoreCase(ORDERED_LIST)) { start(output, new Ol()); olNextIndex.push(olNextIndex.pop() + 1); } else if (parentList.equalsIgnoreCase(UNORDERED_LIST)) { start(output, new Ul()); } } } else if (tag.equalsIgnoreCase("code")) { start(output, new Code()); } else if (tag.equalsIgnoreCase("center")) { start(output, new Center()); } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) { start(output, new Strike()); } else if (tag.equalsIgnoreCase("table")) { start(output, new Table()); if (tableTagLevel == 0) { tableHtmlBuilder = new StringBuilder(); // We need some text for the table to be replaced by the span because // the other tags will remove their text when their text is extracted output.append("table placeholder"); } tableTagLevel++; } else if (tag.equalsIgnoreCase("tr")) { start(output, new Tr()); } else if (tag.equalsIgnoreCase("th")) { start(output, new Th()); } else if (tag.equalsIgnoreCase("td")) { start(output, new Td()); } } else { // closing tag if (HtmlTextView.DEBUG) { Log.d(HtmlTextView.TAG, "closing, output: " + output.toString()); } if (tag.equalsIgnoreCase(UNORDERED_LIST)) { lists.pop(); } else if (tag.equalsIgnoreCase(ORDERED_LIST)) { lists.pop(); olNextIndex.pop(); } else if (tag.equalsIgnoreCase(LIST_ITEM)) { if (!lists.isEmpty()) { if (lists.peek().equalsIgnoreCase(UNORDERED_LIST)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, false, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase(ORDERED_LIST)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } NumberSpan numberSpan = new NumberSpan(mTextPaint, olNextIndex.lastElement() - 1); end(output, Ol.class, false, new LeadingMarginSpan.Standard(numberMargin), numberSpan); } } } else if (tag.equalsIgnoreCase("code")) { end(output, Code.class, false, new TypefaceSpan("monospace")); } else if (tag.equalsIgnoreCase("center")) { end(output, Center.class, true, new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER)); } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) { end(output, Strike.class, false, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("table")) { tableTagLevel--; // When we're back at the root-level table if (tableTagLevel == 0) { final String tableHtml = tableHtmlBuilder.toString(); ClickableTableSpan myClickableTableSpan = null; if (clickableTableSpan != null) { myClickableTableSpan = clickableTableSpan.newInstance(); myClickableTableSpan.setTableHtml(tableHtml); } DrawTableLinkSpan myDrawTableLinkSpan = null; if (drawTableLinkSpan != null) { myDrawTableLinkSpan = drawTableLinkSpan.newInstance(); } end(output, Table.class, false, myDrawTableLinkSpan, myClickableTableSpan); } else { end(output, Table.class, false); } } else if (tag.equalsIgnoreCase("tr")) { end(output, Tr.class, false); } else if (tag.equalsIgnoreCase("th")) { end(output, Th.class, false); } else if (tag.equalsIgnoreCase("td")) { end(output, Td.class, false); } } storeTableTags(opening, tag); }
Example 35
Project: life-master File: SpanRecyclerAdapter.java View source code |
@SuppressLint("SetTextI18n") public void setSpanContent(TextView labelTV, TextView contentTV, String content, int position) { SpannableStringBuilder ssb = new SpannableStringBuilder(content); String sub = "Save"; int start = content.indexOf("Save"); switch(position) { case URL_SPAN: { labelTV.setText("URLSpan"); ssb.setSpan(new URLSpan("https://github.com/CaMnter"), start, sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); // 在�击链接时凡是有�执行的动作,都必须设置MovementMethod对象 contentTV.setMovementMethod(LinkMovementMethod.getInstance()); // 设置点击�的颜色,这里涉�到ClickableSpan的点击背景 contentTV.setHighlightColor(0xff8FABCC); break; } case UNDERLINE_SPAN: { labelTV.setText("UnderlineSpan"); ssb.setSpan(new UnderlineSpan(), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case TYPEFACE_SPAN: { labelTV.setText("TypefaceSpan ( Examples include \"monospace\", \"serif\", and \"sans-serif\". )"); ssb.setSpan(new TypefaceSpan("serif"), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case TEXT_APPERARANCE_SPAN: { labelTV.setText("TextAppearanceSpan"); ColorStateList colorStateList; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { colorStateList = this.activity.getColorStateList(R.color.selector_apperarance_span); } else { colorStateList = this.activity.getResources().getColorStateList(R.color.selector_apperarance_span); } ssb.setSpan(new TextAppearanceSpan("serif", Typeface.BOLD_ITALIC, this.activity.getResources().getDimensionPixelSize(R.dimen.text_appearance_span), colorStateList, colorStateList), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case TAB_STOP_SPAN: { labelTV.setText("TabStopSpan.Standard"); String[] subs = content.split(" "); ssb = new SpannableStringBuilder(); /** * TabStopSpan. Standard related to \t and \n * TabStopSpan.Standard 跟 \t 和 \n 有关系 */ for (String sub1 : subs) { ssb.append("\t").append(sub1).append(" "); ssb.append("\n"); } ssb.setSpan(new TabStopSpan.Standard(126), 0, ssb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case SUPERS_SCRIPT_SPAN: { labelTV.setText("SuperscriptSpan"); ssb.replace(start, start + sub.length(), "Save6"); Parcel parcel = Parcel.obtain(); parcel.writeInt(6); int sixPosition = ssb.toString().indexOf("6"); ssb.setSpan(new SuperscriptSpan(parcel), sixPosition, sixPosition + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); parcel.recycle(); contentTV.setText(ssb); break; } case SUB_SCRIPT_SPAN: { labelTV.setText("SubscriptSpan"); ssb.replace(start, start + sub.length(), "Save6"); Parcel parcel = Parcel.obtain(); parcel.writeInt(6); int sixPosition = ssb.toString().indexOf("6"); ssb.setSpan(new SubscriptSpan(parcel), sixPosition, sixPosition + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); parcel.recycle(); contentTV.setText(ssb); break; } case STRIKE_THROUGH_SPAN: { labelTV.setText("StrikethroughSpan"); ssb.setSpan(new StrikethroughSpan(), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case SCALE_X_SPAN: { labelTV.setText("ScaleXSpan"); ssb.setSpan(new ScaleXSpan(2.0f), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case STYLE_SPAN: { labelTV.setText("StyleSpan ( Typeface.NORMAL,Typeface.BOLD,Typeface.ITALIC,Typeface.BOLD_ITALIC ) "); ssb.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case RELATIVE_SIZE_SPAN: { labelTV.setText("RelativeSizeSpan"); ssb.setSpan(new RelativeSizeSpan(6.0f), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case QUOTO_SPAN: { labelTV.setText("QuoteSpan"); ssb.setSpan(new QuoteSpan(0xff000000), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case MASK_FILTER_SPAN: { labelTV.setText("MaskFilterSpan ( BlurMaskFilter EmbossMaskFilter ) \n Activity: android:hardwareAccelerated=\"false\"\n "); MaskFilterSpan embossMaskFilterSpan = new MaskFilterSpan(new EmbossMaskFilter(new float[] { 3, 3, 9 }, 3.0f, 12, 16)); ssb.setSpan(embossMaskFilterSpan, start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); String you = "you"; int indexYou = content.indexOf(you); MaskFilterSpan blurMaskFilterSpan = new MaskFilterSpan(new BlurMaskFilter(3, BlurMaskFilter.Blur.OUTER)); ssb.setSpan(blurMaskFilterSpan, indexYou, indexYou + you.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case LEADING_MARGIN_SPAN: { labelTV.setText("LeadingMarginSpan"); ssb.append(" ").append(ssb.toString()).append(ssb.toString()).append(ssb.toString()); ssb.setSpan(new LeadingMarginSpan.Standard(96, 36), 0, ssb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case IMAGE_SPAN: { labelTV.setText("ImageSpan"); ssb.replace(start, start + sub.length(), " Save"); ssb.setSpan(new ImageSpan(this.activity, R.drawable.ic_mm_normal, ImageSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case ICON_MARGIN_SPAN: { labelTV.setText("IconMarginSpan"); Bitmap bitmap = BitmapFactory.decodeResource(this.activity.getResources(), R.drawable.ic_mm_normal); ssb.setSpan(new IconMarginSpan(bitmap, 60), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //bitmap.recycle(); contentTV.setText(ssb); break; } case FOREGROUND_COLOR_SPAN: { labelTV.setText("ForegroundColorSpan"); ssb.setSpan(new ForegroundColorSpan(0xff303F9F), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); contentTV.setText(ssb); break; } case DRAWABLE_MARGIN_SPAN: { labelTV.setText("DrawableMarginSpan"); ssb.setSpan(new DrawableMarginSpan(ResourcesUtils.getDrawable(this.activity, R.drawable.ic_mm_normal), 6), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); break; } case BULLET_SPAN: { labelTV.setText("BulletSpan"); ssb.setSpan(new BulletSpan(66, 0xff303F9F), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); break; } case BACKGROUND_COLOR_SPAN: { labelTV.setText("BackgroundColorSpan"); String you = "you"; int indexYou = content.indexOf(you); ssb.setSpan(new BackgroundColorSpan(0x2f303F9F), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new BackgroundColorSpan(0x2fFF4081), indexYou, indexYou + you.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); break; } case ALIGNMENT_SPAN_STANDARD: { labelTV.setText("AlignmentSpan.Standard"); ssb.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); break; } case ABSOLUTE_SIZE_SPAN: { labelTV.setText("AbsoluteSizeSpan"); ssb.setSpan(new AbsoluteSizeSpan(26, true), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); break; } case CLICKABLE_SPAN: { labelTV.setText("ClickableSpan ( Please click \"Save\" )"); SpanClickableSpan spanClickableSpan = new SpanClickableSpan(0xffFF4081, new ClickableSpanNoUnderline.OnClickListener<SpanClickableSpan>() { /** * ClickableSpan被点击 * * @param widget widget * @param span span */ @Override public void onClick(View widget, SpanClickableSpan span) { String urlString = span.getUrlString(); if (TextUtils.isEmpty(urlString)) return; Uri uri = Uri.parse(urlString); Context context = widget.getContext(); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); try { context.startActivity(intent); } catch (ActivityNotFoundException e) { Log.w("URLSpan", "Activity was not found for intent, " + intent.toString()); } } }); spanClickableSpan.setUrlString("https://github.com/CaMnter"); ssb.setSpan(spanClickableSpan, start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); contentTV.setText(ssb); // 在�击链接时凡是有�执行的动作,都必须设置MovementMethod对象 contentTV.setMovementMethod(LinkMovementMethod.getInstance()); // 设置点击�的颜色,这里涉�到ClickableSpan的点击背景 contentTV.setHighlightColor(0x00000000); break; } } }
Example 36
Project: nusic-master File: TextUtil.java View source code |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); // TODO: add support for lists starting other index than 1 olNextIndex.push(Integer.valueOf(1)).toString(); } else { lists.pop(); olNextIndex.pop().toString(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet // and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 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 -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of // nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else { if (opening) { // Log unknown tags if (!IGNORED_TAGS.contains(tag)) Log.d("TagHandler", "Found an unsupported tag " + tag); } } }
Example 37
Project: OdyAndroidStore-master File: SpannableStringUtils.java View source code |
/**
* è®¾ç½®æ ·å¼?
*/
private void setSpan() {
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new QuoteSpan(quoteColor), start, end, 0);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new BulletSpan(gapWidth, bulletColor), start, end, 0);
isBullet = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (align != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(align), start, end, flag);
align = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), bitmap), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new ImageSpan(drawable), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), uri), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new ImageSpan(Utils.getContext(), resourceId), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 38
Project: plaid-master File: Bypass.java View source code |
// The 'numberOfSiblings' parameters refers to the number of siblings within the parent, including // the 'element' parameter, as in "How many siblings are you?" rather than "How many siblings do // you have?". private CharSequence recurseElement(Element element, int indexWithinParent, int numberOfSiblings, TextView textView, LoadImageCallback loadImageCallback) { Type type = element.getType(); boolean isOrderedList = false; if (type == Type.LIST) { String flagsStr = element.getAttribute("flags"); if (flagsStr != null) { int flags = Integer.parseInt(flagsStr); isOrderedList = (flags & Element.F_LIST_ORDERED) != 0; if (isOrderedList) { mOrderedListNumber.put(element, 1); } } } int size = element.size(); CharSequence[] spans = new CharSequence[size]; for (int i = 0; i < size; i++) { spans[i] = recurseElement(element.children[i], i, size, textView, loadImageCallback); } // Clean up after we're done if (isOrderedList) { mOrderedListNumber.remove(this); } CharSequence concat = TextUtils.concat(spans); SpannableStringBuilder builder = new ReverseSpannableStringBuilder(); String text = element.getText(); if (element.size() == 0 && element.getParent() != null && element.getParent().getType() != Type.BLOCK_CODE) { text = text.replace('\n', ' '); } switch(type) { case LIST: if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { builder.append("\n"); } break; case LINEBREAK: builder.append("\n"); break; case LIST_ITEM: builder.append(" "); if (mOrderedListNumber.containsKey(element.getParent())) { int number = mOrderedListNumber.get(element.getParent()); builder.append(Integer.toString(number) + "."); mOrderedListNumber.put(element.getParent(), number + 1); } else { builder.append(mOptions.mUnorderedListItem); } builder.append(" "); break; case AUTOLINK: builder.append(element.getAttribute("link")); break; case HRULE: // This ultimately gets drawn over by the line span, but // we need something here or the span isn't even drawn. builder.append("-"); break; case IMAGE: if (loadImageCallback != null && !TextUtils.isEmpty(element.getAttribute("link"))) { // prepend a new line so that images are always on a new line builder.append("\n"); // Display alt text (or title text) if there is no image String alt = element.getAttribute("alt"); if (TextUtils.isEmpty(alt)) { alt = element.getAttribute("title"); } if (!TextUtils.isEmpty(alt)) { alt = "[" + alt + "]"; builder.append(alt); } else { // Character to be replaced builder.append(""); } } else { // Character to be replaced builder.append(""); } break; } builder.append(text); builder.append(concat); // of the last child within the parent. if (element.getParent() != null || indexWithinParent < (numberOfSiblings - 1)) { if (type == Type.LIST_ITEM) { if (element.size() == 0 || !element.children[element.size() - 1].isBlockElement()) { builder.append("\n"); } } else if (element.isBlockElement() && type != Type.BLOCK_QUOTE) { if (type == Type.LIST) { // If this is a nested list, don't include newlines if (element.getParent() == null || element.getParent().getType() != Type.LIST_ITEM) { builder.append("\n"); } } else if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { // List items should never double-space their entries builder.append("\n"); } else { builder.append("\n\n"); } } } switch(type) { case HEADER: String levelStr = element.getAttribute("level"); int level = Integer.parseInt(levelStr); setSpan(builder, new RelativeSizeSpan(mOptions.mHeaderSizes[level - 1])); setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case LIST: setBlockSpan(builder, new LeadingMarginSpan.Standard(mListItemIndent)); break; case EMPHASIS: setSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case DOUBLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case TRIPLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD_ITALIC)); break; case BLOCK_CODE: setSpan(builder, new LeadingMarginSpan.Standard(mCodeBlockIndent)); setSpan(builder, new TypefaceSpan("monospace")); break; case CODE_SPAN: setSpan(builder, new TypefaceSpan("monospace")); break; case LINK: case AUTOLINK: String link = element.getAttribute("link"); if (!TextUtils.isEmpty(link) && Patterns.EMAIL_ADDRESS.matcher(link).matches()) { link = "mailto:" + link; } setSpan(builder, new TouchableUrlSpan(link, textView.getLinkTextColors(), textView.getHighlightColor())); break; case BLOCK_QUOTE: // We add two leading margin spans so that when the order is reversed, // the QuoteSpan will always be in the same spot. setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); //setBlockSpan(builder, new QuoteSpan(mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new FancyQuoteSpan(mBlockQuoteLineWidth, mBlockQuoteLineIndent, mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new ForegroundColorSpan(mOptions.mBlockQuoteTextColor)); setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); setBlockSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case STRIKETHROUGH: setSpan(builder, new StrikethroughSpan()); break; case HRULE: setSpan(builder, new HorizontalLineSpan(mOptions.mHruleColor, mHruleSize, mHruleTopBottomPadding)); break; case IMAGE: String url = element.getAttribute("link"); if (loadImageCallback != null && !TextUtils.isEmpty(url)) { setPrependedNewlineSpan(builder, mOptions.mPreImageLinebreakHeight); ImageLoadingSpan loadingSpan = new ImageLoadingSpan(); setSpanWithPrependedNewline(builder, loadingSpan); // make the (eventually loaded) image span clickable to open in browser setSpanWithPrependedNewline(builder, new TouchableUrlSpan(url, textView.getLinkTextColors(), textView.getHighlightColor())); loadImageCallback.loadImage(url, loadingSpan); } break; } return builder; }
Example 39
Project: sbt-android-master File: Bypass.java View source code |
// The 'numberOfSiblings' parameters refers to the number of siblings within the parent, including // the 'element' parameter, as in "How many siblings are you?" rather than "How many siblings do // you have?". private CharSequence recurseElement(Element element, int indexWithinParent, int numberOfSiblings, TextView textView, LoadImageCallback loadImageCallback) { Type type = element.getType(); boolean isOrderedList = false; if (type == Type.LIST) { String flagsStr = element.getAttribute("flags"); if (flagsStr != null) { int flags = Integer.parseInt(flagsStr); isOrderedList = (flags & Element.F_LIST_ORDERED) != 0; if (isOrderedList) { mOrderedListNumber.put(element, 1); } } } int size = element.size(); CharSequence[] spans = new CharSequence[size]; for (int i = 0; i < size; i++) { spans[i] = recurseElement(element.children[i], i, size, textView, loadImageCallback); } // Clean up after we're done if (isOrderedList) { mOrderedListNumber.remove(this); } CharSequence concat = TextUtils.concat(spans); SpannableStringBuilder builder = new ReverseSpannableStringBuilder(); String text = element.getText(); if (element.size() == 0 && element.getParent() != null && element.getParent().getType() != Type.BLOCK_CODE) { text = text.replace('\n', ' '); } switch(type) { case LIST: if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { builder.append("\n"); } break; case LINEBREAK: builder.append("\n"); break; case LIST_ITEM: builder.append(" "); if (mOrderedListNumber.containsKey(element.getParent())) { int number = mOrderedListNumber.get(element.getParent()); builder.append(Integer.toString(number) + "."); mOrderedListNumber.put(element.getParent(), number + 1); } else { builder.append(mOptions.mUnorderedListItem); } builder.append(" "); break; case AUTOLINK: builder.append(element.getAttribute("link")); break; case HRULE: // This ultimately gets drawn over by the line span, but // we need something here or the span isn't even drawn. builder.append("-"); break; case IMAGE: if (loadImageCallback != null && !TextUtils.isEmpty(element.getAttribute("link"))) { // prepend a new line so that images are always on a new line builder.append("\n"); // Display alt text (or title text) if there is no image String alt = element.getAttribute("alt"); if (TextUtils.isEmpty(alt)) { alt = element.getAttribute("title"); } if (!TextUtils.isEmpty(alt)) { alt = "[" + alt + "]"; builder.append(alt); } else { // Character to be replaced builder.append(""); } } else { // Character to be replaced builder.append(""); } break; } builder.append(text); builder.append(concat); // of the last child within the parent. if (element.getParent() != null || indexWithinParent < (numberOfSiblings - 1)) { if (type == Type.LIST_ITEM) { if (element.size() == 0 || !element.children[element.size() - 1].isBlockElement()) { builder.append("\n"); } } else if (element.isBlockElement() && type != Type.BLOCK_QUOTE) { if (type == Type.LIST) { // If this is a nested list, don't include newlines if (element.getParent() == null || element.getParent().getType() != Type.LIST_ITEM) { builder.append("\n"); } } else if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) { // List items should never double-space their entries builder.append("\n"); } else { builder.append("\n\n"); } } } switch(type) { case HEADER: String levelStr = element.getAttribute("level"); int level = Integer.parseInt(levelStr); setSpan(builder, new RelativeSizeSpan(mOptions.mHeaderSizes[level - 1])); setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case LIST: setBlockSpan(builder, new LeadingMarginSpan.Standard(mListItemIndent)); break; case EMPHASIS: setSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case DOUBLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD)); break; case TRIPLE_EMPHASIS: setSpan(builder, new StyleSpan(Typeface.BOLD_ITALIC)); break; case BLOCK_CODE: setSpan(builder, new LeadingMarginSpan.Standard(mCodeBlockIndent)); setSpan(builder, new TypefaceSpan("monospace")); break; case CODE_SPAN: setSpan(builder, new TypefaceSpan("monospace")); break; case LINK: case AUTOLINK: String link = element.getAttribute("link"); if (!TextUtils.isEmpty(link) && Patterns.EMAIL_ADDRESS.matcher(link).matches()) { link = "mailto:" + link; } setSpan(builder, new TouchableUrlSpan(link, textView.getLinkTextColors(), textView.getHighlightColor())); break; case BLOCK_QUOTE: // We add two leading margin spans so that when the order is reversed, // the QuoteSpan will always be in the same spot. setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); //setBlockSpan(builder, new QuoteSpan(mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new FancyQuoteSpan(mBlockQuoteLineWidth, mBlockQuoteLineIndent, mOptions.mBlockQuoteLineColor)); setBlockSpan(builder, new ForegroundColorSpan(mOptions.mBlockQuoteTextColor)); setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent)); setBlockSpan(builder, new StyleSpan(Typeface.ITALIC)); break; case STRIKETHROUGH: setSpan(builder, new StrikethroughSpan()); break; case HRULE: setSpan(builder, new HorizontalLineSpan(mOptions.mHruleColor, mHruleSize, mHruleTopBottomPadding)); break; case IMAGE: String url = element.getAttribute("link"); if (loadImageCallback != null && !TextUtils.isEmpty(url)) { setPrependedNewlineSpan(builder, mOptions.mPreImageLinebreakHeight); ImageLoadingSpan loadingSpan = new ImageLoadingSpan(); setSpanWithPrependedNewline(builder, loadingSpan); // make the (eventually loaded) image span clickable to open in browser setSpanWithPrependedNewline(builder, new TouchableUrlSpan(url, textView.getLinkTextColors(), textView.getHighlightColor())); loadImageCallback.loadImage(url, loadingSpan); } break; } return builder; }
Example 40
Project: TL-android-app-master File: RenderUBB.java View source code |
private void renderTagNode(TagNode node) throws IOException {
String nodeString = node.toString();
if (nodeString.equals("br")) {
curEditable.append("\n");
renderChildren(node);
} else if (nodeString.equals("b") || nodeString.equals("strong")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
((Spannable) curEditable).setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
curEditable.append(" ");
} else if (nodeString.equals("i")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
((Spannable) curEditable).setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
curEditable.append(" ");
} else if (nodeString.equals("font")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
int size;
if (node.hasAttribute("size")) {
size = Integer.parseInt(node.getAttributeByName("size"));
if (size == 4) {
((Spannable) curEditable).setSpan(new TextAppearanceSpan(null, 0, 20, null, null), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
if (node.hasAttribute("style")) {
String style = node.getAttributeByName("style");
renderStyleAttribute(style, start, end);
}
} else if (nodeString.equals("div") && node.hasAttribute("id") && (node.getAttributeByName("id").contains("spoiler") || node.getAttributeByName("id").contains("Quote"))) {
TextView temp = curTextView;
Editable tempEditable = curEditable;
makeTextView();
curEditable.append("\n");
SpoilerSpan tempSpoilerSpan = curSpoilerSpan;
// In retrospect perhaps I should have just gone with an actually recursive implementation
SpoilerSpan tempParentSpoilerSpan = parentSpoilerSpan;
parentSpoilerSpan = curSpoilerSpan;
renderChildren(node);
curSpoilerSpan = tempSpoilerSpan;
parentSpoilerSpan = tempParentSpoilerSpan;
curSpoilerSpan.setTagNode(node);
curSpoilerSpan.setCharSequence((CharSequence) curTextView.getText());
curTextView = temp;
curEditable = tempEditable;
} else if (nodeString.equals("div") && node.hasAttribute("class") && node.getAttributeByName("class").equals("quote")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
((Spannable) curEditable).setSpan(new QuoteSpan(R.color.TLBlueBlack), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((Spannable) curEditable).setSpan(new LeadingMarginSpan.Standard(10), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((Spannable) curEditable).setSpan(new TextAppearanceSpan(null, 0, 12, null, null), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (nodeString.equals("div")) {
curEditable.append("\n");
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
if (node.hasAttribute("style")) {
String style = node.getAttributeByName("style");
renderStyleAttribute(style, start, end);
}
} else if (nodeString.equals("a")) {
if (// spoiler tag
node.hasAttribute("onclick")) {
String txt = "";
//the spoiler 'a' tag contains two span like this <span>+ Show </span> Spoiler<span> + </span>
if (node.getAttributeByName("onclick").contains("ShowSpoiler")) {
Iterator itTagNode = node.getChildren().iterator();
TagNode firstSpan = (TagNode) itTagNode.next();
String middleString = HtmlTools.unescapeHtml(itTagNode.next().toString().trim());
TagNode thirdSpan = (TagNode) itTagNode.next();
txt = HtmlTools.unescapeHtml(firstSpan.getChildren().iterator().next().toString().trim()) + " " + middleString + " " + HtmlTools.unescapeHtml(thirdSpan.getChildren().iterator().next().toString().trim());
} else //this is for the nested quotes
{
txt = HtmlTools.unescapeHtml(node.getChildren().iterator().next().toString().trim());
}
int start = curEditable.length();
curTextView.append(txt);
int end = curEditable.length();
curSpoilerSpan = new SpoilerSpan(end, globalTextView);
if (parentSpoilerSpan != null) {
parentSpoilerSpan.spoilerSpanList.add(curSpoilerSpan);
}
((Spannable) curEditable).setSpan(curSpoilerSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (node.hasAttribute("href")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
String link = node.getAttributeByName("href");
if (DisplayableLinkSpan.isDisplayable(link)) {
((Spannable) curEditable).setSpan(new DisplayableLinkSpan(link, context), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
if (link.charAt(0) == '/') {
link = TLLib.getAbsoluteURL(link);
}
((Spannable) curEditable).setSpan(new URLSpan(link), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
curTextView.append(" ");
}
} else if (nodeString.equals("img")) {
if (Config.showImages) {
if (node.getAttributeByName("src").charAt(0) == '/' || node.getAttributeByName("src").startsWith("http://www.teamliquid.net")) {
curTextView.append(Html.fromHtml(serializer.getXmlAsString(node), imageGetter, null));
} else {
String imageLink = "<a href=\"" + node.getAttributeByName("src") + "\">View Image</a><br/>";
curTextView.append(Html.fromHtml(imageLink));
}
}
} else if (nodeString.equals("center")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
Spannable span = (Spannable) curEditable;
span.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (nodeString.equals("hr")) {
curTextView.append("\n----------------\n");
} else if (nodeString.equals("p")) {
curTextView.append("\n");
renderChildren(node);
curTextView.append("\n");
} else if (nodeString.equals("object")) {
String youtubeURL = node.getAttributeByName("data");
String imageLink = String.format("<a href=\"%s\">Watch Video</a>", youtubeURL);
curTextView.append(Html.fromHtml(imageLink));
} else if (nodeString.equals("table") || nodeString.equals("tbody") || nodeString.equals("tr") || nodeString.equals("td")) {
renderChildren(node);
} else if (nodeString.equals("ul")) {
curTextView.append("\n");
renderChildren(node);
curTextView.append("\n");
} else if (nodeString.equals("li")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
Spannable span = (Spannable) curEditable;
span.setSpan(new BulletSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (nodeString.equals("s")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
((Spannable) curEditable).setSpan(new StrikethroughSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
curTextView.append(" ");
} else if (nodeString.equals("u")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
((Spannable) curEditable).setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
curTextView.append(" ");
} else if (nodeString.equals("span")) {
int start = curEditable.length();
renderChildren(node);
int end = curEditable.length();
if (node.hasAttribute("style")) {
renderStyleAttribute(node.getAttributeByName("style"), start, end);
}
} else {
Spanned span = Html.fromHtml(node.toString(), null, null);
curTextView.append(span);
renderChildren(node);
}
}
Example 41
Project: XFrame-master File: XSpannableStringUtils.java View source code |
/**
* è®¾ç½®æ ·å¼?
*/
private void setSpan() {
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new QuoteSpan(quoteColor), start, end, 0);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new BulletSpan(gapWidth, bulletColor), start, end, 0);
isBullet = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (align != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(align), start, end, flag);
align = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new ImageSpan(XFrame.getContext(), bitmap), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new ImageSpan(drawable), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new ImageSpan(XFrame.getContext(), uri), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new ImageSpan(XFrame.getContext(), resourceId), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 42
Project: android-15-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan());
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 43
Project: cnAndroidDocs-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan());
break;
case LOCALE_SPAN:
readSpan(p, sp, new LocaleSpan(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 44
Project: frameworks_base_disabled-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan());
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 45
Project: property-db-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan());
break;
case LOCALE_SPAN:
readSpan(p, sp, new LocaleSpan(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 46
Project: XobotOS-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan());
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 47
Project: TextJustify-Android-master File: SpannableDocumentLayout.java View source code |
@SuppressWarnings("ConstantConditions") @Override public boolean onMeasure(IProgress<Float> progress, ICancel<Boolean> cancelled) { boolean done = true; float parentWidth = params.getParentWidth(); float boundWidth = params.getParentWidth() - params.getInsetPaddingLeft() - params.getInsetPaddingRight(); mLeadMarginSpanDrawEvents = new LinkedList<>(); StaticLayout staticLayout = new StaticLayout(getText(), (TextPaint) getPaint(), (int) boundWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0, false); int[] newTokens = new int[TOKEN_LENGTH * 1000]; LeadingMarginSpan[] activeLeadSpans = new LeadingMarginSpan[0]; HashMap<LeadingMarginSpan, Integer> leadSpans = new HashMap<>(); TextAlignment defAlign = params.textAlignment; Spannable textCpy = (Spannable) this.text; Paint.FontMetricsInt fmi = paint.getFontMetricsInt(); int maxTextIndex = textCpy.length() - 1; int lines = staticLayout.getLineCount(); int enableLineBreak = 0; int index = 0; int lineNumber; float x; float y = params.insetPaddingTop; float left = params.insetPaddingLeft; float right = params.insetPaddingRight; float lineHeightAdd = params.lineHeightMultiplier; float lastAscent; float lastDescent; boolean isParaStart = true; boolean isReverse = params.reverse; for (lineNumber = 0; lineNumber < lines; lineNumber++) { if (cancelled.isCancelled()) { done = false; break; } progress.onUpdate((float) lineNumber / (float) lines); newTokens = ammortizeArray(newTokens, index); int start = staticLayout.getLineStart(lineNumber); int end = staticLayout.getLineEnd(lineNumber); float realWidth = boundWidth; if (params.debugging) { Console.log(start + " => " + end + " :: " + " " + -staticLayout.getLineAscent(lineNumber) + " " + staticLayout.getLineDescent(lineNumber) + " " + textCpy.subSequence(start, end).toString()); } // start == end => end of textCpy if (start == end || lineNumber >= params.maxLines) { break; } // Get textCpy alignment for the line TextAlignmentSpan[] textAlignmentSpans = textCpy.getSpans(start, end, TextAlignmentSpan.class); TextAlignment lineTextAlignment = textAlignmentSpans.length == 0 ? defAlign : textAlignmentSpans[0].getTextAlignment(); // Calculate components of line height lastAscent = -staticLayout.getLineAscent(lineNumber); lastDescent = staticLayout.getLineDescent(lineNumber) + lineHeightAdd; // Handle reverse DirectionSpan[] directionSpans = textCpy.getSpans(start, end, DirectionSpan.class); isReverse = directionSpans.length > 0 ? directionSpans[0].isReverse() : params.reverse; // Line is ONLY a <br/> or \n if (start + 1 == end && (Character.getNumericValue(textCpy.charAt(start)) == -1 || textCpy.charAt(start) == '\n')) { // Line break indicates a new paragraph // is next isParaStart = true; // Use the line-height of the next line if (lineNumber + 1 < lines) { y += enableLineBreak * (-staticLayout.getLineAscent(lineNumber + 1) + staticLayout.getLineDescent(lineNumber + 1)); } // Don't ignore the next line breaks enableLineBreak = 1; continue; } else { // Ignore the next line break enableLineBreak = 0; } x = lineTextAlignment == TextAlignment.RIGHT ? right : left; y += lastAscent; // Line CONTAINS a \n boolean isParaEnd = end == maxTextIndex || textCpy.charAt(Math.min(end, maxTextIndex)) == '\n' || textCpy.charAt(end - 1) == '\n'; if (isParaEnd) { enableLineBreak = 1; } // LeadingMarginSpan block if (isParaStart) { // Process LeadingMarginSpan activeLeadSpans = textCpy.getSpans(start, end, LeadingMarginSpan.class); // Set up all the spans if (activeLeadSpans.length > 0) { for (LeadingMarginSpan leadSpan : activeLeadSpans) { if (!leadSpans.containsKey(leadSpan)) { // Default margin is everything int marginLineCount = -1; if (leadSpan instanceof LeadingMarginSpan.LeadingMarginSpan2) { LeadingMarginSpan.LeadingMarginSpan2 leadSpan2 = ((LeadingMarginSpan.LeadingMarginSpan2) leadSpan); marginLineCount = leadSpan2.getLeadingMarginLineCount(); } leadSpans.put(leadSpan, marginLineCount); } } } } float totalMargin = 0.0f; int top = (int) (y - lastAscent); int baseline = (int) (y); int bottom = (int) (y + lastDescent); for (LeadingMarginSpan leadSpan : activeLeadSpans) { // TOKEN_X based on alignment float calcX = x; // LineAlignment int lineAlignmentVal = 1; if (lineTextAlignment == TextAlignment.RIGHT) { lineAlignmentVal = -1; calcX = parentWidth - x; } // Get current line count int spanLines = leadSpans.get(leadSpan); // Update only if the valid next valid if (spanLines > 0 || spanLines == -1) { leadSpans.put(leadSpan, spanLines == -1 ? -1 : spanLines - 1); mLeadMarginSpanDrawEvents.add(new LeadingMarginSpanDrawParameters(leadSpan, (int) calcX, lineAlignmentVal, top, baseline, bottom, start, end, isParaStart)); // Is margin required? totalMargin += leadSpan.getLeadingMargin(isParaStart); } } x += totalMargin; realWidth -= totalMargin; // Disable/enable new paragraph isParaStart = isParaEnd; // TextAlignmentSpan block if (isParaEnd && lineTextAlignment == TextAlignment.JUSTIFIED) { lineTextAlignment = isReverse ? TextAlignment.RIGHT : TextAlignment.LEFT; } if (params.debugging) { Console.log(String.format("Align: %s, X: %fpx, Y: %fpx, PWidth: %fpx", lineTextAlignment, x, y, parentWidth)); } switch(lineTextAlignment) { case RIGHT: { float lineWidth = Styled.measureText(paint, workPaint, textCpy, start, end, fmi); index = pushToken(newTokens, index, start, end, parentWidth - x - lineWidth, y, lastAscent, lastDescent, lineNumber); y += lastDescent; continue; } case CENTER: { float lineWidth = Styled.measureText(paint, workPaint, textCpy, start, end, fmi); index = pushToken(newTokens, index, start, end, x + (realWidth - lineWidth) / 2, y, lastAscent, lastDescent, lineNumber); y += lastDescent; continue; } case LEFT: { index = pushToken(newTokens, index, start, end, x, y, lastAscent, lastDescent, lineNumber); y += lastDescent; continue; } } // FIXME: Space at the end of each line, possibly due to scrollbar offset // LinkedList<Integer> tokenized = tokenize(textCpy, start, end - 1); // FIXME: 2016/4/16 Issue #105 bug LinkedList<Integer> tokenized = tokenize(textCpy, start, end); // If one long word without any spaces if (tokenized.size() == 1) { int stop = tokenized.get(0); // characters individually if (getTrimmedLength(textCpy, start, stop) != 0) { float[] textWidths = new float[stop - start]; float sum = 0.0f, textsOffset = 0.0f, offset; int m = 0; Styled.getTextWidths(paint, workPaint, textCpy, start, stop, textWidths, fmi); for (float tw : textWidths) { sum += tw; } offset = (realWidth - sum) / (textWidths.length - 1); for (int k = start; k < stop; k++) { index = pushToken(newTokens, index, k, k + 1, x + textsOffset + (offset * m), y, lastAscent, lastDescent, lineNumber); newTokens = ammortizeArray(newTokens, index); textsOffset += textWidths[m++]; } } } else // Handle multiple words { int m = 1; int indexOffset = 0; int startIndex = index; int reqSpaces = (tokenized.size() - 1) * TOKEN_LENGTH; int rtlZero = 0; float rtlRight = 0; float rtlMul = 1; float lineWidth = 0; float offset; if (isReverse) { indexOffset = -2 * TOKEN_LENGTH; rtlRight = parentWidth; rtlMul = -1; rtlZero = 1; // reverse index index += reqSpaces; } // more space newTokens = ammortizeArray(newTokens, index + reqSpaces); for (int stop : tokenized) { float wordWidth = Styled.measureText(paint, workPaint, textCpy, start, stop, fmi); // add word index = pushToken(newTokens, index, start, stop, rtlRight + rtlMul * (x + lineWidth + rtlZero * wordWidth), y, lastAscent, lastDescent, lineNumber); lineWidth += wordWidth; start = stop + 1; // based on if rtl index += indexOffset; } if (isReverse) { index = startIndex + reqSpaces + TOKEN_LENGTH; } offset = (realWidth - lineWidth) / (float) (tokenized.size() - 1); if (isReverse) { for (int pos = index - TOKEN_LENGTH * 2; pos >= startIndex; pos -= TOKEN_LENGTH) { newTokens[pos + TOKEN_X] = (int) (((float) newTokens[pos + TOKEN_X]) - (offset * (float) m++)); } } else { for (int pos = startIndex + TOKEN_LENGTH; pos < index; pos += TOKEN_LENGTH) { newTokens[pos + TOKEN_X] = (int) (((float) newTokens[pos + TOKEN_X]) + (offset * (float) m++)); } } } y += lastDescent; } lineCount = lineNumber; tokens = newTokens; params.changed = false; textChange = !done; measuredHeight = (int) (y - lineHeightAdd + params.insetPaddingBottom); return done; }
Example 48
Project: themes-platform-packages-apps-Mms-master File: MessageListItem.java View source code |
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mMsgListItem = findViewById(R.id.msg_list_item);
mBodyTextView = (TextView) findViewById(R.id.text_view);
mLockedIndicator = (ImageView) findViewById(R.id.locked_indicator);
mDeliveredIndicator = (ImageView) findViewById(R.id.delivered_indicator);
mDetailsIndicator = (ImageView) findViewById(R.id.details_indicator);
mAvatar = (QuickContactBadge) findViewById(R.id.avatar);
ViewGroup.MarginLayoutParams badgeParams = (MarginLayoutParams) mAvatar.getLayoutParams();
final int badgeWidth = badgeParams.width + badgeParams.rightMargin + badgeParams.leftMargin;
int lineHeight = mBodyTextView.getLineHeight();
int effectiveBadgeHeight = badgeParams.height + badgeParams.topMargin - mBodyTextView.getPaddingTop();
final int indentLineCount = (int) ((effectiveBadgeHeight - 1) / lineHeight) + 1;
mLeadingMarginSpan = new LeadingMarginSpan.LeadingMarginSpan2() {
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) {
// no op
}
public int getLeadingMargin(boolean first) {
return first ? badgeWidth : 0;
}
public int getLeadingMarginLineCount() {
return indentLineCount;
}
};
}
Example 49
Project: ti.styledlabel-master File: HtmlToSpannedConverter.java View source code |
private void endLi(TagMarker tm) {
int end = mSB.length();
int start = tm.getStart();
if (start != end) {
mSB.append('\n');
Object span;
if (mListIsOrdered) {
span = new NumberedSpan(++mListCount);
} else {
span = new BulletSpan();
}
mSB.setSpan(new LeadingMarginSpan.Standard(12, 12), start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mSB.setSpan(span, start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
Example 50
Project: android-sdk-sources-for-api-level-23-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan(p));
break;
case LOCALE_SPAN:
readSpan(p, sp, new LocaleSpan(p));
break;
case TTS_SPAN:
readSpan(p, sp, new TtsSpan(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 51
Project: android_frameworks_base-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan(p));
break;
case LOCALE_SPAN:
readSpan(p, sp, new LocaleSpan(p));
break;
case TTS_SPAN:
readSpan(p, sp, new TtsSpan(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 52
Project: platform_frameworks_base-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
String string = p.readString();
if (string == null) {
return null;
}
if (kind == 1) {
return string;
}
SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
case SUGGESTION_SPAN:
readSpan(p, sp, new SuggestionSpan(p));
break;
case SPELL_CHECK_SPAN:
readSpan(p, sp, new SpellCheckSpan(p));
break;
case SUGGESTION_RANGE_SPAN:
readSpan(p, sp, new SuggestionRangeSpan(p));
break;
case EASY_EDIT_SPAN:
readSpan(p, sp, new EasyEditSpan(p));
break;
case LOCALE_SPAN:
readSpan(p, sp, new LocaleSpan(p));
break;
case TTS_SPAN:
readSpan(p, sp, new TtsSpan(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 53
Project: 920-Text-Editor-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
if (kind == 1)
return p.readString();
SpannableString sp = new SpannableString(p.readString());
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 54
Project: android-imf-ext-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
if (kind == 1)
return p.readString();
SpannableString sp = new SpannableString(p.readString());
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 55
Project: AndroidUtilCode-master File: SpannableStringUtils.java View source code |
/**
* è®¾ç½®æ ·å¼?
*/
private void setSpan() {
if (text == null || text.length() == 0)
return;
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (margin != -1) {
mBuilder.setSpan(new MarginSpan(margin), start, end, flag);
margin = -1;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new CustomQuoteSpan(quoteColor, stripeWidth, quoteGapWidth), start, end, flag);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new CustomBulletSpan(bulletColor, bulletRadius, bulletGapWidth), start, end, flag);
isBullet = false;
}
if (fontSize != -1) {
mBuilder.setSpan(new AbsoluteSizeSpan(fontSize, fontSizeIsDp), start, end, flag);
fontSize = -1;
fontSizeIsDp = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (typeface != null) {
mBuilder.setSpan(new CustomTypefaceSpan(typeface), start, end, flag);
typeface = null;
}
if (alignment != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(alignment), start, end, flag);
alignment = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), bitmap, align), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new CustomImageSpan(drawable, align), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), uri, align), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), resourceId, align), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(blurRadius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 56
Project: folio100_frameworks_base-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
if (kind == 1)
return p.readString();
SpannableString sp = new SpannableString(p.readString());
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 57
Project: gh4a-master File: HtmlUtils.java View source code |
private static void setSpanFromMark(Spannable text, Object mark, Object... spans) {
int where = text.getSpanStart(mark);
text.removeSpan(mark);
int len = text.length();
if (where != len) {
for (Object span : spans) {
if (span instanceof LeadingMarginSpan) {
span = new NeedsReversingSpan(span);
}
text.setSpan(span, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
Example 58
Project: legacy-patchrom-master File: StaticLayout.java View source code |
/* package */ void generate(CharSequence source, int bufstart, int bufend, TextPaint paint, int outerwidth, int outerheight, Alignment align, float spacingmult, float spacingadd, boolean includepad, boolean trackpad, boolean breakOnlyAtSpaces, float ellipsizedWidth, TextUtils.TruncateAt where) { mLineCount = 0; int v = 0; boolean needMultiply = (spacingmult != 1 || spacingadd != 0); Paint.FontMetricsInt fm = mFontMetricsInt; int[] choosehtv = null; int end = TextUtils.indexOf(source, '\n', bufstart, bufend); int bufsiz = end >= 0 ? end - bufstart : bufend - bufstart; boolean first = true; if (mChdirs == null) { mChdirs = new byte[ArrayUtils.idealByteArraySize(bufsiz + 1)]; mChs = new char[ArrayUtils.idealCharArraySize(bufsiz + 1)]; mWidths = new float[ArrayUtils.idealIntArraySize((bufsiz + 1) * 2)]; } byte[] chdirs = mChdirs; char[] chs = mChs; float[] widths = mWidths; AlteredCharSequence alter = null; Spanned spanned = null; if (source instanceof Spanned) spanned = (Spanned) source; // XXX int DEFAULT_DIR = DIR_LEFT_TO_RIGHT; for (int start = bufstart; start <= bufend; start = end) { if (first) first = false; else end = TextUtils.indexOf(source, '\n', start, bufend); if (end < 0) end = bufend; else end++; int firstWidthLineCount = 1; int firstwidth = outerwidth; int restwidth = outerwidth; LineHeightSpan[] chooseht = null; if (spanned != null) { LeadingMarginSpan[] sp; sp = spanned.getSpans(start, end, LeadingMarginSpan.class); for (int i = 0; i < sp.length; i++) { LeadingMarginSpan lms = sp[i]; firstwidth -= sp[i].getLeadingMargin(true); restwidth -= sp[i].getLeadingMargin(false); if (lms instanceof LeadingMarginSpan.LeadingMarginSpan2) { firstWidthLineCount = ((LeadingMarginSpan.LeadingMarginSpan2) lms).getLeadingMarginLineCount(); } } chooseht = spanned.getSpans(start, end, LineHeightSpan.class); if (chooseht.length != 0) { if (choosehtv == null || choosehtv.length < chooseht.length) { choosehtv = new int[ArrayUtils.idealIntArraySize(chooseht.length)]; } for (int i = 0; i < chooseht.length; i++) { int o = spanned.getSpanStart(chooseht[i]); if (o < start) { // starts in this layout, before the // current paragraph choosehtv[i] = getLineTop(getLineForOffset(o)); } else { // starts in this paragraph choosehtv[i] = v; } } } } if (end - start > chdirs.length) { chdirs = new byte[ArrayUtils.idealByteArraySize(end - start)]; mChdirs = chdirs; } if (end - start > chs.length) { chs = new char[ArrayUtils.idealCharArraySize(end - start)]; mChs = chs; } if ((end - start) * 2 > widths.length) { widths = new float[ArrayUtils.idealIntArraySize((end - start) * 2)]; mWidths = widths; } TextUtils.getChars(source, start, end, chs, 0); final int n = end - start; boolean easy = true; boolean altered = false; // XXX int dir = DEFAULT_DIR; for (int i = 0; i < n; i++) { if (chs[i] >= FIRST_RIGHT_TO_LEFT) { easy = false; break; } } if (source instanceof Spanned) { Spanned sp = (Spanned) source; ReplacementSpan[] spans = sp.getSpans(start, end, ReplacementSpan.class); for (int y = 0; y < spans.length; y++) { int a = sp.getSpanStart(spans[y]); int b = sp.getSpanEnd(spans[y]); for (int x = a; x < b; x++) { chs[x - start] = ''; } } } if (!easy) { // XXX put override flags, etc. into chdirs dir = bidi(dir, chs, chdirs, n, false); for (int i = 0; i < n; i++) { if (chdirs[i] == Character.DIRECTIONALITY_RIGHT_TO_LEFT) { int j; for (j = i; j < n; j++) { if (chdirs[j] != Character.DIRECTIONALITY_RIGHT_TO_LEFT) break; } if (AndroidCharacter.mirror(chs, i, j - i)) altered = true; i = j - 1; } } } CharSequence sub; if (altered) { if (alter == null) alter = AlteredCharSequence.make(source, chs, start, end); else alter.update(chs, start, end); sub = alter; } else { sub = source; } int width = firstwidth; float w = 0; int here = start; int ok = start; float okwidth = w; int okascent = 0, okdescent = 0, oktop = 0, okbottom = 0; int fit = start; float fitwidth = w; int fitascent = 0, fitdescent = 0, fittop = 0, fitbottom = 0; boolean tab = false; int next; for (int i = start; i < end; i = next) { if (spanned == null) next = end; else next = spanned.nextSpanTransition(i, end, MetricAffectingSpan.class); if (spanned == null) { paint.getTextWidths(sub, i, next, widths); System.arraycopy(widths, 0, widths, end - start + (i - start), next - i); paint.getFontMetricsInt(fm); } else { mWorkPaint.baselineShift = 0; Styled.getTextWidths(paint, mWorkPaint, spanned, i, next, widths, fm); System.arraycopy(widths, 0, widths, end - start + (i - start), next - i); if (mWorkPaint.baselineShift < 0) { fm.ascent += mWorkPaint.baselineShift; fm.top += mWorkPaint.baselineShift; } else { fm.descent += mWorkPaint.baselineShift; fm.bottom += mWorkPaint.baselineShift; } } int fmtop = fm.top; int fmbottom = fm.bottom; int fmascent = fm.ascent; int fmdescent = fm.descent; if (false) { StringBuilder sb = new StringBuilder(); for (int j = i; j < next; j++) { sb.append(widths[j - start + (end - start)]); sb.append(' '); } Log.e("text", sb.toString()); } for (int j = i; j < next; j++) { char c = chs[j - start]; float before = w; if (c == '\n') { ; } else if (c == '\t') { w = Layout.nextTab(sub, start, end, w, null); tab = true; } else if (EmojiSmileys.isEmoji(c)) { Paint whichPaint; if (spanned == null) { whichPaint = paint; } else { whichPaint = mWorkPaint; } float wid = whichPaint.descent() - whichPaint.ascent() + EMOJI_PADDING_PX * 2; w += wid; tab = true; } else { w += widths[j - start + (end - start)]; } if (w <= width) { fitwidth = w; fit = j + 1; if (fmtop < fittop) fittop = fmtop; if (fmascent < fitascent) fitascent = fmascent; if (fmdescent > fitdescent) fitdescent = fmdescent; if (fmbottom > fitbottom) fitbottom = fmbottom; if (c == ' ' || c == '\t' || ((c == '.' || c == ',' || c == ':' || c == ';') && (j - 1 < here || !Character.isDigit(chs[j - 1 - start])) && (j + 1 >= next || !Character.isDigit(chs[j + 1 - start]))) || ((c == '/' || c == '-') && (j + 1 >= next || !Character.isDigit(chs[j + 1 - start]))) || (c >= FIRST_CJK && isIdeographic(c, true) && j + 1 < next && isIdeographic(chs[j + 1 - start], false))) { okwidth = w; ok = j + 1; if (fittop < oktop) oktop = fittop; if (fitascent < okascent) okascent = fitascent; if (fitdescent > okdescent) okdescent = fitdescent; if (fitbottom > okbottom) okbottom = fitbottom; } } else if (breakOnlyAtSpaces && where != TextUtils.TruncateAt.END && outerheight == OUTERHEIGHT_INFINITE) { if (ok != here) { while (ok < next && chs[ok - start] == ' ') { ok++; } v = out(source, here, ok, okascent, okdescent, oktop, okbottom, v, spacingmult, spacingadd, chooseht, choosehtv, fm, tab, needMultiply, start, chdirs, dir, easy, ok == bufend, includepad, trackpad, widths, start, end - start, where, ellipsizedWidth, okwidth, paint); here = ok; } else { // Act like it fit even though it didn't. fitwidth = w; fit = j + 1; if (fmtop < fittop) fittop = fmtop; if (fmascent < fitascent) fitascent = fmascent; if (fmdescent > fitdescent) fitdescent = fmdescent; if (fmbottom > fitbottom) fitbottom = fmbottom; } } else { if (ok != here) { while (ok < next && chs[ok - start] == ' ') { ok++; } v = out(source, here, ok, okascent, okdescent, oktop, okbottom, v, spacingmult, spacingadd, chooseht, choosehtv, fm, tab, needMultiply, start, chdirs, dir, easy, ok == bufend, includepad, trackpad, widths, start, end - start, where, ellipsizedWidth, okwidth, paint); here = ok; } else if (fit != here) { // Log.e("text", "output fit " + here + " to " +fit); v = out(source, here, fit, fitascent, fitdescent, fittop, fitbottom, v, spacingmult, spacingadd, chooseht, choosehtv, fm, tab, needMultiply, start, chdirs, dir, easy, fit == bufend, includepad, trackpad, widths, start, end - start, where, ellipsizedWidth, fitwidth, paint); here = fit; } else { // Log.e("text", "output one " + here + " to " +(here + 1)); measureText(paint, mWorkPaint, source, here, here + 1, fm, tab, null); v = out(source, here, here + 1, fm.ascent, fm.descent, fm.top, fm.bottom, v, spacingmult, spacingadd, chooseht, choosehtv, fm, tab, needMultiply, start, chdirs, dir, easy, here + 1 == bufend, includepad, trackpad, widths, start, end - start, where, ellipsizedWidth, widths[here - start], paint); here = here + 1; } if (here < i) { // must remeasure j = next = here; } else { // continue looping j = here - 1; } ok = fit = here; w = 0; fitascent = fitdescent = fittop = fitbottom = 0; okascent = okdescent = oktop = okbottom = 0; if (--firstWidthLineCount <= 0) { width = restwidth; } } } } if (end != here) { if ((fittop | fitbottom | fitdescent | fitascent) == 0) { paint.getFontMetricsInt(fm); fittop = fm.top; fitbottom = fm.bottom; fitascent = fm.ascent; fitdescent = fm.descent; } // Log.e("text", "output rest " + here + " to " + end); v = out(source, here, end, fitascent, fitdescent, fittop, fitbottom, v, spacingmult, spacingadd, chooseht, choosehtv, fm, tab, needMultiply, start, chdirs, dir, easy, end == bufend, includepad, trackpad, widths, start, end - start, where, ellipsizedWidth, w, paint); } start = end; if (end == bufend) break; } if (bufend == bufstart || source.charAt(bufend - 1) == '\n') { // Log.e("text", "output last " + bufend); paint.getFontMetricsInt(fm); v = out(source, bufend, bufend, fm.ascent, fm.descent, fm.top, fm.bottom, v, spacingmult, spacingadd, null, null, fm, false, needMultiply, bufend, chdirs, DEFAULT_DIR, true, true, includepad, trackpad, widths, bufstart, 0, where, ellipsizedWidth, 0, paint); } }
Example 59
Project: platform_sdk-master File: ApiDetectorTest.java View source code |
public void testInnerClassPositions() throws Exception { // See http://code.google.com/p/android/issues/detail?id=38113 assertEquals("src/test/pkg/ApiCallTest8.java:8: Error: Class requires API level 8 (current min is 4): android.text.style.LeadingMarginSpan.LeadingMarginSpan2 [NewApi]\n" + " LeadingMarginSpan.LeadingMarginSpan2 span = null; \n" + " ~~~~~~~~~~~~~~~~~~\n" + "1 errors, 0 warnings\n", lintProject("apicheck/classpath=>.classpath", "apicheck/minsdk4.xml=>AndroidManifest.xml", "apicheck/ApiCallTest8.java.txt=>src/test/pkg/ApiCallTest8.java", "apicheck/ApiCallTest8.class.data=>bin/classes/test/pkg/ApiCallTest8.class")); }
Example 60
Project: SPD8810GA-master File: MessageListItem.java View source code |
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// mMsgListItem = this;
// = findViewById(R.id.msg_list_item);
mBodyTextView = (TextView) findViewById(R.id.text_view);
mDownloadLimitText = (TextView) findViewById(R.id.download_beyond_limit_warnning);
mLockedIndicator = (ImageView) findViewById(R.id.locked_indicator);
mDeliveredIndicator = (ImageView) findViewById(R.id.delivered_indicator);
mDetailsIndicator = (ImageView) findViewById(R.id.details_indicator);
mSimIndicator = (ImageView) findViewById(R.id.sim_indicator);
mWarningDownloadIndicator = (ImageView) findViewById(R.id.not_allow_download);
mAvatar = (QuickContactBadge) findViewById(R.id.avatar);
mAvatar.setVisibility(View.GONE);
ViewGroup.MarginLayoutParams badgeParams = (MarginLayoutParams) mAvatar.getLayoutParams();
//liaobz hide the avatar
//badgeParams.width + badgeParams.rightMargin + badgeParams.leftMargin;
final int badgeWidth = 0;
int lineHeight = mBodyTextView.getLineHeight();
int effectiveBadgeHeight = badgeParams.height + badgeParams.topMargin - mBodyTextView.getPaddingTop();
final int indentLineCount = (int) ((effectiveBadgeHeight - 1) / lineHeight) + 1;
mLeadingMarginSpan = new LeadingMarginSpan.LeadingMarginSpan2() {
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) {
// no op
}
public int getLeadingMargin(boolean first) {
return first ? badgeWidth : 0;
}
public int getLeadingMarginLineCount() {
//via liaobz 图片挤压效果影�行数
return 1;
}
};
}
Example 61
Project: Sun-master File: SpannableStringUtils.java View source code |
/**
* è®¾ç½®æ ·å¼?
*/
private void setSpan() {
if (text == null || text.length() == 0)
return;
int start = mBuilder.length();
mBuilder.append(this.text);
int end = mBuilder.length();
if (backgroundColor != defaultValue) {
mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
backgroundColor = defaultValue;
}
if (foregroundColor != defaultValue) {
mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
foregroundColor = defaultValue;
}
if (isLeadingMargin) {
mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
isLeadingMargin = false;
}
if (margin != -1) {
mBuilder.setSpan(new MarginSpan(margin), start, end, flag);
margin = -1;
}
if (quoteColor != defaultValue) {
mBuilder.setSpan(new CustomQuoteSpan(quoteColor, stripeWidth, quoteGapWidth), start, end, flag);
quoteColor = defaultValue;
}
if (isBullet) {
mBuilder.setSpan(new CustomBulletSpan(bulletColor, bulletRadius, bulletGapWidth), start, end, flag);
isBullet = false;
}
if (fontSize != -1) {
mBuilder.setSpan(new AbsoluteSizeSpan(fontSize, fontSizeIsDp), start, end, flag);
fontSize = -1;
fontSizeIsDp = false;
}
if (proportion != -1) {
mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
proportion = -1;
}
if (xProportion != -1) {
mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
xProportion = -1;
}
if (isStrikethrough) {
mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
isStrikethrough = false;
}
if (isUnderline) {
mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
isUnderline = false;
}
if (isSuperscript) {
mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
isSuperscript = false;
}
if (isSubscript) {
mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
isSubscript = false;
}
if (isBold) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
isBold = false;
}
if (isItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
isItalic = false;
}
if (isBoldItalic) {
mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
isBoldItalic = false;
}
if (fontFamily != null) {
mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
fontFamily = null;
}
if (typeface != null) {
mBuilder.setSpan(new CustomTypefaceSpan(typeface), start, end, flag);
typeface = null;
}
if (alignment != null) {
mBuilder.setSpan(new AlignmentSpan.Standard(alignment), start, end, flag);
alignment = null;
}
if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) {
if (imageIsBitmap) {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), bitmap, align), start, end, flag);
bitmap = null;
imageIsBitmap = false;
} else if (imageIsDrawable) {
mBuilder.setSpan(new CustomImageSpan(drawable, align), start, end, flag);
drawable = null;
imageIsDrawable = false;
} else if (imageIsUri) {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), uri, align), start, end, flag);
uri = null;
imageIsUri = false;
} else {
mBuilder.setSpan(new CustomImageSpan(Utils.getContext(), resourceId, align), start, end, flag);
resourceId = 0;
imageIsResourceId = false;
}
}
if (clickSpan != null) {
mBuilder.setSpan(clickSpan, start, end, flag);
clickSpan = null;
}
if (url != null) {
mBuilder.setSpan(new URLSpan(url), start, end, flag);
url = null;
}
if (isBlur) {
mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(blurRadius, style)), start, end, flag);
isBlur = false;
}
flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
}
Example 62
Project: WS171-frameworks-base-master File: TextUtils.java View source code |
/**
* Read and return a new CharSequence, possibly with styles,
* from the parcel.
*/
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
if (kind == 1)
return p.readString();
SpannableString sp = new SpannableString(p.readString());
while (true) {
kind = p.readInt();
if (kind == 0)
break;
switch(kind) {
case ALIGNMENT_SPAN:
readSpan(p, sp, new AlignmentSpan.Standard(p));
break;
case FOREGROUND_COLOR_SPAN:
readSpan(p, sp, new ForegroundColorSpan(p));
break;
case RELATIVE_SIZE_SPAN:
readSpan(p, sp, new RelativeSizeSpan(p));
break;
case SCALE_X_SPAN:
readSpan(p, sp, new ScaleXSpan(p));
break;
case STRIKETHROUGH_SPAN:
readSpan(p, sp, new StrikethroughSpan(p));
break;
case UNDERLINE_SPAN:
readSpan(p, sp, new UnderlineSpan(p));
break;
case STYLE_SPAN:
readSpan(p, sp, new StyleSpan(p));
break;
case BULLET_SPAN:
readSpan(p, sp, new BulletSpan(p));
break;
case QUOTE_SPAN:
readSpan(p, sp, new QuoteSpan(p));
break;
case LEADING_MARGIN_SPAN:
readSpan(p, sp, new LeadingMarginSpan.Standard(p));
break;
case URL_SPAN:
readSpan(p, sp, new URLSpan(p));
break;
case BACKGROUND_COLOR_SPAN:
readSpan(p, sp, new BackgroundColorSpan(p));
break;
case TYPEFACE_SPAN:
readSpan(p, sp, new TypefaceSpan(p));
break;
case SUPERSCRIPT_SPAN:
readSpan(p, sp, new SuperscriptSpan(p));
break;
case SUBSCRIPT_SPAN:
readSpan(p, sp, new SubscriptSpan(p));
break;
case ABSOLUTE_SIZE_SPAN:
readSpan(p, sp, new AbsoluteSizeSpan(p));
break;
case TEXT_APPEARANCE_SPAN:
readSpan(p, sp, new TextAppearanceSpan(p));
break;
case ANNOTATION:
readSpan(p, sp, new Annotation(p));
break;
default:
throw new RuntimeException("bogus span encoding " + kind);
}
}
return sp;
}
Example 63
Project: chessonline-master File: DroidFish.java View source code |
private final void newLine(boolean eof) {
if (!col0) {
if (paraIndent > 0) {
int paraEnd = sb.length();
int indent = paraIndent * indentStep;
sb.setSpan(new LeadingMarginSpan.Standard(indent), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (paraBold) {
int paraEnd = sb.length();
sb.setSpan(new StyleSpan(Typeface.BOLD), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!eof)
sb.append('\n');
paraStart = sb.length();
paraIndent = nestLevel;
paraBold = false;
}
col0 = true;
}
Example 64
Project: CuckooChess-master File: DroidFish.java View source code |
private final void newLine(boolean eof) {
if (!col0) {
if (paraIndent > 0) {
int paraEnd = sb.length();
int indent = paraIndent * indentStep;
sb.setSpan(new LeadingMarginSpan.Standard(indent), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (paraBold) {
int paraEnd = sb.length();
sb.setSpan(new StyleSpan(Typeface.BOLD), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!eof)
sb.append('\n');
paraStart = sb.length();
paraIndent = nestLevel;
paraBold = false;
}
col0 = true;
}
Example 65
Project: droidfish-master File: DroidFish.java View source code |
private final void newLine(boolean eof) {
if (!col0) {
if (paraIndent > 0) {
int paraEnd = sb.length();
int indent = paraIndent * indentStep;
sb.setSpan(new LeadingMarginSpan.Standard(indent), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (paraBold) {
int paraEnd = sb.length();
sb.setSpan(new StyleSpan(Typeface.BOLD), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!eof)
sb.append('\n');
paraStart = sb.length();
paraIndent = nestLevel;
paraBold = false;
}
col0 = true;
}
Example 66
Project: droidfishchess_android-master File: DroidFish.java View source code |
private final void newLine(boolean eof) {
if (!col0) {
if (paraIndent > 0) {
int paraEnd = sb.length();
int indent = paraIndent * indentStep;
sb.setSpan(new LeadingMarginSpan.Standard(indent), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (paraBold) {
int paraEnd = sb.length();
sb.setSpan(new StyleSpan(Typeface.BOLD), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!eof)
sb.append('\n');
paraStart = sb.length();
paraIndent = nestLevel;
paraBold = false;
}
col0 = true;
}
Example 67
Project: stockfishchess-android-master File: DroidFish.java View source code |
private final void newLine(boolean eof) {
if (!col0) {
if (paraIndent > 0) {
int paraEnd = sb.length();
int indent = paraIndent * indentStep;
sb.setSpan(new LeadingMarginSpan.Standard(indent), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (paraBold) {
int paraEnd = sb.length();
sb.setSpan(new StyleSpan(Typeface.BOLD), paraStart, paraEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!eof)
sb.append('\n');
paraStart = sb.length();
paraIndent = nestLevel;
paraBold = false;
}
col0 = true;
}
Example 68
Project: dante-master File: LeadingMarginSpanListener.java View source code |
@Override
protected Object getStyleSpan() {
return new LeadingMarginSpan.Standard(margin, 0);
}
Example 69
Project: FastHub-master File: MarginHandler.java View source code |
public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
builder.setSpan(new LeadingMarginSpan.Standard(30), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
this.appendNewLine(builder);
this.appendNewLine(builder);
}