List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.samknows.measurement.util.LoginHelper.java
public static Dialog showLoginDialog(Context c) { Dialog dialog = ProgressDialog.show(c, "", c.getString(R.string.logging_in), true); dialog.show();// w w w . j av a2 s. c o m return dialog; }
From source file:Main.java
public static String getApplicationName(Context context) { ApplicationInfo applicationInfo = context.getApplicationInfo(); int stringId = applicationInfo.labelRes; return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId); }
From source file:Main.java
public static String getStringByName(Context context, String name) { int resid = context.getResources().getIdentifier(name, "string", context.getPackageName()); if (resid == 0) return null; return context.getString(resid); }
From source file:Main.java
static String getStringResourceByName(String name, Context context) { try {//from w w w. j a v a 2s . com String packageName = context.getPackageName(); int resId = context.getResources().getIdentifier(name, "string", packageName); return context.getString(resId); } catch (Exception ignored) { } return null; }
From source file:Main.java
/** * Returns the Google API CLIENT ID to use in API calls * * @param applicationContext/*from w w w . j a v a2 s . c om*/ * @return */ private static String GetClientID(Context applicationContext) { int RClientId = applicationContext.getResources().getIdentifier("gdocs_clientid", "string", applicationContext.getPackageName()); return applicationContext.getString(RClientId); }
From source file:Main.java
/** * Function use through the app to show Toast information. Function is called so often from * background, that it's content is explicitly called from UIThread. * * @param appContext - application context * @param stringResourceId of text we show * @param handler to UIThread/*w w w . j av a 2 s. c o m*/ */ public static void showToast(final Context appContext, final int stringResourceId, Handler handler) { handler.post(new Runnable() { @Override public void run() { Toast.makeText(appContext, appContext.getString(stringResourceId), Toast.LENGTH_SHORT).show(); } }); }
From source file:com.hippo.util.ExceptionUtils.java
@NonNull public static String getReadableString(@NonNull Context context, @NonNull Exception e) { if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException) { return context.getString(R.string.error_timeout); } else if (e instanceof UnknownHostException) { return context.getString(R.string.error_unknown_host); } else if (e instanceof StatusCodeException) { StatusCodeException sce = (StatusCodeException) e; StringBuilder sb = new StringBuilder(); sb.append(context.getString(R.string.error_bad_status_code, sce.getResponseCode())); if (sce.isIdentifiedResponseCode()) { sb.append(", ").append(sce.getMessage()); }//from www. jav a2 s. c o m return sb.toString(); } else if (e instanceof ProtocolException && e.getMessage().startsWith("Too many follow-up requests:")) { return context.getString(R.string.error_redirection); } else if (e instanceof ProtocolException || e instanceof SocketException) { return context.getString(R.string.error_socket); } else if (e instanceof EhException) { return e.getMessage(); } else { return context.getString(R.string.error_unknown); } }
From source file:Main.java
/** * Returns the Google API CLIENT SECRET to use in API calls * * @param applicationContext/*from w ww . j ava2s. com*/ * @return */ private static String GetClientSecret(Context applicationContext) { int RClientSecret = applicationContext.getResources().getIdentifier("gdocs_clientsecret", "string", applicationContext.getPackageName()); return applicationContext.getString(RClientSecret); }
From source file:org.gc.networktester.util.Util.java
public static String typicalHttpclientExceptionToString(Context ctx, Exception e) { return e instanceof UnknownHostException ? ctx.getString(R.string.typical_error_unknownhost) : e instanceof ConnectTimeoutException ? ctx.getString(R.string.typical_error_connectiontimeout) : e instanceof ConnectException ? ctx.getString(R.string.typical_error_connectionrefused) : e instanceof SocketTimeoutException ? ctx.getString(R.string.typical_error_sockettimeout) : exceptionMessageOrClass(e); }
From source file:com.geotrackin.gpslogger.senders.osm.OSMHelper.java
public static OAuthProvider GetOSMAuthProvider(Context ctx) { return new CommonsHttpOAuthProvider(ctx.getString(R.string.osm_requesttoken_url), ctx.getString(R.string.osm_accesstoken_url), ctx.getString(R.string.osm_authorize_url)); }