Java Code Examples for android.text.style.RelativeSizeSpan

The following are top voted examples for showing how to use android.text.style.RelativeSizeSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Cable-Android   File: PassphrasePromptActivity.java   Source Code and License 7 votes vote down vote up
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);

  showButton       = (ImageButton)     findViewById(R.id.passphrase_visibility);
  hideButton       = (ImageButton)     findViewById(R.id.passphrase_visibility_off);
  visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
  passphraseText   = (EditText)        findViewById(R.id.passphrase_edit);
  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"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  showButton.setOnClickListener(new ShowButtonOnClickListener());
  hideButton.setOnClickListener(new HideButtonOnClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
 
Example 2
Project: GoSCELE   File: ScheduleDailyProvider.java   Source Code and License 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    ScheduleDailyGroupModel model = list.get(position);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_schedule_daily_widget);

    remoteViews.setTextViewText(R.id.title_schedule_daily, model.day);

    CharSequence builder = null;
    for (ScheduleDailyModel e : model.scheduleDailyModels()) {
        String course = e.desc.substring(0, e.desc.indexOf(" Ruang: "));
        String room = e.desc.substring(e.desc.indexOf(" Ruang: ") + 8);
        SpannableString title = new SpannableString(course);
        title.setSpan(new RelativeSizeSpan(1.2f), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        SpannableString time = new SpannableString("R. " + room + "\t\t" + e.time);
        time.setSpan(new ForegroundColorSpan(context.getResources().getColor(android.R.color.darker_gray)), 0, time.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (builder == null) {
            builder = TextUtils.concat(title, "\n", time + "\n\n");
        } else {
            builder = TextUtils.concat(builder, title, "\n", time + "\n\n");
        }
    }
    remoteViews.setTextViewText(R.id.content_schedule_daily, builder == null ? "(empty)\n\n" : builder);

    return remoteViews;
}
 
Example 3
Project: PeSanKita-android   File: PassphrasePromptActivity.java   Source Code and License 6 votes vote down vote up
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);

  showButton       = (ImageButton)     findViewById(R.id.passphrase_visibility);
  hideButton       = (ImageButton)     findViewById(R.id.passphrase_visibility_off);
  visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
  passphraseText   = (EditText)        findViewById(R.id.passphrase_edit);
  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"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  showButton.setOnClickListener(new ShowButtonOnClickListener());
  hideButton.setOnClickListener(new HideButtonOnClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
 
Example 4
Project: PeSanKita-android   File: ComposeText.java   Source Code and License 6 votes vote down vote up
public void setHint(@NonNull String hint, @Nullable CharSequence subHint) {
  this.hint = new SpannableString(hint);
  this.hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

  if (subHint != null) {
    this.subHint = new SpannableString(subHint);
    this.subHint.setSpan(new RelativeSizeSpan(0.8f), 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 5
Project: Watermark   File: BucketAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void onBindViewHolder(BucketViewHolder holder, int position) {
    BucketBean bucketBean = mBucketList.get(position);
    String bucketName = bucketBean.getBucketName();
    if (position != 0) {
        SpannableString nameSpannable = new SpannableString(bucketName + "\n" + bucketBean.getImageCount() + "张");
        nameSpannable.setSpan(new ForegroundColorSpan(Color.GRAY), bucketName.length(), nameSpannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        nameSpannable.setSpan(new RelativeSizeSpan(0.8f), bucketName.length(), nameSpannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.mTvBucketName.setText(nameSpannable);
    } else {
        holder.mTvBucketName.setText(bucketName);
    }
    if (mSelectedBucket != null && TextUtils.equals(mSelectedBucket.getBucketId(), bucketBean.getBucketId())) {
        holder.mRbSelected.setVisibility(View.VISIBLE);
        holder.mRbSelected.setChecked(true);
    } else {
        holder.mRbSelected.setVisibility(View.GONE);
    }

    String path = bucketBean.getCover();
    mConfiguration.getImageLoader()
            .displayImage(holder.itemView.getContext(), path, holder.mIvBucketCover, mDefaultImage, mConfiguration.getImageConfig(),
                    true, mConfiguration.isPlayGif(), 100, 100, bucketBean.getOrientation());
}
 
Example 6
Project: DailyStudy   File: SpannableStringActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    switch (msg.what) {
        case 0x001:
            SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
            RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
            string.setSpan(sizeSpan, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            bgtext.setText(string);
            pos++;
            if (pos >= bgtext.getText().length()) {
                pos = 0;
            }
            Message ms = Message.obtain();
            ms.what = 0x001;
            handler.sendEmptyMessageDelayed(0x001, 150);
            break;
    }
}
 
Example 7
Project: ShangHanLun   File: ShowFragment.java   Source Code and License 6 votes vote down vote up
public SpannableStringBuilder spannerbleTitleForHeaderInSection(
        ATableView tableView, int section) {
    HH2SectionData sd = data.get(section);
    String text = sd.getHeader();
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    builder.setSpan(new ForegroundColorSpan(Color.BLUE), 0,
            text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (text.contains("$")) {
        int index = text.indexOf("$") + 1;
        builder.setSpan(new ForegroundColorSpan(Color.RED), index,
                text.length(),
                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new RelativeSizeSpan(0.55f), index,
                text.length(),
                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.replace(index - 1, index, "\n");
    }

    return builder;
}
 
Example 8
Project: HtmlCompat   File: HtmlToSpannedConverter.java   Source Code and License 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
Project: Cable-Android   File: ComposeText.java   Source Code and License 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 10
Project: DeviceInfo   File: Methods.java   Source Code and License 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 11
Project: android_packages_apps_tv   File: CaptionWindowLayout.java   Source Code and License 6 votes vote down vote up
public void setPenAttr(CaptionPenAttr penAttr) {
    mCharacterStyles.clear();
    if (penAttr.italic) {
        mCharacterStyles.add(new StyleSpan(Typeface.ITALIC));
    }
    if (penAttr.underline) {
        mCharacterStyles.add(new UnderlineSpan());
    }
    switch (penAttr.penSize) {
        case CaptionPenAttr.PEN_SIZE_SMALL:
            mCharacterStyles.add(new RelativeSizeSpan(PROPORTION_PEN_SIZE_SMALL));
            break;
        case CaptionPenAttr.PEN_SIZE_LARGE:
            mCharacterStyles.add(new RelativeSizeSpan(PROPORTION_PEN_SIZE_LARGE));
            break;
    }
    switch (penAttr.penOffset) {
        case CaptionPenAttr.OFFSET_SUBSCRIPT:
            mCharacterStyles.add(new SubscriptSpan());
            break;
        case CaptionPenAttr.OFFSET_SUPERSCRIPT:
            mCharacterStyles.add(new SuperscriptSpan());
            break;
    }
}
 
Example 12
Project: memoir   File: ConverterHtmlToSpanned.java   Source Code and License 6 votes vote down vote up
private void endHeader() {
    int len = mResult.length();
    Object obj = getLast(Header.class);

    int where = mResult.getSpanStart(obj);

    mResult.removeSpan(obj);

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

    if (where != len) {
        Header h = (Header) obj;
        mResult.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mResult.setSpan(new BoldSpan(), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 13
Project: memoir   File: ConverterHtmlToSpanned.java   Source Code and License 6 votes vote down vote up
private void endHeader() {
    int len = mResult.length();
    Object obj = getLast(Header.class);

    int where = mResult.getSpanStart(obj);

    mResult.removeSpan(obj);

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

    if (where != len) {
        Header h = (Header) obj;
        mResult.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mResult.setSpan(new BoldSpan(), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 14
Project: TextSecure   File: PassphrasePromptActivity.java   Source Code and License 6 votes vote down vote up
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
  mitigateAndroidTilingBug();

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));

  hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new ForegroundColorSpan(0x66000000), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
 
Example 15
Project: iqra-android   File: SearchResultsActivity.java   Source Code and 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 16
Project: nono-android   File: MyHtmlTagHandler.java   Source Code and License 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 17
Project: chaincloud-v   File: BitcoinUtil.java   Source Code and License 6 votes vote down vote up
public static void formatSignificant(final Editable s, final RelativeSizeSpan
        insignificantRelativeSizeSpan) {
    s.removeSpan(SIGNIFICANT_SPAN);
    if (insignificantRelativeSizeSpan != null) {
        s.removeSpan(insignificantRelativeSizeSpan);
    }

    final Matcher m = P_SIGNIFICANT.matcher(s);
    if (m.find()) {
        final int pivot = m.group().length();
        s.setSpan(SIGNIFICANT_SPAN, 0, pivot, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (s.length() > pivot && insignificantRelativeSizeSpan != null) {
            s.setSpan(insignificantRelativeSizeSpan, pivot, s.length(), Spannable
                    .SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
Example 18
Project: lbry-android   File: WalletUtils.java   Source Code and License 6 votes vote down vote up
public static void formatSignificant(@Nonnull final Spannable spannable, @Nullable final RelativeSizeSpan insignificantRelativeSizeSpan)
{
    spannable.removeSpan(SIGNIFICANT_SPAN);
    if (insignificantRelativeSizeSpan != null)
        spannable.removeSpan(insignificantRelativeSizeSpan);

    final Matcher m = P_SIGNIFICANT.matcher(spannable);
    if (m.find())
    {
        final int pivot = m.group().length();
        if (pivot > 0)
            spannable.setSpan(SIGNIFICANT_SPAN, 0, pivot, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (spannable.length() > pivot && insignificantRelativeSizeSpan != null)
            spannable.setSpan(insignificantRelativeSizeSpan, pivot, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 19
Project: smoothnovelreader   File: ChangeLogUtils.java   Source Code and License 6 votes vote down vote up
public CharSequence toSpannable() {
    LinkedList<ChangeLogRow> rows = mChangeLog.getRows();
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    boolean isFirstRow = true;
    for (ChangeLogRow row : rows) {
        if(row.isHeader()) {
            if(!isFirstRow)
                stringBuilder.append("\n");
            int versionStart = stringBuilder.length();
            int versionEnd = versionStart + row.getVersionName().length();
            stringBuilder.append(row.getVersionName());
            stringBuilder.setSpan(new StyleSpan(Typeface.BOLD), versionStart, versionEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            stringBuilder.setSpan(new RelativeSizeSpan(1.5f), versionStart, versionEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            isFirstRow = false;
        } else {
            CharSequence displayChange = Html.fromHtml(row.getChangeText());
            int changeStart = stringBuilder.length();
            int changeEnd = changeStart + displayChange.length();
            stringBuilder.append("    \u2022  ").append(displayChange);
            //stringBuilder.setSpan(new BulletSpan(15), changeStart, changeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            //stringBuilder.append("\n");
        }
        stringBuilder.append("\n");
    }
    return stringBuilder;
}
 
Example 20
Project: RichEditText   File: HtmlToSpannedConverter.java   Source Code and License 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;
        if (h == null) {
            Log.e("endHeader", "h = null");
            return;
        }
        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 21
Project: AyoSunny   File: HtmlTagHandler.java   Source Code and License 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 22
Project: Doctor   File: ConverterHtmlToSpanned.java   Source Code and License 6 votes vote down vote up
private void endHeader() {
    int len = mResult.length();
    Object obj = getLast(Header.class);

    int where = mResult.getSpanStart(obj);

    mResult.removeSpan(obj);

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

    if (where != len) {
        Header h = (Header) obj;
        mResult.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mResult.setSpan(new BoldSpan(), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 23
Project: GitHub   File: PiePolylineChartActivity.java   Source Code and 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 24
Project: GitHub   File: HalfPieChartActivity.java   Source Code and 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 25
Project: GitHub   File: RealmDatabaseActivityPie.java   Source Code and License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("Realm.io\nmobile database");
        s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
        s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
        s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
        return s;
    }
 
Example 26
Project: GitHub   File: PieChartItem.java   Source Code and 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 27
Project: GitHub   File: PieChartActivity.java   Source Code and 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 28
Project: GitHub   File: Utils.java   Source Code and License 5 votes vote down vote up
public static void setSpannableStr(TextView textView, String str, int startIndex, int endIndex, float proporation) {
    SpannableString spannableString = new SpannableString(str);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#393939"));
    spannableString.setSpan(colorSpan, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    RelativeSizeSpan sizeSpan01 = new RelativeSizeSpan(proporation);
    spannableString.setSpan(sizeSpan01, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    textView.setText(spannableString);
}
 
Example 29
Project: mapbox-navigation-android   File: TimeUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableStringBuilder formatTimeRemaining(double routeDuration) {
  long seconds = (long) routeDuration;

  if (seconds < 0) {
    throw new IllegalArgumentException("Duration must be greater than zero.");
  }

  long days = TimeUnit.SECONDS.toDays(seconds);
  seconds -= TimeUnit.DAYS.toSeconds(days);
  long hours = TimeUnit.SECONDS.toHours(seconds);
  seconds -= TimeUnit.HOURS.toSeconds(hours);
  long minutes = TimeUnit.SECONDS.toMinutes(seconds);
  seconds -= TimeUnit.MINUTES.toSeconds(minutes);

  if (seconds >= 30) {
    minutes = minutes + 1;
  }

  List<SpanItem> spanItems = new ArrayList<>();
  if (days != 0) {
    String dayFormat = days > 1 ? DAYS : DAY;
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(days)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), dayFormat));
  }
  if (hours != 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(hours)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), HOUR));
  }
  if (minutes != 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(minutes)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
  }
  if (days == 0 && hours == 0 && minutes == 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(1)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
  }

  return SpanUtils.combineSpans(spanItems);
}
 
Example 30
Project: PeSanKita-android   File: MessageRecord.java   Source Code and License 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 31
Project: markor   File: Highlighter.java   Source Code and License 5 votes vote down vote up
protected void clearSpans(Editable editable) {
    clearCharacterSpanType(editable, TextAppearanceSpan.class);
    clearCharacterSpanType(editable, ForegroundColorSpan.class);
    clearCharacterSpanType(editable, BackgroundColorSpan.class);
    clearCharacterSpanType(editable, StrikethroughSpan.class);
    clearCharacterSpanType(editable, RelativeSizeSpan.class);
    clearCharacterSpanType(editable, StyleSpan.class);
    clearCharacterSpanType(editable, ColorUnderlineSpan.class);
    clearParagraphSpanType(editable, LineBackgroundSpan.class);
    clearParagraphSpanType(editable, LineHeightSpan.class);
}
 
Example 32
Project: SpanEZ   File: SpanEZTest.java   Source Code and License 5 votes vote down vote up
@Test
public void relative_size_should_add_only_one_span() {
    spanBuilder.relativeSize(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(RelativeSizeSpan.class));
}
 
Example 33
Project: MyBP   File: Span.java   Source Code and License 5 votes vote down vote up
public static void span(String text, String subText, Switch switchView) {
    SpannableString spanText = new SpannableString(text);
    spanText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, text.length(), 0);
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);

    SpannableString spanSubText = new SpannableString(subText);
    spanSubText.setSpan(new RelativeSizeSpan(0.75f), 0, subText.length(), 0);
    spanSubText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, subText.length(), 0);
    switchView.setText("");
    switchView.append(spanText);
    switchView.append("\n");
    switchView.append(spanSubText);
}
 
Example 34
Project: MyBP   File: Span.java   Source Code and License 5 votes vote down vote up
public static void span(String text, String subText, TextView textView) {
    SpannableString spanText = new SpannableString(text);
    spanText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, text.length(), 0);
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);

    SpannableString spanSubText = new SpannableString(subText);
    spanSubText.setSpan(new RelativeSizeSpan(0.75f), 0, subText.length(), 0);
    spanSubText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, subText.length(), 0);
    textView.setText("");
    textView.append(spanText);
    textView.append("\n");
    textView.append(spanSubText);
}
 
Example 35
Project: JewelryUI   File: MainActivity.java   Source Code and License 5 votes vote down vote up
private void setSpannableText(String src) {
    //tvName.setText(src);
    String temp = src.replace("\n", " ");
    List<Integer> mList = new ArrayList<>();
    int index = 0;
    int max = 0;
    if (temp.indexOf(" ", index) > 0) {
        while (temp.indexOf(" ", index) > 0 || index >= temp.length() || max < 50) {
            max++;
            index = temp.indexOf(" ", index);
            if (index <0 ) {
                break;
            } else {
                //Log.e(TAG, "空格位置: " + String.valueOf(index));
                mList.add(index);
                index++;
            }
        }
    }
    SpannableString spannable = new SpannableString(src);
    spannable.setSpan(new RelativeSizeSpan(1.5f), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (mList.size() > 0) {
        for (int i = 0; i < mList.size(); i++) {
            int position = mList.get(i) + 1;
            //Log.e(TAG, "变更样式位置: " + String.valueOf(position));
            spannable.setSpan(new RelativeSizeSpan(1.5f), position, position + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    tvName.setText(spannable);
}
 
Example 36
Project: Mix   File: OrderDialogFragment.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("app:spanOffset")
public static void setItemSpan(View v, int spanOffset) {
    final String itemText = ((TextView) v).getText().toString();
    final SpannableString sString = new SpannableString(itemText);

    sString.setSpan(new RelativeSizeSpan(1.65f), itemText.length() - spanOffset, itemText.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ((TextView) v).setText(sString);
}
 
Example 37
Project: amap   File: MIP_TextStyle.java   Source Code and License 5 votes vote down vote up
public MIP_TextStyle setRelativeSize(float size, int start, int end)
{
    if (spannableString == null)
    {
        return this;
    }
    spannableString.setSpan(new RelativeSizeSpan(size), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认字体大小的一半
    return this;
}
 
Example 38
Project: DateRangePickerLibrary   File: SampleDecorator.java   Source Code and License 5 votes vote down vote up
@Override
public void decorate(CalendarCellView cellView, Date date) {
  String dateString = Integer.toString(date.getDate());
  SpannableString string = new SpannableString(dateString + "\ntitle");
  string.setSpan(new RelativeSizeSpan(0.5f), 0, dateString.length(),
      Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
  cellView.getDayOfMonthTextView().setText(string);
}
 
Example 39
Project: From-design-to-Android-part1   File: OrderDialogFragment.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("app:spanOffset")
public static void setItemSpan(View v, int spanOffset) {
    final String itemText = ((TextView) v).getText().toString();
    final SpannableString sString = new SpannableString(itemText);

    sString.setSpan(new RelativeSizeSpan(1.65f), itemText.length() - spanOffset, itemText.length(),
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ((TextView) v).setText(sString);
}
 
Example 40
Project: mvvm-template   File: HeaderHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handleTagNode(TagNode tagNode, SpannableStringBuilder builder, int start, int end) {
    builder.setSpan(new RelativeSizeSpan(this.size), start, end, 33);
    FontFamilySpan originalSpan = this.getFontFamilySpan(builder, start, end);
    FontFamilySpan boldSpan;
    if (originalSpan == null) {
        boldSpan = new FontFamilySpan(getSpanner().getDefaultFont());
    } else {
        boldSpan = new FontFamilySpan(originalSpan.getFontFamily());
        boldSpan.setItalic(originalSpan.isItalic());
    }
    boldSpan.setBold(true);
    builder.setSpan(boldSpan, start, end, 33);
    appendNewLine(builder);
}
 
Example 41
Project: Matrix-Calculator-for-Android   File: FunctionMaker.java   Source Code and License 5 votes vote down vote up
private SpannableStringBuilder ConvertToExponent(String s) { //This Function makes the Normal text into Exponents and base, position being the index of exponent
    int position = s.indexOf("x") + 1;
    SpannableStringBuilder builder = new SpannableStringBuilder(s);
    builder.setSpan(new SuperscriptSpan(), position, position + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new RelativeSizeSpan(0.50f), position, position + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 42
Project: spanner   File: Spans.java   Source Code and License 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 43
Project: DailyStudy   File: SpannableStringActivity.java   Source Code and License 5 votes vote down vote up
/**
 * RelativeSizeSpan,设置文字相对大小,在TextView原有的文字大小的基础上,相对设置文字大小
 */
private void relativeSize () {
    SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
    string.setSpan(sizeSpan, 9, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    bgtext.setText(string);
}
 
Example 44
Project: DailyStudy   File: SpannableStringActivity.java   Source Code and License 5 votes vote down vote up
/**
 * SuperscriptSpan,设置上标
 */
private void superscript () {
    SpannableString string = new SpannableString("为文字设置下划线");
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f);
    string.setSpan(sizeSpan, 5, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    SuperscriptSpan superscriptSpan = new SuperscriptSpan();
    string.setSpan(superscriptSpan, 5, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    bgtext.setText(string);
}
 
Example 45
Project: DailyStudy   File: SpannableStringActivity.java   Source Code and License 5 votes vote down vote up
/**
 * SubscriptSpan,设置下标
 */
private void subscript () {
    SpannableString string = new SpannableString("为文字设置下划线");
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f);
    string.setSpan(sizeSpan, 5, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    SubscriptSpan superscriptSpan = new SubscriptSpan();
    string.setSpan(superscriptSpan, 5, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    bgtext.setText(string);
}
 
Example 46
Project: AndroidCollection   File: WidgetActivity.java   Source Code and License 5 votes vote down vote up
public SpannableString combo(int count) {

        SpannableString spanStr = new SpannableString("X" + String.valueOf(count));
        spanStr.setSpan(new RelativeSizeSpan(1.7f), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanStr.setSpan(new RelativeSizeSpan(3.1f), 1, spanStr.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spanStr;
    }
 
Example 47
Project: PocketGopher   File: TextPage.java   Source Code and License 5 votes vote down vote up
public void render(final TextView textView, Context context, String line)
{

    final SpannableString text = new SpannableString(line + "\n");

    //Change the font size if it's a title (UNTESTED!!!)
    if (this.selector.equals("TITLE"))
    {
        if (textView.getText().toString().matches(""))
        {
            text.setSpan(new RelativeSizeSpan(MAIN_TITLE_SIZE), 0, text.length(), 0);
        }
        else
        {
            text.setSpan(new RelativeSizeSpan(SUB_TITLE_SIZE), 0, text.length(), 0);
        }
    }


    final Handler handler = new Handler(Looper.getMainLooper());

    //display the line
    handler.post(new Runnable()
    {
        @Override
        public void run()
        {
            textView.append(text);
        }
    });
}
 
Example 48
Project: boohee_v5.6   File: TimeLineUtility.java   Source Code and License 5 votes vote down vote up
private static void handleLinksWithShowMore(TextView view, Post post) {
    String showMore = " [详细] ";
    String content = post.body + showMore;
    SpannableString spannable = convertNormalStringToSpannableString(content);
    spannable.setSpan(new RelativeSizeSpan(0.8f), content.length() - showMore.length(),
            content.length(), 17);
    spannable.setSpan(new ShowMoreSpan("showMore"), content.length() - showMore.length(),
            content.length(), 17);
    view.setText(spannable);
    view.setTag(R.id.timeline_post_id, Integer.valueOf(post.id));
}
 
Example 49
Project: HtmlCompat   File: HtmlToSpannedConverter.java   Source Code and License 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 50
Project: Cable-Android   File: MessageRecord.java   Source Code and License 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 51
Project: okwallet   File: CurrencyTextView.java   Source Code and License 5 votes vote down vote up
public void setInsignificantRelativeSize(final float insignificantRelativeSize) {
    if (insignificantRelativeSize != 1) {
        this.prefixRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize);
        this.insignificantRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize);
    } else {
        this.prefixRelativeSizeSpan = null;
        this.insignificantRelativeSizeSpan = null;
    }
}
 
Example 52
Project: Quizca-UI-Concept   File: MainActivity.java   Source Code and License 5 votes vote down vote up
public SpannableString getStatsText()
{
    String text = txtStats.getText().toString();

    SpannableString s = new SpannableString(text);

    s.setSpan(new RelativeSizeSpan(1.3f), 0, text.indexOf("A"), 0);
    s.setSpan(new ForegroundColorSpan(Color.WHITE), 0, text.indexOf("A"),0);

    s.setSpan(new RelativeSizeSpan(1.3f), text.indexOf("1"), text.indexOf("Q"), 0);
    s.setSpan(new ForegroundColorSpan(Color.WHITE), text.indexOf("1"), text.indexOf("Q"), 0);

    return s;
}
 
Example 53
Project: Mobike   File: Utils.java   Source Code and License 5 votes vote down vote up
public static void setSpannableStr(TextView textView, String str, int startIndex, int endIndex, float proporation) {
    SpannableString spannableString = new SpannableString(str);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#393939"));
    spannableString.setSpan(colorSpan, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    RelativeSizeSpan sizeSpan01 = new RelativeSizeSpan(proporation);
    spannableString.setSpan(sizeSpan01, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    textView.setText(spannableString);
}
 
Example 54
Project: TenguChat   File: MessageAdapter.java   Source Code and License 5 votes vote down vote up
private void displayEmojiMessage(final ViewHolder viewHolder, final String body) {
	viewHolder.download_button.setVisibility(View.GONE);
	viewHolder.audioPlayer.setVisibility(View.GONE);
	viewHolder.image.setVisibility(View.GONE);
	viewHolder.messageBody.setVisibility(View.VISIBLE);
	Spannable span = new SpannableString(body);
	float size = Emoticons.isEmoji(body) ? 3.0f : 2.0f;
	span.setSpan(new RelativeSizeSpan(size), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	viewHolder.messageBody.setText(span);
}
 
Example 55
Project: coinblesk-client-gui   File: UIUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableString toLargeSpannable(Context context, String amount, String currency) {
    final int amountLength = amount.length();
    SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency));
    result.setSpan(new RelativeSizeSpan(2), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(Color.WHITE), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), amountLength, result.length(), 0);
    return result;
}
 
Example 56
Project: coinblesk-client-gui   File: UIUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableString toLargeSpannable(Context context, String amount, String currency, float sizeSpan) {
    final int amountLength = amount.length();
    SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency));
    result.setSpan(new RelativeSizeSpan(sizeSpan), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(Color.WHITE), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), amountLength, result.length(), 0);
    return result;
}
 
Example 57
Project: coinblesk-client-gui   File: UIUtils.java   Source Code and License 5 votes vote down vote up
private static SpannableString coinFiatSpannable(Context context, String amountFirst, String codeFirst, String amountSecond, String codeSecond, float secondaryRelativeSize) {
    if (amountFirst == null) amountFirst = "";
    if (codeFirst == null) codeFirst = "";
    if (amountSecond == null) amountSecond = "";
    if (codeSecond == null) codeSecond = "";

    StringBuffer resultBuffer = new StringBuffer();

    resultBuffer.append(amountFirst).append(" ");
    int lenFirstAmount = resultBuffer.length();
    resultBuffer.append(codeFirst);
    int lenFirstCode = resultBuffer.length();

    resultBuffer.append(" ").append(amountSecond).append(" ").append(codeSecond);
    int lenSecond = resultBuffer.length();

    SpannableString formattedString = new SpannableString(resultBuffer);
    formattedString.setSpan(
            new ForegroundColorSpan(Color.WHITE),
            0, lenFirstAmount, 0);
    formattedString.setSpan(
            new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)),
            lenFirstAmount, lenFirstCode, 0);
    formattedString.setSpan(
            new RelativeSizeSpan(secondaryRelativeSize),
            lenFirstAmount, lenFirstCode, 0);

    formattedString.setSpan(
            new ForegroundColorSpan(ContextCompat.getColor(context, R.color.main_color_400)),
            lenFirstCode, lenSecond, 0);
    formattedString.setSpan(
            new RelativeSizeSpan(secondaryRelativeSize),
            lenFirstCode, lenSecond, 0);

    return formattedString;
}
 
Example 58
Project: coinblesk-client-gui   File: UIUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableString toFriendlyAmountString(Context context, TransactionWrapper transaction) {
    StringBuffer friendlyAmount = new StringBuffer();

    MonetaryFormat formatter = getMoneyFormat(context);
    String btcCode = formatter.code();
    String scaledAmount = formatter.noCode().format(transaction.getAmount()).toString();
    friendlyAmount.append(scaledAmount).append(" ");
    final int coinLength = friendlyAmount.length();

    friendlyAmount.append(btcCode).append(" ");
    final int codeLength = friendlyAmount.length();

    ExchangeRate exchangeRate = transaction.getTransaction().getExchangeRate();
    if (exchangeRate != null) {
        Fiat fiat = exchangeRate.coinToFiat(transaction.getAmount());
        friendlyAmount.append("~ " + fiat.toFriendlyString());
        friendlyAmount.append(System.getProperty("line.separator") + "(1 BTC = "
                + exchangeRate.fiat.toFriendlyString() + " as of now)");
    }
    final int amountLength = friendlyAmount.length();

    SpannableString friendlySpannable = new SpannableString(friendlyAmount);
    friendlySpannable.setSpan(new RelativeSizeSpan(2), 0, coinLength, 0);
    friendlySpannable.setSpan(
            new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)),
            coinLength, codeLength, 0);
    friendlySpannable.setSpan(
            new ForegroundColorSpan(context.getResources().getColor(R.color.main_color_400)),
            codeLength, amountLength, 0);
    return friendlySpannable;

}
 
Example 59
Project: Stayfit   File: RealmDatabaseActivityPie.java   Source Code and License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("Realm.io\nmobile database");
        s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
        s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
        s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
        return s;
    }
 
Example 60
Project: Stayfit   File: PieChartActivity.java   Source Code and 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;
    }