android.text.SpannableString Java Examples

The following examples show how to use android.text.SpannableString. 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: DoNothingService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static SpannableString nanoStatus() {
    SpannableString pingStatus = null;
    if (lastMessageReceived > 0) {
        long pingSince = JoH.msSince(lastMessageReceived);
        if (pingSince > Constants.MINUTE_IN_MS * 30) {
            pingStatus = Span.colorSpan("No follower sync for: " + JoH.niceTimeScalar(pingSince), BAD.color());
        }
    }
    if (Home.get_follower()) {
        updateLastBg();
        final SpannableString remoteStatus = NanoStatus.getRemote();
        if (last_bg != null) {
            if (JoH.msSince(last_bg.timestamp) > Constants.MINUTE_IN_MS * 15) {
                final SpannableString lastBgStatus = Span.colorSpan("Last from master: " + JoH.niceTimeSince(last_bg.timestamp) + " ago", NOTICE.color());
                return Span.join(true, remoteStatus, pingStatus, lastBgStatus);
            }
        } else {
            return Span.join(true, pingStatus, new SpannableString(gs(R.string.no_data_received_from_master_yet)));
        }
    } else {
        return Span.join(true, pingStatus);
    }
    return null;
}
 
Example #2
Source File: SourceDebugActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void printDebugLog(String msg) {
    int titleIndex = msg.indexOf("◆[");
    if (titleIndex >= 0) {
        SpannableString spannableString = new SpannableString(msg);
        spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), titleIndex, msg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (!TextUtils.isEmpty(tvContent.getText())) {
            tvContent.append("\n");
        }
        tvContent.append(spannableString);
    } else {
        if (!TextUtils.isEmpty(tvContent.getText())) {
            tvContent.append("\n");
        }
        tvContent.append(msg);
    }

    scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));

}
 
Example #3
Source File: SavePasswordInfoBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
        SpannableString title = new SpannableString(mTitle);
        title.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                onLinkClicked();
            }
        }, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        layout.setMessage(title);
    }

    if (!TextUtils.isEmpty(mFirstRunExperienceMessage)) {
        InfoBarControlLayout controlLayout = layout.addControlLayout();
        controlLayout.addDescription(mFirstRunExperienceMessage);
    }
}
 
Example #4
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 6 votes vote down vote up
void createMoreChipPlainText()
{
// Take the first <= CHIP_LIMIT addresses and get to the end of the second one.
final Editable text=getText();
int start=0;
int end=start;
for(int i=0;i<CHIP_LIMIT;i++)
  {
  end=movePastTerminators(mTokenizer.findTokenEnd(text,start));
  start=end; // move to the next token and get its end.
  }
// Now, count total addresses.
start=0;
final int tokenCount=countTokens(text);
final MoreImageSpan moreSpan=createMoreSpan(tokenCount-CHIP_LIMIT);
final SpannableString chipText=new SpannableString(text.subSequence(end,text.length()));
chipText.setSpan(moreSpan,0,chipText.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.replace(end,text.length(),chipText);
mMoreChip=moreSpan;
}
 
Example #5
Source File: SocialAutoCompleteTextView.java    From socialview with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    if (i > 0 && chars.contains(text.charAt(i - 1))) {
        return text;
    } else {
        if (text instanceof Spanned) {
            final Spannable sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example #6
Source File: ItemsAdapter.java    From sqlbrite with Apache License 2.0 6 votes vote down vote up
@Override public View getView(int position, View convertView, ViewGroup parent) {
  if (convertView == null) {
    convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false);
  }

  TodoItem item = getItem(position);
  CheckedTextView textView = (CheckedTextView) convertView;
  textView.setChecked(item.complete());

  CharSequence description = item.description();
  if (item.complete()) {
    SpannableString spannable = new SpannableString(description);
    spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
    description = spannable;
  }

  textView.setText(description);

  return convertView;
}
 
Example #7
Source File: EmotionUtils.java    From LoveTalkClient with Apache License 2.0 6 votes vote down vote up
public static CharSequence replace(Context ctx, String text) {
	SpannableString spannableString = new SpannableString(text);
	Matcher matcher = pattern.matcher(text);
	while (matcher.find()) {
		String factText = matcher.group();
		String key = factText.substring(1);
		if (emotionTexts.contains(factText)) {
			Bitmap bitmap = getDrawableByName(ctx, key);
			ImageSpan image = new ImageSpan(ctx, bitmap);
			int start = matcher.start();
			int end = matcher.end();
			spannableString.setSpan(image, start, end,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
	}
	return spannableString;
}
 
Example #8
Source File: StringUtils.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
public static SpannableString getDateStringDayAndTime (Date dateValue) {
    DateFormat timeFormat = new SimpleDateFormat("  h:mm", Locale.US);
    DateFormat ampmFormat = new SimpleDateFormat(" a", Locale.US);
    DateFormat dateFormat = new SimpleDateFormat("EEE", Locale.US);
    DateFormat dateFormatWithTime = new SimpleDateFormat("    h:mm a", Locale.US);

    if (dateValue == null) {
        return new SpannableString(ArcusApplication.getContext().getString(R.string.unknown_time_value));
    }

    // Date is today; just show the time
    else if (StringUtils.isDateToday(dateValue)) {
        return StringUtils.getSuperscriptSpan(ArcusApplication.getContext().getString(R.string.today), dateFormatWithTime.format(dateValue));
    }

    // Date is yesterday; show "YESTERDAY"
    else if (StringUtils.isDateYesterday(dateValue)) {
        return new SpannableString(ArcusApplication.getContext().getString(R.string.yesterday));
    }

    // Date is in the past; show date
    else {
        return StringUtils.getSuperscriptSpan(WordUtils.capitalize(dateFormat.format(dateValue)), dateFormatWithTime.format(dateValue));
    }
}
 
Example #9
Source File: MainActivity.java    From RefreashTabView with Apache License 2.0 6 votes vote down vote up
private void initDesc() {
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    stringBuilder.append(getString(R.string.head_title_desc));
    String link = getString(R.string.head_title_desc_link);
    SpannableString span = new SpannableString(link);
    span.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            //
            Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_LONG).show();
        }
    }, 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    stringBuilder.append(span);
    stringBuilder.append(" ");
    descTextView.setText(stringBuilder);
    //descTextView.setMovementMethod(LinkMovementMethod.getInstance());
    // fix TextView has LinkMovementMethod intercept Scroll event
    descTextView.setOnTouchListener(LinkMovement.getInstance());
}
 
Example #10
Source File: AutoExpandTextView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the list of sections in the text view.  This will take the first character of each
 * and space it out in the text view using letter spacing
 */
public void setSections(ArrayList<HighlightedText> sections) {
    mPositions = null;
    if (sections == null || sections.size() == 0) {
        setText("");
        return;
    }

    Resources r = getContext().getResources();
    int highlightColor = r.getColor(R.color.app_scrubber_highlight_color);
    int grayColor = r.getColor(R.color.app_scrubber_gray_color);

    SpannableStringBuilder builder = new SpannableStringBuilder();
    for (HighlightedText highlightText : sections) {
        SpannableString spannable = new SpannableString(highlightText.mText.substring(0, 1));
        spannable.setSpan(
                new ForegroundColorSpan(highlightText.mHighlight ? highlightColor : grayColor),
                0, spannable.length(), 0);
        builder.append(spannable);
    }

    setText(builder);
}
 
Example #11
Source File: ImageClassifierTF.java    From AIIA-DNN-benchmark with Apache License 2.0 6 votes vote down vote up
/** Classifies a frame from the preview stream. */
void classifyFrame(Bitmap bitmap, SpannableStringBuilder builder) {
  if (tflite == null) {
    Log.e(TAG, "Image classifier has not been initialized; Skipped.");
    builder.append(new SpannableString("Uninitialized Classifier."));
  }
  convertBitmapToByteBuffer(bitmap);
  // Here's where the magic happens!!!
  long startTime = SystemClock.uptimeMillis();
  runInference();
  long endTime = SystemClock.uptimeMillis();
  Log.d(TAG, "Timecost to run model inference: " + Long.toString(endTime - startTime));

  // Smooth the results across frames.
  applyFilter();

  // Print the results.
  printTopKLabels(builder);
  long duration = endTime - startTime;
  SpannableString span = new SpannableString(duration + " ms");
  span.setSpan(new ForegroundColorSpan(android.graphics.Color.LTGRAY), 0, span.length(), 0);
  builder.append(span);
}
 
Example #12
Source File: HelpsMainAdapter.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 替换表情
 *
 * @param str
 * @param context
 * @return
 */
private SpannableString getSpannableString(String str, Context context) {
    SpannableString spannableString = new SpannableString(str);
    String s = "\\[(.+?)\\]";
    Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(spannableString);
    while (matcher.find()) {
        String key = matcher.group();
        int id = Expression.getIdAsName(key);
        if (id != 0) {
            Drawable drawable = context.getResources().getDrawable(id);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            ImageSpan imageSpan = new ImageSpan(drawable);
            spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}
 
Example #13
Source File: VoIPActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private CharSequence getFormattedDebugString() {
    String in = VoIPService.getSharedInstance().getDebugString();
    SpannableString ss = new SpannableString(in);

    int offset = 0;
    do {
        int lineEnd = in.indexOf('\n', offset + 1);
        if (lineEnd == -1)
            lineEnd = in.length();
        String line = in.substring(offset, lineEnd);
        if (line.contains("IN_USE")) {
            ss.setSpan(new ForegroundColorSpan(0xFF00FF00), offset, lineEnd, 0);
        } else {
            if (line.contains(": ")) {
                ss.setSpan(new ForegroundColorSpan(0xAAFFFFFF), offset, offset + line.indexOf(':') + 1, 0);
            }
        }
    } while ((offset = in.indexOf('\n', offset + 1)) != -1);

    return ss;
}
 
Example #14
Source File: SmileyPicker.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
private void addEmotions(SpannableString value, Map<String, Integer> smiles) {
    Paint.FontMetrics fontMetrics = mEditText.getPaint().getFontMetrics();
    int size = (int) (fontMetrics.descent - fontMetrics.ascent);


    Matcher localMatcher = EMOTION_URL.matcher(value);
    while (localMatcher.find()) {
        String key = localMatcher.group(0);
        if (smiles.containsKey(key)) {
            int k = localMatcher.start();
            int m = localMatcher.end();
            if (m - k < 8) {
                Drawable drawable = mContext.getResources().getDrawable(smiles.get(key));
                if (drawable != null) {
                    drawable.setBounds(0, 0, size, size);
                }
                ImageSpan localImageSpan = new ImageSpan(drawable);
                value.setSpan(localImageSpan, k, m, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }

    }
}
 
Example #15
Source File: TalkBackDumpAccessibilityEventActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
EventDumperSwitchPreference(Context context, int eventType) {
  super(context);
  this.eventType = eventType;
  setOnPreferenceChangeListener(this);

  String title = AccessibilityEvent.eventTypeToString(eventType);
  // Add TtsSpan to the titles to improve readability.
  SpannableString spannableString = new SpannableString(title);
  TtsSpan ttsSpan = new TtsSpan.TextBuilder(title.replaceAll("_", " ")).build();
  spannableString.setSpan(ttsSpan, 0, title.length(), 0 /* no flag */);
  setTitle(spannableString);

  // Set initial value.
  SharedPreferences prefs = SharedPreferencesUtils.getSharedPreferences(getContext());
  int value = prefs.getInt(getContext().getString(R.string.pref_dump_event_mask_key), 0);
  setChecked((value & eventType) != 0);
}
 
Example #16
Source File: BindingAdapters.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("android:text")
public static void setText(final TextView textView, final FullEmail.From from) {
    if (from instanceof FullEmail.NamedFrom) {
        final FullEmail.NamedFrom named = (FullEmail.NamedFrom) from;
        textView.setText(named.getName());
    } else if (from instanceof FullEmail.DraftFrom) {
        final Context context = textView.getContext();
        final SpannableString spannable = new SpannableString(context.getString(R.string.draft));
        spannable.setSpan(
                new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorPrimary)),
                0,
                spannable.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        );
        textView.setText(spannable);
    }
}
 
Example #17
Source File: StringUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static SpannableString highlightParamText(String inputString, int index, String highlight, int color) {
    inputString = String.format(inputString, new Object[]{highlight});
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = index;
        if (beginPos > -1) {
            spanString.setSpan(new ForegroundColorSpan(color), beginPos, highlight.length() + beginPos, 33);
        }
    }
    return spanString;
}
 
Example #18
Source File: WinnerFeedItemView.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
private void setRank() {
  String part1 = "Ranked ";
  String part2 = String.format(Locale.US, "#%d", mData.getRank());
  int spanStart = part1.length();
  int spanEnd = spanStart + part2.length();
  Spannable wordtoSpan = new SpannableString(part1 + part2);
  wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#3F72AF")),
    spanStart,
    spanEnd,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  rankAssigned.setText(wordtoSpan);
}
 
Example #19
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void setUpUrlSpan(Span span, SpannableString ss, String text, int start, int end) {
    if (span.isUrl()) {
        ss.setSpan(
                new URLSpan(text),
                start,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #20
Source File: SmsMessageRecord.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SpannableString getDisplayBody() {
  if (SmsDatabase.Types.isFailedDecryptType(type)) {
    return emphasisAdded(context.getString(R.string.MessageDisplayHelper_bad_encrypted_message));
  } else if (isCorruptedKeyExchange()) {
    return emphasisAdded(context.getString(R.string.common_record_received_corrupted_key_exchange_message));
  } else if (isInvalidVersionKeyExchange()) {
    return emphasisAdded(context.getString(R.string.common_record_received_key_exchange_message_for_invalid_protocol_version));
  } else if (MmsSmsColumns.Types.isLegacyType(type)) {
    return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
  } else if (isBundleKeyExchange()) {
    return emphasisAdded(context.getString(R.string.common_record_received_message_with_new_safety_number_tap_to_process));
  } else if (isKeyExchange() && isOutgoing()) {
    return new SpannableString("");
  } else if (isKeyExchange() && !isOutgoing()) {
    return emphasisAdded(context.getString(R.string.common_conversation_received_key_exchange_message_tap_to_process));
  } else if (SmsDatabase.Types.isDuplicateMessageType(type)) {
    return emphasisAdded(context.getString(R.string.common_record_duplicate_message));
  } else if (SmsDatabase.Types.isDecryptInProgressType(type)) {
    return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
  } else if (SmsDatabase.Types.isNoRemoteSessionType(type)) {
    return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
  } else if (!getBody().isPlaintext()) {
    return emphasisAdded(context.getString(R.string.common_locked_message_description));
  } else if (isEndSession() && isOutgoing()) {
    return emphasisAdded(context.getString(R.string.common_record_secure_session_reset));
  } else if (isEndSession()) {
    return emphasisAdded(context.getString(R.string.common_record_secure_session_reset_s, getIndividualRecipient().toShortString()));
  } else {
    return super.getDisplayBody();
  }
}
 
Example #21
Source File: PhotoTextView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void setText(CharSequence text, BufferType type) {
	if (!TextUtils.isEmpty(text) && text.toString().contains("/")) {
		String[] s = text.toString().split("/");
		SpannableString sp = new SpannableString(text);
		sp.setSpan(new AbsoluteSizeSpan((int) (this.getTextSize() + 25)),
				0, s[0].length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
		super.setText(sp, type);
	} else {
		super.setText(text, type);
	}
}
 
Example #22
Source File: StyleSmallDecimal.java    From px-android with MIT License 5 votes vote down vote up
@Override
public Spannable apply(final int holder, final Context context) {
    final Spannable spanned = apply(null);
    final Currency currency = amountFormatter.currencyFormatter.currency;
    final Character decimalSeparator = currency.getDecimalSeparator();
    final SpannableString spannableString = new SpannableString(TextUtil.format(context, holder, spanned));
    final String totalText = spannableString.toString();
    return makeSmallAfterSeparator(decimalSeparator, totalText);
}
 
Example #23
Source File: HomeAssistantServer.java    From homeassist with Apache License 2.0 5 votes vote down vote up
public CharSequence getLine(Context context) {
    Spannable wordtoSpan1 = new SpannableString(getName());
    wordtoSpan1.setSpan(new RelativeSizeSpan(1.2f), 0, wordtoSpan1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    Spannable wordtoSpan2 = new SpannableString(baseurl);
    wordtoSpan2.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(context.getResources(), R.color.md_grey_100, null)), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan2.setSpan(new RelativeSizeSpan(0.8f), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return TextUtils.concat(wordtoSpan1, " \n", wordtoSpan2);
}
 
Example #24
Source File: ArmsUtils.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 设置hint大小
 *
 * @param size
 * @param v
 * @param res
 */
public static void setViewHintSize(Context context, int size, TextView v, int res) {
    SpannableString ss = new SpannableString(getResources(context).getString(
            res));
    // 新建一个属性对象,设置文字的大小
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
    // 附加属性到文本  
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // 设置hint  
    v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
 
Example #25
Source File: SnackbarBuilderTest.java    From SnackbarBuilder with Apache License 2.0 5 votes vote down vote up
@Test
public void givenSpan_whenMessage_thenMessageSet() {
  SnackbarBuilder builder = createBuilder();
  Spannable spannable = new SpannableString("testMessage");
  spannable.setSpan(new ForegroundColorSpan(Color.CYAN), 0, spannable.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  builder.message(spannable);

  assertThat(builder.message.toString()).isEqualTo("testMessage");
  SpannableString actual = SpannableString.valueOf(builder.message);
  ForegroundColorSpan[] spans = actual.getSpans(0, spannable.length(), ForegroundColorSpan.class);
  assertThat(spans).hasSize(1);
  assertThat(spans[0].getForegroundColor()).isEqualTo(Color.CYAN);
}
 
Example #26
Source File: UsernameTokenizer.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence terminateToken (final CharSequence text) {
	int i = text.length();
	while (i > 0 && text.charAt(i - 1) == ' ') {
		i--;
	}
	if (i > 0 && text.charAt(i - 1) == ' ') return text;
	if (text instanceof Spanned) {
		final SpannableString sp = new SpannableString(text + " ");
		TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
		return sp;
	}
	return text + " ";
}
 
Example #27
Source File: GosBaseActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
/**
 * 设置ActionBar(工具方法*GosAirlinkChooseDeviceWorkWiFiActivity.java中使用*)
 * 
 * @param HBE
 * @param DSHE
 * @param Title
 */
public void setActionBar(Boolean HBE, Boolean DSHE, CharSequence Title) {

	SpannableString ssTitle = new SpannableString(Title);
	ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.setNavigationBarTextColor()), 0, ssTitle.length(),
			Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
	actionBar = getActionBar();// 初始化ActionBar
	actionBar.setBackgroundDrawable(GosDeploy.setNavigationBarColor());
	actionBar.setHomeButtonEnabled(HBE);
	actionBar.setIcon(R.drawable.back_bt_);
	actionBar.setTitle(ssTitle);
	actionBar.setDisplayShowHomeEnabled(DSHE);
}
 
Example #28
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void setUpUnderlineSpan(Span span, SpannableString ss, int start, int end) {
    if (span.isUnderline()) {
        ss.setSpan(
                new UnderlineSpan(),
                start,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #29
Source File: FontPreferenceCompat.java    From Stringlate with 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 #30
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;
}