android.text.style.AbsoluteSizeSpan Java Examples

The following examples show how to use android.text.style.AbsoluteSizeSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StarActivity.java    From letv with Apache License 2.0 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 #2
Source File: CustomSpanData.java    From customview-samples with Apache License 2.0 6 votes vote down vote up
@Override
public CharacterStyle onCreateSpan() {
    switch (mSpanType){
            case TYPE_ABS_SIZE_SPAN:
                switch (mUnit){
                        case UNIT_PX:
                            return new AbsoluteSizeSpan((int) mTextSize);
                        case UNIT_SP:
                            return new AbsoluteSizeSpan((int) mTextSize,true);
                }
            case TYPE_CUSTOM_TEXT_SPAN:
                return new CustomTextSpan(mUnit,mTextSize,
                    mTypeface,
                    mColor,
                    mLeftMarginDp,
                    mAlign);

            default:
                return new CustomTextSpan(mUnit,mTextSize,
                    mTypeface,
                    mColor,
                    mLeftMarginDp,
                    mAlign);
    }
}
 
Example #3
Source File: EmbeddedNavigationActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
private void setSpeed(Location location) {
  String string = String.format("%d\nMPH", (int) (location.getSpeed() * 2.2369));
  int mphTextSize = getResources().getDimensionPixelSize(R.dimen.mph_text_size);
  int speedTextSize = getResources().getDimensionPixelSize(R.dimen.speed_text_size);

  SpannableString spannableString = new SpannableString(string);
  spannableString.setSpan(new AbsoluteSizeSpan(mphTextSize),
    string.length() - 4, string.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

  spannableString.setSpan(new AbsoluteSizeSpan(speedTextSize),
    0, string.length() - 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

  speedWidget.setText(spannableString);
  if (!instructionListShown) {
    speedWidget.setVisibility(View.VISIBLE);
  }
}
 
Example #4
Source File: StockAdapter.java    From PinnedSectionItemDecoration with Apache License 2.0 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 #5
Source File: HtmlToSpannedConverter.java    From HtmlCompat with Apache License 2.0 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 #6
Source File: ListView.java    From appinventor-extensions with Apache License 2.0 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 #7
Source File: DiscountAdapter.java    From FastWaiMai with MIT License 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, MultipleItemEntity item) {
    switch (helper.getItemViewType()){
        case DiscountCardItemType.ITEM_NORMAL_AVAILIABLE:
            String shopName = item.getField(DiscountItemFields.SHOP_NAME);
            helper.setText(R.id.tv_item_discount_shopname, shopName);

            String type = item.getField(DiscountItemFields.TYPE);
            helper.setText(R.id.tv_item_discount_type, type);
            String expireTime = item.getField(DiscountItemFields.EXPIRE_TIME);
            helper.setText(R.id.tv_item_discount_expiretime, "有效期至" + expireTime);

            String orimoney = item.getField(DiscountItemFields.MONEY);
            final SpannableString money = new SpannableString(orimoney);
            money.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            helper.setText(R.id.tv_item_discount_money, money);
            String condition = item.getField(DiscountItemFields.CONDITION);
            helper.setText(R.id.tv_item_discount_condition, condition);

            break;
        case DiscountCardItemType.ITEM_NORMAL_UNAVAILIABLE:
            break;
        default:
            break;
    }
}
 
Example #8
Source File: CouponPriceUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 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 #9
Source File: MineFragment.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置 "文章"、"评论"、"收藏"
 */
private void setArticleInfoSpanInfo(TextView textView,
                                    int sourceId,
                                    String info) {
    String content = String.format(getString(sourceId), info);

    AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(20, true);

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(absoluteSizeSpan,
            0,
            info == null ? 0 : info.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(spannableString);
}
 
Example #10
Source File: ConverterSpannedToHtml.java    From memoir with Apache License 2.0 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 #11
Source File: MineFragment.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置信息
 *
 * @param textView
 * @param sourceId
 * @param info
 */
private void setSpanInfo(TextView textView,
                         int sourceId,
                         String info) {
    String content = String.format(getString(sourceId), info);

    AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(18, true);

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(absoluteSizeSpan,
            content.length() - info.length(),
            content.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(spannableString);
}
 
Example #12
Source File: CharacterFactory.java    From RichEditor with Apache License 2.0 5 votes vote down vote up
/**
 * 创建字号span
 */
private void createSizeSpan(String code, List<CharacterStyle> characterStyles) {
    try {
        if (TextUtils.isEmpty(code) || Integer.parseInt(code) <= 0) return;
        AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(Integer.parseInt(code));
        characterStyles.add(sizeSpan);
    } catch (NumberFormatException e) {
        Log.e(Const.BASE_LOG, "font size value is not true!");
    }
}
 
Example #13
Source File: HtmlActivity.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(
        @NonNull MarkwonVisitor visitor,
        @NonNull MarkwonHtmlRenderer renderer,
        @NonNull HtmlTag tag) {

    final SpannableBuilder builder = visitor.builder();

    // text content is already added, we should only apply spans

    for (int i = tag.start(), end = tag.end(); i < end; i++) {
        final int size = (int) (base * (random.nextFloat() + 0.5F) + 0.5F);
        builder.setSpan(new AbsoluteSizeSpan(size, false), i, i + 1);
    }
}
 
Example #14
Source File: ArmsUtils.java    From MVPArms with Apache License 2.0 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 #15
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 5 votes vote down vote up
public TextDecorator setAbsoluteSize(final int size, final boolean dip, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new AbsoluteSizeSpan(size, dip), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example #16
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 5 votes vote down vote up
public TextDecorator setAbsoluteSize(final int size, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new AbsoluteSizeSpan(size), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example #17
Source File: PhotoTextView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void setText(CharSequence text, BufferType type) {
	if (!TextUtils.isEmpty(text) && text.toString().contains("/")) {
		String[] s = text.toString().split("/");
		SpannableString sp = new SpannableString(text);
		sp.setSpan(new AbsoluteSizeSpan((int) (this.getTextSize() + 25)),
				0, s[0].length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
		super.setText(sp, type);
	} else {
		super.setText(text, type);
	}
}
 
Example #18
Source File: WXTextDomObject.java    From weex-uikit with MIT 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) {
      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;
}
 
Example #19
Source File: WXTextDomObject.java    From weex-uikit with MIT 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 #20
Source File: UiUtils.java    From MVVMArms with Apache License 2.0 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 #21
Source File: StarActivity.java    From letv with Apache License 2.0 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 #22
Source File: StringUtil.java    From letv with Apache License 2.0 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 #23
Source File: WXTextDomObject.java    From ucar-weex-core with Apache License 2.0 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 #24
Source File: WXTextDomObject.java    From ucar-weex-core with Apache License 2.0 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 #25
Source File: SpanEZTest.java    From SpanEZ with Apache License 2.0 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 #26
Source File: SpanEZTest.java    From SpanEZ with Apache License 2.0 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 #27
Source File: MarkDownParser.java    From RichEditor with Apache License 2.0 5 votes vote down vote up
private String paragraphToMarkDown(List<Object> mSpans, StringBuilder source) {
    if (mSpans == null || mSpans.size() == 0) {
        return source.toString();
    }
    String str = source.toString();
    for (Object obj : mSpans) {
        if (obj instanceof ReferSpan) {
            str = formater.formatRefer(str);
        } else if (obj instanceof AlignmentSpan) {
            //markdown是不支持居中的!!!,后期考虑注释掉
            // str = formater.formatCenter(str);
        } else if (obj instanceof AbsoluteSizeSpan) {
            AbsoluteSizeSpan sizeSpan = (AbsoluteSizeSpan) obj;
            switch (sizeSpan.getSize()) {
                case Const.T1_SIZE:
                    str = formater.formatH1(str);
                    break;
                case Const.T2_SIZE:
                    str = formater.formatH2(str);
                    break;
                case Const.T3_SIZE:
                    str = formater.formatH3(str);
                    break;
                case Const.T4_SIZE:
                    str = formater.formatH4(str);
                    break;
            }
        }
    }
    return str;
}
 
Example #28
Source File: RichShowAdapter.java    From RichEditor with Apache License 2.0 5 votes vote down vote up
private void bindTextComponent(RecyclerView.ViewHolder holder, int i, RichModel item) {
    if (holder instanceof TextViewHolder) {
        TextViewHolder textHolder = (TextViewHolder) holder;
        TextView tv = textHolder.mTv;
        if (item.isParagraphStyle) {
            SpannableStringBuilder spannableString = new SpannableStringBuilder(item.source);
            for (Object obj : item.paragraphSpan.mSpans) {
                if (obj instanceof AbsoluteSizeSpan) {
                    AbsoluteSizeSpan sizeSpan = (AbsoluteSizeSpan) obj;
                    tv.setTextSize(sizeSpan.getSize());
                    continue;
                }
                spannableString.setSpan(obj, 0, item.source.length(), Spanned
                        .SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            tv.setText(spannableString);
            paragraphHelper.handleTextStyle(tv, item.paragraphSpan.paragraphType);
        } else {
            mSpanString.clear();
            mSpanString.clearSpans();
            mSpanString.append(item.source);
            if (item.getSpanList() != null) {
                for (SpanModel span : item.getSpanList()) {
                    mSpanString.setMultiSpans(span.mSpans, span.start, span.end, Spanned
                            .SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
            tv.setText(mSpanString);
            paragraphHelper.handleTextStyle(tv, -1);
        }
    }
}
 
Example #29
Source File: StockAdapter.java    From StickyItemDecoration with Apache License 2.0 5 votes vote down vote up
private void setData(RecyclerViewHolder 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);

    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)) + "%");
}
 
Example #30
Source File: UiUtils.java    From Aurora with Apache License 2.0 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)); // 一定要进行转换,否则属性会消失
}