List of usage examples for android.content.res Resources getString
@NonNull public String getString(@StringRes int id) throws NotFoundException
From source file:gr.scify.newsum.Utils.java
public static java.util.Map<CharSequence, Integer> getThemesToResourceIDs(Activity activity) { if (mThemesToResourceIDs == null) { mThemesToResourceIDs = new java.util.TreeMap<CharSequence, Integer>(); Resources rRes = NewSumUiActivity.getAppContext(activity).getResources(); mThemesToResourceIDs.put(rRes.getString(R.string.theme_black_name), R.style.Theme); mThemesToResourceIDs.put(rRes.getString(R.string.theme_orange_name), R.style.Theme_Orangesilver); mThemesToResourceIDs.put(rRes.getString(R.string.theme_blue_name), R.style.Theme_blue); }//from www. ja va 2 s . c om return mThemesToResourceIDs; }
From source file:ee.ioc.phon.android.speak.Utils.java
public static String getPrefString(SharedPreferences prefs, Resources res, int key, int defaultValue) { return prefs.getString(res.getString(key), res.getString(defaultValue)); }
From source file:ee.ioc.phon.android.speak.Utils.java
public static boolean getPrefBoolean(SharedPreferences prefs, Resources res, int key, int defaultValue) { return prefs.getBoolean(res.getString(key), res.getBoolean(defaultValue)); }
From source file:com.freshdigitable.udonroad.UserInfoActivity.java
public static void bindUserScreenName(TextView textView, User user) { final Resources resources = textView.getContext().getResources(); textView.setText(String.format(resources.getString(R.string.tweet_name), user.getScreenName())); }
From source file:eu.faircode.netguard.ServiceJob.java
private static void submit(Rule rule, PersistableBundle bundle, Context context) { PackageManager pm = context.getPackageManager(); JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); // Get english application label String label = null;/* w ww. ja v a 2 s . co m*/ try { Configuration config = new Configuration(); config.setLocale(new Locale("en")); Resources res = pm.getResourcesForApplication(rule.info.packageName); res.updateConfiguration(config, res.getDisplayMetrics()); label = res.getString(rule.info.applicationInfo.labelRes); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); CharSequence cs = rule.info.applicationInfo.loadLabel(pm); if (cs != null) label = cs.toString(); } // Add application data bundle.putInt("uid", rule.info.applicationInfo.uid); bundle.putString("package", rule.info.packageName); bundle.putInt("version_code", rule.info.versionCode); bundle.putString("version_name", rule.info.versionName); bundle.putString("label", label); bundle.putInt("system", rule.system ? 1 : 0); try { bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName)); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); bundle.putString("installer", null); } // Cancel overlapping jobs for (JobInfo pending : scheduler.getAllPendingJobs()) { String type = pending.getExtras().getString("type"); if (type != null && type.equals(bundle.getString("type"))) { if (type.equals("rule")) { int uid = pending.getExtras().getInt("uid"); if (uid == bundle.getInt("uid")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } else if (type.equals("host")) { int uid = pending.getExtras().getInt("uid"); int version = pending.getExtras().getInt("version"); int protocol = pending.getExtras().getInt("protocol"); String daddr = pending.getExtras().getString("daddr"); int dport = pending.getExtras().getInt("dport"); if (uid == bundle.getInt("uid") && version == bundle.getInt("version") && protocol == bundle.getInt("protocol") && daddr != null && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } } } // Schedule job ComponentName serviceName = new ComponentName(context, ServiceJob.class); JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle) .setPersisted(true).build(); if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS) Log.i(TAG, "Scheduled job=" + job.getId() + " success"); else Log.e(TAG, "Scheduled job=" + job.getId() + " failed"); }
From source file:com.digitalarx.android.utils.ErrorMessageAdapter.java
public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation, Resources res) { String message = null;// ww w .ja v a 2 s . com if (operation instanceof UploadFileOperation) { if (result.isSuccess()) { message = String.format(res.getString(R.string.uploader_upload_succeeded_content_single), ((UploadFileOperation) operation).getFileName()); } else { if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL || result.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) { message = String.format(res.getString(R.string.error__upload__local_file_not_copied), ((UploadFileOperation) operation).getFileName(), res.getString(R.string.app_name)); } else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) { message = res.getString(R.string.failed_upload_quota_exceeded_text); } else { message = String.format(res.getString(R.string.uploader_upload_failed_content_single), ((UploadFileOperation) operation).getFileName()); } } } else if (operation instanceof DownloadFileOperation) { if (result.isSuccess()) { message = String.format(res.getString(R.string.downloader_download_succeeded_content), new File(((DownloadFileOperation) operation).getSavePath()).getName()); } else { message = String.format(res.getString(R.string.downloader_download_failed_content), new File(((DownloadFileOperation) operation).getSavePath()).getName()); } } else if (operation instanceof RemoveFileOperation) { if (result.isSuccess()) { message = res.getString(R.string.remove_success_msg); } else { if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { message = res.getString(R.string.remove_fail_msg); } } } else if (operation instanceof RenameFileOperation) { if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { message = res.getString(R.string.rename_local_fail_msg); } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { message = res.getString(R.string.filename_forbidden_characters); } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { message = res.getString(R.string.rename_server_fail_msg); } } else if (operation instanceof SynchronizeFileOperation) { if (!((SynchronizeFileOperation) operation).transferWasRequested()) { message = res.getString(R.string.sync_file_nothing_to_do_msg); } } else if (operation instanceof CreateFolderOperation) { if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) { message = res.getString(R.string.filename_forbidden_characters); } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { message = res.getString(R.string.create_dir_fail_msg); } } else if (operation instanceof CreateShareOperation) { if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND message = res.getString(R.string.share_link_file_no_exist); } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.share_link_file_error); } } else if (operation instanceof UnshareLinkOperation) { if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND message = res.getString(R.string.unshare_link_file_no_exist); } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.unshare_link_file_error); } } return message; }
From source file:com.cerema.cloud2.utils.ErrorMessageAdapter.java
private static String getErrorMessage(RemoteOperationResult result, Resources res) { String message = null;/*from w ww . j av a 2 s . c o m*/ if (!result.isSuccess()) { if (result.getCode() == ResultCode.WRONG_CONNECTION) { message = res.getString(R.string.network_error_socket_exception); } else if (result.getCode() == ResultCode.TIMEOUT) { message = res.getString(R.string.network_error_socket_exception); if (result.getException() instanceof SocketTimeoutException) { message = res.getString(R.string.network_error_socket_timeout_exception); } else if (result.getException() instanceof ConnectTimeoutException) { message = res.getString(R.string.network_error_connect_timeout_exception); } } else if (result.getCode() == ResultCode.HOST_NOT_AVAILABLE) { message = res.getString(R.string.network_host_not_available); } } return message; }
From source file:Main.java
/** * Returns the string corresponding to a resource name in a specific package. * * @param context The parent context./*www .j av a 2 s . c o m*/ * @param packageName The application's package name, e.g. "com.android.settings". * @param resName The short name of the resource, e.g. "ok". * @return A package-specific string, or {@code null}. */ public static String getPackageString(Context context, String packageName, String resName) { final PackageManager pm = context.getPackageManager(); final Resources packageRes; try { packageRes = pm.getResourcesForApplication(packageName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } final int resId = packageRes.getIdentifier(resName, "string", packageName); if (resId <= 0) { return null; } final String result; try { result = packageRes.getString(resId); } catch (Resources.NotFoundException e) { e.printStackTrace(); return null; } return result; }
From source file:cm.android.download.providers.downloads.DownloadNotifier.java
private static CharSequence getDownloadTitle(Resources res, DownloadInfo info) { if (!TextUtils.isEmpty(info.mTitle)) { return info.mTitle; } else {/* w ww .j a va 2s . co m*/ return res.getString(R.string.download_unknown_title); } }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
static private String transformPassword(String password) { Context context = App.getAppContext(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Resources res = context.getResources(); String showPasswordString = res.getString(R.string.show_password_default); boolean showPassword = showPasswordString.equals("true"); showPassword = sp.getBoolean("show_password", showPassword); if (showPassword) return password; else {// w ww.j av a2 s .c o m StringBuilder sb = new StringBuilder(password.length()); for (int i = 0; i < password.length(); ++i) sb.append('*'); return sb.toString(); } }