android.text.style.RelativeSizeSpan Java Examples

The following examples show how to use android.text.style.RelativeSizeSpan. 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: DonationFragment.java    From oversec with 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 #2
Source File: ComposeText.java    From mollyim-android with 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 File: ComposeText.java    From deltachat-android with 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 #4
Source File: Methods.java    From DeviceInfo with 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 #5
Source File: PassphrasePromptActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
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 #6
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 #7
Source File: Html.java    From MHViewer with 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 #8
Source File: SearchResultsActivity.java    From iqra-android with 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 #9
Source File: MyHtmlTagHandler.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
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 #10
Source File: SpanUtils.java    From styT with 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 #11
Source File: Html.java    From ForPDA with GNU General Public License v3.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 #12
Source File: SharedPrefItemModel.java    From SharedPrefManager with Apache License 2.0 5 votes vote down vote up
SharedPrefItemModel(@NonNull String key, @NonNull Object value, @ColorInt int keyColor) {
    this.mKey = key;
    this.mValue = value;

    String valueString = mValue.toString();

    if (mValue instanceof String) {
        // check if there is a better way  to do this
        try {
            valueString = new JSONObject(valueString).toString(4);
        } catch (JSONException ex) {
            try {
                valueString = new JSONArray(valueString).toString(4);
            } catch (JSONException ex1) {

            }
        }
    }

    SpannableString textToDisplay = new SpannableString(key + " \n\n " + valueString);

    textToDisplay.setSpan(new ForegroundColorSpan(keyColor), 0, mKey.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textToDisplay.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, mKey.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textToDisplay.setSpan(new RelativeSizeSpan(1.5f), 0, mKey.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    mDisplayText = textToDisplay;
}
 
Example #13
Source File: Spans.java    From spanner with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.text.style.RelativeSizeSpan#RelativeSizeSpan(float)
 */
public static Span scaleSize(@FloatRange(from = 0.0) final float proportion) {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new RelativeSizeSpan(proportion);
        }
    });
}
 
Example #14
Source File: CountFragment.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 生成图标中心文字的 SpannableString
 *
 * @return SpannableString
 */
private SpannableString generateCenterSpannableText(String money, String descText) {
    SpannableString s = new SpannableString(UiUtils.getString(R.string.rmb)
            .concat(money).concat("\n").concat(descText));
    s.setSpan(new RelativeSizeSpan(1.7f), 0, s.length() - descText.length(), 0);
    s.setSpan(new StyleSpan(Typeface.BOLD), 0, s.length() - descText.length(), 0);
    s.setSpan(new ForegroundColorSpan(UiUtils.getColor(R.color.textRed))
            , 0, s.length() - descText.length(), 0);
    s.setSpan(new RelativeSizeSpan(.9f), s.length() - descText.length(), s.length(), 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - descText.length(), s.length(), 0);
    s.setSpan(new ForegroundColorSpan(UiUtils.getColor(R.color.textGrayish))
            , s.length() - descText.length(), s.length(), 0);
    return s;
}
 
Example #15
Source File: MainActivity.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
private void chartViewAdjusted() {
    chartChangeTimestamp = System.currentTimeMillis();

    long end = timeLastSGV == 0 ? chartChangeTimestamp - chartTimeOffset : timeLastSGV - chartTimeOffset;
    long start = end - chartZoom * 60 * 60000L;

    String t = String.format(getString(R.string.main_screen__value_hour_chart), chartZoom);

    String m = String.format("\n%s %s",
            FormatKit.getInstance().formatAsMonthName(start),
            FormatKit.getInstance().formatAsDay(start)
    );

    String d = String.format("\n%s - %s",
            FormatKit.getInstance().formatAsDayClock(start),
            FormatKit.getInstance().formatAsDayClock(end)
    );

    SpannableStringBuilder ssb = new SpannableStringBuilder();
    ssb.append(t);
    ssb.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), ssb.length() - t.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new StyleSpan(Typeface.BOLD), ssb.length() - t.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ssb.append(m);
    ssb.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), ssb.length() - m.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new RelativeSizeSpan(0.75f), ssb.length() - m.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ssb.append(d);
    ssb.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), ssb.length() - d.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new RelativeSizeSpan(0.85f), ssb.length() - d.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    toast = serveToast(ssb, toast, findViewById(R.id.view_sgv));

    refreshDisplayChart();
}
 
Example #16
Source File: StringStyleUtil.java    From gank with GNU General Public License v3.0 5 votes vote down vote up
public static SpannableString getGankStyleStr(Gank gank){
    String gankStr = gank.desc + " @" + gank.who;
    SpannableString spannableString = new SpannableString(gankStr);
    spannableString.setSpan(new RelativeSizeSpan(0.8f),gank.desc.length()+1,gankStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new ForegroundColorSpan(Color.GRAY),gank.desc.length()+1,gankStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}
 
Example #17
Source File: AudioBookAdapter.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private SpannableStringBuilder getBookName(String name, int newChapters) {
    SpannableStringBuilder sbs = new SpannableStringBuilder(name);
    if (newChapters == 0) {
        return sbs;
    }
    SpannableString chaptersSpan = new SpannableString(String.format(Locale.getDefault(), "(新增%d章)", newChapters));
    chaptersSpan.setSpan(new RelativeSizeSpan(0.75f), 0, chaptersSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    chaptersSpan.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorTextSecondary)), 0, chaptersSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    sbs.append(chaptersSpan);
    return sbs;
}
 
Example #18
Source File: BookShelfListAdapter.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private SpannableStringBuilder getBookName(String name, int newChapters) {
    SpannableStringBuilder sbs = new SpannableStringBuilder(name);
    if (newChapters == 0) {
        return sbs;
    }
    SpannableString chaptersSpan = new SpannableString(String.format(Locale.getDefault(), "(新增%d章)", newChapters));
    chaptersSpan.setSpan(new RelativeSizeSpan(0.75f), 0, chaptersSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    chaptersSpan.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorTextSecondary)), 0, chaptersSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    sbs.append(chaptersSpan);
    return sbs;
}
 
Example #19
Source File: HtmlToSpannedConverter.java    From HtmlCompat with Apache License 2.0 5 votes vote down vote up
private void endHeading(String tag, 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(tag, text, h, new RelativeSizeSpan(HEADING_SIZES[h.mLevel]),
                new StyleSpan(Typeface.BOLD));
    }
    endBlockElement(tag, text);
}
 
Example #20
Source File: CustomDialog.java    From Wifi-Connect with Apache License 2.0 5 votes vote down vote up
public static SpannableString getSpannedText(Context context, float textSize, String text) {
    SpannableString spannableString = new SpannableString(text);
    if(text.indexOf("\n") != -1) {
        spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.activity_login_edittext_txt)),
                text.indexOf("\n"), text.length(), 0);
        spannableString.setSpan(new RelativeSizeSpan(textSize), text.indexOf("\n"), text.length(), 0);
    }

    return spannableString;
}
 
Example #21
Source File: MainActivity.java    From iqra-android with MIT License 5 votes vote down vote up
private void callApi(String arabicText) {
    lockScreenOrientation();

    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(context);
    requestDelegate.performSearchQuery(arabicText, prefs.getString("translation", "en-hilali"), new NetworkRequestCallback() {
        @Override
        public void onSuccess(JSONObject response) {
            progress.dismiss();
            Log.v(TAG, response.toString());
            parseSearchQueryResponse(response);
        }

        @Override
        public void onFailure(Throwable error) {
            progress.dismiss();
            onSearchQueryError(error);
        }
    });
}
 
Example #22
Source File: PieChartItem.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
    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
Source File: HalfPieChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
 
Example #24
Source File: ConversationItem.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 #25
Source File: CurrenciesUtil.java    From px-android with MIT License 5 votes vote down vote up
private static void symbolUp(@NonNull final Currency currency, final String localizedAmount,
    final Spannable spannableAmount) {
    final int fromSymbolPosition = localizedAmount.indexOf(currency.getSymbol());
    final int toSymbolPosition = fromSymbolPosition + currency.getSymbol().length();
    spannableAmount.setSpan(new RelativeSizeSpan(0.5f), fromSymbolPosition, toSymbolPosition,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableAmount.setSpan(new SuperscriptSpanAdjuster(0.65f), fromSymbolPosition, toSymbolPosition,
        SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example #26
Source File: PiePolylineChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
 
Example #27
Source File: DistanceFormatter.java    From graphhopper-navigation-android with 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;
}
 
Example #28
Source File: TimeFormatter.java    From graphhopper-navigation-android with 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 #29
Source File: TimeFormatter.java    From graphhopper-navigation-android with 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 #30
Source File: LogbookActivity.java    From homeassist with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final LogbookViewHolder viewHolder, final int position) {
    final LogSheet logSheet = items.get(position);
    Log.d("YouQi", "rendering: " + position + "logSheet.message: " + logSheet.message);
    //viewHolder.mNameView.setText(logSheet.name);
    viewHolder.mStateText.setText(TextUtils.concat(dateFormat.format(logSheet.when.getTime()), "\n", CommonUtil.getSpanText(LogbookActivity.this, DateUtils.getRelativeTimeSpanString(logSheet.when.getTime()).toString(), null, 0.9f)));
    viewHolder.mIconView.setText(MDIFont.getIcon("mdi:information-outline"));

    Entity entity = getEntity(logSheet.entityId);
    if (entity != null) {
        viewHolder.mIconView.setText(entity.getMdiIcon());
    }


    Spannable wordtoSpan1 = new SpannableString(logSheet.name);
    wordtoSpan1.setSpan(new RelativeSizeSpan(1.0f), 0, wordtoSpan1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan1.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, wordtoSpan1.length(), 0);

    Spannable wordtoSpan2 = new SpannableString(logSheet.message);
    wordtoSpan2.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.md_grey_500, null)), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan2.setSpan(new RelativeSizeSpan(0.95f), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    //viewHolder.mNameView.setText(TextUtils.concat(wordtoSpan1, " ", wordtoSpan2));
    viewHolder.mNameView.setText(logSheet.name);
    viewHolder.mSubText.setText(logSheet.message);

}