List of usage examples for android.text.style RelativeSizeSpan RelativeSizeSpan
public RelativeSizeSpan(@NonNull Parcel src)
From source file:Main.java
public static CharSequence small(CharSequence sequence) { SpannableString spannable = new SpannableString(sequence); spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; }
From source file:Main.java
public static CharSequence scaleEmotions(String text) { SpannableString spannableString = new SpannableString(text); for (String emotion : emotions) { Pattern pattern = Pattern.compile(emotion); Matcher matcher = pattern.matcher(text); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); spannableString.setSpan(new RelativeSizeSpan(1.2f), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }//from w w w . ja v a2 s.c om } return spannableString; }
From source file:Main.java
public static SpannableString getSmallCapsString(String input) { // values needed to record start/end points of blocks of lowercase letters char[] chars = input.toCharArray(); int currentBlock = 0; int[] blockStarts = new int[chars.length]; int[] blockEnds = new int[chars.length]; boolean blockOpen = false; // record where blocks of lowercase letters start/end for (int i = 0; i < chars.length; ++i) { char c = chars[i]; if (c >= 'a' && c <= 'z') { if (!blockOpen) { blockOpen = true;/*from w ww .j ava 2 s.co m*/ blockStarts[currentBlock] = i; } // replace with uppercase letters chars[i] = (char) (c - 'a' + '\u0041'); } else { if (blockOpen) { blockOpen = false; blockEnds[currentBlock] = i; ++currentBlock; } } } // add the string end, in case the last character is a lowercase letter blockEnds[currentBlock] = chars.length; // shrink the blocks found above SpannableString output = new SpannableString(String.valueOf(chars)); for (int i = 0; i < Math.min(blockStarts.length, blockEnds.length); ++i) { output.setSpan(new RelativeSizeSpan(0.8f), blockStarts[i], blockEnds[i], Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } return output; }
From source file:Main.java
public static SpannableStringBuilder getSpannableStringFromList(List<HashMap<String, Object>> list) { SpannableStringBuilder ssb = new SpannableStringBuilder(""); int position = 0; for (int i = 0; i < list.size(); i++) { HashMap<String, Object> map = list.get(i); try {/*from ww w. j a v a 2 s .c om*/ String st = (String) map.get(RICHTEXT_STRING); ssb.append(st); int len = st.length(); if (map.containsKey(RICHTEXT_COLOR)) { int color = ((Integer) map.get(RICHTEXT_COLOR)).intValue(); ssb.setSpan(new ForegroundColorSpan(color), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_SIZE)) { int size = ((Integer) map.get(RICHTEXT_SIZE)).intValue(); ssb.setSpan(new AbsoluteSizeSpan(size), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_RSIZE)) { float size = ((Float) map.get(RICHTEXT_RSIZE)).floatValue(); ssb.setSpan(new RelativeSizeSpan(size), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (map.containsKey(RICHTEXT_DELETE)) { ssb.setSpan(new StrikethroughSpan(), position, position + len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } // android.text.style.RelativeSizeSpan position = position + len; } catch (Exception e) { return null; } } return ssb; }
From source file:Main.java
public static void showChangelog(final Context context, final String title, final String appname, final int resChanges, final int resNotes) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); final String v0 = p.getString(PREFS_LAST_RUN, ""); String v1 = null;// ww w. ja va 2 s. co m try { v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e(TAG, "package not found: " + context.getPackageName(), e); } p.edit().putString(PREFS_LAST_RUN, v1).commit(); if (v0.length() == 0) { Log.d(TAG, "first boot, skip changelog"); // return; } if (v0.equals(v1)) { Log.d(TAG, "no changes"); return; } String[] changes = context.getResources().getStringArray(resChanges); String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null; final SpannableStringBuilder sb = new SpannableStringBuilder(); for (String s : notes) { SpannableString ss = new SpannableString(s + "\n"); int j = s.indexOf(":"); if (j > 0) { if (!TextUtils.isEmpty(s)) { ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } sb.append(ss); sb.append("\n"); } if (notes != null && notes.length > 0) { sb.append("\n"); } for (String s : changes) { s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n"; SpannableString ss = new SpannableString(s); int j = s.indexOf(":"); if (j > 0) { ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } sb.append(ss); sb.append("\n"); } sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); changes = null; notes = null; AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(title); b.setMessage(sb); b.setCancelable(true); b.setPositiveButton(android.R.string.ok, null); b.show(); }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
@Override protected void onFinishInflate() { super.onFinishInflate(); ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)).append(makeAsteriskSpan()); SpannableString spannable = new SpannableString("+5"); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.greenA700)), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable); TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment); SpannableStringBuilder sb = new SpannableStringBuilder("46"); sb.append(makeAsteriskSpan());//from w w w. j a v a 2 s. co m comments.setText(sb); }
From source file:com.ncatz.yeray.calendarview.CalendarDecorator.SelectedDayDecorator.java
@Override public void decorate(DayViewFacade view) { view.addSpan(new StyleSpan(Typeface.BOLD)); view.addSpan(new RelativeSizeSpan(1.4f)); view.setSelectionDrawable(drawable); }
From source file:de.schildbach.wallet.ui.CurrencyTextView.java
public void setInsignificantRelativeSize(final float insignificantRelativeSize) { if (insignificantRelativeSize != 1) { this.prefixRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize); this.insignificantRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize); } else {//from ww w. ja v a2 s. c o m this.prefixRelativeSizeSpan = null; this.insignificantRelativeSizeSpan = null; } }
From source file:com.androidinspain.deskclock.timer.TimerSetupView.java
public TimerSetupView(Context context, AttributeSet attrs) { super(context, attrs); final BidiFormatter bf = BidiFormatter.getInstance(false /* rtlContext */); final String hoursLabel = bf.unicodeWrap(context.getString(R.string.hours_label)); final String minutesLabel = bf.unicodeWrap(context.getString(R.string.minutes_label)); final String secondsLabel = bf.unicodeWrap(context.getString(R.string.seconds_label)); // Create a formatted template for "00h 00m 00s". mTimeTemplate = TextUtils.expandTemplate("^1^4 ^2^5 ^3^6", bf.unicodeWrap("^1"), bf.unicodeWrap("^2"), bf.unicodeWrap("^3"), FormattedTextUtils.formatText(hoursLabel, new RelativeSizeSpan(0.5f)), FormattedTextUtils.formatText(minutesLabel, new RelativeSizeSpan(0.5f)), FormattedTextUtils.formatText(secondsLabel, new RelativeSizeSpan(0.5f))); LayoutInflater.from(context).inflate(R.layout.timer_setup_container, this); }
From source file:cat.mvmike.minimalcalendarwidget.service.DayService.java
private static void setInstanceNumber(final Context context, final RemoteViews cellRv, final String dayOfMonth, final boolean isToday, final int found) { Symbol symbols = ConfigurationService.getInstancesSymbols(context); Character[] symbolArray = symbols.getArray(); int max = symbolArray.length - 1; String symbol = String.valueOf(found > max ? symbolArray[max] : symbolArray[found]); String dayOfMonthSpSt = PADDING + (dayOfMonth.length() == 1 ? dayOfMonth + DOUBLE_PADDING : dayOfMonth) + PADDING + symbol;//www . j a v a 2s. co m SpannableString daySpSt = new SpannableString(dayOfMonthSpSt); daySpSt.setSpan(new StyleSpan(Typeface.BOLD), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); int color; if (isToday) { color = ContextCompat.getColor(context, R.color.instances_today); daySpSt.setSpan(new StyleSpan(Typeface.BOLD), 0, dayOfMonthSpSt.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { color = ContextCompat.getColor(context, ConfigurationService.getInstancesSymbolsColours(context).getHexValue()); } daySpSt.setSpan(new ForegroundColorSpan(color), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); daySpSt.setSpan(new RelativeSizeSpan(symbols.getRelativeSize()), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); cellRv.setTextViewText(android.R.id.text1, daySpSt); }