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) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.hichinaschool.flashcards.anki.ReadText.java

public static void textToSpeech(String text, long did, int ord, int qa) {
    mTextToSpeak = text;//from ww w .j  a  v a  2s  . com
    mQuestionAnswer = qa;
    mDid = did;
    mOrd = ord;

    String language = getLanguage(mDid, mOrd, mQuestionAnswer);
    if (availableTtsLocales.isEmpty()) {
        Locale[] systemLocales = Locale.getAvailableLocales();
        for (Locale loc : systemLocales) {
            if (mTts.isLanguageAvailable(loc) == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
                availableTtsLocales.add(new String[] { loc.getISO3Language(), loc.getDisplayName() });
            }
        }
    }

    // Check, if stored language is available
    for (int i = 0; i < availableTtsLocales.size(); i++) {
        if (language.equals(NO_TTS)) {
            return;
        } else if (language.equals(availableTtsLocales.get(i)[0])) {
            speak(mTextToSpeak, language);
            return;
        }
    }

    // Otherwise ask
    Resources res = mReviewer.getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(mReviewer);
    if (availableTtsLocales.size() == 0) {
        builder.setTitle(res.getString(R.string.no_tts_available_title));
        builder.setMessage(res.getString(R.string.no_tts_available_message));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.ok), null);
    } else {
        ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
        final ArrayList<String> dialogIds = new ArrayList<String>();
        builder.setTitle(R.string.select_locale_title);
        // Add option: "no tts"
        dialogItems.add(res.getString(R.string.tts_no_tts));
        dialogIds.add(NO_TTS);
        for (int i = 0; i < availableTtsLocales.size(); i++) {
            dialogItems.add(availableTtsLocales.get(i)[1]);
            dialogIds.add(availableTtsLocales.get(i)[0]);
        }
        String[] items = new String[dialogItems.size()];
        dialogItems.toArray(items);

        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                MetaDB.storeLanguage(mReviewer, mDid, mOrd, mQuestionAnswer, dialogIds.get(which));
                speak(mTextToSpeak, dialogIds.get(which));
            }
        });
    }
    builder.create().show();
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java

public static String buildDescription(SensorTrigger trigger, Activity activity) {
    Resources res = activity.getResources();
    int actionType = trigger.getActionType();
    String action = "";
    if (actionType == TriggerInformation.TRIGGER_ACTION_START_RECORDING) {
        action = res.getString(R.string.trigger_type_start_recording);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_STOP_RECORDING) {
        action = res.getString(R.string.trigger_type_stop_recording);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_NOTE) {
        action = res.getString(R.string.trigger_type_note);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_ALERT) {
        action = res.getString(R.string.trigger_type_alert);
    }/*from w  ww  .  jav a 2  s .  c  o  m*/
    String units = AppSingleton.getInstance(activity).getSensorAppearanceProvider()
            .getAppearance(trigger.getSensorId()).getUnits(activity);
    Double value = trigger.getValueToTrigger();
    String result = "";
    int when = trigger.getTriggerWhen();
    if (when == TriggerInformation.TRIGGER_WHEN_AT) {
        result = res.getString(R.string.trigger_when_at_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_RISES_ABOVE) {
        result = res.getString(R.string.trigger_when_rises_above_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_DROPS_BELOW) {
        result = res.getString(R.string.trigger_when_drops_below_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_ABOVE) {
        result = res.getString(R.string.trigger_when_above_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_BELOW) {
        result = res.getString(R.string.trigger_when_above_description, action, value, units);
    }
    return result;
}

From source file:com.deepak.myclock.alarms.AlarmNotifications.java

public static void showHighPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying high priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, MainActivity.class, alarmId);
    //viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());//  w  ww.j  a va 2  s.  co m
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.deepak.myclock.alarms.AlarmNotifications.java

public static void showLowPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying low priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance,
            AlarmInstance.HIDE_NOTIFICATION_STATE);
    notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, MainActivity.class, alarmId);
    //viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());//from w  w  w.j  ava 2 s  .c  o m
    nm.notify(instance.hashCode(), notification.build());
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static String getPrefString(SharedPreferences prefs, Resources res, int key) {
    return prefs.getString(res.getString(key), null);
}

From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java

public static void showHighPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying high priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM);

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId);
    viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());/*from w  w  w.j  ava  2 s  . co m*/
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.google.android.gms.common.internal.zzt.java

private static String a(final Context context, String s, final String s2) {
    final Resources resources = context.getResources();
    String s3;//  w  ww. ja v a  2s  .  c  o m
    s = (s3 = a(context, s));
    if (s == null) {
        s3 = resources.getString(R$string.common_google_play_services_unknown_issue);
    }
    return String.format(resources.getConfiguration().locale, s3, s2);
}

From source file:com.google.android.gms.common.internal.zzt.java

@NonNull
public static String e(final Context context, final int n) {
    final Resources resources = context.getResources();
    String s = null;/*from ww w. ja v  a2 s . co  m*/
    switch (n) {
    default: {
        s = resources.getString(17039370);
        break;
    }
    case 1: {
        s = resources.getString(R$string.common_google_play_services_install_button);
        break;
    }
    case 3: {
        s = resources.getString(R$string.common_google_play_services_enable_button);
        break;
    }
    case 2: {
        s = resources.getString(R$string.common_google_play_services_update_button);
        break;
    }
    }
    return s;
}

From source file:gr.scify.newsum.Utils.java

public static java.util.Map<CharSequence, Integer> getThemeMap(Activity activity) {
    if (mThemesToIDs == null) {
        mThemesToIDs = new java.util.TreeMap<CharSequence, Integer>();
        Resources rRes = NewSumUiActivity.getAppContext(activity).getResources();
        mThemesToIDs.put(rRes.getString(R.string.theme_black_name), 0);
        mThemesToIDs.put(rRes.getString(R.string.theme_orange_name), 1);
        mThemesToIDs.put(rRes.getString(R.string.theme_blue_name), 2);
    }// w w w.  java 2  s . c om

    return mThemesToIDs;

}

From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java

public static void showLowPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying low priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT).setCategory(NotificationCompat.CATEGORY_ALARM);

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance,
            AlarmInstance.HIDE_NOTIFICATION_STATE);
    notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId);
    viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());/*from   www .j a v a  2s.co  m*/
    nm.notify(instance.hashCode(), notification.build());
}