Example usage for android.app Activity getString

List of usage examples for android.app Activity getString

Introduction

In this page you can find the example usage for android.app Activity 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(Activity activity, int stringId) {
    String message = activity.getString(stringId);
    if (message != null) {
        Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
    }//from   w w w.j a v a 2 s .  c  om
}

From source file:Main.java

public static void fireAlertDialog(Activity aty, int stringID) {
    new AlertDialog.Builder(aty).setMessage(aty.getString(stringID)).show();
}

From source file:Main.java

/**
 * Toast dialog with R.String/* w w  w  .j  a  v a2s .c  o  m*/
 */
public static void showToast(final int messageRes, final Activity activity) {
    showToast(activity.getString(messageRes), activity);
}

From source file:Main.java

/**
 * A method to get the string values from the res/strings.xml file.
 *
 * @param activity/* w w  w .j  av a2  s. c o  m*/
 * @param resId
 * @return string
 */
public static String getStringFromId(final Activity activity, int resId) {
    if (activity == null)
        return "";

    return activity.getString(resId);
}

From source file:de.k3b.android.toGoZip.PermissionHelper.java

public static void showNowPermissionMessage(Activity activity) {
    String format = activity.getString(R.string.ERR_NO_WRITE_PERMISSIONS);

    String msg = String.format(format, "", "");

    Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
}

From source file:Main.java

public static void updateTitle(Activity activity, int viewId, int resourceId) {
    TextView view = (TextView) activity.findViewById(viewId);
    String title = activity.getString(resourceId);
    updateTitle(view, title);/*from  w  w w  .ja  va  2 s  .c  o m*/
}

From source file:Main.java

public static final void setActivityTitle(Activity activity, int... ids) {
    StringBuilder title = new StringBuilder();
    for (int i = 0; i < ids.length; i++) {
        title.append(activity.getString(ids[i]));
        if (i < ids.length - 1) {
            title.append(TITLE_ENTRIES_SEPARATOR);
        }//from   ww  w  . j  a  v a 2  s  .  co  m
    }

    activity.setTitle(title);
}

From source file:com.viktorrudometkin.burramys.utils.UiUtils.java

static public void showMessage(@NonNull Activity activity, @StringRes int messageId) {
    showMessage(activity, activity.getString(messageId));
}

From source file:com.hemou.android.util.ToastUtils.java

/**
 * Show the message with the given resource id in a {@link Toast}
 * <p>// w  w  w . jav  a  2  s .  c  o  m
 * This method may be called from any thread
 * 
 * @param activity
 * @param resId
 */
public static void show(final Activity activity, final int resId) {
    if (activity == null)
        return;

    show(activity, activity.getString(resId));
}

From source file:com.google.samples.apps.iosched.util.RecentTasksStyler.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void styleRecentTasksEntry(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;//  w  w  w. j a v a  2  s.  co m
    }

    final String label = activity.getString(activity.getApplicationInfo().labelRes);
    final int colorPrimary = UIUtils.getThemeColor(activity, R.attr.colorPrimary, R.color.theme_primary);
    if (sIcon == null) {
        // Cache to avoid decoding the same bitmap on every Activity change
        sIcon = UIUtils.vectorToBitmap(activity, R.drawable.ic_recents_logo);
    }
    activity.setTaskDescription(new ActivityManager.TaskDescription(label, sIcon, colorPrimary));
}