Java Code Examples for android.text.style.RelativeSizeSpan

The following examples show how to use android.text.style.RelativeSizeSpan. These examples are extracted from open source projects. 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
private void initializeResources() {
  Toolbar     toolbar  = findViewById(R.id.toolbar);

  passphraseAuthContainer = findViewById(R.id.password_auth_container);
  passphraseLayout        = findViewById(R.id.passphrase_layout);
  passphraseInput         = findViewById(R.id.passphrase_input);
  okButton                = findViewById(R.id.ok_button);
  successView             = findViewById(R.id.success);

  setSupportActionBar(toolbar);
  getSupportActionBar().setTitle("");

  SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));
  hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new TypefaceSpan("sans-serif-light"), 0, hint.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

  passphraseInput.setHint(hint);
  passphraseInput.setOnEditorActionListener(new PassphraseActionListener());

  okButton.setOnClickListener(v -> handlePassphrase());
}
 
Example 2
Source Project: mollyim-android   Source File: ComposeText.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void setHint(@NonNull String hint, @Nullable CharSequence subHint) {
  this.hint = hint;

  if (subHint != null) {
    this.subHint = new SpannableString(subHint);
    this.subHint.setSpan(new RelativeSizeSpan(0.5f), 0, subHint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  } else {
    this.subHint = null;
  }

  if (this.subHint != null) {
    super.setHint(new SpannableStringBuilder().append(ellipsizeToWidth(this.hint))
                                              .append("\n")
                                              .append(ellipsizeToWidth(this.subHint)));
  } else {
    super.setHint(ellipsizeToWidth(this.hint));
  }
}
 
Example 3
Source Project: MHViewer   Source File: Html.java    License: Apache License 2.0 6 votes vote down vote up
private static void endHeader(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Header.class);

    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    // Back off not to change only the text, not the blank line.
    while (len > where && text.charAt(len - 1) == '\n') {
        len--;
    }

    if (where != len) {
        Header h = (Header) obj;

        text.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]),
                where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new StyleSpan(Typeface.BOLD),
                where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 4
Source Project: iqra-android   Source File: SearchResultsActivity.java    License: MIT License 6 votes vote down vote up
private void onTranslationChanged() throws JSONException {
    SpannableString ss1 = new SpannableString(getResources().getString(R.string.getting_match));
    ss1.setSpan(new RelativeSizeSpan(1.7f), 0, ss1.length(), 0);

    final ProgressDialog progress = new ProgressDialog(this);
    progress.setMessage(ss1);
    progress.setCancelable(false);
    progress.show();

    RequestDelegate requestDelegate = RequestDelegate.getInstance(getApplicationContext());
    requestDelegate.performTranslationChange(prefs.getString("translation", "en-hilali"), getAllCurrentAyahs(), new NetworkRequestCallback() {
        @Override
        public void onSuccess(JSONObject response) {
            Log.v(TAG, response.toString());
            parseTranslationResponse(response);
            progress.dismiss();
        }

        @Override
        public void onFailure(Throwable error) {
            onSearchQueryError(error);
            progress.dismiss();
        }
    });
}
 
Example 5
private void processSup( boolean opening, Editable output) {
    int len = output.length();
    if(opening) {
        //output.setSpan(new AbsoluteSizeSpan(scriptSize,false), len, len, Spannable.SPAN_MARK_MARK);
        //output.setSpan(new RelativeSizeSpan(0.5f), len, len, Spannable.SPAN_MARK_MARK);
        output.setSpan(new SuperscriptSpan(), len, len, Spannable.SPAN_MARK_MARK);
    } else {
        Object obj = getLast(output, SuperscriptSpan.class);
        int where = output.getSpanStart(obj);
        output.removeSpan(obj);
        //obj = getLast(output, RelativeSizeSpan.class);
        //output.removeSpan(obj);
        if (where != len&&where>=0) {
            //output.setSpan(new AbsoluteSizeSpan(scriptSize, false), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            output.setSpan(new RelativeSizeSpan(0.7f), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            output.setSpan(new SuperscriptSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        //obj = getLast(output, AbsoluteSizeSpan.class);
        //where = output.getSpanStart(obj);
        //output.removeSpan(obj);
        //if (where != len) {
        //    output.setSpan(new AbsoluteSizeSpan(scriptSize, false), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //    //output.setSpan(new RelativeSizeSpan(0.5f), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //}
    }
}
 
Example 6
Source Project: styT   Source File: SpanUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static SpannableString getRelativeSizeSpan() {
    SpannableString spannableString = new SpannableString("我心情忐忑不安七上八下");
    RelativeSizeSpan sizeSpan1 = new RelativeSizeSpan(1.2f);
    RelativeSizeSpan sizeSpan2 = new RelativeSizeSpan(1.4f);
    RelativeSizeSpan sizeSpan3 = new RelativeSizeSpan(1.6f);
    RelativeSizeSpan sizeSpan4 = new RelativeSizeSpan(1.8f);

    spannableString.setSpan(sizeSpan1, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan2, 1, 2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan3, 2, 3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan4, 3, 4, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan3, 4, 5, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan2, 5, 6, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan1, 6, 7, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan2, 7, 8, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan3, 8, 9, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan4, 9, 10, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    return spannableString;
}
 
Example 7
Source Project: oversec   Source File: DonationFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setButton(final View v, int buttonId, int textId, final String address) {
    Button b = v.findViewById(buttonId);
    String coin = getString(textId);

    SpannableString spannable = new SpannableString(coin + "\n" + address);
    spannable.setSpan(
            new RelativeSizeSpan(1.5f),
            0, coin.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(
            new RelativeSizeSpan(0.85f),
            coin.length() + 1, spannable.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    b.setText(spannable);

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(getString(R.string.donate_clip_label), address);
            clipboard.setPrimaryClip(clip);
            Toast.makeText(v.getContext(), R.string.donate_toast_copied, Toast.LENGTH_LONG).show();
        }
    });
}
 
Example 8
Source Project: HtmlCompat   Source File: HtmlToSpannedConverter.java    License: 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 9
Source Project: DeviceInfo   Source File: Methods.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * Set string with spannable.
     */
    public static SpannableStringBuilder getSpannablePriceTotalText(Context context, String text, String fontPath, boolean setFontBigger) {

        String[] result = text.split("=");
        String first = result[0];
        String second = result[1];
        first = first.concat("=");

//        Typeface font = Typeface.createFromAsset(context.getAssets(), fontPath);

        SpannableStringBuilder builder = new SpannableStringBuilder();

        SpannableString dkgraySpannable = new SpannableString(first + "");
        builder.append(dkgraySpannable);

        SpannableString blackSpannable = new SpannableString(second);
        if (setFontBigger) {
            blackSpannable.setSpan(new RelativeSizeSpan(1.3f), 0, second.length(), 0); // set size
        }
//        blackSpannable.setSpan(new CustomTypefaceSpan("", font), 0, second.length(), 0); // font weight
        builder.append(blackSpannable);

        return builder;
    }
 
Example 10
public void setHint(@NonNull String hint, @Nullable CharSequence subHint) {
  this.hint = hint;

  if (subHint != null) {
    this.subHint = new SpannableString(subHint);
    this.subHint.setSpan(new RelativeSizeSpan(0.5f), 0, subHint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  } else {
    this.subHint = null;
  }

  if (this.subHint != null) {
    super.setHint(new SpannableStringBuilder().append(ellipsizeToWidth(this.hint))
                                              .append("\n")
                                              .append(ellipsizeToWidth(this.subHint)));
  } else {
    super.setHint(ellipsizeToWidth(this.hint));
  }
}
 
Example 11
private void setBodyText(MessageRecord messageRecord, @Nullable String searchQuery) {
  bodyText.setClickable(false);
  bodyText.setFocusable(false);
  bodyText.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSecurePreferences.getMessageBodyTextSize(context));
  bodyText.setMovementMethod(LongClickMovementMethod.getInstance(getContext()));

  if (messageRecord.isRemoteDelete()) {
    String deletedMessage = context.getString(R.string.ConversationItem_this_message_was_deleted);
    SpannableString italics = new SpannableString(deletedMessage);
    italics.setSpan(new RelativeSizeSpan(0.9f), 0, deletedMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    italics.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, deletedMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    bodyText.setText(italics);
  } else if (isCaptionlessMms(messageRecord)) {
    bodyText.setVisibility(View.GONE);
  } else {
    Spannable styledText = linkifyMessageBody(messageRecord.getDisplayBody(getContext()), batchSelected.isEmpty());
    styledText = SearchUtil.getHighlightedSpan(locale, () -> new BackgroundColorSpan(Color.YELLOW), styledText, searchQuery);
    styledText = SearchUtil.getHighlightedSpan(locale, () -> new ForegroundColorSpan(Color.BLACK), styledText, searchQuery);

    if (hasExtraText(messageRecord)) {
      bodyText.setOverflowText(getLongMessageSpan(messageRecord));
    } else {
      bodyText.setOverflowText(null);
    }

    bodyText.setText(styledText);
    bodyText.setVisibility(View.VISIBLE);
  }
}
 
Example 12
protected SpannableString emphasisAdded(String sequence) {
  SpannableString spannable = new SpannableString(sequence);
  spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return spannable;
}
 
Example 13
Source Project: arcusandroid   Source File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
public static SpannableString appendSmallTextToHint(@NonNull String original, String append) {
    String span = original + " " + append;
    SpannableString ss = new SpannableString(span);
    ss.setSpan(new RelativeSizeSpan(0.5f), original.length() + 1, span.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return ss;
}
 
Example 14
Source Project: arcusandroid   Source File: StringUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * helper method to get a superscripted string
 * @param normal string displayed in its normal position
 * @param sup string displayed on the top right
 * @return a SpannableString accepted by a textview
 */
public static SpannableString getSuperscriptSpan(@NonNull final String normal, @NonNull final String sup){
    SpannableStringBuilder cs = new SpannableStringBuilder(normal + sup);
    cs.setSpan(new SuperscriptSpan(), normal.length(), normal.length() + sup.length(), 0);
    cs.setSpan(new RelativeSizeSpan(0.5f), normal.length(), normal.length() + sup.length(), 0);
    return SpannableString.valueOf(cs);
}
 
Example 15
Source Project: arcusandroid   Source File: StringUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SpannableString getSuperscriptSpan(@NonNull final String normal, @NonNull final String sup, final int superScriptColor) {
    SpannableStringBuilder cs = new SpannableStringBuilder(normal + sup);
    cs.setSpan(new SuperscriptSpan(), normal.length(), normal.length() + sup.length(), 0);
    cs.setSpan(new RelativeSizeSpan(0.5f), normal.length(), normal.length() + sup.length(), 0);
    cs.setSpan(new ForegroundColorSpan(superScriptColor), normal.length(), normal.length() + sup.length(), 0);
    return SpannableString.valueOf(cs);
}
 
Example 16
Source Project: arcusandroid   Source File: StringUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * helper method to get prefix superscripted
 * @param sup string displayed on the top left
 * @param normal string displayed in its normal position
 * @return a SpannableString accepted by a textview
 */
public static SpannableString getPrefixSuperscriptSpan(@NonNull final String sup, @NonNull final String normal){
    SpannableStringBuilder cs = new SpannableStringBuilder(sup + normal);
    cs.setSpan(new SuperscriptSpan(), 0, sup.length(), 0);
    cs.setSpan(new RelativeSizeSpan(0.5f), 0, sup.length(), 0);
    return SpannableString.valueOf(cs);
}
 
Example 17
Source Project: bcm-android   Source File: MessageRecord.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected SpannableString emphasisAdded(String sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannable;
}
 
Example 18
Source Project: Stringlate   Source File: FontPreferenceCompat.java    License: MIT License 5 votes vote down vote up
private void loadFonts(Context context, @Nullable AttributeSet attrs) {
    _defaultValue = _fontValues[0];
    if (attrs != null) {
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            String attrName = attrs.getAttributeName(i);
            String attrValue = attrs.getAttributeValue(i);
            if (attrName.equalsIgnoreCase("defaultValue")) {
                if (attrValue.startsWith("@")) {
                    int resId = Integer.valueOf(attrValue.substring(1));
                    attrValue = getContext().getString(resId);
                }
                _defaultValue = attrValue;
                break;
            }
        }
    }

    Spannable[] fontText = new Spannable[_fontNames.length];
    for (int i = 0; i < _fontNames.length; i++) {
        fontText[i] = new SpannableString(_fontNames[i] + "\n" + _fontValues[i]);
        fontText[i].setSpan(new TypefaceSpan(_fontValues[i]), 0, _fontNames[i].length(), 0);
        fontText[i].setSpan(new RelativeSizeSpan(0.7f), _fontNames[i].length() + 1, fontText[i].length(), 0);

    }
    setDefaultValue(_defaultValue);
    setEntries(fontText);
    setEntryValues(_fontValues);
}
 
Example 19
Source Project: android_9.0.0_r45   Source File: Html.java    License: Apache License 2.0 5 votes vote down vote up
private static void endHeading(Editable text) {
    // RelativeSizeSpan and StyleSpan are CharacterStyles
    // Their ranges should not include the newlines at the end
    Heading h = getLast(text, Heading.class);
    if (h != null) {
        setSpanFromMark(text, h, new RelativeSizeSpan(HEADING_SIZES[h.mLevel]),
                new StyleSpan(Typeface.BOLD));
    }

    endBlockElement(text);
}
 
Example 20
Source Project: user-interface-samples   Source File: MarkdownBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void buildQuoteSpans(@NonNull Element element, SpannableStringBuilder builder) {
    int startIndex = builder.length();
    builder.append(element.getText());
    // You can set multiple spans for the same text
    builder.setSpan(new StyleSpan(Typeface.ITALIC), startIndex, builder.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new LeadingMarginSpan.Standard(40), startIndex, builder.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new RelativeSizeSpan(1.1f), startIndex, builder.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 21
Source Project: openlauncher   Source File: SearchBar.java    License: Apache License 2.0 5 votes vote down vote up
public void updateClock() {
    AppSettings appSettings = AppSettings.get();
    if (_searchClock != null) {
        _searchClock.setTextColor(appSettings.getDesktopDateTextColor());
    }

    ZonedDateTime now = ZonedDateTime.now();
    _clockFormatter = getSearchBarClockFormat(Setup.appSettings().getDesktopDateMode());

    String text = now.format(_clockFormatter);
    String[] lines = text.split("\n");
    Spannable span = new SpannableString(text);
    span.setSpan(new RelativeSizeSpan(_searchClockSubTextFactor), lines[0].length() + 1, lines[0].length() + 1 + lines[1].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    _searchClock.setText(span);
}
 
Example 22
Source Project: memorize   Source File: PieChartItem.java    License: MIT License 5 votes vote down vote up
private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("Memorize\ncreated by\nTurtuvshin");
    s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
    s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
    s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
    return s;
}
 
Example 23
public void applyRelativeSpan(float proportion){
    int selStart=getSelectionStart();
    int selEnd=getSelectionEnd();
    if(selEnd-selStart>0){
        RelativeSizeSpan[] ss = getEditableText().getSpans(selStart, selEnd, RelativeSizeSpan.class);
        for (RelativeSizeSpan span:ss) {
            removeSpan(span, selStart, selEnd);
        }
        setSpan(new RelativeSizeSpan(proportion),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 24
Source Project: ratebeer   Source File: BeerRatingsAdapter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
	BeerRating rating = ratings.get(position);
	Images.with(holder.avatarImage.getContext()).loadUser(rating.userName).placeholder(android.R.color.white).fit().centerCrop()
			.into(holder.avatarImage);
	if (rating.timeEntered == null) {
		// Directly show comments
		holder.ratingCommentsText.setText(asHtml(rating.comments));
	} else {
		// Show comments and (in grey) the rating date
		Context context = holder.ratingCommentsText.getContext();
		String timeEnteredText = DateUtils.formatDateTime(context, rating.timeEntered.getTime(),
				DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE);
		SpannableStringBuilder commentsMarkup = new SpannableStringBuilder(asHtml(rating.comments));
		commentsMarkup.append(" ");
		commentsMarkup.append(timeEnteredText);
		commentsMarkup.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.grey_light)),
				commentsMarkup.length() - timeEnteredText.length(), commentsMarkup.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		commentsMarkup.setSpan(new RelativeSizeSpan(0.8F), commentsMarkup.length() - timeEnteredText.length(), commentsMarkup.length(),
				Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		holder.ratingCommentsText.setText(commentsMarkup);
	}
	holder.ratingMarkText.setBackgroundResource(ImageUrls.getColor(position, true));
	holder.userNameText.setText(rating.userName);
	holder.userCountText.setText(String.format(Locale.getDefault(), "%1$d", rating.userRateCount));
	if (rating.timeEntered == null) {
		holder.offlineBadge.setVisibility(View.VISIBLE);
		holder.userCountryText.setVisibility(View.GONE);
		holder.ratingMarkText.setText("-");
	} else {
		holder.offlineBadge.setVisibility(View.GONE);
		holder.userCountryText.setVisibility(View.VISIBLE);
		holder.userCountryText.setText(rating.userCountryName);
		holder.ratingMarkText.setText(String.format(Locale.getDefault(), "%1$.1f", rating.total));
	}
}
 
Example 25
Source Project: styT   Source File: SpanUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SpannableString getSuperscriptSpan() {
    SpannableString spannableString = new SpannableString("刚在北京望京买了套1202m的房子");
    SuperscriptSpan superscriptSpan = new SuperscriptSpan();
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f);
    spannableString.setSpan(superscriptSpan, 12, 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan, 12, 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}
 
Example 26
Source Project: styT   Source File: SpanUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SpannableString getSubscriptSpan() {
    SpannableString spannableString = new SpannableString("水分子化学式为H20");
    SubscriptSpan subscriptSpan = new SubscriptSpan();
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f);
    spannableString.setSpan(subscriptSpan, 8, 9, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan, 8, 9, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}
 
Example 27
Source Project: DoubleDatePicker   Source File: DoubleDateSelectDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 格式化显示的数据,必须返回SpannableString对象
 *
 * @param priFix  前缀
 * @param content 内容
 * @return 返回格式化的数据
 */
private SpannableString makeFormatContent(String priFix, String content) {
    SpannableString spannableString = new SpannableString(priFix + content);
    spannableString.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.black33)),
            priFix.length(), spannableString.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    spannableString.setSpan(new RelativeSizeSpan(1.33f),
            priFix.length(), spannableString.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    return spannableString;
}
 
Example 28
Source Project: graphhopper-navigation-android   Source File: TimeFormatter.java    License: MIT License 5 votes vote down vote up
private static void formatHours(Context context, long hours, List<SpanItem> textSpanItems) {
  if (hours != 0) {
    String hourString = String.format(TIME_STRING_FORMAT, context.getString(R.string.hr));
    textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(hours)));
    textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), hourString));
  }
}
 
Example 29
Source Project: graphhopper-navigation-android   Source File: TimeFormatter.java    License: MIT License 5 votes vote down vote up
private static void formatNoData(Context context, long days, long hours, long minutes,
                                 List<SpanItem> textSpanItems) {
  if (days == 0 && hours == 0 && minutes == 0) {
    String minuteString = String.format(TIME_STRING_FORMAT, context.getString(R.string.min));
    textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(1)));
    textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), minuteString));
  }
}
 
Example 30
Source Project: graphhopper-navigation-android   Source File: DistanceFormatter.java    License: MIT License 5 votes vote down vote up
/**
 * Takes in a distance and units and returns a formatted SpannableString where the number is bold
 * and the unit is shrunked to .65 times the size
 *
 * @param distance formatted with appropriate decimal places
 * @param unit     string from TurfConstants. This will be converted to the abbreviated form.
 * @return String with bolded distance and shrunken units
 */
private SpannableString getDistanceString(String distance, String unit) {
  SpannableString spannableString = new SpannableString(String.format("%s %s", distance, unitStrings.get(unit)));

  spannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, distance.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  spannableString.setSpan(new RelativeSizeSpan(0.65f), distance.length() + 1,
    spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

  return spannableString;
}