List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId, Object... formatArgs)
From source file:Main.java
public static void showErrorMessage(Context context, int message, Object... args) { Toast.makeText(context, context.getString(message, args), Toast.LENGTH_LONG).show(); }
From source file:Main.java
public static void toast(Context context, int messageId, boolean shortDuration, Object... formatArgs) { toast(context, context.getString(messageId, formatArgs), shortDuration); }
From source file:ru.gkpromtech.exhibition.organizations.OrganizationFilesDownloader.java
private static void confirmAndDownload(final Context context, final Organization organization, final String url, int size) { String sizeStr = MiscUtils.humanReadableByteCount(size, true); String message = context.getString(R.string.download_materials_to_device, sizeStr); new AlertDialog.Builder(context).setTitle(R.string.save_materials).setMessage(message) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override/*from w w w .ja va2 s. co m*/ public void onClick(DialogInterface dialog, int which) { download(context, url, organization); } }).setNegativeButton(R.string.no, null).show(); }
From source file:Main.java
/** * @param context//from ww w. java2 s. co m * @param type * @param field * @param errResId * @param methodPrefix * @param methodParameters */ public static void checkIfMethodExists(Context context, Class<?> type, Field field, int errResId, String methodPrefix, Class<?>... methodParameters) { try { Method m = type.getDeclaredMethod(methodPrefix + getFirstLetterUppercased(field.getName()), methodParameters); if (!Modifier.isPublic(m.getModifiers()) || Modifier.isStatic(m.getModifiers())) throw new RuntimeException(context.getString(errResId, field.getName())); } catch (NoSuchMethodException e) { throw new RuntimeException(context.getString(errResId, field.getName())); } }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static void showShortMessage(Context context, int resId, Object... formatArgs) { showShortMessage(context, context.getString(resId, formatArgs)); }
From source file:com.hybris.mobile.app.commerce.helper.ProductHelper.java
/** * Fill Spinner list with arraylist of variantMatrixElement * * @param context/*w w w . ja v a 2 s.com*/ * @param spinner * @param variants * @param position */ public static void populateSpinner(Context context, Spinner spinner, List<VariantOption> variants, int position) { if (spinner != null && variants != null && !variants.isEmpty()) { VariantAdapter mVariantAdapter = new VariantAdapter(context, R.layout.item_product_variant, variants); spinner.setAdapter(mVariantAdapter); spinner.setPrompt(context.getString(R.string.choose_variant, ((List<VariantOptionQualifier>) variants.get(0).getVariantOptionQualifiers()).get(0) .getName())); spinner.setVisibility(View.VISIBLE); spinner.setSelection(position < variants.size() ? position : 0); } }
From source file:edu.mit.mobile.android.livingpostcards.data.Card.java
/** * Creates an {@link Intent#ACTION_SEND} intent to share the given card. * * @param context/*from w w w . j a va 2 s .c o m*/ * @param webUrl * the content of the card's {@link Card#COL_WEB_URL} field. Can be a relative URL. * @param title * the title of the card * @return an intent, within a chooser, that can be used with * {@link Context#startActivity(Intent)} */ public static Intent createShareIntent(Context context, String webUrl, CharSequence title) { final NetworkClient nc = LocastApplication.getNetworkClient(context, Authenticator.getFirstAccount(context)); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.send_intent_message, nc.getFullUrlAsString(webUrl))); sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.send_intent_subject, title)); return Intent.createChooser(sendIntent, context.getString(R.string.send_intent_chooser_title)); }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
@NonNull public static String toHumanReadableSize(Context context, long size, long precision) { Base2Abbrev abbrev = null;// w ww. jav a2 s . c om for (Base2Abbrev b2a : BASE2_ABBREVS) { if (size >= b2a.factor) { abbrev = b2a; break; } } if (abbrev == null) { return context.getString(R.string.format_bytes, size); } String decimal = String.format("%." + precision + "f", (double) size / abbrev.factor); return context.getString(abbrev.stringResId, decimal); }
From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java
/** * Given a logout handler and information about the app, create a standard logout dialog box * that prompts the user if they want to logout. * * @param context//from ww w. j ava 2s . co m * @param appName * the name of your app. This is integrated into the text using the * {@code auth_logout_title} and {@code auth_logout_message} string resources. * @param onLogoutHandler * @return */ public static Dialog createLogoutDialog(Context context, CharSequence appName, LogoutHandler onLogoutHandler) { final AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(context.getString(R.string.auth_logout_title, appName)); b.setMessage(context.getString(R.string.auth_logout_message, appName)); b.setCancelable(true); b.setPositiveButton(R.string.auth_logout, onLogoutHandler); b.setNegativeButton(android.R.string.cancel, null); return b.create(); }
From source file:com.ruesga.rview.misc.ActivityHelper.java
public static void handleUri(Context ctx, Uri uri) { try {/* w w w .jav a 2 s .c om*/ Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true); intent.putExtra(Constants.EXTRA_HAS_PARENT, true); intent.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName()); intent.setPackage(ctx.getPackageName()); ctx.startActivity(intent); } catch (ActivityNotFoundException ex) { // Fallback to default browser String msg = ctx.getString(R.string.exception_browser_not_found, uri.toString()); Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show(); } }