List of usage examples for android.content.res Resources getQuantityString
@NonNull public String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) throws NotFoundException
From source file:org.akop.crosswords.fragment.SelectorFragment.java
private void confirmEmptyTrash() { int count = mAdapter.getCount(); if (count < 1) { return;/*from w ww . j ava2 s. co m*/ } Resources res = getResources(); String message = res.getQuantityString(R.plurals.permanently_delete_puzzles_f, count, count); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setMessage(message) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { emptyTrash(); } }).setNegativeButton(R.string.no, null).create(); dialog.show(); }
From source file:com.android.mail.utils.NotificationUtils.java
/** * @param context a context used to construct the title * @param unseenCount the number of unseen messages * @return e.g. "1 new message" or "2 new messages" *///w w w . j a v a 2s . com private static String createTitle(Context context, int unseenCount) { final Resources resources = context.getResources(); return resources.getQuantityString(R.plurals.new_messages, unseenCount, unseenCount); }
From source file:org.croudtrip.fragments.join.JoinDrivingFragment.java
private void showJoinedTrip(List<JoinTripRequest> requests) { if (requests == null || requests.isEmpty()) { Timber.e("List<JoinTripRequest> is empty or doesn't exist"); return;/*from w w w . j ava 2 s. c o m*/ } if (flMap.getVisibility() == View.VISIBLE) { drawRoutesOnMap(requests); } // Show drivers for (JoinTripRequest r : requests) { adapter.updateRequest(r); } progressBarDrivers.setVisibility(View.GONE); // Show correct plural of drivers int numDrivers = adapter.getNumDrivers(); Resources res = getResources(); tvMyDrivers.setText(res.getQuantityString(R.plurals.join_trip_results_my_drivers, numDrivers, numDrivers)); // TODO: for first/next driver // Show arrival time String dateAsString = ""; Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getDefault()); calendar.setTimeInMillis(1000 * (requests.get(0).getEstimatedArrivalTimestamp())); //Display remaining time in the format hh:mm if ((calendar.get(Calendar.HOUR_OF_DAY) < 10) && (calendar.get((Calendar.MINUTE)) < 10)) dateAsString = "0" + calendar.get(Calendar.HOUR_OF_DAY) + ":0" + calendar.get(Calendar.MINUTE); else if (calendar.get(Calendar.HOUR_OF_DAY) < 10) dateAsString = "0" + calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE); else if (calendar.get((Calendar.MINUTE)) < 10) dateAsString = calendar.get(Calendar.HOUR_OF_DAY) + ":0" + calendar.get(Calendar.MINUTE); else dateAsString = calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE); tvPickupTime.setText(dateAsString); }
From source file:io.plaidapp.ui.PlayerActivity.java
void bindPlayer() { if (player == null) return;// w ww .j av a 2 s.c om final Resources res = getResources(); final NumberFormat nf = NumberFormat.getInstance(); Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder) .transform(circleTransform).into(avatar); playerName.setText(player.name.toLowerCase()); if (!TextUtils.isEmpty(player.bio)) { DribbbleUtils.parseAndSetText(bio, player.bio); } else { bio.setVisibility(View.GONE); } shotCount .setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count))); if (player.shots_count == 0) { shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null); } setFollowerCount(player.followers_count); likesCount .setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count))); // load the users shots dataManager = new PlayerShotsDataManager(this, player) { @Override public void onDataLoaded(List<Shot> data) { if (data != null && data.size() > 0) { if (adapter.getDataItemCount() == 0) { loading.setVisibility(View.GONE); ViewUtils.setPaddingTop(shots, likesCount.getBottom()); } adapter.addAndResort(data); } } }; adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this)); shots.setAdapter(adapter); shots.setItemAnimator(new SlideInItemAnimator()); shots.setVisibility(View.VISIBLE); layoutManager = new GridLayoutManager(this, columns); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return adapter.getItemColumnSpan(position); } }); shots.setLayoutManager(layoutManager); shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) { @Override public void onLoadMore() { dataManager.loadData(); } }); shots.setHasFixedSize(true); // forward on any clicks above the first item in the grid (i.e. in the paddingTop) // to 'pass through' to the view behind shots.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int firstVisible = layoutManager.findFirstVisibleItemPosition(); if (firstVisible > 0) return false; // if no data loaded then pass through if (adapter.getDataItemCount() == 0) { return container.dispatchTouchEvent(event); } final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0); if (vh == null) return false; final int firstTop = vh.itemView.getTop(); if (event.getY() < firstTop) { return container.dispatchTouchEvent(event); } return false; } }); // check if following if (dataManager.getDribbblePrefs().isLoggedIn()) { if (player.id == dataManager.getDribbblePrefs().getUserId()) { TransitionManager.beginDelayedTransition(container); follow.setVisibility(View.GONE); ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin); } else { final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id); followingCall.enqueue(new Callback<Void>() { @Override public void onResponse(Call<Void> call, Response<Void> response) { following = response.isSuccessful(); if (!following) return; TransitionManager.beginDelayedTransition(container); follow.setText(R.string.following); follow.setActivated(true); } @Override public void onFailure(Call<Void> call, Throwable t) { } }); } } if (player.shots_count > 0) { dataManager.loadData(); // kick off initial load } else { loading.setVisibility(View.GONE); } }
From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java
@Override protected ApplyChangesInfo getApplyChangesInfo() { saveChanges();//w ww . j a v a2 s . c o m final List<Task> editedTasks = getEditedTasks(); final int editedTasksCount = editedTasks.size(); final ModificationSet modificationSet = createModificationSet(editedTasks); final Resources resources = getResources(); final ApplyChangesInfo applyChangesInfo = new ApplyChangesInfo( modificationSet.toContentProviderActionItemList(), resources.getQuantityString(R.plurals.toast_save_task, editedTasksCount, editedTasksCount), resources.getQuantityString(R.plurals.toast_save_task_ok, editedTasksCount, editedTasksCount), resources.getQuantityString(R.plurals.toast_save_task_failed, editedTasksCount)); return applyChangesInfo; }
From source file:com.ubuntuone.android.files.service.UpDownService.java
private synchronized void showFailedTransfersNotification(int failed) { String title = "Ubuntu One"; Resources r = getResources(); String text = r.getQuantityString(R.plurals.failed_to_upload_n_files, failed, failed); final Intent intent = new Intent(UpDownService.this, PreferencesActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(PreferencesActivity.SHOW_RETRY_FAILED, 1); final PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), REQUEST_RETRY_SCREEN, intent, 0);// w ww.j av a 2s. c o m Notification notification = new NotificationCompat.Builder(this).setOngoing(false).setTicker(title) .setSmallIcon(R.drawable.stat_u1_logo).setOnlyAlertOnce(true).setAutoCancel(true).getNotification(); notification.setLatestEventInfo(this, title, text, pi); notificationManager.notify(R.id.stat_failed_upload_id, notification); }
From source file:cgeo.geocaching.CacheListActivity.java
private static String getCacheNumberString(final Resources res, final int count) { return res.getQuantityString(R.plurals.cache_counts, count, count); }
From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java
private void onNewItemsInserted(final Uri uri, final ContentValues... values) { if (uri == null || values == null || values.length == 0) return;/* w w w . j a v a 2 s . c om*/ if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) return; final Context context = getContext(); final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); switch (getTableId(uri)) { case TABLE_ID_STATUSES: { if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false)) return; final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount); final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED); final Bundle delete_extras = new Bundle(); delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE); delete_intent.putExtras(delete_extras); final Intent content_intent = new Intent(context, HomeActivity.class); content_intent.setAction(Intent.ACTION_MAIN); content_intent.addCategory(Intent.CATEGORY_LAUNCHER); final Bundle content_extras = new Bundle(); content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME); content_intent.putExtras(content_extras); builder.setOnlyAlertOnce(true); buildNotification(builder, res.getString(R.string.new_notifications), message, message, R.drawable.ic_stat_tweet, null, content_intent, delete_intent); mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, builder.build()); break; } case TABLE_ID_MENTIONS: { if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false)) { displayMentionsNotification(context, values); } break; } case TABLE_ID_DIRECT_MESSAGES_INBOX: { if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false)) { displayMessagesNotification(context, values); } break; } } }
From source file:org.mariotaku.twidere.provider.TweetStoreProvider.java
private void onNewItemsInserted(final Uri uri, final int count, final ContentValues... values) { if (uri == null || values == null || values.length == 0 || count == 0) return;//w ww . j av a 2s.com if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) return; final Context context = getContext(); final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH)); final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image); switch (getTableId(uri)) { case URI_STATUSES: { if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false)) return; final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount); final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED); final Bundle delete_extras = new Bundle(); delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE); delete_intent.putExtras(delete_extras); final Intent content_intent = new Intent(context, HomeActivity.class); content_intent.setAction(Intent.ACTION_MAIN); content_intent.addCategory(Intent.CATEGORY_LAUNCHER); final Bundle content_extras = new Bundle(); content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME); content_intent.putExtras(content_extras); builder.setOnlyAlertOnce(true); final Notification notification = buildNotification(builder, res.getString(R.string.new_notifications), message, message, R.drawable.ic_stat_tweet, null, content_intent, delete_intent); mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, notification); break; } case URI_MENTIONS: { if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false)) return; if (mNewMentionsCount > 1) { builder.setNumber(mNewMentionsCount); } final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED); final Bundle delete_extras = new Bundle(); delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS); delete_intent.putExtras(delete_extras); final Intent content_intent; final List<String> screen_names = new NoDuplicatesArrayList<String>(); ContentValues notification_value = null; int notified_count = 0; for (final ContentValues value : values) { final String screen_name = value.getAsString(Statuses.SCREEN_NAME); if (!isFiltered(mDatabase, screen_name, value.getAsString(Statuses.SOURCE), value.getAsString(Statuses.TEXT_PLAIN))) { if (notification_value == null) { notification_value = value; } screen_names.add(screen_name); notified_count++; } } if (notified_count == 1) { final Uri.Builder uri_builder = new Uri.Builder(); uri_builder.scheme(SCHEME_TWIDERE); uri_builder.authority(AUTHORITY_STATUS); uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, notification_value.getAsString(Statuses.ACCOUNT_ID)); uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, notification_value.getAsString(Statuses.STATUS_ID)); content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build()); } else { content_intent = new Intent(context, HomeActivity.class); content_intent.setAction(Intent.ACTION_MAIN); content_intent.addCategory(Intent.CATEGORY_LAUNCHER); final Bundle content_extras = new Bundle(); content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS); content_intent.putExtras(content_extras); } if (notification_value == null) return; final String title; if (screen_names.size() > 1) { title = res.getString(R.string.notification_mention_multiple, display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME) : notification_value.getAsString(Statuses.NAME), screen_names.size() - 1); } else { title = res.getString(R.string.notification_mention, display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME) : notification_value.getAsString(Statuses.NAME)); } final String message = notification_value.getAsString(Statuses.TEXT_PLAIN); final String profile_image_url_string = notification_value.getAsString(Statuses.PROFILE_IMAGE_URL); final File profile_image_file = mProfileImageLoader.getCachedImageFile( display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width); final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height); builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile() ? BitmapFactory.decodeFile(profile_image_file.getPath()) : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true)); final Notification notification = buildNotification(builder, title, title, message, R.drawable.ic_stat_mention, null, content_intent, delete_intent); mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, notification); break; } case URI_DIRECT_MESSAGES_INBOX: { if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false)) return; if (mNewMessagesCount > 1) { builder.setNumber(mNewMessagesCount); } final List<String> screen_names = new NoDuplicatesArrayList<String>(); final ContentValues notification_value = values[0]; for (final ContentValues value : values) { screen_names.add(value.getAsString(DirectMessages.SENDER_SCREEN_NAME)); } if (notification_value == null) return; final String title; if (screen_names.size() > 1) { title = res.getString(R.string.notification_direct_message_multiple, display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME) : notification_value.getAsString(DirectMessages.SENDER_NAME), screen_names.size() - 1); } else { title = res.getString(R.string.notification_direct_message, display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME) : notification_value.getAsString(DirectMessages.SENDER_NAME)); } final String message = notification_value.getAsString(DirectMessages.TEXT_PLAIN); final String profile_image_url_string = notification_value .getAsString(DirectMessages.SENDER_PROFILE_IMAGE_URL); final File profile_image_file = mProfileImageLoader.getCachedImageFile( display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width); final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height); builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile() ? BitmapFactory.decodeFile(profile_image_file.getPath()) : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true)); final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED); final Bundle delete_extras = new Bundle(); delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES); delete_intent.putExtras(delete_extras); final Intent content_intent; if (values.length == 1) { final Uri.Builder uri_builder = new Uri.Builder(); final long account_id = notification_value.getAsLong(DirectMessages.ACCOUNT_ID); final long conversation_id = notification_value.getAsLong(DirectMessages.SENDER_ID); uri_builder.scheme(SCHEME_TWIDERE); uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION); uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id)); uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id)); content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build()); } else { content_intent = new Intent(context, HomeActivity.class); content_intent.setAction(Intent.ACTION_MAIN); content_intent.addCategory(Intent.CATEGORY_LAUNCHER); final Bundle content_extras = new Bundle(); content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES); content_intent.putExtras(content_extras); } final Notification notification = buildNotification(builder, title, title, message, R.drawable.ic_stat_direct_message, null, content_intent, delete_intent); mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, notification); break; } } }
From source file:com.tct.email.NotificationController.java
/** * @param context a context used to construct the title * @param failedCount the number of failed messages * @return e.g. "1 Email not send" or "2 emails not send" *///from ww w . j a v a 2s .c o m private String createTitle(int failedCount) { final Resources resources = mContext.getResources(); return resources.getQuantityString(R.plurals.send_failed_messages, failedCount, failedCount); }