当前位置: 首页>>代码示例>>Java>>正文


Java Resources.getQuantityString方法代码示例

本文整理汇总了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 "";
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:22,代码来源:ICalendarUtils.java

示例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);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:20,代码来源:Utils.java

示例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();
}
 
开发者ID:laramartin,项目名称:android_firebase_green_thumb,代码行数:25,代码来源:ShoppingCartAdapter.java

示例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);
}
 
开发者ID:laramartin,项目名称:android_firebase_green_thumb,代码行数:19,代码来源:PlantAdapter.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:RecentTabsGroupView.java

示例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);
    }
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:41,代码来源:ZenModeVoiceActivity.java

示例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);
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:34,代码来源:SeasonPresenter.java

示例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);
    }
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:37,代码来源:TimeUtils.java

示例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;
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:14,代码来源:TimeUtils.java

示例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);
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:12,代码来源:MainActivity.java

示例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);
}
 
开发者ID:wahibhaq,项目名称:urdu-font-comparator-app,代码行数:51,代码来源:MainFragment.java

示例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);
}
 
开发者ID:Tubitv,项目名称:TubiPlayer,代码行数:6,代码来源:TubiPlayerControlView.java

示例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);
}
 
开发者ID:AndProx,项目名称:AndProx,代码行数:14,代码来源:Utils.java


注:本文中的android.content.res.Resources.getQuantityString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。