List of usage examples for android.content.res Resources getString
@NonNull public String getString(@StringRes int id) throws NotFoundException
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
public static void showErrorNotification(int errorCode, Context context) { Resources resources = context.getResources(); Notification notification = new Notification(17301642, resources.getString(C0192R.string.common_google_play_services_notification_ticker), System.currentTimeMillis()); notification.flags |= 16;/*from ww w . ja va 2s.co m*/ CharSequence e = m116e(context, errorCode); String u = m119u(context); notification.setLatestEventInfo(context, e, resources.getString(C0192R.string.common_google_play_services_error_notification_requested_by_msg, new Object[] { u }), getErrorPendingIntent(errorCode, context, 0)); ((NotificationManager) context.getSystemService("notification")).notify(39789, notification); }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
public static String m116e(Context context, int i) { Resources resources = context.getResources(); switch (i) {//from ww w . j av a 2 s . c o m case Std.STD_FILE /*1*/: return resources.getString(C0192R.string.f17x8f024ee1); case Std.STD_URL /*2*/: return resources.getString(C0192R.string.common_google_play_services_notification_needs_update_title); case Std.STD_URI /*3*/: return resources.getString(C0192R.string.common_google_play_services_needs_enabling_title); case Std.STD_JAVA_TYPE /*5*/: return resources.getString(C0192R.string.common_google_play_services_invalid_account_text); case Std.STD_PATTERN /*7*/: return resources.getString(C0192R.string.common_google_play_services_network_error_text); case Std.STD_CHARSET /*9*/: return resources.getString(C0192R.string.common_google_play_services_unsupported_text); case Std.STD_INET_SOCKET_ADDRESS /*12*/: return resources.getString(C0192R.string.common_google_play_services_unsupported_date_text); default: return resources.getString(C0192R.string.common_google_play_services_unknown_issue); } }
From source file:com.google.android.gms.common.internal.C1339l.java
private static String m4743a(Context context, String str) { synchronized (f3100a) { String str2 = (String) f3100a.get(str); if (str2 != null) { return str2; }/*from w w w . j av a 2 s . c o m*/ Resources b = C1296d.m4596b(context); if (b == null) { return null; } int identifier = b.getIdentifier(str, "string", "com.google.android.gms"); if (identifier == 0) { String str3 = "GoogleApiAvailability"; String str4 = "Missing resource: "; str2 = String.valueOf(str); Log.w(str3, str2.length() != 0 ? str4.concat(str2) : new String(str4)); return null; } Object string = b.getString(identifier); if (TextUtils.isEmpty(string)) { str3 = "GoogleApiAvailability"; str4 = "Got empty resource: "; str2 = String.valueOf(str); Log.w(str3, str2.length() != 0 ? str4.concat(str2) : new String(str4)); return null; } f3100a.put(str, string); return string; } }
From source file:Main.java
/** * Applies stirng to View by Reflection//from ww w . j a v a2 s . c o m * * @param context Context * @param view View to apply to. * @param attrs Attributes of Layout */ public static void applyResourceStringToView(Context context, View view, AttributeSet attrs) { if (attrs != null) { Resources res = context.getResources(); for (int i = 0; i < attrs.getAttributeCount(); i++) { int resId = attrs.getAttributeResourceValue(i, 0); if (resId > 0) { String resType = res.getResourceTypeName(resId); if (resType.equals("string")) { String attrName = attrs.getAttributeName(i); try { Method method = view.getClass().getMethod("set" + capitalize(attrName), CharSequence.class); method.setAccessible(true); method.invoke(view, res.getString(resId)); } catch (NoSuchMethodException e) { } catch (Exception e) { } } } } } }
From source file:com.owncloud.android.ui.errorhandling.ErrorMessageAdapter.java
/** * Return a user message corresponding to an operation result and specific for the operation * performed./*ww w. ja va 2s . com*/ * * @param result Result of a {@link RemoteOperation} performed. * @param operation Operation performed. * @param res Reference to app resources, for i18n. * @return User message corresponding to 'result' and 'operation', or NULL if there is no * specific message for both. */ @Nullable private static String getSpecificMessageForResultAndOperation(RemoteOperationResult result, RemoteOperation operation, Resources res) { String message = null; 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.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.uploader_upload_forbidden_permissions)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) { message = res.getString(R.string.failed_upload_quota_exceeded_text); } } } 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 { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.downloader_download_file_not_found); } } } else if (operation instanceof RemoveFileOperation) { if (result.isSuccess()) { message = res.getString(R.string.remove_success_msg); } else { if (result.getCode().equals(ResultCode.FORBIDDEN)) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_delete)); } } } else if (operation instanceof RenameFileOperation) { if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { message = res.getString(R.string.rename_local_fail_msg); } else if (result.getCode().equals(ResultCode.FORBIDDEN)) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_rename)); } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { message = res.getString(R.string.filename_forbidden_characters); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } } 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 (result.getCode().equals(ResultCode.FORBIDDEN)) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_create)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } } else if (operation instanceof CreateShareViaLinkOperation || operation instanceof CreateShareWithShareeOperation) { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.share_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.share_link_forbidden_permissions)); } } else if (operation instanceof UnshareOperation) { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.unshare_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.unshare_link_forbidden_permissions)); } } else if (operation instanceof UpdateShareViaLinkOperation || operation instanceof UpdateSharePermissionsOperation) { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.update_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.update_link_forbidden_permissions)); } } else if (operation instanceof MoveFileOperation) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.move_file_not_found); } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) { message = res.getString(R.string.move_file_invalid_into_descendent); } else if (result.getCode() == ResultCode.INVALID_OVERWRITE) { message = res.getString(R.string.move_file_invalid_overwrite); } else if (result.getCode() == ResultCode.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_move)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } } else if (operation instanceof SynchronizeFolderOperation) { if (!result.isSuccess()) { String folderPathName = new File(((SynchronizeFolderOperation) operation).getFolderPath()) .getName(); if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = String.format(res.getString(R.string.sync_current_folder_was_removed), folderPathName); } } } else if (operation instanceof CopyFileOperation) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.copy_file_not_found); } else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) { message = res.getString(R.string.copy_file_invalid_into_descendent); } else if (result.getCode() == ResultCode.INVALID_OVERWRITE) { message = res.getString(R.string.copy_file_invalid_overwrite); } else if (result.getCode() == ResultCode.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_copy)); } } return message; }
From source file:com.owncloud.android.utils.ErrorMessageAdapter.java
public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation, Resources res) { String message = null;//w ww . j ava2 s . c o m if (!result.isSuccess() && isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else 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 if (result.getCode() == ResultCode.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.uploader_upload_forbidden_permissions)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } 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 { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.downloader_download_file_not_found); } 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 (result.getCode().equals(ResultCode.FORBIDDEN)) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_delete)); } 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); } else if (result.getCode().equals(ResultCode.FORBIDDEN)) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_rename)); } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { message = res.getString(R.string.filename_forbidden_characters); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } 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 (result.getCode().equals(ResultCode.FORBIDDEN)) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_create)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } else { message = res.getString(R.string.create_dir_fail_msg); } } else if (operation instanceof CreateShareViaLinkOperation || operation instanceof CreateShareWithShareeOperation) { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.share_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.share_link_forbidden_permissions)); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.share_link_file_error); } } else if (operation instanceof UnshareOperation) { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.unshare_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { // Error --> No permissions message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.unshare_link_forbidden_permissions)); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.unshare_link_file_error); } } else if (operation instanceof MoveFileOperation) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.move_file_not_found); } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) { message = res.getString(R.string.move_file_invalid_into_descendent); } else if (result.getCode() == ResultCode.INVALID_OVERWRITE) { message = res.getString(R.string.move_file_invalid_overwrite); } else if (result.getCode() == ResultCode.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_move)); } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { message = res.getString(R.string.filename_forbidden_charaters_from_server); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.move_file_error); } } else if (operation instanceof SynchronizeFolderOperation) { if (!result.isSuccess()) { String folderPathName = new File(((SynchronizeFolderOperation) operation).getFolderPath()) .getName(); if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = String.format(res.getString(R.string.sync_current_folder_was_removed), folderPathName); } else { // Generic error // Show a Message, operation finished without success message = String.format(res.getString(R.string.sync_folder_failed_content), folderPathName); } } } else if (operation instanceof CopyFileOperation) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) { message = res.getString(R.string.copy_file_not_found); } else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) { message = res.getString(R.string.copy_file_invalid_into_descendent); } else if (result.getCode() == ResultCode.INVALID_OVERWRITE) { message = res.getString(R.string.copy_file_invalid_overwrite); } else if (result.getCode() == ResultCode.FORBIDDEN) { message = String.format(res.getString(R.string.forbidden_permissions), res.getString(R.string.forbidden_permissions_copy)); } else { // Generic error // Show a Message, operation finished without success message = res.getString(R.string.copy_file_error); } } return message; }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
public static String m113c(Context context, int i) { Resources resources = context.getResources(); switch (i) {//w w w . j a va 2 s . c om case Std.STD_FILE /*1*/: return m106a(context.getResources()) ? resources.getString(C0192R.string.common_google_play_services_install_text_tablet) : resources.getString(C0192R.string.common_google_play_services_install_text_phone); case Std.STD_URL /*2*/: return resources.getString(C0192R.string.common_google_play_services_update_text); case Std.STD_URI /*3*/: return resources.getString(C0192R.string.common_google_play_services_enable_text); case Std.STD_JAVA_TYPE /*5*/: return resources.getString(C0192R.string.common_google_play_services_invalid_account_text); case Std.STD_PATTERN /*7*/: return resources.getString(C0192R.string.common_google_play_services_network_error_text); case Std.STD_CHARSET /*9*/: return resources.getString(C0192R.string.common_google_play_services_unsupported_text); case Std.STD_INET_SOCKET_ADDRESS /*12*/: return resources.getString(C0192R.string.common_google_play_services_unsupported_date_text); default: return resources.getString(C0192R.string.common_google_play_services_unknown_issue); } }
From source file:in.shick.diode.common.util.Util.java
/** * To the second, not millisecond like reddit * @param timeSeconds// w w w . j a v a2 s. c om * @return */ public static String getTimeAgo(long utcTimeSeconds, Resources resources) { long systime = System.currentTimeMillis() / 1000; long diff = systime - utcTimeSeconds; if (diff <= 0) return resources.getString(R.string.just_now); else if (diff < 60) { if (diff == 1) return resources.getString(R.string.one_second_ago); else return String.format(resources.getString(R.string.n_seconds_ago), diff); } else if (diff < 3600) { if ((diff / 60) == 1) return resources.getString(R.string.one_minute_ago); else return String.format(resources.getString(R.string.n_minutes_ago), (diff / 60)); } else if (diff < 86400) { // 86400 seconds in a day if ((diff / 3600) == 1) return resources.getString(R.string.one_hour_ago); else return String.format(resources.getString(R.string.n_hours_ago), (diff / 3600)); } else if (diff < 604800) { // 86400 * 7 if ((diff / 86400) == 1) return resources.getString(R.string.one_day_ago); else return String.format(resources.getString(R.string.n_days_ago), (diff / 86400)); } else if (diff < 2592000) { // 86400 * 30 if ((diff / 604800) == 1) return resources.getString(R.string.one_week_ago); else return String.format(resources.getString(R.string.n_weeks_ago), (diff / 604800)); } else if (diff < 31536000) { // 86400 * 365 if ((diff / 2592000) == 1) return resources.getString(R.string.one_month_ago); else return String.format(resources.getString(R.string.n_months_ago), (diff / 2592000)); } else { if ((diff / 31536000) == 1) return resources.getString(R.string.one_year_ago); else return String.format(resources.getString(R.string.n_years_ago), (diff / 31536000)); } }
From source file:can.yrt.onebusaway.TripInfoActivity.java
static String getRepeatText(Context ctx, int days) { final Resources res = ctx.getResources(); if ((days & ObaContract.Trips.DAY_ALL) == ObaContract.Trips.DAY_ALL) { return res.getString(R.string.trip_info_repeat_everyday); }//w w w .j a v a 2 s . co m if (((days & ObaContract.Trips.DAY_WEEKDAY) == ObaContract.Trips.DAY_WEEKDAY) && (days & ~ObaContract.Trips.DAY_WEEKDAY) == 0) { return res.getString(R.string.trip_info_repeat_weekdays); } if (days == 0) { return res.getString(R.string.trip_info_repeat_norepeat); } // Otherwise, it's not normal -- format a string final boolean[] array = ObaContract.Trips.daysToArray(days); final String[] dayNames = res.getStringArray(R.array.reminder_days); StringBuffer buf = new StringBuffer(); // Find the first day int rangeStart = 0; while (rangeStart < 7) { for (; rangeStart < 7 && array[rangeStart] != true; ++rangeStart) { } if (rangeStart == 7) { break; } int rangeEnd = rangeStart + 1; for (; rangeEnd < 7 && array[rangeEnd] == true; ++rangeEnd) { } if (buf.length() != 0) { // TODO: Move to string table buf.append(", "); } // Single day? if ((rangeEnd - rangeStart) == 1) { buf.append(dayNames[rangeStart]); } else { buf.append(dayNames[rangeStart]); // TODO: Move to string table buf.append(" - "); buf.append(dayNames[rangeEnd - 1]); } rangeStart = rangeEnd; } return res.getString(R.string.trip_info_repeat_every, buf.toString()); }
From source file:com.google.android.apps.santatracker.SantaNotificationBuilder.java
private static Notification GetNotification(Context c, int headline) { Resources r = c.getResources(); Bitmap largeIcon = BitmapFactory.decodeResource(r, R.drawable.santa_notification_background); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setHintHideIcon(false).setBackground(largeIcon); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c) .setSmallIcon(R.drawable.notification_small) .setColor(c.getResources().getColor(R.color.brandSantaTracker)).setAutoCancel(true) .setContentTitle(r.getString(headline)).setContentText(r.getString(R.string.track_santa)) .extend(wearableExtender);/*from ww w .j av a 2s .c om*/ Intent i = new Intent(c, StartupActivity.class); i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, NotificationConstants.TAKEOFF_PATH); TaskStackBuilder stackBuilder = TaskStackBuilder.create(c); stackBuilder.addParentStack(StartupActivity.class); stackBuilder.addNextIntent(i); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); return mBuilder.build(); }