Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id, Object... formatArgs) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID, substituting the format arguments as defined in java.util.Formatter and java.lang.String#format .

Usage

From source file:com.tassadar.multirommgr.installfragment.InstallCard.java

@Override
public View getCardContent(Context context) {
    m_view = LayoutInflater.from(context).inflate(R.layout.install_card, null);

    Resources res = m_view.getResources();

    CheckBox b = (CheckBox) m_view.findViewById(R.id.install_multirom);
    b.setText(res.getString(R.string.install_multirom, m_manifest.getMultiromVersion()));
    b.setChecked(m_manifest.hasMultiromUpdate());
    b.setOnCheckedChangeListener(this);

    b = (CheckBox) m_view.findViewById(R.id.install_recovery);
    if (m_manifest.getRecoveryFile() != null) {
        final Date rec_date = m_manifest.getRecoveryVersion();
        final String recovery_ver = Recovery.DISPLAY_FMT.format(rec_date);
        b.setText(res.getString(R.string.install_recovery, recovery_ver));
        b.setChecked(m_manifest.hasRecoveryUpdate());
        b.setOnCheckedChangeListener(this);

        // Force user to install recovery if not yet installed - it is needed to flash ZIPs
        if (m_manifest.hasRecoveryUpdate() && m_forceRecovery) {
            b.append(Html.fromHtml(res.getString(R.string.required)));
            b.setClickable(false);//  www.  jav  a  2s.  c o  m
        }
    } else {
        b.setChecked(false);
        b.setVisibility(View.GONE);
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
            android.R.layout.simple_spinner_dropdown_item);
    adapter.addAll(m_manifest.getKernels().keySet());
    Spinner s = (Spinner) m_view.findViewById(R.id.kernel_options);
    s.setAdapter(adapter);
    s.setEnabled(false);
    s.setSelection(getDefaultKernel());

    b = (CheckBox) m_view.findViewById(R.id.install_kernel);
    b.setOnCheckedChangeListener(this);
    b.setEnabled(!adapter.isEmpty());
    b.setChecked(!adapter.isEmpty() && m_manifest.hasKernelUpdate());

    Button install_btn = (Button) m_view.findViewById(R.id.install_btn);
    install_btn.setOnClickListener(this);

    ImageButton changelog_btn = (ImageButton) m_view.findViewById(R.id.changelog_btn);
    if (m_manifest.getChangelogs() == null || m_manifest.getChangelogs().length == 0)
        changelog_btn.setVisibility(View.GONE);
    else
        changelog_btn.setOnClickListener(this);

    if (m_savedState != null)
        restoreInstanceState();

    enableInstallBtn();
    return m_view;
}

From source file:com.classiqo.nativeandroid_32bitz.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createBrowsableMediaItemForGenre(String genre, Resources resources) {
    MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
            .setMediaId(createMediaID(null, MEDIA_ID_MUSICS_BY_GENRE, genre)).setTitle(genre)
            .setSubtitle(resources.getString(R.string.browse_musics_by_genre_subtitle, genre)).build();

    return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private void showUpdated(String packageName, int size) {
    try {// w w  w  .  ja  v a2s . co m
        PackageManager pm = mContext.getPackageManager();
        Resources resources = pm.getResourcesForApplication(BuildConfig.APPLICATION_ID);
        String message = resources.getString(R.string.updated_prevents, size) + "(" + getLabel(pm, packageName)
                + ")";
        Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
    } catch (PackageManager.NameNotFoundException e) {
        PreventLog.d("cannot find application " + BuildConfig.APPLICATION_ID, e);
    } catch (RuntimeException e) {
        PreventLog.d("cannot show toast", e);
    }
}

From source file:com.example.android.AudioArchive.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createBrowsableMediaItemForGenre(String genre, Resources resources) {
    MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
            .setMediaId(createMediaID(null, MEDIA_ID_MUSICS_BY_GENRE, genre)).setTitle(genre)
            .setSubtitle(resources.getString(R.string.browse_musics_by_genre_subtitle, genre)).build();
    return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}

From source file:com.ewintory.footballscores.ui.adapter.ScoresAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final Resources res = mFragment.getResources();
    mCursor.moveToPosition(position);// w w  w . j  av a2s .c  o  m

    holder.mLeagueName.setText(Utilities.getLeague(res, mCursor.getInt(ScoresQuery.LEAGUE)));
    holder.mHomeName.setText(mCursor.getString(ScoresQuery.HOME));
    holder.mAwayName.setText(mCursor.getString(ScoresQuery.AWAY));
    holder.mMatchDay.setText(res.getString(R.string.match_day, mCursor.getInt(ScoresQuery.MATCH_DAY)));
    holder.mScore.setText(Utilities.getScores(res, mCursor.getInt(ScoresQuery.HOME_GOALS),
            mCursor.getInt(ScoresQuery.AWAY_GOALS)));

    holder.mHomeCrest.setImageResource(Utilities.getTeamCrestByTeamName(mCursor.getString(ScoresQuery.HOME)));
    holder.mAwayCrest.setImageResource(Utilities.getTeamCrestByTeamName(mCursor.getString(ScoresQuery.AWAY)));

    //        Uri uri = Uri.parse(mCursor.getString(ScoresQuery.HOME_CREST));
    //        requestBuilder
    //                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    //                .load(uri)
    //                .into(holder.mHomeCrest);
    //
    //        uri = Uri.parse(mCursor.getString(ScoresQuery.AWAY_CREST));
    //        requestBuilder
    //                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    //                .load(uri)
    //                .into(holder.mAwayCrest);
}

From source file:com.google.android.apps.iosched.calendar.SessionAlarmService.java

/**
 * Constructs and triggers system notification for when starred sessions are about to begin.
 *//*from ww  w  . jav a 2s  .  c  o m*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime = System.currentTimeMillis();
    if (sessionStart < currentTime) {
        return;
    }

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver resolver = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor cursor = resolver.query(starredBlockUri, new String[] { ScheduleContract.Blocks.NUM_STARRED_SESSIONS,
            ScheduleContract.Sessions.SESSION_TITLE }, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    while (cursor.moveToNext()) {
        starredSessionTitles.add(cursor.getString(1));
        starredCount = cursor.getInt(0);
    }

    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user touches on the notification.
    Intent sessionIntent = new Intent(Intent.ACTION_VIEW, starredBlockUri);
    sessionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pi = PendingIntent.getActivity(this, 0, sessionIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    // Construct a notification. Use Jelly Bean (API 16) rich notifications if possible.
    Notification notification;
    if (UIUtils.hasJellyBean()) {
        // Rich notifications
        Notification.Builder builder = new Notification.Builder(this)
                .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
                .setTicker(res
                        .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
                .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
        if (minutesLeft > 5) {
            builder.addAction(R.drawable.ic_alarm_holo_dark,
                    String.format(res.getString(R.string.snooze_x_min), 5),
                    createSnoozeIntent(sessionStart, sessionEnd, 5));
        }
        Notification.InboxStyle richNotification = new Notification.InboxStyle(builder)
                .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                        minutesLeft, starredCount));

        // Adds starred sessions starting at this time block to the notification.
        for (int i = 0; i < starredCount; i++) {
            richNotification.addLine(starredSessionTitles.get(i));
        }
        notification = richNotification.build();

    } else {
        // Pre-Jelly Bean non-rich notifications
        notification = new NotificationCompat.Builder(this).setContentTitle(starredSessionTitles.get(0))
                .setContentText(contentText)
                .setTicker(res
                        .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi).getNotification();
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, notification);
}

From source file:com.conferenceengineer.android.iosched.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime;
    if (sessionStart < (currentTime = UIUtils.getCurrentTime(this)))
        return;//w ww  . j a va 2  s  .  c o m

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver cr = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    ArrayList<String> starredSessionRoomIds = new ArrayList<String>();
    String sessionId = null; // needed to get session track icon
    while (c.moveToNext()) {
        sessionId = c.getString(SessionDetailQuery.SESSION_ID);
        starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class))
            .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri))
            .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.conference_ic_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (starredCount == 1) {
        // get the track icon to show as the notification big picture
        Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId);
        Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null);
        if (tracksCursor.moveToFirst()) {
            String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME);
            int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR);
            Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour);
            if (trackIcon != null) {
                notifBuilder.setLargeIcon(trackIcon);
            }
        }
    }
    if (minutesLeft > 5) {
        notifBuilder.addAction(R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, sessionEnd, 5));
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                    minutesLeft, starredCount));

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:com.gdgdevfest.android.apps.devfestbcn.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime;
    if (sessionStart < (currentTime = UIUtils.getCurrentTime(this)))
        return;//  w w w.j ava  2  s .  com

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver cr = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    ArrayList<String> starredSessionRoomIds = new ArrayList<String>();
    String sessionId = null; // needed to get session track icon
    while (c.moveToNext()) {
        sessionId = c.getString(SessionDetailQuery.SESSION_ID);
        starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class))
            .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri))
            .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (starredCount == 1) {
        // get the track icon to show as the notification big picture
        Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId);
        Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null);
        if (tracksCursor.moveToFirst()) {
            String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME);
            int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR);
            Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour);
            if (trackIcon != null) {
                notifBuilder.setLargeIcon(trackIcon);
            }
        }
    }
    if (minutesLeft > 5) {
        notifBuilder.addAction(R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, sessionEnd, 5));
    }
    if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) {
        notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map),
                createRoomMapIntent(starredSessionRoomIds.get(0)));
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                    minutesLeft, starredCount));

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:com.ichi2.anki.dialogs.CustomStudyDialog.java

private String getText1() {
    Resources res = AnkiDroidApp.getAppResources();
    Collection col = CollectionHelper.getInstance().getCol(getActivity());
    switch (getArguments().getInt("id")) {
    case CUSTOM_STUDY_NEW:
        return res.getString(R.string.custom_study_new_total_new, col.getSched().totalNewForCurrentDeck());
    case CUSTOM_STUDY_REV:
        return res.getString(R.string.custom_study_rev_total_rev, col.getSched().totalRevForCurrentDeck());
    default:/*from  www . ja  v a  2 s .  co m*/
        return "";
    }
}

From source file:com.ichi2.anki.stats.OverviewStatsBuilder.java

private void appendTodaysStats(StringBuilder stringBuilder) {
    Stats stats = new Stats(mCol, mWholeCollection);
    int[] todayStats = stats.calculateTodayStats();
    stringBuilder.append(_title(mWebView.getResources().getString(R.string.stats_today)));
    Resources res = mWebView.getResources();
    final int minutes = (int) Math.round(todayStats[THETIME_INDEX] / 60.0);
    final String span = res.getQuantityString(R.plurals.time_span_minutes, minutes, minutes);
    stringBuilder.append(res.getQuantityString(R.plurals.stats_today_cards, todayStats[CARDS_INDEX],
            todayStats[CARDS_INDEX], span));
    stringBuilder.append("<br>");
    stringBuilder.append(res.getString(R.string.stats_today_again_count, todayStats[FAILED_INDEX]));
    if (todayStats[CARDS_INDEX] > 0) {
        stringBuilder.append(" ");
        stringBuilder.append(res.getString(R.string.stats_today_correct_count,
                (((1 - todayStats[FAILED_INDEX] / (float) (todayStats[CARDS_INDEX])) * 100.0))));
    }/*from   w  ww . jav  a2  s .  c  om*/
    stringBuilder.append("<br>");
    stringBuilder.append(res.getString(R.string.stats_today_type_breakdown, todayStats[LRN_INDEX],
            todayStats[REV_INDEX], todayStats[RELRN_INDEX], todayStats[FILT_INDEX]));
    stringBuilder.append("<br>");
    if (todayStats[MCNT_INDEX] != 0) {
        stringBuilder.append(res.getString(R.string.stats_today_mature_cards, todayStats[MSUM_INDEX],
                todayStats[MCNT_INDEX], (todayStats[MSUM_INDEX] / (float) (todayStats[MCNT_INDEX]) * 100.0)));
    } else {
        stringBuilder.append(res.getString(R.string.stats_today_no_mature_cards));
    }
}