Resources res = getResources(); String text = res.getQuantityString(R.plurals.welcome_messages, mailCount, username, mailCount);
public CharSequence toString(Context context) { if (formatArgs == null || formatArgs.length == 0) { return context.getResources().getQuantityString(id, quantity); } else { return context.getResources().getQuantityString(id, quantity, formatArgs); } }
public static final String makeLabel(final Context context, final int pluralInt, final int number) { return context.getResources().getQuantityString(pluralInt, number, number); }
public static final String makeLabel(final Context context, final int pluralInt, final int number) { return context.getResources().getQuantityString(pluralInt, number, number); }
public static final String makeLabel(final Context context, final int pluralInt, final int number) { return context.getResources().getQuantityString(pluralInt, number, number); }
@Override protected void showProgressDialog() { String title = mActivity.getString(R.string.settings_import_activate_account_header); int passwordCount = (mOutgoingPassword == null) ? 1 : 2; String message = mActivity.getResources().getQuantityString( R.plurals.settings_import_setting_passwords, passwordCount); mProgressDialog = ProgressDialog.show(mActivity, title, message, true); }
private static String getQuantity(Context context, @PluralsRes int pluralId, @StringRes int zeroCaseStringId, long count, String formattedCount) { if (count == 0) return context.getString(zeroCaseStringId); // As we use the already formatted count, is not the responsibility of this method handle long numbers // (it probably will fall in the "other" category, or some language have some specific rule... then we have to change it) int safeCount = count > Integer.MAX_VALUE ? Integer.MAX_VALUE : count < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) count; return context.getResources().getQuantityString(pluralId, safeCount, formattedCount); }
@Override public CharSequence getPageTitle(int position) { if (position == 0) { if (mItem instanceof Item) { int count = ((Item) mItem).getKidCount(); return mContext.getResources() .getQuantityString(R.plurals.comments_count, count, count); } return mContext.getString(R.string.title_activity_item); } return mContext.getString(mItem.isStoryType() ? R.string.article : R.string.full_text); }
@Override public void remoteSearchServerQueryComplete(String folderServerId, int numResults, int maxResults) { handler.progress(true); if (maxResults != 0 && numResults > maxResults) { handler.updateFooter(context.getResources().getQuantityString(R.plurals.remote_search_downloading_limited, maxResults, maxResults, numResults)); } else { handler.updateFooter(context.getResources().getQuantityString(R.plurals.remote_search_downloading, numResults, numResults)); } fragmentListener.setMessageListProgress(Window.PROGRESS_START); }
public void bindView(FeedItem feedItem) { this.feedItem = feedItem; int adapterPosition = getAdapterPosition(); ivFeedCenter.setImageResource(adapterPosition % 2 == 0 ? R.drawable.img_feed_center_1 : R.drawable.img_feed_center_2); ivFeedBottom.setImageResource(adapterPosition % 2 == 0 ? R.drawable.img_feed_bottom_1 : R.drawable.img_feed_bottom_2); btnLike.setImageResource(feedItem.isLiked ? R.drawable.ic_heart_red : R.drawable.ic_heart_outline_grey); tsLikesCounter.setCurrentText(vImageRoot.getResources().getQuantityString( R.plurals.likes_count, feedItem.likesCount, feedItem.likesCount )); }
/** * Updates the TextView to display the new charging reminder count from SharedPreferences */ private void updateChargingReminderCount() { int chargingReminders = PreferenceUtilities.getChargingReminderCount(this); String formattedChargingReminders = getResources().getQuantityString( R.plurals.charge_notification_count, chargingReminders, chargingReminders); mChargingCountDisplay.setText(formattedChargingReminders); }
/** * Updates the TextView to display the new charging reminder count from SharedPreferences */ private void updateChargingReminderCount() { int chargingReminders = PreferenceUtilities.getChargingReminderCount(this); String formattedChargingReminders = getResources().getQuantityString( R.plurals.charge_notification_count, chargingReminders, chargingReminders); mChargingCountDisplay.setText(formattedChargingReminders); }
private void updateLikesCounter(FeedAdapter.CellFeedViewHolder holder, int toValue) { String likesCountTextFrom = holder.tsLikesCounter.getResources().getQuantityString( R.plurals.likes_count, toValue - 1, toValue - 1 ); holder.tsLikesCounter.setCurrentText(likesCountTextFrom); String likesCountTextTo = holder.tsLikesCounter.getResources().getQuantityString( R.plurals.likes_count, toValue, toValue ); holder.tsLikesCounter.setText(likesCountTextTo); }
@Override public void onPrepareDialog(int dialogId, @NonNull Dialog dialog) { AlertDialog alert = (AlertDialog) dialog; switch (dialogId) { case DIALOG_CONFIRM: { int messageCount = messagesToDelete.size(); alert.setMessage(getResources().getQuantityString( R.plurals.dialog_confirm_delete_messages, messageCount, messageCount)); break; } } super.onPrepareDialog(dialogId, dialog); }
private void changeToggleState(ToggleItemViewHolder holder, Item item, boolean expanded) { holder.mToggle.setText(mContext.getResources() .getQuantityString(R.plurals.comments_count, item.getKidCount(), item.getKidCount())); holder.mToggle.setCompoundDrawablesWithIntrinsicBounds(0, 0, expanded ? R.drawable.ic_expand_less_white_24dp : R.drawable.ic_expand_more_white_24dp, 0); }
@Implementation protected String getQuantityString(int id, int quantity, Object... formatArgs) throws Resources.NotFoundException { if (isLegacyAssetManager()) { String raw = getQuantityString(id, quantity); return String.format(Locale.ENGLISH, raw, formatArgs); } else { return directlyOn(realResources, Resources.class).getQuantityString(id, quantity, formatArgs); } }
@Test @Config(qualifiers = "de") public void getQuantityString() throws Exception { assertThat(resources.getQuantityString(R.plurals.minute, 2)).isEqualTo( resources.getString(R.string.minute_plural)); }
@Test public void getQuantityString() { assertThat(resources.getQuantityString(R.plurals.beer, 1)).isEqualTo("a beer"); assertThat(resources.getQuantityString(R.plurals.beer, 2)).isEqualTo("some beers"); assertThat(resources.getQuantityString(R.plurals.beer, 3)).isEqualTo("some beers"); }
@Test public void quantityStringIsSet() { int pluralString = R.plurals.plural_test_string; ViewWithAnnotationsForIntegrationTestModel_ model = new ViewWithAnnotationsForIntegrationTestModel_() .requiredTextQuantityRes(pluralString, 1); ViewWithAnnotationsForIntegrationTest view = bind(model); assertEquals(view.getContext().getResources().getQuantityString(pluralString, 1), view.requiredText); }
@Test public void quantityStringWithArgsIsSet() { int pluralString = R.plurals.plural_test_string_with_args; ViewWithAnnotationsForIntegrationTestModel_ model = new ViewWithAnnotationsForIntegrationTestModel_() .requiredTextQuantityRes(pluralString, 1, 3); ViewWithAnnotationsForIntegrationTest view = bind(model); assertEquals(view.getContext().getResources().getQuantityString(pluralString, 1, 3), view.requiredText); }