本文整理匯總了Java中android.content.res.Resources.getQuantityString方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getQuantityString方法的具體用法?Java Resources.getQuantityString怎麽用?Java Resources.getQuantityString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getQuantityString方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildRule
import android.content.res.Resources; //導入方法依賴的package包/類
static String buildRule(Recurrence recurrence, Resources resources) {
Frequency frequency = recurrence.getFrequency();
Integer interval = recurrence.getInterval();
switch (frequency) {
case SECONDLY:
return resources.getQuantityString(R.plurals.ical_recurrence_second, interval, interval);
case MINUTELY:
return resources.getQuantityString(R.plurals.ical_recurrence_minute, interval, interval);
case HOURLY:
return resources.getQuantityString(R.plurals.ical_recurrence_hourly, interval, interval);
case DAILY:
return resources.getQuantityString(R.plurals.ical_recurrence_daily, interval, interval);
case WEEKLY:
return resources.getQuantityString(R.plurals.ical_recurrence_weekly, interval, interval);
case MONTHLY:
return resources.getQuantityString(R.plurals.ical_recurrence_monthly, interval, interval);
case YEARLY:
return resources.getQuantityString(R.plurals.ical_recurrence_yearly, interval, interval);
}
return "";
}
示例2: formatLastUpdated
import android.content.res.Resources; //導入方法依賴的package包/類
public static String formatLastUpdated(@NonNull Resources res, @NonNull Date date) {
long msDiff = Calendar.getInstance().getTimeInMillis() - date.getTime();
long days = msDiff / DateUtils.DAY_IN_MILLIS;
long weeks = msDiff / (DateUtils.DAY_IN_MILLIS * 7);
long months = msDiff / (DateUtils.DAY_IN_MILLIS * 30);
long years = msDiff / (DateUtils.DAY_IN_MILLIS * 365);
if (days < 1) {
return res.getString(R.string.details_last_updated_today);
} else if (weeks < 1) {
return res.getQuantityString(R.plurals.details_last_update_days, (int) days, days);
} else if (months < 1) {
return res.getQuantityString(R.plurals.details_last_update_weeks, (int) weeks, weeks);
} else if (years < 1) {
return res.getQuantityString(R.plurals.details_last_update_months, (int) months, months);
} else {
return res.getQuantityString(R.plurals.details_last_update_years, (int) years, years);
}
}
示例3: onBindViewHolder
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (mCursor == null) {
return;
}
mCursor.moveToPosition(position);
int id = mCursor.getColumnIndexOrThrow(PlantEntry._ID);
String name = mCursor.getString(mCursor.getColumnIndexOrThrow(PlantEntry.COLUMN_NAME));
int price = mCursor.getInt(mCursor.getColumnIndexOrThrow(PlantEntry.COLUMN_PRICE));
int quantity = mCursor.getInt(mCursor.getColumnIndexOrThrow(PlantEntry.COLUMN_CART_QUANTITY));
int totalPrice = price * quantity;
ViewHolder view = (ViewHolder) holder;
Resources resources = view.itemView.getContext().getResources();
String itemPrice = resources.getQuantityString(R.plurals.number_of_credits, price, price);
String totalPriceString = resources.getQuantityString(R.plurals.number_of_credits, totalPrice, totalPrice);
view.itemId = mCursor.getInt(id);
view.mTextViewItemName.setText(name);
view.mTextViewItemPrice.setText(itemPrice);
view.mTextViewItemQuantity.setText(String.valueOf(quantity));
view.mTextViewItemTotalPrice.setText(totalPriceString);
view.updateUi();
}
示例4: onBindViewHolder
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (mCursor == null) {
return;
}
mCursor.moveToPosition(position);
int id = mCursor.getColumnIndexOrThrow(PlantEntry._ID);
String name = mCursor.getString(mCursor.getColumnIndexOrThrow(PlantEntry.COLUMN_NAME));
int price = mCursor.getInt(mCursor.getColumnIndexOrThrow(PlantEntry.COLUMN_PRICE));
ViewHolder view = (ViewHolder) holder;
Resources resources = view.itemView.getContext().getResources();
String priceString = resources.getQuantityString(R.plurals.number_of_credits, price, price);
view.itemId = mCursor.getInt(id);
view.mTextViewItemName.setText(name);
view.mTextViewItemPrice.setText(priceString);
}
示例5: getTimeString
import android.content.res.Resources; //導入方法依賴的package包/類
private CharSequence getTimeString(ForeignSession session) {
long timeDeltaMs = System.currentTimeMillis() - session.modifiedTime;
if (timeDeltaMs < 0) timeDeltaMs = 0;
int daysElapsed = (int) (timeDeltaMs / (24L * 60L * 60L * 1000L));
int hoursElapsed = (int) (timeDeltaMs / (60L * 60L * 1000L));
int minutesElapsed = (int) (timeDeltaMs / (60L * 1000L));
Resources res = getResources();
String relativeTime;
if (daysElapsed > 0L) {
relativeTime = res.getQuantityString(R.plurals.n_days_ago, daysElapsed, daysElapsed);
} else if (hoursElapsed > 0L) {
relativeTime = res.getQuantityString(R.plurals.n_hours_ago, hoursElapsed, hoursElapsed);
} else if (minutesElapsed > 0L) {
relativeTime = res.getQuantityString(R.plurals.n_minutes_ago, minutesElapsed,
minutesElapsed);
} else {
relativeTime = res.getString(R.string.just_now);
}
return getResources().getString(R.string.ntp_recent_tabs_last_synced, relativeTime);
}
示例6: getChangeSummary
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Produce a summary of the Zen mode change to be read aloud as TTS.
*/
private CharSequence getChangeSummary(int mode, int minutes) {
int indefinite = -1;
int byMinute = -1;
int byHour = -1;
int byTime = -1;
switch (mode) {
case Global.ZEN_MODE_ALARMS:
indefinite = R.string.zen_mode_summary_alarms_only_indefinite;
byMinute = R.plurals.zen_mode_summary_alarms_only_by_minute;
byHour = R.plurals.zen_mode_summary_alarms_only_by_hour;
byTime = R.string.zen_mode_summary_alarms_only_by_time;
break;
case Global.ZEN_MODE_OFF:
indefinite = R.string.zen_mode_summary_always;
break;
};
if (minutes < 0 || mode == Global.ZEN_MODE_OFF) {
return getString(indefinite);
}
long time = System.currentTimeMillis() + minutes * MINUTES_MS;
String skeleton = DateFormat.is24HourFormat(this, UserHandle.myUserId()) ? "Hm" : "hma";
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
CharSequence formattedTime = DateFormat.format(pattern, time);
Resources res = getResources();
if (minutes < 60) {
return res.getQuantityString(byMinute, minutes, minutes, formattedTime);
} else if (minutes % 60 != 0) {
return res.getString(byTime, formattedTime);
} else {
int hours = minutes / 60;
return res.getQuantityString(byHour, hours, hours, formattedTime);
}
}
示例7: onBindViewHolder
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
VideoViewHolder vh = (VideoViewHolder)viewHolder;
Season season = (Season) item;
// setup the watched flag BEFORE the poster because it is handled in a strange way in the ImageCardViewTarget
// We show the top-right corner icon like for the individual videos, for consistency
vh.mImageCardViewTarget.setWatchedFlag(season.allEpisodesWatched());
vh.updateCardView(season.getPosterUri());
final ImageCardView card = vh.getImageCardView();
card.setTitleText(mContext.getString(R.string.season_identification, season.getSeasonNumber()));
card.setContentText(mContext.getResources().getQuantityString(R.plurals.Nepisodes, season.getEpisodeTotalCount(), season.getEpisodeTotalCount()));
final Resources r = mContext.getResources();
String desc;
int color;
if (season.allEpisodesWatched()) {
desc = r.getString(R.string.all_episodes_watched);
color = r.getColor(R.color.leanback_all_episodes_watched);
}
else if (season.allEpisodesNotWatched()) {
desc = r.getString(R.string.no_episode_watched);
color = r.getColor(R.color.leanback_no_episode_watched);
}
else {
desc = r.getQuantityString(R.plurals.n_episodes_watched, season.getEpisodeWatchedCount(), season.getEpisodeWatchedCount());
color = r.getColor(R.color.leanback_n_episodes_watched);
}
vh.setWatchedMessage(desc);
vh.setWatchedColor(color);
}
示例8: getTimeSince
import android.content.res.Resources; //導入方法依賴的package包/類
public static String getTimeSince(long time, Context c) {
if (time < 1000000000000L) {
// if timestamp given in seconds, convert to millis
time *= 1000;
}
long now = System.currentTimeMillis();
if (time > now || time <= 0) {
return null;
}
Resources res = c.getResources();
final long diff = now - time;
if (diff < SECOND_MILLIS) {
return res.getQuantityString(R.plurals.time_seconds, 0, 0);
} else if (diff < MINUTE_MILLIS) {
int seconds = longToInt(diff / MINUTE_MILLIS);
return res.getQuantityString(R.plurals.time_seconds, seconds, seconds);
} else if (diff < HOUR_MILLIS) {
int minutes = longToInt(diff / MINUTE_MILLIS);
return res.getQuantityString(R.plurals.time_minutes, minutes, minutes);
} else if (diff < DAY_MILLIS) {
int hours = longToInt(diff / HOUR_MILLIS);
return res.getQuantityString(R.plurals.time_hours, hours, hours);
} else if (diff < MONTH_MILLIS) {
int days = longToInt(diff / DAY_MILLIS);
return res.getQuantityString(R.plurals.time_days, days, days);
} else if (diff < YEAR_MILLIS) {
int months = longToInt(diff / MONTH_MILLIS);
return res.getQuantityString(R.plurals.time_months, months, months);
} else {
int years = longToInt(diff / YEAR_MILLIS);
return res.getQuantityString(R.plurals.time_years, years, years);
}
}
示例9: getTimeInHoursAndMins
import android.content.res.Resources; //導入方法依賴的package包/類
public static String getTimeInHoursAndMins(int mins, Context c) {
int hours = mins / 60;
int minutes = mins - (hours * 60);
Resources res = c.getResources();
String hour = "";
String minute = "";
if (hours > 0)
hour = res.getQuantityString(R.plurals.time_hours, hours, hours);
if (minutes > 0)
minute = res.getQuantityString(R.plurals.time_minutes, minutes, minutes);
return hour.isEmpty() ? minute : hour + " " + minute;
}
示例10: getActionModeQuantityString
import android.content.res.Resources; //導入方法依賴的package包/類
private String getActionModeQuantityString(final int quantity) {
final Resources res = getResources();
if (getCurrentFeedFragment().isAdded()) {
return res.getQuantityString(R.plurals.action_mode_current_feed, quantity);
} else if (getFeedSubscriptionsFragment().isAdded()) {
return res.getQuantityString(R.plurals.action_mode_feed_subscriptions, quantity);
}
return res.getQuantityString(R.plurals.action_mode_saved_entries, quantity);
}
示例11: showFontDetailsDialog
import android.content.res.Resources; //導入方法依賴的package包/類
public void showFontDetailsDialog(Context context, String title, String message, double rating,
int ratingCount) {
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View viewFontDetails = inflater.inflate(R.layout.dialog_font_details, null);
//To make sure Font FileName doesn't end up as a clickable url because it is automatically
//turned into a url
final SpannableString content = new SpannableString(message);
Linkify.addLinks(content, Patterns.WEB_URL, null, new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence seq, int start, int end) {
String url = seq.subSequence(start, end).toString();
//Apply the default matcher too. This will remove filenames that matched.
return !url.contains(".ttf") && Linkify.sUrlMatchFilter
.acceptMatch(seq, start, end);
}
}, null);
TextView tvMessage = (TextView) viewFontDetails
.findViewById(R.id.text_font_details_message);
if (tvMessage != null) {
tvMessage.setText(content);
tvMessage.setMovementMethod(LinkMovementMethod.getInstance()); //Making link clickable
tvMessage.setLinkTextColor(ContextCompat.getColor(context, R.color.blue));
}
final Dialog dialog = new LovelyCustomDialog(context)
.setView(viewFontDetails)
.setTopColorRes(R.color.colorPrimaryLight)
.setTitle(title)
.setIcon(R.drawable.ic_info_outline)
.show();
TextView btnGotIt = (TextView) viewFontDetails.findViewById(R.id.button_font_details_got_it);
btnGotIt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
});
TextView tvRating = (TextView) viewFontDetails.findViewById(R.id.tv_rating);
Resources res = getResources();
String text = res.getQuantityString(R.plurals.dialog_font_rating, ratingCount,
formatToOneDecimalPlace(rating),
formatToOneDecimalPlace(res.getInteger(R.integer.rating_max_possible_value)),
ratingCount);
tvRating.setText(text);
}
示例12: setAvailableAdLeft
import android.content.res.Resources; //導入方法依賴的package包/類
public void setAvailableAdLeft(int count) {
Resources res = getResources();
String numberofAdLeftInString = res.getQuantityString(R.plurals.view_tubi_ad_learn_more_ads_resume_shortly_text, count, count);
this.tubiObservable.numberOfAdLeft.set(numberofAdLeftInString);
}
示例13: localizePlural
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 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);
}