Java Code Examples for android.text.style.AbsoluteSizeSpan

The following are top voted examples for showing how to use android.text.style.AbsoluteSizeSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: weex-3d-map   File: WXTextDomObject.java   Source Code and License 6 votes vote down vote up
/**
 * Update {@link #spanned} according to the give charSequence and styles
 * @param text the give raw text.
 * @return an Spanned contains text and spans
 */
private
@NonNull
Spanned createSpanned(String text) {
  if (!TextUtils.isEmpty(text)) {
    SpannableString spannable = new SpannableString(text);
    List<SetSpanOperation> ops = createSetSpanOperation(spannable.length());
    if (mFontSize == UNSET) {
      ops.add(new SetSpanOperation(0, spannable.length(),
                                   new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE)));
    }
    Collections.reverse(ops);
    for (SetSpanOperation op : ops) {
      op.execute(spannable);
    }
    return spannable;
  }
  return new SpannableString("");
}
 
Example 2
Project: letv   File: StarActivity.java   Source Code and License 6 votes vote down vote up
private void drawFollowNum(long num) {
    LogInfo.log("clf", "drawFollowNum....num=" + num);
    String followNum = StringUtils.getPlayCountsToStr(num);
    if (TextUtils.isEmpty(followNum)) {
        this.mFollowNum.setText("0");
        return;
    }
    String unit = "";
    String lastChar = followNum.substring(followNum.length() - 1);
    if (!StringUtils.isInt(lastChar)) {
        unit = " " + lastChar;
        followNum = followNum.substring(0, followNum.length() - 1) + unit;
    }
    int start = followNum.length() - unit.length();
    int end = followNum.length();
    SpannableStringBuilder sb = new SpannableStringBuilder(followNum);
    sb.setSpan(new StyleSpan(1), 0, start, 33);
    sb.setSpan(new AbsoluteSizeSpan(getResources().getDimensionPixelSize(2131165476)), start, end, 33);
    this.mFollowNum.setText(sb);
}
 
Example 3
Project: OSchina_resources_android   File: RichEditText.java   Source Code and License 6 votes vote down vote up
/**
 * 设置字体大小
 * @param textSize textSize
 */
void setTextSize(int textSize) {
    Editable edit = getEditableText();
    int index = getSelectionIndex();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (star >= end)
        return;
    if (index >= 0 && index < mSections.size()) {
        TextSection section = mSections.get(index);
        section.setTextSize(textSize);
        if (mListener != null) {
            mListener.onSectionChange(section);
        }
    }
    AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
    for (AbsoluteSizeSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    update(index);
}
 
Example 4
Project: HtmlCompat   File: HtmlToSpannedConverter.java   Source Code and License 6 votes vote down vote up
private void endCssStyle(String tag, Editable text) {
    Strikethrough s = getLast(text, Strikethrough.class);
    if (s != null) {
        setSpanFromMark(tag, text, s, new StrikethroughSpan());
    }
    Background b = getLast(text, Background.class);
    if (b != null) {
        setSpanFromMark(tag, text, b, new BackgroundColorSpan(b.mBackgroundColor));
    }
    Foreground f = getLast(text, Foreground.class);
    if (f != null) {
        setSpanFromMark(tag, text, f, new ForegroundColorSpan(f.mForegroundColor));
    }
    AbsoluteSize a = getLast(text, AbsoluteSize.class);
    if (a != null) {
        setSpanFromMark(tag, text, a, new AbsoluteSizeSpan(a.getTextSize()));
    }
    RelativeSize r = getLast(text, RelativeSize.class);
    if (r != null) {
        setSpanFromMark(tag, text, r, new RelativeSizeSpan(r.getTextProportion()));
    }
}
 
Example 5
Project: appinventor-extensions   File: ListView.java   Source Code and License 6 votes vote down vote up
public Spannable[] itemsToColoredText() {
  // TODO(hal): Generalize this so that different items could have different
  // colors and even fonts and sizes
  int size = items.size();
  int displayTextSize = textSize;
  Spannable [] objects = new Spannable[size];
  for (int i = 1; i <= size; i++) {
    // Note that the ListPicker and otherPickers pickers convert Yail lists to string by calling
    // YailList.ToStringArray.
    // ListView however, does the string conversion via the adapter, so we must ensure
    // that the adapter uses YailListElementToSring
    String itemString = YailList.YailListElementToString(items.get(i));
    // Is there a more efficient way to do conversion to spannable strings that does not
    // need to allocate new objects?
    Spannable chars = new SpannableString(itemString);
    chars.setSpan(new ForegroundColorSpan(textColor),0,chars.length(),0);
    if (!container.$form().getCompatibilityMode()) {
      displayTextSize = (int) (textSize * container.$form().deviceDensity());
    }
    chars.setSpan(new AbsoluteSizeSpan(displayTextSize),0,chars.length(),0);
    objects[i - 1] = chars;
  }
  return objects;
}
 
Example 6
Project: weex-3d-map   File: WXTextDomObject.java   Source Code and License 6 votes vote down vote up
/**
 * Update {@link #spanned} according to the give charSequence and styles
 * @param text the give raw text.
 * @return an Spanned contains text and spans
 */
private
@NonNull
Spanned createSpanned(String text) {
  if (!TextUtils.isEmpty(text)) {
    SpannableString spannable = new SpannableString(text);
    List<SetSpanOperation> ops = createSetSpanOperation(spannable.length());
    if (mFontSize == UNSET) {
      ops.add(new SetSpanOperation(0, spannable.length(),
                                   new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE)));
    }
    Collections.reverse(ops);
    for (SetSpanOperation op : ops) {
      op.execute(spannable);
    }
    return spannable;
  }
  return new SpannableString("");
}
 
Example 7
Project: memoir   File: ConverterSpannedToHtml.java   Source Code and License 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example 8
Project: memoir   File: ConverterSpannedToHtml.java   Source Code and License 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example 9
Project: SprintNBA   File: StringUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 创建{文字内容、字体颜色、字体大小}分段文字集合体
 *
 * @param text
 * @param color
 * @param textSize
 * @return
 */
public static SpannableStringBuilder creSpanString(String[] text, int[] color, int[] textSize) {
    if (text == null || color == null || textSize == null)
        throw new IllegalArgumentException("参数不能为空");
    if (text.length != color.length || text.length != textSize.length)
        throw new IllegalArgumentException("参数数组长度不一致");
    SpannableStringBuilder sb = new SpannableStringBuilder();
    try {
        for (int i = 0; i < text.length; i++) {
            SpannableString sp = new SpannableString(text[i]);
            sp.setSpan(new ForegroundColorSpan(color[i]), 0, sp.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            sp.setSpan(new AbsoluteSizeSpan(textSize[i], true), 0, sp.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            sb.append(sp);
        }
        return sb;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb;
}
 
Example 10
Project: Weex-TestDemo   File: WXTextDomObject.java   Source Code and License 6 votes vote down vote up
/**
 * Update {@link #spanned} according to the give charSequence and styles
 * @param text the give raw text.
 * @return an Spanned contains text and spans
 */
private
@NonNull
Spanned createSpanned(String text) {
  if (!TextUtils.isEmpty(text)) {
    SpannableString spannable = new SpannableString(text);
    List<SetSpanOperation> ops = createSetSpanOperation(spannable.length());
    if (mFontSize == UNSET) {
      ops.add(new SetSpanOperation(0, spannable.length(),
                                   new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE)));
    }
    Collections.reverse(ops);
    for (SetSpanOperation op : ops) {
      op.execute(spannable);
    }
    return spannable;
  }
  return new SpannableString("");
}
 
Example 11
Project: PinnedSectionItemDecoration   File: StockAdapter.java   Source Code and License 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder holder, StockEntity.StockInfo item) {
    switch (holder.getItemViewType()) {

        case StockEntity.StockInfo.TYPE_HEADER:
            holder.setText(R.id.tv_stock_name, item.pinnedHeaderName).addOnClickListener(R.id.checkbox).setChecked(R.id.checkbox, item.check);
            break;

        case StockEntity.StockInfo.TYPE_DATA:

            final String stockNameAndCode = item.stock_name + "\n" + item.stock_code;
            SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode);
            ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new AbsoluteSizeSpan(StockActivity.dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            holder.setText(R.id.tv_stock_name_code, ssb).setText(R.id.tv_current_price, item.current_price)
                    .setText(R.id.tv_rate, (item.rate < 0 ? String.format("%.2f", item.rate) : "+" + String.format("%.2f", item.rate)) + "%");
            break;

    }
}
 
Example 12
Project: UPMiss   File: RecordsViewHolder.java   Source Code and License 6 votes vote down vote up
private void setTimeDay(TextView textView, String day) {
    final Resources resources = textView.getResources();
    final String suffix = resources.getString(R.string.txt_day);
    final int dayLen = day.length();

    SpannableStringBuilder sBuilder = new SpannableStringBuilder();
    sBuilder.append(day) // Bold this
            .append('\n') // Default TextView font.
            .append(suffix); // Default TextView font.

    // Create the Typeface you want to apply to certain text
    CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(resources.getAssets(), "fonts/Hero.otf"));
    sBuilder.setSpan(typefaceSpan, 0, dayLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    // Font
    sBuilder.setSpan(new AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.font_24)),
            0, dayLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // Color
    sBuilder.setSpan(new ForegroundColorSpan(resources.getColor(R.color.cyan_700)),
            0, dayLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(sBuilder, TextView.BufferType.SPANNABLE);
}
 
Example 13
Project: weex   File: WXTextDomObject.java   Source Code and License 6 votes vote down vote up
/**
 * Update {@link #spannableStringBuilder} according to the give charSequence and {@link #style}
 * @param text the give raw text.
 * @return an editable contains text and spans
 */
private Editable updateSpannableStringBuilder(String text) {
  spannableStringBuilder.clear();
  if (text != null) {
    spannableStringBuilder.append(text);
  }
  List<SetSpanOperation> ops = createSetSpanOperation(spannableStringBuilder.length());
  if (mFontSize == UNSET) {
    spannableStringBuilder.setSpan(
        new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), 0, spannableStringBuilder
            .length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  }
  Collections.reverse(ops);
  for (SetSpanOperation op : ops) {
    op.execute(spannableStringBuilder);
  }
  return spannableStringBuilder;
}
 
Example 14
Project: AndroidStudyDemo   File: CouponPriceUtil.java   Source Code and License 6 votes vote down vote up
/**
 * 现金券显示价格样式
 */
public static SpannableString getCashPrice(Context context, double oldPrice, double newPrice) {
    StringBuilder builder = new StringBuilder();
    builder.append(handleDouble(newPrice)).append("元").append(" ").append(handleDouble(oldPrice)).append("元");
    int start = 0;
    int middle = builder.indexOf(" ") + 1;
    int end = builder.length();
    SpannableString string = new SpannableString(builder);
    /*改变文字的大小*/
    string.setSpan(new AbsoluteSizeSpan(sp2px(context, 20)), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    string.setSpan(new AbsoluteSizeSpan(sp2px(context, 14)), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    /*给文字设置删除线*/
    string.setSpan(new StrikethroughSpan(), middle, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    /*改变文字的颜色*/
    int textOrange = context.getResources().getColor(android.R.color.holo_red_light);
    int textGray = context.getResources().getColor(android.R.color.darker_gray);
    string.setSpan(new ForegroundColorSpan(textOrange), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    string.setSpan(new ForegroundColorSpan(textGray), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return string;
}
 
Example 15
Project: Codebase   File: SpannableBuilder.java   Source Code and License 6 votes vote down vote up
public Spannable build() {
    SpannableStringBuilder textSpan = new SpannableStringBuilder();

    int start = 0;
    int end = 0;

    for (int i = 0; i < list.size(); i++) {
        SpanWrapper wrapper = list.get(i);
        String text = wrapper.getText();
        start = end;
        end = end + text.length();
        textSpan.append(text);

        AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(getContext().getResources().getDimensionPixelSize(wrapper.getTextSize()));
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(getContext().getResources().getColor(wrapper.getTextColor()));

        textSpan.setSpan(sizeSpan, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        textSpan.setSpan(colorSpan, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }
    return textSpan;
}
 
Example 16
Project: ReadWorld   File: MainActivity.java   Source Code and License 6 votes vote down vote up
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);

}
 
Example 17
Project: ReadWorld   File: MainActivity.java   Source Code and License 6 votes vote down vote up
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);

}
 
Example 18
Project: Doctor   File: ConverterSpannedToHtml.java   Source Code and License 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example 19
Project: 4Fun   File: MovieAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void onBindViewHolder(MovieHolder holder, final int position) {
    String movieName = list.get(position).getMovieName();
    String briefIntro = list.get(position).getBriefIntro();

    String content = movieName + "\n\n" + briefIntro;
    SpannableStringBuilder style = new SpannableStringBuilder(content);
    style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), 0, movieName.length(),
            SPAN_INCLUSIVE_INCLUSIVE);
    style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(14)), movieName.length() + 2, content.length
            () - 1, SPAN_INCLUSIVE_INCLUSIVE);
    holder.mTvContent.setText(style);

    GlideUtil.setImage(mContext, list.get(position).getPic(), holder.mIvMovie);
    holder.mCvMovie.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.click(list.get(position));
            }
        }
    });
}
 
Example 20
Project: 4Fun   File: ReadFragment.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 21
Project: 4Fun   File: MovieDetailActivity.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 22
Project: Android-RTEditor   File: ConverterSpannedToHtml.java   Source Code and License 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example 23
Project: flowzr-android-black   File: BudgetListFragment.java   Source Code and License 6 votes vote down vote up
@Override
protected void onPostExecute(Total result) {
	if (isRunning) {
		if (BudgetListFragment.this.getActivity()!=null) {
               Utils u = new Utils(BudgetListFragment.this.getActivity());
               if (adapter!=null && totalText!=null) {
               	u.setTotal(totalText, result);

				SpannableString spannablecontent=new SpannableString(totalText.getText());
				spannablecontent.setSpan(new AbsoluteSizeSpan(20,true), 0, spannablecontent.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				// set Text here
				totalText.setText(spannablecontent);
               	((BudgetListAdapter)adapter).notifyDataSetChanged();
               }
		}
	}
}
 
Example 24
Project: shoppinglist   File: ProductPagerAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public CharSequence getPageTitle(int position)
{
    Category category = categoryList.get(position);
    String title = category.getName();
    int fontSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics());

    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(title);

    Typeface font = Fonts.getDefaultFont();
    ForegroundColorSpan fcs = new ForegroundColorSpan(category.getIntColor());
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(fontSize);
    StyleSpan bss = new StyleSpan(Typeface.BOLD);

    spannableStringBuilder.setSpan(new CustomTypefaceSpan(font), 0, title.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    spannableStringBuilder.setSpan(fcs, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    spannableStringBuilder.setSpan(bss, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    spannableStringBuilder.setSpan(ass, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    return spannableStringBuilder;
}
 
Example 25
Project: speech-android-sdk   File: MainActivity.java   Source Code and License 6 votes vote down vote up
protected void setText() {

            Typeface roboto = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/Roboto-Bold.ttf");
            Typeface notosans = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/NotoSans-Regular.ttf");

            // title
            TextView viewTitle = (TextView)mView.findViewById(R.id.title);
            String strTitle = getString(R.string.sttTitle);
            SpannableStringBuilder spannable = new SpannableStringBuilder(strTitle);
            spannable.setSpan(new AbsoluteSizeSpan(47), 0, strTitle.length(), 0);
            spannable.setSpan(new CustomTypefaceSpan("", roboto), 0, strTitle.length(), 0);
            viewTitle.setText(spannable);
            viewTitle.setTextColor(0xFF325C80);

            // instructions
            TextView viewInstructions = (TextView)mView.findViewById(R.id.instructions);
            String strInstructions = getString(R.string.sttInstructions);
            SpannableString spannable2 = new SpannableString(strInstructions);
            spannable2.setSpan(new AbsoluteSizeSpan(20), 0, strInstructions.length(), 0);
            spannable2.setSpan(new CustomTypefaceSpan("", notosans), 0, strInstructions.length(), 0);
            viewInstructions.setText(spannable2);
            viewInstructions.setTextColor(0xFF121212);
        }
 
Example 26
Project: speech-android-sdk   File: MainActivity.java   Source Code and License 6 votes vote down vote up
protected void setText() {

            Typeface roboto = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/Roboto-Bold.ttf");
            Typeface notosans = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/NotoSans-Regular.ttf");

            TextView viewTitle = (TextView)mView.findViewById(R.id.title);
            String strTitle = getString(R.string.ttsTitle);
            SpannableString spannable = new SpannableString(strTitle);
            spannable.setSpan(new AbsoluteSizeSpan(47), 0, strTitle.length(), 0);
            spannable.setSpan(new CustomTypefaceSpan("", roboto), 0, strTitle.length(), 0);
            viewTitle.setText(spannable);
            viewTitle.setTextColor(0xFF325C80);

            TextView viewInstructions = (TextView)mView.findViewById(R.id.instructions);
            String strInstructions = getString(R.string.ttsInstructions);
            SpannableString spannable2 = new SpannableString(strInstructions);
            spannable2.setSpan(new AbsoluteSizeSpan(20), 0, strInstructions.length(), 0);
            spannable2.setSpan(new CustomTypefaceSpan("", notosans), 0, strInstructions.length(), 0);
            viewInstructions.setText(spannable2);
            viewInstructions.setTextColor(0xFF121212);
        }
 
Example 27
Project: countdown   File: Utils.java   Source Code and License 6 votes vote down vote up
/***
 * @param amPmFontSize - size of am/pm label (label removed is size is 0).
 * @return format string for 12 hours mode time
 */
public static CharSequence get12ModeFormat(int amPmFontSize) {
    String skeleton = "hma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    // Remove the am/pm
    if (amPmFontSize <= 0) {
        pattern.replaceAll("a", "").trim();
    }
    // Replace spaces with "Hair Space"
    pattern = pattern.replaceAll(" ", "\u200A");
    // Build a spannable so that the am/pm will be formatted
    int amPmPos = pattern.indexOf('a');
    if (amPmPos == -1) {
        return pattern;
    }
    Spannable sp = new SpannableString(pattern);
    sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    sp.setSpan(new AbsoluteSizeSpan(amPmFontSize), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    return sp;
}
 
Example 28
Project: CountDownView   File: CountDownView.java   Source Code and License 6 votes vote down vote up
Layout createTextLayout(String text) {
    int textWidth = (int) textPaint.measureText(text);
    int unitTextSize = (int) (textPaint.getTextSize() / 2);
    spannableString.clear();
    spannableString.clearSpans();
    spannableString.append(text);
    if (textAppearanceSpan != null) {
        spannableString.setSpan(textAppearanceSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    int hrIndex = text.indexOf("h");
    int minIndex = text.indexOf("m");
    int secIndex = text.indexOf("s");
    spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), hrIndex, hrIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), minIndex, minIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), secIndex, secIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return new StaticLayout(spannableString, textPaint, textWidth, Layout.Alignment.ALIGN_CENTER, 0, 0, true);
}
 
Example 29
Project: showroom-android   File: OuterItem.java   Source Code and License 5 votes vote down vote up
void setContent(@NonNull List<InnerData> innerDataList) {
    final Context context = itemView.getContext();

    final InnerData header = innerDataList.subList(0, 1).get(0);
    final List<InnerData> tail = innerDataList.subList(1, innerDataList.size());

    mRecyclerView.setLayoutManager(new InnerLayoutManager());
    ((InnerAdapter) mRecyclerView.getAdapter()).addData(tail);

    Glide.with(context)
            .load(header.avatarUrl)
            .placeholder(R.drawable.gv_avatar_placeholder)
            .bitmapTransform(new CropCircleTransformation(context))
            .into(mAvatar);

    final String title1 = header.title + "?";

    final Spannable title2 = new SpannableString(header.title + "? - " + header.name);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize1), 0, title1.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize2), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new ForegroundColorSpan(Color.argb(204, 255, 255, 255)), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);

    mHeaderCaption1.setText(title1);
    mHeaderCaption2.setText(title2);

    mName.setText(String.format("%s %s", header.name, context.getString(R.string.gv_asked)));
    mInfo.setText(String.format("%s %s · %s", header.age, context.getString(R.string.gv_years), header.address));
}
 
Example 30
Project: q-mail   File: MessageListAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Create a span section for the sender, and assign the correct font size and weight
 */
private AbsoluteSizeSpan buildSenderSpan() {
    int fontSize = (fragment.senderAboveSubject) ?
            fontSizes.getMessageListSubject():
            fontSizes.getMessageListSender();
    return new AbsoluteSizeSpan(fontSize, true);
}
 
Example 31
Project: GitHub   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources().getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 32
Project: LiteReader   File: MovieItemDialog.java   Source Code and License 5 votes vote down vote up
public Spanned getRating() {
    String text = item.rating.average + "/" + item.rating.max;
    Spannable builder = new SpannableStringBuilder(text);
    int start = text.indexOf('/');
    builder.setSpan(new AbsoluteSizeSpan(60), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorPrimary)), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    return builder;
}
 
Example 33
Project: yyox   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources().getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 34
Project: yyox   File: ServicePriceActivity.java   Source Code and License 5 votes vote down vote up
@Override
    public void priceFee(String totalCostStr) {
//        mFreight_money.setText("RMB:"+totalCostStr);

        SpannableString styledText = new SpannableString("RMB"+totalCostStr);
        styledText.setSpan(new AbsoluteSizeSpan(15,true), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        styledText.setSpan(new AbsoluteSizeSpan(20,true), 3, ("RMB"+totalCostStr).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mFreight_money.setText(styledText, BufferType.SPANNABLE);
    }
 
Example 35
Project: Hitalk   File: RegisterLayout.java   Source Code and License 5 votes vote down vote up
private void initPassHint() {
    String hintPart1 = mRes.getString(R.string.passwordRegTips);
    String hintPart2 = mRes.getString(R.string.passwordRegSubTips);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    SpannableString sPart1 = new SpannableString(hintPart1);
    SpannableString sPart2 = new SpannableString(hintPart2);
    AbsoluteSizeSpan span = new AbsoluteSizeSpan(DisplayUtil.dip2px(mAppCtx,12));
    sPart2.setSpan(span,0,hintPart2.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.append(sPart1).append(sPart2);
    mPassdEt.setHint(spannableStringBuilder);
}
 
Example 36
Project: AppCommonFrame   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources().getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 37
Project: lex   File: MyListItemView.java   Source Code and License 5 votes vote down vote up
public void bind(BookList item) {
    Lex.say(R.string.name_template)
            .with(LexKey.FIRST_NAME, item.firstName)
            .with(LexKey.LAST_NAME, item.lastName)
            .into(title);

    Lex.list(item.titles)
            .wrappedIn(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC))
            .wrappedIn(new ForegroundColorSpan(Color.WHITE))
            .separator(R.string.comma_separator)
            .twoItemSeparator(R.string.and_separator)
            .lastItemSeparator(R.string.comma_and_separator)
            .into(description);

    Lex.say(R.string.item_count_template)
            .withNumber(LexKey.COUNT, item.titles.length)
            .wrappedIn(new AbsoluteSizeSpan(24, true))
            .wrappedIn(new ForegroundColorSpan(Color.WHITE))
            .withPlural(LexKey.ITEM, item.titles.length, R.plurals.book)
            .wrappedIn(new ForegroundColorSpan(Color.YELLOW))
            .into(bookCount);

    Lex.say(R.string.gpa_template)
            .withNumber(LexKey.NUMBER, item.gpa, GPA_FORMAT)
            .wrappedIn(new AbsoluteSizeSpan(24, true))
            .into(gpa);
}
 
Example 38
Project: SpanEZ   File: SpanEZTest.java   Source Code and License 5 votes vote down vote up
@Test
public void absolute_size_should_add_only_one_span() {
    spanBuilder.absoluteSize(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class));
}
 
Example 39
Project: SpanEZ   File: SpanEZTest.java   Source Code and License 5 votes vote down vote up
@Test
public void absolute_size_pixel_independent_should_add_only_one_span() {
    spanBuilder.absoluteSizeDP(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class));
}
 
Example 40
Project: MVPArms_Fragment-fragment   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(Context context, int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources(context).getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 41
Project: MoligyMvpArms   File: ArmsUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(Context context, int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources(context).getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 42
Project: weex-3d-map   File: WXTextDomObject.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 43
Project: ucar-weex-core   File: WXTextDomObject.java   Source Code and License 5 votes vote down vote up
protected void updateSpannable(Spannable spannable, int spanFlag) {
  List<SetSpanOperation> ops = createSetSpanOperation(spannable.length(), spanFlag);
  if (mFontSize == UNSET) {
    ops.add(new SetSpanOperation(0, spannable.length(),
                                 new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), spanFlag));
  }
  Collections.reverse(ops);
  for (SetSpanOperation op : ops) {
    op.execute(spannable);
  }
}
 
Example 44
Project: ucar-weex-core   File: WXTextDomObject.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 45
Project: orgzly-android   File: TitleGenerator.java   Source Code and License 5 votes vote down vote up
public TitleAttributes(int colorTodo, int colorDone, int colorUnknown, int postTitleTextSize, int postTitleTextColor) {
    this.colorTodo = new ForegroundColorSpan(colorTodo);
    this.colorDone = new ForegroundColorSpan(colorDone);
    this.colorUnknown = new ForegroundColorSpan(colorUnknown);
    this.postTitleTextSize = new AbsoluteSizeSpan(postTitleTextSize);
    this.postTitleTextColor = new ForegroundColorSpan(postTitleTextColor);
}
 
Example 46
Project: garland-view-android   File: OuterItem.java   Source Code and License 5 votes vote down vote up
void setContent(@NonNull List<InnerData> innerDataList) {
    final Context context = itemView.getContext();

    final InnerData header = innerDataList.subList(0, 1).get(0);
    final List<InnerData> tail = innerDataList.subList(1, innerDataList.size());

    mRecyclerView.setLayoutManager(new InnerLayoutManager());
    ((InnerAdapter)mRecyclerView.getAdapter()).addData(tail);

    Glide.with(context)
            .load(header.avatarUrl)
            .placeholder(R.drawable.avatar_placeholder)
            .bitmapTransform(new CropCircleTransformation(context))
            .into(mAvatar);

    final String title1 = header.title + "?";

    final Spannable title2 = new SpannableString(header.title + "? - " + header.name);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize1), 0, title1.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize2), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new ForegroundColorSpan(Color.argb(204, 255, 255, 255)), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);

    mHeaderCaption1.setText(title1);
    mHeaderCaption2.setText(title2);

    mName.setText(String.format("%s %s", header.name, context.getString(R.string.asked)));
    mInfo.setText(String.format("%s %s · %s", header.age, context.getString(R.string.years), header.address));
}
 
Example 47
Project: UltimateRecyclerView   File: StickyAdapter.java   Source Code and License 5 votes vote down vote up
private void setData(SuperViewHolder holder, StockEntity.StockInfo item) {
    final String stockNameAndCode = item.stock_name + "\n" + item.stock_code;
    SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode);
    ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new AbsoluteSizeSpan(dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ((TextView) holder.getView(R.id.tv_stock_name_code)).setText(ssb);
    ((TextView) holder.getView(R.id.tv_current_price)).setText(item.current_price);
    ((TextView) holder.getView(R.id.tv_rate)).setText(item.rate < 0 ? String.format("%.2f", item.rate) : ("+" + String.format("%.2f", item.rate)) + "%");
}
 
Example 48
Project: chromium-for-android-56-debug-video   File: PaymentRequestSection.java   Source Code and License 5 votes vote down vote up
private CharSequence convertOptionToString(PaymentOption item, boolean useBoldLabel) {
    SpannableStringBuilder builder = new SpannableStringBuilder(item.getLabel());
    if (useBoldLabel) {
        builder.setSpan(
                new StyleSpan(android.graphics.Typeface.BOLD), 0, builder.length(), 0);
    }

    if (!TextUtils.isEmpty(item.getSublabel())) {
        if (builder.length() > 0) builder.append("\n");
        builder.append(item.getSublabel());
    }

    if (!TextUtils.isEmpty(item.getTertiaryLabel())) {
        if (builder.length() > 0) builder.append("\n");
        builder.append(item.getTertiaryLabel());
    }

    if (!item.isComplete() && !TextUtils.isEmpty(item.getEditMessage())) {
        if (builder.length() > 0) builder.append("\n");
        String editMessage = item.getEditMessage();
        builder.append(editMessage);
        Object foregroundSpanner = new ForegroundColorSpan(ApiCompatibilityUtils.getColor(
                getContext().getResources(), R.color.google_blue_700));
        Object sizeSpanner = new AbsoluteSizeSpan(14, true);
        int startIndex = builder.length() - editMessage.length();
        builder.setSpan(foregroundSpanner, startIndex, builder.length(), 0);
        builder.setSpan(sizeSpanner, startIndex, builder.length(), 0);
    }

    return builder;
}
 
Example 49
Project: chromium-for-android-56-debug-video   File: AnswerTextBuilder.java   Source Code and License 5 votes vote down vote up
/**
 * Append the styled text in textField to the supplied builder.
 *
 * @param builder The builder to append the text to.
 * @param textField The text field (with text and type) to append.
 * @param maxTextHeightSp The height in SP of the largest text field in the entire line. Used to
 *                        top-align text when specified.
 * @param metrics Font metrics which will be used to properly size and layout images and top-
 *                aligned text.
 * @param density Screen density which will be used to properly size and layout images and top-
 *                aligned text.
*/
private static void appendAndStyleText(
        SpannableStringBuilder builder, SuggestionAnswer.TextField textField,
        int maxTextHeightSp, Paint.FontMetrics metrics, float density) {
    String text = textField.getText();
    int type = textField.getType();

    // Unescape HTML entities (e.g. "&quot;", "&gt;").
    text = Html.fromHtml(text).toString();

    // Append as HTML (answer responses contain simple markup).
    int start = builder.length();
    builder.append(Html.fromHtml(text));
    int end = builder.length();

    // Apply styles according to the type.
    AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(getAnswerTextSizeSp(type), true);
    builder.setSpan(sizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ForegroundColorSpan colorSpan = new ForegroundColorSpan(getAnswerTextColor(type));
    builder.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (type == ANSWERS_TOP_ALIGNED_TEXT_TYPE) {
        TopAlignedSpan topAlignedSpan =
                new TopAlignedSpan(
                        ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP, maxTextHeightSp, metrics, density);
        builder.setSpan(topAlignedSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 50
Project: letv   File: StringUtil.java   Source Code and License 5 votes vote down vote up
public static SpannableStringBuilder textSpan(Context context, String textResId, String subText, String colorResId, String fontSizeResId, int start) {
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(context.getString(ResourceUtil.getStringResource(context, textResId), new Object[]{subText}));
    spannableStringBuilder.setSpan(new ForegroundColorSpan(context.getResources().getColor(ResourceUtil.getColorResource(context, colorResId))), start, subText.length() + start, 34);
    if (fontSizeResId != null) {
        spannableStringBuilder.setSpan(new AbsoluteSizeSpan((int) context.getResources().getDimension(ResourceUtil.getDimenResource(context, fontSizeResId))), start, subText.length() + start, 33);
    }
    return spannableStringBuilder;
}
 
Example 51
Project: letv   File: StarActivity.java   Source Code and License 5 votes vote down vote up
private void drawStarVoteNum(String num, String unit) {
    if (!TextUtils.isEmpty(num) && !TextUtils.isEmpty(unit)) {
        String str = num + " " + unit;
        int start = num.length();
        int end = str.length();
        SpannableStringBuilder sb = new SpannableStringBuilder(str);
        sb.setSpan(new ForegroundColorSpan(getResources().getColor(2131493270)), start, end, 33);
        sb.setSpan(new StyleSpan(1), 0, start, 33);
        sb.setSpan(new AbsoluteSizeSpan(getResources().getDimensionPixelSize(2131165477)), start, end, 33);
        this.mStarRankVoteNum.setText(sb);
    }
}
 
Example 52
Project: amap   File: MIP_TextStyle.java   Source Code and License 5 votes vote down vote up
public MIP_TextStyle setAbsoluteSize(int size, int start, int end, boolean dp)
{
    if (spannableString == null)
    {
        return this;
    }
    spannableString.setSpan(new AbsoluteSizeSpan(size, dp), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 第二个参数boolean
                                                                                                           // dip,如果为true,表示前面的字体大小单位为dip,否则为像素,同上。
    return this;
}
 
Example 53
Project: Aurora   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(Context context, int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources(context).getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 54
Project: Aurora   File: ArmsUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(Context context, int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources(context).getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 55
Project: GongXianSheng   File: DateFormateUtil.java   Source Code and License 5 votes vote down vote up
public static SpannableString formatData(String time) {
	if ( TextUtils.isEmpty(time) ) {
		return null;
	}
	// 24小时内:几分钟前。。。,超过24小时:4月11日 20:20, 历史年份:2014年4月12日;
	final Calendar calend = dateFormatFromString(time,
			DateFormateUtil.FORMAT_FULL_DATE_TIME_WITH_SYMBOL);
	if (isToday(calend)) {
		SpannableString ss = new SpannableString("今天");
		ss.setSpan(new AbsoluteSizeSpan(18,true),0,ss.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		return ss;
	}
	else if (isYesterday(calend)) {
		SpannableString yy = new SpannableString("昨天");
		yy.setSpan(new AbsoluteSizeSpan(18,true),0,yy.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		return yy;
	}
	else {
		int day = calend.get(Calendar.DAY_OF_MONTH);
		String datStr = String.format("%02d",day);
		int month = calend.get(Calendar.MONTH)+1;
		String monthStr = getMonthForStr(month);
		SpannableString spannableString = new SpannableString(datStr+"\n"+monthStr);
		spannableString.setSpan(new AbsoluteSizeSpan(20,true),0,datStr.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		spannableString.setSpan(new AbsoluteSizeSpan(16,true),datStr.length()+1,spannableString.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		return spannableString;
	}
}
 
Example 56
Project: OSchina_resources_android   File: RichEditText.java   Source Code and License 5 votes vote down vote up
private void setTextSizeSpan(int textSize, int index) {
    Editable edit = getEditableText();
    int star = getSectionStart(index);
    int end = getSectionEnd(index);
    if (star >= end)
        return;
    AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
    for (AbsoluteSizeSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 57
Project: OSchina_resources_android   File: RichEditText.java   Source Code and License 5 votes vote down vote up
private void setTextSizeSpan(int textSize) {
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (star >= end)
        return;
    AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
    for (AbsoluteSizeSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 58
Project: PicShow-zhaipin   File: UiUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources().getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example 59
Project: JkShoppingCart   File: StringUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 设置商品总金额显示样式
 * @author leibing
 * @createTime 2017/3/16
 * @lastModify 2017/3/16
 * @param totalPrice
 * @return
 */
public static SpannableString setTotalPriceType(double totalPrice){
	String targetStr = doubleTwoDecimal(totalPrice);
	targetStr = "¥" + targetStr;
	int length = targetStr.length();
	SpannableString msp = new SpannableString(targetStr);
	// 第二个参数boolean dip,如果为true,表示前面的字体大小单位为dip,否则为像素。
	msp.setSpan(new AbsoluteSizeSpan(15,true), 0, 1,
			Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	msp.setSpan(new AbsoluteSizeSpan(24,true), 1, length-3,
			Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	msp.setSpan(new AbsoluteSizeSpan(15,true), length-3, length,
			Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	return msp;
}
 
Example 60
Project: boohee_v5.6   File: LessonDetailActivity.java   Source Code and License 5 votes vote down vote up
private void refreshView() {
    if (this.lesson != null) {
        if (this.isDownloaded) {
            this.tvDownloadStatus.setText(R.string.jt);
        } else {
            this.tvDownloadStatus.setText("");
        }
        this.adapter = new MentionRecyclerAdapter(this, this.lesson.mentions);
        this.recyclerView.setAdapter(this.adapter);
        this.tvSportTime.setText(String.valueOf(this.lesson.total_time));
        this.tvCalory.setText(String.valueOf(this.lesson.calorie));
        this.tvMentonCount.setText(String.valueOf(this.lesson.mentions.size()));
        this.tvMentionDes.setText(String.valueOf(this.lesson.description));
        this.progressBarHorizontal.setProgress(this.lesson.progress, this.lesson
                .total_progress);
        this.progressBarHorizontal.setItemWidth(ViewUtils.dip2px(MyApplication.getContext(),
                40.0f));
        this.progressTime = String.format(getString(R.string.ss), new Object[]{Integer
                .valueOf(this.lesson.progress)});
        this.spannableString = new SpannableString(this.progressTime);
        this.spannableString.setSpan(new AbsoluteSizeSpan(14, true), 0, this.spannableString
                .length(), 18);
        this.spannableString.setSpan(new AbsoluteSizeSpan(50, true), 1, this.spannableString
                .length() - 1, 17);
        this.tvTime.setText(this.spannableString);
        ImageLoader.getInstance().displayImage(this.lesson.banner_url, this.ivTop,
                ImageLoaderOptions.randomColor());
    }
}