List of usage examples for android.text.style RelativeSizeSpan RelativeSizeSpan
public RelativeSizeSpan(@NonNull Parcel src)
From source file:com.silentcircle.contacts.vcard.ManageVCardActivity.java
private Dialog getVCardFileSelectDialog(boolean multipleSelect) { final int size = mAllVCardFileList.size(); final VCardSelectedListener listener = new VCardSelectedListener(multipleSelect); final AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(R.string.select_vcard_title_remove).setPositiveButton(android.R.string.ok, listener) .setOnCancelListener(mCancelListener).setNegativeButton(android.R.string.cancel, mCancelListener); CharSequence[] items = new CharSequence[size]; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < size; i++) { VCardFile vcardFile = mAllVCardFileList.get(i); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); stringBuilder.append(vcardFile.getName()); stringBuilder.append('\n'); int indexToBeSpanned = stringBuilder.length(); // Smaller date text looks better, since each file name becomes easier to read. // The value set to RelativeSizeSpan is arbitrary. You can change it to any other // value (but the value bigger than 1.0f would not make nice appearance :) stringBuilder.append("(" + dateFormat.format(new Date(vcardFile.getLastModified())) + ")"); stringBuilder.setSpan(new RelativeSizeSpan(0.7f), indexToBeSpanned, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); items[i] = stringBuilder;//from w w w .j ava 2s. co m } if (multipleSelect) { builder.setMultiChoiceItems(items, (boolean[]) null, listener); } else { builder.setSingleChoiceItems(items, 0, listener); } return builder.create(); }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Show "donate" dialog.// w w w . j av a 2 s .c o m * * @param context * {@link Context} * @param title * title * @param btnDonate * button text for donate * @param btnNoads * button text for "i did a donation" * @param messages * messages for dialog body */ public static void showDonationDialog(final Activity context, final String title, final String btnDonate, final String btnNoads, final String[] messages) { final Intent marketIntent = Market.getInstallAppIntent(context, DONATOR_PACKAGE, null); String btnTitle = String.format(btnDonate, "Play Store"); SpannableStringBuilder sb = new SpannableStringBuilder(); for (String m : messages) { sb.append(m); sb.append("\n"); } sb.delete(sb.length() - 1, sb.length()); sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(title); b.setMessage(sb); b.setCancelable(true); b.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { context.startActivity(marketIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "activity not found", e); Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show(); } } }); b.setNeutralButton(btnNoads, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://code.google.com/p/ub0rapps/downloads/list?" + "can=3&q=Product%3DDonator"))); } catch (ActivityNotFoundException e) { Log.e(TAG, "activity not found", e); Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show(); } } }); b.show(); }
From source file:com.coinblesk.client.utils.UIUtils.java
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);//from w w w . ja v a 2 s . c o m 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; }
From source file:com.stasbar.knowyourself.Utils.java
/** * @param amPmRatio a value between 0 and 1 that is the ratio of the relative size of the * am/pm string to the time string * @return format string for 12 hours mode time */// w ww.ja v a2s . c om public static CharSequence get12ModeFormat(float amPmRatio) { String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "hma"); if (amPmRatio <= 0) { pattern = pattern.replaceAll("a", "").trim(); } // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); // Build a spannable so that the am/pm will be formatted int amPmPos = pattern.indexOf('a'); if (amPmPos == -1) { return pattern; } final Spannable sp = new SpannableString(pattern); sp.setSpan(new RelativeSizeSpan(amPmRatio), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sp.setSpan(new StyleSpan(Typeface.NORMAL), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sp.setSpan(new TypefaceSpan("sans-serif"), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sp; }
From source file:com.androidinspain.deskclock.Utils.java
/** * @param amPmRatio a value between 0 and 1 that is the ratio of the relative size of the * am/pm string to the time string * @param includeSeconds whether or not to include seconds in the time string * @return format string for 12 hours mode time, not including seconds *///ww w . j a va2 s . c om public static CharSequence get12ModeFormat(float amPmRatio, boolean includeSeconds) { String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), includeSeconds ? "hmsa" : "hma"); if (amPmRatio <= 0) { pattern = pattern.replaceAll("a", "").trim(); } // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); // Build a spannable so that the am/pm will be formatted int amPmPos = pattern.indexOf('a'); if (amPmPos == -1) { return pattern; } final Spannable sp = new SpannableString(pattern); sp.setSpan(new RelativeSizeSpan(amPmRatio), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sp.setSpan(new StyleSpan(Typeface.NORMAL), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sp.setSpan(new TypefaceSpan("sans-serif"), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sp; }
From source file:es.usc.citius.servando.calendula.activities.ScheduleCreationActivity.java
public void onMedicineSelected(Medicine m, boolean step) { ScheduleHelper.instance().setSelectedMed(m); if (!step) {/*w w w . ja v a2 s . c om*/ autoStepDone = true; } if (!autoStepDone) { autoStepDone = true; new Handler().postDelayed(new Runnable() { @Override public void run() { mViewPager.setCurrentItem(1); } }, 500); } if (mScheduleId == -1) { String titleStart = getString(R.string.title_create_schedule_activity); String medName = " (" + m.name() + ")"; String fullTitle = titleStart + medName; SpannableString title = new SpannableString(fullTitle); title.setSpan(new RelativeSizeSpan(0.7f), titleStart.length(), titleStart.length() + medName.length(), 0); title.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.white_50)), titleStart.length(), titleStart.length() + medName.length(), 0); getSupportActionBar().setTitle(title); } }
From source file:com.coinblesk.client.utils.UIUtils.java
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)"); }/*from w ww .j a va 2 s.c om*/ 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; }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleBusRoute(@NonNull final FavoritesViewHolder holder, @NonNull final BusRoute busRoute) { holder.stationNameTextView.setText(busRoute.getId()); holder.favoriteImage.setImageResource(R.drawable.ic_directions_bus_white_24dp); final List<BusDetailsDTO> busDetailsDTOs = new ArrayList<>(); final Map<String, Map<String, List<BusArrival>>> busArrivals = favoritesData .getBusArrivalsMapped(busRoute.getId()); for (final Entry<String, Map<String, List<BusArrival>>> entry : busArrivals.entrySet()) { // Build data for button outside of the loop final String stopName = entry.getKey(); final String stopNameTrimmed = Util.trimBusStopNameIfNeeded(stopName); final Map<String, List<BusArrival>> value = entry.getValue(); for (final String key2 : value.keySet()) { final BusArrival busArrival = value.get(key2).get(0); final String boundTitle = busArrival.getRouteDirection(); final BusDirection.BusDirectionEnum busDirectionEnum = BusDirection.BusDirectionEnum .fromString(boundTitle); final BusDetailsDTO busDetails = BusDetailsDTO.builder().busRouteId(busArrival.getRouteId()) .bound(busDirectionEnum.getShortUpperCase()).boundTitle(boundTitle) .stopId(Integer.toString(busArrival.getStopId())).routeName(busRoute.getName()) .stopName(stopName).build(); busDetailsDTOs.add(busDetails); }//from w w w . j a v a 2 s .c o m boolean newLine = true; int i = 0; for (final Entry<String, List<BusArrival>> entry2 : value.entrySet()) { final LinearLayout.LayoutParams containParams = getInsideParams(newLine, i == value.size() - 1); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); container.setLayoutParams(containParams); // Left final LinearLayout.LayoutParams leftParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParams); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId); destinationParams.setMargins(pixelsHalf, 0, 0, 0); final String bound = BusDirection.BusDirectionEnum.fromString(entry2.getKey()).getShortLowerCase(); final String leftString = stopNameTrimmed + " " + bound; final SpannableString destinationSpannable = new SpannableString(leftString); destinationSpannable.setSpan(new RelativeSizeSpan(0.65f), stopNameTrimmed.length(), leftString.length(), 0); // set size destinationSpannable.setSpan(new ForegroundColorSpan(grey5), 0, leftString.length(), 0); // set color final TextView boundCustomTextView = new TextView(context); boundCustomTextView.setText(destinationSpannable); boundCustomTextView.setSingleLine(true); boundCustomTextView.setLayoutParams(destinationParams); left.addView(lineIndication); left.addView(boundCustomTextView); // Right final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rightParams.setMargins(marginLeftPixel, 0, 0, 0); final LinearLayout right = new LinearLayout(context); right.setOrientation(LinearLayout.VERTICAL); right.setLayoutParams(rightParams); final List<BusArrival> buses = entry2.getValue(); final StringBuilder currentEtas = new StringBuilder(); for (final BusArrival arri : buses) { currentEtas.append(" ").append(arri.getTimeLeftDueDelay()); } final TextView arrivalText = new TextView(context); arrivalText.setText(currentEtas); arrivalText.setGravity(Gravity.END); arrivalText.setSingleLine(true); arrivalText.setTextColor(grey5); arrivalText.setEllipsize(TextUtils.TruncateAt.END); right.addView(arrivalText); container.addView(left); container.addView(right); holder.mainLayout.addView(container); newLine = false; i++; } } holder.mapButton.setText(activity.getString(R.string.favorites_view_buses)); holder.detailsButton .setOnClickListener(new BusStopOnClickListener(activity, holder.parent, busDetailsDTOs)); holder.mapButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else { final Set<String> bounds = Stream.of(busDetailsDTOs).map(BusDetailsDTO::getBound) .collect(Collectors.toSet()); final Intent intent = new Intent(activity.getApplicationContext(), BusMapActivity.class); final Bundle extras = new Bundle(); extras.putString(activity.getString(R.string.bundle_bus_route_id), busRoute.getId()); extras.putStringArray(activity.getString(R.string.bundle_bus_bounds), bounds.toArray(new String[bounds.size()])); intent.putExtras(extras); activity.startActivity(intent); } }); }
From source file:com.softminds.matrixcalculator.dialog_activity.FunctionMaker.java
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; }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private void handleEndTag(String tag) { if (tag.equalsIgnoreCase("br")) { handleBr(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("p")) { handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength); } else if (tag.equalsIgnoreCase("div")) { handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength); } else if (tag.equalsIgnoreCase("strong")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); } else if (tag.equalsIgnoreCase("b")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); } else if (tag.equalsIgnoreCase("em")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("cite")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("dfn")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("i")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("s")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("big")) { end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f)); } else if (tag.equalsIgnoreCase("small")) { end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f)); } else if (tag.equalsIgnoreCase("font")) { endFont(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("blockquote")) { handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength); endBlockquote(mSpannableStringBuilder, mColors); } else if (tag.equalsIgnoreCase("tt")) { end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace")); } else if (tag.equalsIgnoreCase("code")) { end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace")); } else if (tag.equalsIgnoreCase("ul")) { if (!mListTags.isEmpty()) mListTags.removeFirst();//w w w . j av a 2 s . c o m } else if (tag.equalsIgnoreCase("ol")) { if (!mListTags.isEmpty()) mListTags.removeFirst(); } else if (tag.equalsIgnoreCase("li")) { //?? ?? <li> } else if (tag.equalsIgnoreCase("tr")) { handleTr(mSpannableStringBuilder, false); } else if (tag.equalsIgnoreCase("td")) { handleTd(mSpannableStringBuilder, false); } else if (tag.equalsIgnoreCase("a")) { endA(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("u")) { end(mSpannableStringBuilder, Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("sup")) { end(mSpannableStringBuilder, Super.class, new SuperscriptSpan()); } else if (tag.equalsIgnoreCase("sub")) { end(mSpannableStringBuilder, Sub.class, new SubscriptSpan()); } else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') { handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength); endHeader(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("span")) { endSpan(mSpannableStringBuilder, mColors, mOpenSpoilers); } else if (tag.equalsIgnoreCase("aibquote")) { end(mSpannableStringBuilder, Aibquote.class, new ForegroundColorSpan(mColors != null ? mColors.quoteForeground : Color.GREEN)); } else if (tag.equalsIgnoreCase("aibspoiler")) { endAibspoiler(mSpannableStringBuilder, mColors, mOpenSpoilers); } /* else if (mTagHandler != null) { mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader); }*/ }