android.text.style.ScaleXSpan#android.text.style.AbsoluteSizeSpan源码实例Demo

下面列出了android.text.style.ScaleXSpan#android.text.style.AbsoluteSizeSpan 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tysq-android   文件: MineFragment.java
/**
 * 设置信息
 *
 * @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);
}
 
源代码2 项目: tysq-android   文件: MineFragment.java
/**
 * 设置 "文章"、"评论"、"收藏"
 */
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);
}
 
源代码3 项目: FastWaiMai   文件: DiscountAdapter.java
@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;
    }
}
 
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);
  }
}
 
源代码5 项目: customview-samples   文件: CustomSpanData.java
@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);
    }
}
 
源代码6 项目: letv   文件: StarActivity.java
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);
}
 
@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;

    }
}
 
源代码8 项目: HtmlCompat   文件: HtmlToSpannedConverter.java
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()));
    }
}
 
源代码9 项目: appinventor-extensions   文件: ListView.java
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;
}
 
源代码10 项目: memoir   文件: ConverterSpannedToHtml.java
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>");
    }
}
 
源代码11 项目: AndroidStudyDemo   文件: CouponPriceUtil.java
/**
 * 现金券显示价格样式
 */
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;
}
 
源代码12 项目: XMiTools   文件: BatteryMeterViewHook.java
private void hookUpdateShowPercent() {
    XposedWrapper.findAndHookMethod(CLASS_BATTERY_VIEW,
            mClassLoader,
            "updateShowPercent",
            new MethodHookWrapper() {
                @Override
                protected void after(MethodHookParam param) {

                    TextView mBatteryPercentView = (TextView) XposedHelpers
                            .getObjectField(param.thisObject, "mBatteryPercentView");
                    if (mBatteryPercentView != null) {
                        CharSequence cs = mBatteryPercentView.getText();
                        if (cs == null) {
                            return;
                        }
                        String text = cs.toString();
                        int percentSignIdx = text.indexOf('%');
                        if (percentSignIdx != -1) {
                            SpannableString ss = new SpannableString(text);
                            float originSize = mBatteryPercentView.getTextSize();
                            ss.setSpan(new AbsoluteSizeSpan((int) (originSize * 3 / 4)), percentSignIdx, percentSignIdx + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            mBatteryPercentView.setText(ss);
                        }
                    }
                }
            });
}
 
源代码13 项目: weex   文件: WXTextDomObject.java
/**
 * 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;
}
 
源代码14 项目: tysq-android   文件: PersonalHomePageFragment.java
/**
 * 设置个人成就富文本
 */
private void setAchievementInfo(TextView textView, String quantity, int stringRes) {

    String content = getString(stringRes);

    String resultContent = String.format(content, quantity);

    int length = quantity.length();

    SpannableStringBuilder builder = new SpannableStringBuilder(resultContent);
    builder.setSpan(new JerryBoldSpan(),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    builder.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.main_text_color)),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    builder.setSpan(new AbsoluteSizeSpan(16, true),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(builder);

}
 
源代码15 项目: FastWaiMai   文件: SubmitDelegate.java
@Override
public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) {
	//支付方式
	initPayCheckBox();

	//订单支付剩余时间15min开始倒计时
	initPayLeftTime();

	//支付金额
	final SpannableString paymoney = new SpannableString("¥24.8");
	paymoney.setSpan(new AbsoluteSizeSpan(20, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	mTvPayMoney.setText(paymoney);
}
 
源代码16 项目: FastWaiMai   文件: PersonalDelegate.java
private void initView() {
	final SpannableString redEnvelope = new SpannableString("0个未使用");
	redEnvelope.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	redEnvelope.setSpan(new AbsoluteSizeSpan(17, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	redEnvelope.setSpan(new AbsoluteSizeSpan(13, true), 1, redEnvelope.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

	final SpannableString discount = new SpannableString("12张未使用");
	discount.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	discount.setSpan(new AbsoluteSizeSpan(17, true), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	discount.setSpan(new AbsoluteSizeSpan(13, true), 2, discount.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

	final SpannableString bounty = new SpannableString("20元可叠加满减");
	bounty.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	bounty.setSpan(new AbsoluteSizeSpan(17, true), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	bounty.setSpan(new AbsoluteSizeSpan(13, true), 2, bounty.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);


	mTvRedEnvelope.setText(redEnvelope);
	mTvDiscount.setText(discount);
	mTvBounty.setText(bounty);

	final SpannableString payment = new SpannableString("28元");
	payment.setSpan(new AbsoluteSizeSpan(17, true), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	bounty.setSpan(new AbsoluteSizeSpan(9, true), 2, payment.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

	final SpannableString benefit = new SpannableString("165元");
	benefit.setSpan(new AbsoluteSizeSpan(17, true), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	bounty.setSpan(new AbsoluteSizeSpan(9, true), 3, benefit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

	mTvPayment.setText(payment);
	mTvBenefit.setText(benefit);
}
 
源代码17 项目: youqu_master   文件: UiUtils.java
/**
 * 设置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)); // 一定要进行转换,否则属性会消失
}
 
源代码18 项目: TikTok   文件: MvpUtils.java
/**
 * 设置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)); // 一定要进行转换,否则属性会消失
}
 
源代码19 项目: nono-android   文件: BaseRichEditText.java
public void applyAbsoluteSpan(int px){
    int selStart=getSelectionStart();
    int selEnd=getSelectionEnd();
    if(selEnd-selStart>0){
        AbsoluteSizeSpan[] ss = getEditableText().getSpans(selStart, selEnd, AbsoluteSizeSpan.class);
        for (AbsoluteSizeSpan span:ss) {
            removeSpan(span, selStart, selEnd);
        }
        setSpan(new AbsoluteSizeSpan(px),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
源代码20 项目: timecat   文件: MeechaoDataUtils.java
/**
 * 标签格式化
 *
 * @param labelTopicValue 标签 内容
 *
 * @return s
 */
public static SpannableStringBuilder covTopicVal(String labelTopicValue) {
    SpannableStringBuilder spannableString = new SpannableStringBuilder(labelTopicValue);
    if (TextUtils.isEmpty(labelTopicValue)) {
        return spannableString;
    }
    spannableString.setSpan(new AbsoluteSizeSpan(0, true), labelTopicValue.indexOf("["),
            labelTopicValue.indexOf("]") + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}
 
源代码21 项目: UPMiss   文件: QuickFragment.java
private CharSequence getTopText(long occupancy, final String suffix) {
    final String str = String.valueOf(occupancy) + "\n" + suffix;
    final int len = str.length();
    final int lenFx = len - suffix.length();
    final Resources resources = getResources();

    SpannableString span = new SpannableString(str);
    span.setSpan(new AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.font_20)),
            0, lenFx, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(new ForegroundColorSpan(resources.getColor(R.color.white_alpha_224)),
            0, lenFx, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return span;
}
 
源代码22 项目: SimpleProject   文件: SpannableStringUtil.java
/**
 * 设置多个位置的文字大小
 * @param text
 * @param textSize
 * @param startPos
 * @param len
 * @return
 */
public static SpannableString getTextSizeSpannable(String text, int textSize, int[] startPos, int[] len) {
	SpannableString span = new SpannableString(text);
	if (startPos != null && len != null && startPos.length > 0 && len.length > 0 && startPos.length == len.length) {
		for (int i = 0; i < startPos.length; i++) {
			span.setSpan(new AbsoluteSizeSpan(textSize), startPos[i], startPos[i]+len[i], Spanned.SPAN_INCLUSIVE_INCLUSIVE);
		}
	}

	return span;
}
 
源代码23 项目: react-native-GPay   文件: ReactEditText.java
/**
 * Remove and/or add {@link Spanned.SPAN_EXCLUSIVE_EXCLUSIVE} spans, since they should only exist
 * as long as the text they cover is the same. All other spans will remain the same, since they
 * will adapt to the new text, hence why {@link SpannableStringBuilder#replace} never removes
 * them.
 */
private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
  Object[] spans = getText().getSpans(0, length(), Object.class);
  for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
    // Remove all styling spans we might have previously set
    if (ForegroundColorSpan.class.isInstance(spans[spanIdx]) ||
        BackgroundColorSpan.class.isInstance(spans[spanIdx]) ||
        AbsoluteSizeSpan.class.isInstance(spans[spanIdx]) ||
        CustomStyleSpan.class.isInstance(spans[spanIdx]) ||
        ReactTagSpan.class.isInstance(spans[spanIdx])) {
      getText().removeSpan(spans[spanIdx]);
    }

    if ((getText().getSpanFlags(spans[spanIdx]) & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) !=
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) {
      continue;
    }
    Object span = spans[spanIdx];
    final int spanStart = getText().getSpanStart(spans[spanIdx]);
    final int spanEnd = getText().getSpanEnd(spans[spanIdx]);
    final int spanFlags = getText().getSpanFlags(spans[spanIdx]);

    // Make sure the span is removed from existing text, otherwise the spans we set will be
    // ignored or it will cover text that has changed.
    getText().removeSpan(spans[spanIdx]);
    if (sameTextForSpan(getText(), spannableStringBuilder, spanStart, spanEnd)) {
      spannableStringBuilder.setSpan(span, spanStart, spanEnd, spanFlags);
    }
  }
}
 
源代码24 项目: react-native-GPay   文件: ReactTextTest.java
@Test
public void testFontSizeApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.FONT_SIZE, 21.0),
      JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));

  AbsoluteSizeSpan sizeSpan = getSingleSpan(
      (TextView) rootView.getChildAt(0), AbsoluteSizeSpan.class);
  assertThat(sizeSpan.getSize()).isEqualTo(21);
}
 
源代码25 项目: PLDroidShortVideo   文件: VideoMixRecordActivity.java
private void showDescription(String filterName, int time) {
    SpannableString description = new SpannableString(String.format("%s%n<<左右滑动切换滤镜>>", filterName));
    description.setSpan(new AbsoluteSizeSpan(30, true), 0, filterName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    description.setSpan(new AbsoluteSizeSpan(14, true), filterName.length(), description.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    mFilterDescription.removeCallbacks(effectDescriptionHide);
    mFilterDescription.setVisibility(View.VISIBLE);
    mFilterDescription.setText(description);
    mFilterDescription.postDelayed(effectDescriptionHide, time);
}
 
源代码26 项目: CrazyDaily   文件: PhotoPickerBucketAdapter.java
private CharSequence getInfo(String bucketId, String bucketName, int count) {
    SpannableStringBuilder builder = new SpannableStringBuilder(bucketName);
    builder.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 0, bucketName.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    builder.setSpan(new AbsoluteSizeSpan(16, true), 0, bucketName.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    if (!String.valueOf(Integer.MAX_VALUE).equals(bucketId)) {
        builder.append("\n").append(String.valueOf(count)).append("张");
        builder.setSpan(new ForegroundColorSpan(Color.parseColor("#999999")), bucketName.length(), builder.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        builder.setSpan(new AbsoluteSizeSpan(12, true), bucketName.length(), builder.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return builder;
}
 
源代码27 项目: StickyItemDecoration   文件: StockAdapter.java
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)) + "%");
}
 
源代码28 项目: RichEditor   文件: RichShowAdapter.java
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);
        }
    }
}
 
源代码29 项目: RichEditor   文件: MarkDownParser.java
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;
}
 
源代码30 项目: RichEditor   文件: CharacterFactory.java
/**
 * 创建字号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!");
    }
}