Example usage for android.text.style AbsoluteSizeSpan AbsoluteSizeSpan

List of usage examples for android.text.style AbsoluteSizeSpan AbsoluteSizeSpan

Introduction

In this page you can find the example usage for android.text.style AbsoluteSizeSpan AbsoluteSizeSpan.

Prototype

public AbsoluteSizeSpan(@NonNull Parcel src) 

Source Link

Document

Creates an AbsoluteSizeSpan from a parcel.

Usage

From source file:Main.java

public static SpannableString setTextSize(String content, int startIndex, int endIndex, int fontSize) {
    if (TextUtils.isEmpty(content) || fontSize <= 0 || startIndex >= endIndex || startIndex < 0
            || endIndex >= content.length()) {
        return null;
    }//  w w  w .  j a  va 2  s  . c  o  m

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new AbsoluteSizeSpan(fontSize), startIndex, endIndex,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static SpannableStringBuilder getFrontTextStyle(String frontText, String afterText, int frontColor,
        int frontTextSize) {
    StringBuilder sb = new StringBuilder();
    sb.append("/").append(afterText);
    int len = sb.length();
    sb.insert(0, frontText);/*w w w .  ja  v  a 2  s  .  co m*/
    SpannableStringBuilder style = new SpannableStringBuilder(sb);
    style.setSpan(new ForegroundColorSpan(frontColor), 0, sb.length() - len,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    style.setSpan(new AbsoluteSizeSpan(frontTextSize), 0, sb.length() - len,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return style;
}

From source file:Main.java

public static SpannableStringBuilder getSpannableStringFromList(List<HashMap<String, Object>> list) {
    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    int position = 0;
    for (int i = 0; i < list.size(); i++) {
        HashMap<String, Object> map = list.get(i);
        try {/*w  w w.j  a v a2 s.  com*/
            String st = (String) map.get(RICHTEXT_STRING);
            ssb.append(st);
            int len = st.length();
            if (map.containsKey(RICHTEXT_COLOR)) {
                int color = ((Integer) map.get(RICHTEXT_COLOR)).intValue();
                ssb.setSpan(new ForegroundColorSpan(color), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_SIZE)) {
                int size = ((Integer) map.get(RICHTEXT_SIZE)).intValue();
                ssb.setSpan(new AbsoluteSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_RSIZE)) {
                float size = ((Float) map.get(RICHTEXT_RSIZE)).floatValue();
                ssb.setSpan(new RelativeSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_DELETE)) {
                ssb.setSpan(new StrikethroughSpan(), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            //              android.text.style.RelativeSizeSpan
            position = position + len;
        } catch (Exception e) {
            return null;
        }
    }
    return ssb;
}

From source file:Main.java

public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor,
        int messageTextSize, CharSequence title, CharSequence message) {
    titleTv.setMinHeight(titleTextSize * 3);

    if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) {
        titleTv.setTextColor(titleColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
        titleTv.getPaint().setFakeBoldText(true);
        titleTv.setText(title);/*from  www  . ja v a 2s .  c  o  m*/
    } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        titleTv.setTextColor(messageColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize);
        titleTv.setText(message);
    } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        SpannableString titleSs = new SpannableString(title + "\n" + message);
        titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleTv.setText(titleSs);
        titleTv.setLineSpacing(0.0f, 1.2f);
    } else {
        titleTv.setVisibility(View.GONE);
    }
}

From source file:it.gulch.linuxday.android.adapters.EventsAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;//  ww w . ja va2s .  c o m
    if (convertView != null) {
        viewHolder = (ViewHolder) convertView.getTag();
    } else {
        convertView = inflater.inflate(R.layout.item_event, parent, false);

        viewHolder = new ViewHolder();
        viewHolder.title = (TextView) convertView.findViewById(R.id.title);
        viewHolder.titleSizeSpan = new AbsoluteSizeSpan(titleTextSize);
        viewHolder.trackName = (TextView) convertView.findViewById(R.id.track_name);
        viewHolder.details = (TextView) convertView.findViewById(R.id.details);
        convertView.setTag(viewHolder);
    }

    Event event = getItem(position);
    bindView(viewHolder, event);

    return convertView;
}

From source file:net.zionsoft.obadiah.ui.adapters.TranslationListAdapter.java

public TranslationListAdapter(Context context, String currentTranslation) {
    App.get(context).getInjectionComponent().inject(this);

    mInflater = LayoutInflater.from(context);
    mResources = context.getResources();
    mCurrentTranslation = currentTranslation;

    mDownloadedTranslationsTitle = mResources.getString(R.string.text_downloaded_translations);

    mTextColor = mSettings.getTextColor();

    mTextSize = mResources.getDimension(mSettings.getTextSize().textSize);
    mMediumSizeSpan = new AbsoluteSizeSpan((int) mTextSize);
    mSmallSizeSpan = new AbsoluteSizeSpan(
            (int) mResources.getDimension(mSettings.getTextSize().smallerTextSize));
}

From source file:org.mariotaku.twidere.view.NameView.java

public void setPrimaryTextSize(final float textSize) {
    mPrimaryTextSize = new AbsoluteSizeSpan((int) calculateTextSize(TypedValue.COMPLEX_UNIT_SP, textSize));
}

From source file:org.mariotaku.twidere.view.NameView.java

public void setSecondaryTextSize(final float textSize) {
    mSecondaryTextSize = new AbsoluteSizeSpan((int) calculateTextSize(TypedValue.COMPLEX_UNIT_SP, textSize));
}

From source file:com.taobao.weex.dom.WXTextDomObject.java

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));//from  w w  w .j a  va 2 s.c om
    }
    Collections.reverse(ops);
    for (SetSpanOperation op : ops) {
        op.execute(spannable);
    }
}

From source file:com.taobao.weex.dom.WXTextDomObject.java

/**
 * Create a task list which contains {@link SetSpanOperation}. The task list will be executed
 * in other method./*from w w  w  .  j  a v  a 2 s  .c o m*/
 * @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;
}