/** * add alignment for text * * @param indent LEFT, RIGHT, CENTER * @return Snippety */ public Snippety align(Indent indent) { AlignmentSpan span; switch (indent) { case RIGHT: span = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE); break; case CENTER: span = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER); break; case LEFT: default: span = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL); break; } spans.add(span); return this; }
private void handleBlockTag(boolean isStart, int type, int start, HtmlNode.HtmlAttr attr) { if (position <= 0) return; if (spannedBuilder.charAt(position - 1) != '\n') { spannedBuilder.append('\n'); position++; } //结束block 标签 if (!isStart && attr != null) { Layout.Alignment align; if (attr.align == HtmlNode.ALIGN_LEFT) { align = Layout.Alignment.ALIGN_NORMAL; } else if (attr.align == HtmlNode.ALIGN_RIGHT) { align = Layout.Alignment.ALIGN_OPPOSITE; } else if (attr.align == HtmlNode.ALIGN_CENTER) { align = Layout.Alignment.ALIGN_CENTER; } else { align = null; } if (align != null) { setSpan(start, position, new AlignmentSpan.Standard(align)); } } }
private void handleParagraph(int start, HtmlNode.HtmlAttr attr) { if (attr == null) return; setSpan(start, new StyleSpan(attr)); Layout.Alignment align; if (attr.textAlign == HtmlNode.ALIGN_LEFT) { align = Layout.Alignment.ALIGN_NORMAL; } else if (attr.textAlign == HtmlNode.ALIGN_RIGHT) { align = Layout.Alignment.ALIGN_OPPOSITE; } else if (attr.textAlign == HtmlNode.ALIGN_CENTER) { align = Layout.Alignment.ALIGN_CENTER; } else { align = null; } if (align != null) { setSpan(start, position, new AlignmentSpan.Standard(align)); } }
private void about() { // 先移除所有的動態view linearLayout.removeView(recycle); linearLayout.removeView(recycle2); linearLayout.removeView(recycle3); linearLayout.removeView(about); linearLayout.removeView(explan); /* TODO 關於我們 * * */ String text = "\n\n\n開發成員 : \n\n陳亮宇\n張弘瑜\n鍾羽函\n蘇柏丞\n謝宣緯\n\n\n\n\t資料來源 : 行政院文化局"; SpannableString spannable = new SpannableString(text); spannable.setSpan(new AbsoluteSizeSpan(80), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#FF533210")), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AbsoluteSizeSpan(100), 3, 7, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AbsoluteSizeSpan(100), 36, 40, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); about.setText(spannable); linearLayout.addView(about); }
private void info() { // 先移除所有的動態view linearLayout.removeView(recycle); linearLayout.removeView(recycle2); linearLayout.removeView(recycle3); linearLayout.removeView(about); linearLayout.removeView(explan); /* TODO 說明 * * */ String text = "\n\n\n 這是一個彙整台灣獨立書店的app,資料取自文化局的開放資源,主要目的在於提供沒接觸過或是剛接觸獨立書店的民眾,可以找尋到自己生活周遭哪裡有獨立書店,該如何拜訪、參觀,並且了解各個獨立店家的特色"; SpannableString spannable = new SpannableString(text); spannable.setSpan(new AbsoluteSizeSpan(80), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#FF533210")), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); explan.setText(spannable); linearLayout.addView(explan); }
@Override public void showArticle(ArticleOne article) { String title = article.getArticleTitle(); String author = article.getArticleAuthor(); String content = article.getArticleContent(); String text = title + "\n" + author + "\n\n" + content; SpannableStringBuilder style = new SpannableStringBuilder(text); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(30)), 0, title.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), title.length() + 1, title .length() + 1 + author.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, title .length() + 1 + author.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(16)), title.length() + author .length() + 3, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); mTvContent.setText(style); }
@Override public void showContent(Movie movie) { String movieName = movie.getMovieName(); String country = movie.getCountry(); String briefIntro = movie.getBriefIntro(); String content = movieName + "\n" + country + "\n" + briefIntro; SpannableStringBuilder style = new SpannableStringBuilder(content); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(30)), 0, movieName.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), movieName.length() + 1, movieName .length() + 1 + country.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, movieName .length() + 1 + country.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(16)), movieName.length() + country .length() + 3, content.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); mTvMovieContent.setText(style); }
private void openAlignment(final Layout.Alignment alignment, Editable output) { output.append("\n"); // new paragraph before aligment span! int len = output.length(); AlignmentSpan span; switch (alignment) { case ALIGN_OPPOSITE: span = new OppositeAlignment(); break; case ALIGN_CENTER: span = new CenterAlignment(); break; default: return; } output.setSpan(span, len, len, Spanned.SPAN_MARK_MARK); mAlignmentStack.add(0, alignment); }
@Override protected void handleTag(boolean opening, String tag, Map<String, String> attrs, Editable output) { if ("span".equalsIgnoreCase(tag)) { if (opening) { Span mark = null; if ("center".equalsIgnoreCase(attrs.get("class"))) { mark = new Center(); handleP(output); start(output, mark); } spanStack.add(mark); } else { // Remove. Object repl = null; Class<? extends Span> kind = Span.class; Span span = spanStack.remove(spanStack.size() - 1); if (span instanceof Center) { handleP(output); kind = Center.class; repl = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER); } end(output, kind, repl); } } }
@Override public void showPIN(final String pin) { RingApplication.uiHandler.post(() -> { mWaitDialog.dismiss(); String pined = getString(R.string.account_end_export_infos).replace("%%", pin); final SpannableString styledResultText = new SpannableString(pined); int pos = pined.lastIndexOf(pin); styledResultText.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); styledResultText.setSpan(new StyleSpan(Typeface.BOLD), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); styledResultText.setSpan(new RelativeSizeSpan(2.8f), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); new AlertDialog.Builder(getActivity()) .setMessage(styledResultText) .setPositiveButton(android.R.string.ok, (dialog, which) -> getFragmentManager().popBackStack()) .show(); }); }
@Override public void showPIN(final String pin) { RingApplication.uiHandler.post(() -> { hideWizard(); mWaitDialog.dismiss(); mLinkAccountView.setVisibility(View.VISIBLE); mPasswordLayout.setVisibility(View.GONE); mEndBtn.setVisibility(View.VISIBLE); mStartBtn.setVisibility(View.GONE); String pined = getString(R.string.account_end_export_infos).replace("%%", pin); final SpannableString styledResultText = new SpannableString(pined); int pos = pined.lastIndexOf(pin); styledResultText.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); styledResultText.setSpan(new StyleSpan(Typeface.BOLD), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); styledResultText.setSpan(new RelativeSizeSpan(2.8f), pos, (pos + pin.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mExportInfos.setText(styledResultText); mExportInfos.requestFocus(); KeyboardVisibilityManager.hideKeyboard(getActivity(), 0); }); }
private Spannable addEndTag(SpannableStringBuilder builder) { //Don't add the tag to the last section. Spine spine = bookView.getSpine(); if (spine == null || spine.getPosition() >= spine.size() -1 ) { return builder; } int length = builder.length(); builder.append("\uFFFC"); builder.append("\n"); builder.append( context.getString(R.string.end_of_section)); //If not, consider it an internal nav link. ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { pageDown(); } }; Drawable img = context.getResources().getDrawable(R.drawable.gateway); img.setBounds(0, 0, img.getIntrinsicWidth(), img.getIntrinsicHeight() ); builder.setSpan(new ImageSpan(img), length, length+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(span, length, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan( (AlignmentSpan) () -> Alignment.ALIGN_CENTER , length, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return builder; }
@Test public void align_start_should_add_only_one_span() { spanBuilder.alignStart(paragraph) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); }
@Test public void align_center_should_add_only_one_span() { spanBuilder.alignCenter(paragraph) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); }
@Test public void align_end_should_add_only_one_span() { spanBuilder.alignEnd(paragraph) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); }
/** * Create a task list which contains {@link SetSpanOperation}. The task list will be executed * in other method. * @param end the end character of the text. * @return a task list which contains {@link SetSpanOperation}. */ private List<SetSpanOperation> createSetSpanOperation(int end) { List<SetSpanOperation> ops = new LinkedList<>(); int start = 0; if (end >= start) { if (mTextDecoration == WXTextDecoration.UNDERLINE) { ops.add(new SetSpanOperation(start, end, new UnderlineSpan())); } if (mTextDecoration == WXTextDecoration.LINETHROUGH) { ops.add(new SetSpanOperation(start, end, new StrikethroughSpan())); } if (mIsColorSet) { ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor))); } if (mFontSize != UNSET) { ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize))); } if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) { ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily))); } ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment))); if (mLineHeight != UNSET) { ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight))); } } return ops; }
/** * Create a task list which contains {@link SetSpanOperation}. The task list will be executed * in other method. * @param end the end character of the text. * @return a task list which contains {@link SetSpanOperation}. */ private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) { List<SetSpanOperation> ops = new LinkedList<>(); int start = 0; if (end >= start) { if (mTextDecoration == WXTextDecoration.UNDERLINE || mTextDecoration == WXTextDecoration.LINETHROUGH) { ops.add(new SetSpanOperation(start, end, new TextDecorationSpan(mTextDecoration), spanFlag)); } if (mIsColorSet) { ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor), spanFlag)); } if (mFontSize != UNSET) { ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag)); } if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) { ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily), spanFlag)); } ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag)); if (mLineHeight != UNSET) { ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag)); } } return ops; }
void setAlignStyle(int align) { int index = getSelectionIndex(); if (index >= 0 && index < mSections.size()) { mSections.get(index).setAlignment(align); } Editable edit = getEditableText(); int star = getSectionStart(); int end = getSectionEnd(); AlignmentSpan[] spans = edit.getSpans(star, end, AlignmentSpan.class); for (AlignmentSpan span : spans) { edit.removeSpan(span); } edit.setSpan(getAlignmentSpan(align), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
private static void encodeTextAlignmentByDiv(Context context, StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (ParagraphStyle style : styles) { if (style instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(context, out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
private static String getTextStyles(Spanned text, int start, int end, boolean forceNoVerticalMargin, boolean includeTextAlign) { String margin = null; String textAlign = null; if (forceNoVerticalMargin) { margin = "margin-top:0; margin-bottom:0;"; } if (includeTextAlign) { final AlignmentSpan[] alignmentSpans = text.getSpans(start, end, AlignmentSpan.class); // Only use the last AlignmentSpan with flag SPAN_PARAGRAPH for (int i = alignmentSpans.length - 1; i >= 0; i--) { AlignmentSpan s = alignmentSpans[i]; if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH) { final Layout.Alignment alignment = s.getAlignment(); if (alignment == Layout.Alignment.ALIGN_NORMAL) { textAlign = "text-align:start;"; } else if (alignment == Layout.Alignment.ALIGN_CENTER) { textAlign = "text-align:center;"; } else if (alignment == Layout.Alignment.ALIGN_OPPOSITE) { textAlign = "text-align:end;"; } break; } } } if (margin == null && textAlign == null) { return ""; } final StringBuilder style = new StringBuilder(" style=\""); if (margin != null && textAlign != null) { style.append(margin).append(" ").append(textAlign); } else if (margin != null) { style.append(margin); } else if (textAlign != null) { style.append(textAlign); } return style.append("\"").toString(); }
private void endBlockElement(String tag, Editable text) { Newline n = getLast(text, Newline.class); if (n != null) { appendNewlines(text, n.mNumNewlines); text.removeSpan(n); } Alignment a = getLast(text, Alignment.class); if (a != null) { setSpanFromMark(tag, text, a, new AlignmentSpan.Standard(a.mAlignment)); } }
/** * Create a task list which contains {@link SetSpanOperation}. The task list will be executed * in other method. * @param end the end character of the text. * @return a task list which contains {@link SetSpanOperation}. */ private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) { List<SetSpanOperation> ops = new LinkedList<>(); int start = 0; if (end >= start) { if (mTextDecoration == WXTextDecoration.UNDERLINE) { ops.add(new SetSpanOperation(start, end, new UnderlineSpan(), spanFlag)); } if (mTextDecoration == WXTextDecoration.LINETHROUGH) { ops.add(new SetSpanOperation(start, end, new StrikethroughSpan(), spanFlag)); } if (mIsColorSet) { ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor), spanFlag)); } if (mFontSize != UNSET) { ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag)); } if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) { ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily), spanFlag)); } ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag)); if (mLineHeight != UNSET) { ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag)); } } return ops; }
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
private static void endBlockElement(Editable text) { Newline n = getLast(text, Newline.class); if (n != null) { appendNewlines(text, n.mNumNewlines); text.removeSpan(n); } Alignment a = getLast(text, Alignment.class); if (a != null) { setSpanFromMark(text, a, new AlignmentSpan.Standard(a.mAlignment)); } }
public TextDecorator alignText(final Layout.Alignment alignment, final String... texts) { int index; for (String text : texts) { if (content.contains(text)) { index = content.indexOf(text); decoratedContent.setSpan(new AlignmentSpan.Standard(alignment), index, index + text.length(), flags); } } return this; }
public static SpannableString getCenteredString(final String string) { SpannableString spannableString = new SpannableString(string); spannableString.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, spannableString.length(), 0); return spannableString; }
private void assertAlignment(Spannable spannable, Layout.Alignment alignment) { if (alignment != null) { AlignmentSpan.Standard[] alignmentSpans = spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class); assertEquals(1, alignmentSpans.length); assertEquals(alignment, alignmentSpans[0].getAlignment()); } else { assertEquals(0, spannable.getSpans (0, spannable.length(), AlignmentSpan.Standard.class).length); } }
private Spannable addEndTag(SpannableStringBuilder builder) { //Don't add the tag to the last section. TyphonSpine spine = bookView.getSpine(); if (spine == null || spine.getPosition() >= spine.size() -1 ) { return builder; } int length = builder.length(); builder.append("\uFFFC"); builder.append("\n"); builder.append( context.getString(net.zorgblub.typhon.R.string.end_of_section)); //If not, consider it an internal nav link. ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { pageDown(); } }; Drawable img = context.getResources().getDrawable(net.zorgblub.typhon.R.drawable.gateway); img.setBounds(0, 0, img.getIntrinsicWidth(), img.getIntrinsicHeight() ); builder.setSpan(new ImageSpan(img), length, length+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(span, length, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan( (AlignmentSpan) () -> Alignment.ALIGN_CENTER , length, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return builder; }
/** * Create a task list which contains {@link SetSpanOperation}. The task list will be executed * in other method. * @param end the end character of the text. * @return a task list which contains {@link SetSpanOperation}. */ private List<SetSpanOperation> createSetSpanOperation(int end) { List<SetSpanOperation> ops = new LinkedList<>(); int start = 0; if (end >= start) { if (mTextDecoration == WXTextDecoration.UNDERLINE) { ops.add(new SetSpanOperation(start, end, new UnderlineSpan())); } if (mTextDecoration == WXTextDecoration.LINETHROUGH) { ops.add(new SetSpanOperation(start, end, new StrikethroughSpan())); } if (mIsColorSet) { ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor))); } if (mFontSize != UNSET) { ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize))); } if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) { ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily))); } ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment))); if(mLineHeight !=UNSET) { ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight))); } } return ops; }
@Override public Spannable getStyle(CharSequence param, CharSequence text) { SpannableString styled = new SpannableString(text); if (param.charAt(0) == 'l') { styled.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL), 0, styled.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (param.charAt(0) == 'c') { styled.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, styled.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { styled.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), 0, styled.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return styled; }
@Override public void showContent(Picture picture) { String vol = picture.getVOL(); String authorWork = picture.getAuthorWork(); String description = picture.getPicDescription(); String date = picture.getPicDate().replace("-", " "); String content = authorWork + "\n\n" + description + "\n\n" + date; SpannableStringBuilder style = new SpannableStringBuilder(content); // 描述 居中 style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL), authorWork.length() + 1, authorWork.length() + description.length() + 1 , Spanned.SPAN_INCLUSIVE_INCLUSIVE); // 描述 字体大小 style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(14)), authorWork.length() + 1, authorWork.length() + description.length() + 1 , Spanned.SPAN_INCLUSIVE_INCLUSIVE); // 作者 偏右 // style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), 0, authorWork.length() // - 1, // Spanned.SPAN_INCLUSIVE_INCLUSIVE); // 日期 偏右 // style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), authorWork.length() + // description.length() + 2, // content.length() // , Spanned.SPAN_INCLUSIVE_INCLUSIVE); mTvDes.setText(style); mTvVOL.setText(vol); GlideUtil.setImage(mActivity, picture.getPicUrl(), mIvContent); this.mPicture = picture; }
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
private void writeSingleParagraphStyle(ParagraphStyle style, DataOutputStream dos) throws IOException { Class clazz = style.getClass(); dos.writeInt(mString.getSpanStart(style)); dos.writeInt(mString.getSpanEnd(style)); dos.writeInt(mString.getSpanFlags(style)); if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) { int tag = mCharacterStylesTags.get(clazz.getSimpleName()); if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) { dos.writeInt(tag); } switch (tag) { case 24: // AligmentSpan.Standard AlignmentSpan.Standard as2 = (AlignmentSpan.Standard)style; dos.writeInt(as2.getAlignment().ordinal()); break; case 25: // BulletSpan BulletSpan bs = (BulletSpan)style; dos.writeInt(bs.getLeadingMargin(true)); dos.writeInt(bs.getLeadingMargin(false)); break; case 30: // LeadingMarginSpan.Sandard LeadingMarginSpan.Standard lms = (LeadingMarginSpan.Standard)style; dos.writeInt(lms.getLeadingMargin(true)); dos.writeInt(lms.getLeadingMargin(false)); break; case 34: // QuoteSpan QuoteSpan qs = (QuoteSpan)style; dos.writeInt(qs.getColor()); break; case 36: // TabStopSpan.Standard TabStopSpan.Standard tss = (TabStopSpan.Standard)style; dos.writeInt(tss.getTabStop()); break; default: } } else { write(style,dos); } }
private SpanPlacementInfo readSingleParagraph(DataInputStream dis) throws IOException { SpanPlacementInfo spi = new SpanPlacementInfo(); spi.start = dis.readInt(); spi.end = dis.readInt(); spi.mode = dis.readInt(); int tag = dis.readInt(); // mCharacterStylesTags.get(clazz.getSimpleName()); switch (tag) { case 24: // AligmentSpan.Standard spi.span = new AlignmentSpan.Standard(Alignment.values()[dis.readInt()]); break; case 25: // BulletSpan spi.span = new BulletSpan(dis.readInt()); dis.readInt(); // skip gap width for other lines break; case 30: // LeadingMarginSpan.Sandard spi.span = new LeadingMarginSpan.Standard(dis.readInt(),dis.readInt()); break; case 34: // QuoteSpan spi.span = new QuoteSpan(dis.readInt()); break; case 36: // TabStopSpan.Standard spi.span = new TabStopSpan.Standard(dis.readInt()); break; case 80: // RemoteDrawableSpan break; default: spi.span = read(tag,dis); } return spi; }