Example usage for android.content Context getString

List of usage examples for android.content Context getString

Introduction

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

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:Main.java

public static void showToast(Context context, int s) {
    showToast(context, context.getString(s));
}

From source file:Main.java

private static String getPreferenceString(SharedPreferences sharedPref, Context context, int StrRes,
        int StrResDefValue) {
    return sharedPref.getString(context.getString(StrRes), context.getString(StrResDefValue));
}

From source file:Main.java

public static Toast show(Context context, @StringRes int showText, int duration) {
    return show(context, context.getString(showText), duration);
}

From source file:Main.java

/**
 * Returns true if the activity type is in the list.
 *
 * @param context the context//from w  w w. ja  v a2  s. c om
 * @param activityType the activity type
 * @param list the list
 */
private static boolean inList(Context context, String activityType, int[] list) {
    for (int i : list) {
        if (context.getString(i).equals(activityType)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String getResourceString(Context cc, int stringId) {
    String s = null;/* w w  w  . j av  a  2  s  .  co  m*/
    if (cc != null) {
        s = cc.getString(stringId);
    }
    return s;
}

From source file:Main.java

/**
 * Gets the application name specified by android:label in the AndroidManifest.xml.
 * It does not work if you hard-code your app name like android:label="MyApp".
 * Use a string resource such as @string/app_name.
 * @param context the context// w ww .  j a  va  2s . c o m
 * @return application name
 */
public static String getApplicationName(@NonNull Context context) {
    int stringId = context.getApplicationInfo().labelRes;
    return context.getString(stringId);
}

From source file:Main.java

public static void setError(Context context, EditText editText, int messageId) {
    editText.setError(Html.fromHtml("<font color='red'>" + context.getString(messageId) + "</font>"));
}

From source file:Main.java

@NonNull
public static Toast showLong(@NonNull Context context, @StringRes int stringRes) {
    return showLong(context, context.getString(stringRes));
}

From source file:Main.java

@NonNull
public static Toast showShort(@NonNull Context context, @StringRes int stringRes) {
    return showShort(context, context.getString(stringRes));
}

From source file:Main.java

/**
 * Gets a preference key from strings/*w  w  w  .  j  av  a2s. c  om*/
 *
 * @param context the context
 * @param keyId   the key id
 * @return the string key
 */
private static String getKey(Context context, @StringRes int keyId) {
    return context.getString(keyId);
}