private void header(@NonNull ContinueReadingCard card) { int age = (int) card.daysOld(); @PluralsRes int subtitlePlural; String subtitle; if (age == 0) { subtitle = getResources().getString(R.string.view_continue_reading_card_subtitle_today); } else { subtitlePlural = R.plurals.view_continue_reading_card_subtitle; subtitle = getResources().getQuantityString(subtitlePlural, age, age); } headerView().setTitle(R.string.view_continue_reading_card_title) .setImage(R.drawable.ic_arrow_forward_black_24dp) .setImageCircleColor(R.color.base30) .setCard(card) .setCallback(getCallback()); largeHeaderView().setTitle(card.title()) .setImage(card.image()) .setSubtitle(subtitle) .onClickListener(new CardClickListener()) .setVisibility(VISIBLE); }
@NonNull @Override public CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException { int realId = getCorrespondResId(id); if (realId > 0) { return mSkinResources.getQuantityText(realId, quantity); } return super.getQuantityText(id, quantity); }
@NonNull @Override public String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) throws NotFoundException { int realId = getCorrespondResId(id); if (realId > 0) { return mSkinResources.getQuantityString(realId, quantity, formatArgs); } return super.getQuantityString(id, quantity, formatArgs); }
@NonNull @Override public String getQuantityString(@PluralsRes int id, int quantity) throws NotFoundException { int realId = getCorrespondResId(id); if (realId > 0) { return mSkinResources.getQuantityString(realId, quantity); } return super.getQuantityString(id, quantity); }
private void updateSummaryWithPlurals(String summaryKey, int value, @PluralsRes int pluralsId, @StringRes int stringId, boolean enabled) { if (enabled) { findPreference(summaryKey).setSummary(getResources() .getQuantityString(pluralsId, value, value)); } else { findPreference(summaryKey).setSummary(getString(stringId)); } findPreference(summaryKey).setEnabled(enabled); }
@Override public void showToast(@PluralsRes final int id, final int quantity, final String... formatArgs) { if (isAvailable()) { Toast.makeText( getContext(), getQuantityString(id, quantity, (Object[]) formatArgs), Toast.LENGTH_LONG) .show(); } }
@NonNull public ParsedLexString withPlural(@NonNull LexKey key, int quantity, @PluralsRes int resourceId) { return with(key, Lex.resources.getQuantityString(resourceId, quantity)); }
public String getPlural(@PluralsRes int resId, int quantity, Object... formatArgs) { return context.getResources().getQuantityString(resId, quantity, formatArgs); }
public static String plural(@PluralsRes int resId, int quantity) { return sContext.getResources().getQuantityString(resId, quantity, quantity); }
private String getQuantityString(@PluralsRes int resId, int n) { return getContext().getResources().getQuantityString(resId, n, n); }
public Builder titlePlurals(@PluralsRes int val) { titlePluralsRes = val; return this; }
public Builder summaryPlurals(@PluralsRes int val) { summaryPluralsRes = val; return this; }
public Builder firstActionPlurals(@PluralsRes int val, View.OnClickListener listener) { firstActionPluralsRes = val; firstActionListener = listener; return this; }
public Builder secondActionPlurals(@PluralsRes int val, View.OnClickListener listener) { secondActionPluralsRes = val; secondActionListener = listener; return this; }
public String formatWithText(@PluralsRes int pluralResource, @StringRes int zeroCountString, Integer count) { if (count == null || count == 0) return resources.getString(zeroCountString); String formattedNumber = NumberFormat.getIntegerInstance().format(count); return resources.getQuantityString(pluralResource, count, formattedNumber); }
public static String getQuantityString(@PluralsRes int pluralsRes, int quantity) throws Resources.NotFoundException { return ContextUtil.getResources().getQuantityString(pluralsRes, quantity); }
public String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) { return getResources().getQuantityString(id, quantity, formatArgs); }
public PluralStringResource(@PluralsRes final int pluralResourceId) { mPluralResourceId = pluralResourceId; }
private static String getResString(@PluralsRes int pluralsId, int value) { return sResources.getQuantityString(pluralsId, value, value); }
private String prettyPrintDuration(int amount, @PluralsRes int pluralsRes) { return amount + " " + getResources().getQuantityString(pluralsRes, amount); }
public static CharSequence getFormattedStringForQuantity(@NonNull Resources resources, @PluralsRes int resourceId, int quantity) { return getFormattedStringForQuantity(resources, resourceId, QuantityHolder, quantity); }
public static CharSequence getFormattedStringForQuantity(@NonNull Resources resources, @PluralsRes int resourceId, @NonNull String key, int quantity) { String template = resources.getQuantityString(resourceId, quantity); return Phrase.from(template).put(key, quantity + "").format(); }
public static String getQuantityString(Context ctx, @PluralsRes int pluralResId, int quantity) { return ctx.getResources().getQuantityString(pluralResId, quantity, quantity); }
@NonNull private String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) { return getResources().getQuantityString(id, quantity, formatArgs); }
/** * Set whole format of edit text field for displaying decimal value. * * @param decimalRounding * Amount of fraction digits. * @param pluralResource * Resource ID of plural strings (don't use plurals with numbers!). */ public void setFormat(int decimalRounding, @PluralsRes int pluralResource) { this.decimalRounding = decimalRounding; if (this.decimalRounding < 0) this.decimalRounding = 0; this.pluralLabel = pluralResource; updateText(); }
/** * Given a plural resource (R.plurals), localize the string according to the language preferences * on the device. * * @param pluralResource R.plurals to localize. * @param quantity Quantity to use for pluaralisation rules * @param formatArgs Formatting arguments to pass * @return Localized string */ public static String localizePlural(@PluralsRes int pluralResource, int quantity, Object... formatArgs) { Resources res = AndProxApplication.getInstance().getResources(); return res.getQuantityString(pluralResource, quantity, formatArgs); }
/** * Get a formatted quantity string resource using the application context. * @param resId String resource ID. * @param count Quantity. * @param formatArgs Format arguments. * @return Formatted quantity string. */ public String getQString(@PluralsRes int resId, int count, Object... formatArgs) { return getResources().getQuantityString(resId, count, formatArgs); }
/** * Gets resource ID of plural for formatting view of input field. * * @return ID of current plural in resources. */ @PluralsRes public int getPluralResource() { return pluralLabel; }
/** * Sets plural for formatting of current value with label and updates view. * * @param pluralResource * Resource ID of plural strings (don't use plurals with numbers!). */ public void setPluralResource(@PluralsRes final int pluralResource) { pluralLabel = pluralResource; updateText(); }
/** * Entry point into this API. * * @throws IllegalArgumentException if pattern contains any syntax errors. */ public static Phrase fromPlural(View v, @PluralsRes int patternResourceId, int quantity) { return fromPlural(v.getResources(), patternResourceId, quantity); }
/** * Entry point into this API. * * @throws IllegalArgumentException if pattern contains any syntax errors. */ public static Phrase fromPlural(Context c, @PluralsRes int patternResourceId, int quantity) { return fromPlural(c.getResources(), patternResourceId, quantity); }
/** * Entry point into this API. * * @throws IllegalArgumentException if pattern contains any syntax errors. */ public static Phrase fromPlural(Resources r, @PluralsRes int patternResourceId, int quantity) { return from(r.getQuantityText(patternResourceId, quantity)); }
/** * Returns the character sequence necessary for grammatically correct pluralization * of the given resource ID for the given quantity. * Note that the character sequence is selected based solely on grammatical necessity, * and that such rules differ between languages. Do not assume you know which string * will be returned for a given quantity. See * <a href="{@docRoot}guide/topics/resources/string-resource.html#Plurals">String Resources</a> * for more detail. * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. * @param quantity The number used to get the correct string for the current language's * plural rules. * @return CharSequence The string data associated with the resource, plus * possibly styled text information. * @throws NotFoundException Throws NotFoundException if the given ID does not exist. */ public static CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException { return resources.getQuantityText(id, quantity); }
/** * Formats the string necessary for grammatically correct pluralization * of the given resource ID for the given quantity, using the given arguments. * Note that the string is selected based solely on grammatical necessity, * and that such rules differ between languages. Do not assume you know which string * will be returned for a given quantity. See * <a href="{@docRoot}guide/topics/resources/string-resource.html#Plurals">String Resources</a> * for more detail. * <p/> * <p>Substitution of format arguments works as if using * {@link java.util.Formatter} and {@link java.lang.String#format}. * The resulting string will be stripped of any styled text information. * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. * @param quantity The number used to get the correct string for the current language's * plural rules. * @param formatArgs The format arguments that will be used for substitution. * @return String The string data associated with the resource, * stripped of styled text information. * @throws NotFoundException Throws NotFoundException if the given ID does not exist. */ public static String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) throws NotFoundException { return resources.getQuantityString(id, quantity, formatArgs); }
/** * Returns the string necessary for grammatically correct pluralization * of the given resource ID for the given quantity. * Note that the string is selected based solely on grammatical necessity, * and that such rules differ between languages. Do not assume you know which string * will be returned for a given quantity. See * <a href="{@docRoot}guide/topics/resources/string-resource.html#Plurals">String Resources</a> * for more detail. * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. * @param quantity The number used to get the correct string for the current language's * plural rules. * @return String The string data associated with the resource, * stripped of styled text information. * @throws NotFoundException Throws NotFoundException if the given ID does not exist. */ public static String getQuantityString(@PluralsRes int id, int quantity) throws NotFoundException { return resources.getQuantityString(id, quantity); }
void showToast(@PluralsRes int id, int quantity, String... formatArgs);