List of usage examples for android.content.res Resources getString
@NonNull public String getString(@StringRes int id, Object... formatArgs) throws NotFoundException
From source file:com.ichi2.anki.StudyOptionsFragment.java
public void configureToolbar() { mToolbar.setOnMenuItemClickListener(this); Menu menu = mToolbar.getMenu(); // Switch on or off rebuild/empty/custom study depending on whether or not filtered deck if (getCol().getDecks().isDyn(getCol().getDecks().selected())) { menu.findItem(R.id.action_rebuild).setVisible(true); menu.findItem(R.id.action_empty).setVisible(true); menu.findItem(R.id.action_custom_study).setVisible(false); } else {/*from w ww . j a v a2 s . c om*/ menu.findItem(R.id.action_rebuild).setVisible(false); menu.findItem(R.id.action_empty).setVisible(false); menu.findItem(R.id.action_custom_study).setVisible(true); } // Don't show custom study icon if congrats shown if (mCurrentContentView == CONTENT_CONGRATS) { menu.findItem(R.id.action_custom_study).setVisible(false); } // Switch on rename / delete / export if tablet layout if (mFragmented) { menu.findItem(R.id.action_rename).setVisible(true); menu.findItem(R.id.action_delete).setVisible(true); menu.findItem(R.id.action_export).setVisible(true); } else { menu.findItem(R.id.action_rename).setVisible(false); menu.findItem(R.id.action_delete).setVisible(false); menu.findItem(R.id.action_export).setVisible(false); } // Switch on or off unbury depending on if there are cards to unbury menu.findItem(R.id.action_unbury).setVisible(getCol().getSched().haveBuried()); // Switch on or off undo depending on whether undo is available if (!getCol().undoAvailable()) { menu.findItem(R.id.action_undo).setVisible(false); } else { menu.findItem(R.id.action_undo).setVisible(true); Resources res = AnkiDroidApp.getAppResources(); menu.findItem(R.id.action_undo) .setTitle(res.getString(R.string.studyoptions_congrats_undo, getCol().undoName(res))); } // Set the back button listener if (!mFragmented) { mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((AnkiActivity) getActivity()).finishWithAnimation(ActivityTransitionAnimation.RIGHT); } }); } }
From source file:com.bayapps.android.robophish.model.MusicProvider.java
private MediaBrowserCompat.MediaItem createBrowsableMediaItemForShow(MediaMetadataCompat show, Resources resources) { String showId = show.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); String venue = show.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE); String location = show.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE); String date = show.getString(MediaMetadataCompat.METADATA_KEY_DATE); MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(createMediaID(null, MEDIA_ID_TRACKS_BY_SHOW, showId)).setTitle(venue) .setSubtitle(resources.getString(R.string.browse_musics_by_genre_subtitle, date)) .setDescription(location).build(); return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE); }
From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long alarmOffset) { long currentTime = UIUtils.getCurrentTime(this); final long intervalEnd = sessionStart + MILLI_TEN_MINUTES; LOGD(TAG, "Considering notifying for time interval."); LOGD(TAG, " Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString()); LOGD(TAG, " Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString()); LOGD(TAG, " Current time is: " + currentTime + "=" + (new Date(currentTime)).toString()); if (sessionStart < currentTime) { LOGD(TAG, "Skipping session notification (too late -- time interval already started)"); return;/*from w w w. j a v a 2 s .c o m*/ } if (!SettingsUtils.shouldShowSessionReminders(this)) { // skip if disabled in settings LOGD(TAG, "Skipping session notification for sessions. Disabled in settings."); return; } // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) { LOGD(TAG, "Skipping session notification (already notified)"); return; } final ContentResolver cr = getContentResolver(); LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd); Cursor c = null; try { c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION, ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION, ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null); int starredCount = c.getCount(); LOGD(TAG, "# starred sessions in that interval: " + c.getCount()); String singleSessionId = null; String singleSessionRoomId = null; ArrayList<String> starredSessionTitles = new ArrayList<String>(); while (c.moveToNext()) { singleSessionId = c.getString(SessionDetailQuery.SESSION_ID); singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. Intent baseIntent = new Intent(this, MyScheduleActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); // For a single session, tapping the notification should open the session details (b/15350787) if (starredCount == 1) { taskBuilder.addNextIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId))); } PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setColor(getResources().getColor(R.color.theme_primary)) .setTicker(res .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, intervalEnd, 5)); } if (starredCount == 1 && SettingsUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map), createRoomMapIntent(singleSessionRoomId)); } String bigContentTitle; if (starredCount == 1 && starredSessionTitles.size() > 0) { bigContentTitle = starredSessionTitles.get(0); } else { bigContentTitle = res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(bigContentTitle); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing notification."); nm.notify(NOTIFICATION_ID, richNotification.build()); } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
private void updateRunningState() { Resources res = getResources(); TwoStatePreference runningPref = findPref("running_switch"); if (FsService.isRunning()) { runningPref.setChecked(true);/*w ww . j a v a 2s .c o m*/ // Fill in the FTP server address InetAddress address = FsService.getLocalInetAddress(); if (address == null) { Cat.v("Unable to retrieve wifi ip address"); runningPref.setSummary(R.string.running_summary_failed_to_get_ip_address); return; } String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/"; String summary = res.getString(R.string.running_summary_started, iptext); runningPref.setSummary(summary); } else { runningPref.setChecked(false); runningPref.setSummary(R.string.running_summary_stopped); } }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java
public static void bindActivityView(final View rootView, Activity activity, ImageLoader imageLoader, boolean singleSourceMode) { // Prepare view holder. ViewHolder tempViews = (ViewHolder) rootView.getTag(); final ViewHolder views; if (tempViews != null) { views = tempViews;//from w w w . java 2 s . c om } else { views = new ViewHolder(); rootView.setTag(views); // Author and metadata box views.authorContainer = rootView.findViewById(R.id.stream_author_container); views.userImage = (ImageView) rootView.findViewById(R.id.stream_user_image); views.userName = (TextView) rootView.findViewById(R.id.stream_user_name); views.time = (TextView) rootView.findViewById(R.id.stream_time); // Author's content views.content = (TextView) rootView.findViewById(R.id.stream_content); // Original share box views.originalContainer = rootView.findViewById(R.id.stream_original_container); views.originalAuthor = (TextView) rootView.findViewById(R.id.stream_original_author); views.originalContent = (TextView) rootView.findViewById(R.id.stream_original_content); // Media box views.mediaContainer = rootView.findViewById(R.id.stream_media_container); views.mediaBackground = (ImageView) rootView.findViewById(R.id.stream_media_background); views.mediaOverlay = (ImageView) rootView.findViewById(R.id.stream_media_overlay); views.mediaTitle = (TextView) rootView.findViewById(R.id.stream_media_title); views.mediaSubtitle = (TextView) rootView.findViewById(R.id.stream_media_subtitle); // Interactions box views.interactionsContainer = rootView.findViewById(R.id.stream_interactions_container); views.plusOnes = (TextView) rootView.findViewById(R.id.stream_plus_ones); views.shares = (TextView) rootView.findViewById(R.id.stream_shares); views.comments = (TextView) rootView.findViewById(R.id.stream_comments); } final Context context = rootView.getContext(); final Resources res = context.getResources(); // Determine if this is a reshare (affects how activity fields are to be interpreted). Activity.PlusObject.Actor originalAuthor = activity.getObject().getActor(); boolean isReshare = "share".equals(activity.getVerb()) && originalAuthor != null; // Author and metadata box views.authorContainer.setVisibility(singleSourceMode ? View.GONE : View.VISIBLE); views.userName.setText(activity.getActor().getDisplayName()); // Find user profile image url String userImageUrl = null; if (activity.getActor().getImage() != null) { userImageUrl = activity.getActor().getImage().getUrl(); } // Load image from network in background thread using Volley library imageLoader.get(userImageUrl, views.userImage, PLACEHOLDER_USER_IMAGE); long thenUTC = activity.getUpdated().getValue() + activity.getUpdated().getTimeZoneShift() * 60000; views.time.setText(DateUtils.getRelativeTimeSpanString(thenUTC, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_RELATIVE)); // Author's additional content String selfContent = isReshare ? activity.getAnnotation() : activity.getObject().getContent(); views.content.setMaxLines(singleSourceMode ? 1000 : 5); if (!TextUtils.isEmpty(selfContent)) { views.content.setVisibility(View.VISIBLE); views.content.setText(Html.fromHtml(selfContent)); } else { views.content.setVisibility(View.GONE); } // Original share box if (isReshare) { views.originalContainer.setVisibility(View.VISIBLE); // Set original author text, highlight author name final String author = res.getString(R.string.stream_originally_shared, originalAuthor.getDisplayName()); final SpannableStringBuilder spannableAuthor = new SpannableStringBuilder(author); spannableAuthor.setSpan(new StyleSpan(Typeface.BOLD), author.length() - originalAuthor.getDisplayName().length(), author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); views.originalAuthor.setText(spannableAuthor, TextView.BufferType.SPANNABLE); String originalContent = activity.getObject().getContent(); views.originalContent.setMaxLines(singleSourceMode ? 1000 : 3); if (!TextUtils.isEmpty(originalContent)) { views.originalContent.setVisibility(View.VISIBLE); views.originalContent.setText(Html.fromHtml(originalContent)); } else { views.originalContent.setVisibility(View.GONE); } } else { views.originalContainer.setVisibility(View.GONE); } // Media box // Set media content. List<Activity.PlusObject.Attachments> attachments = activity.getObject().getAttachments(); if (attachments != null && attachments.size() > 0) { Activity.PlusObject.Attachments attachment = attachments.get(0); String objectType = attachment.getObjectType(); String imageUrl = attachment.getImage() != null ? attachment.getImage().getUrl() : null; if (imageUrl == null && attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) { Thumbnails thumb = attachment.getThumbnails().get(0); imageUrl = thumb.getImage() != null ? thumb.getImage().getUrl() : null; } // Load image from network in background thread using Volley library imageLoader.get(imageUrl, views.mediaBackground, PLACEHOLDER_MEDIA_IMAGE); boolean overlayStyle = false; views.mediaOverlay.setImageDrawable(null); if (("photo".equals(objectType) || "video".equals(objectType) || "album".equals(objectType)) && !TextUtils.isEmpty(imageUrl)) { overlayStyle = true; views.mediaOverlay .setImageResource("video".equals(objectType) ? R.drawable.ic_stream_media_overlay_video : R.drawable.ic_stream_media_overlay_photo); } else if ("article".equals(objectType) || "event".equals(objectType)) { overlayStyle = false; views.mediaTitle.setText(attachment.getDisplayName()); if (!TextUtils.isEmpty(attachment.getUrl())) { Uri uri = Uri.parse(attachment.getUrl()); views.mediaSubtitle.setText(uri.getHost()); } else { views.mediaSubtitle.setText(""); } } views.mediaContainer.setVisibility(View.VISIBLE); views.mediaContainer.setBackgroundResource( overlayStyle ? R.color.plus_stream_media_background : android.R.color.black); if (overlayStyle) { views.mediaBackground.clearColorFilter(); } else { views.mediaBackground.setColorFilter(res.getColor(R.color.plus_media_item_tint)); } views.mediaOverlay.setVisibility(overlayStyle ? View.VISIBLE : View.GONE); views.mediaTitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE); views.mediaSubtitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE); } else { views.mediaContainer.setVisibility(View.GONE); views.mediaBackground.setImageDrawable(null); views.mediaOverlay.setImageDrawable(null); } // Interactions box final int plusOneCount = (activity.getObject().getPlusoners() != null) ? activity.getObject().getPlusoners().getTotalItems().intValue() : 0; if (plusOneCount > 0) { views.plusOnes.setVisibility(View.VISIBLE); views.plusOnes.setText(getPlusOneString(plusOneCount)); } else { views.plusOnes.setVisibility(View.GONE); } final int commentCount = (activity.getObject().getReplies() != null) ? activity.getObject().getReplies().getTotalItems().intValue() : 0; if (commentCount > 0) { views.comments.setVisibility(View.VISIBLE); views.comments.setText(Integer.toString(commentCount)); } else { views.comments.setVisibility(View.GONE); } final int resharerCount = (activity.getObject().getResharers() != null) ? activity.getObject().getResharers().getTotalItems().intValue() : 0; if (resharerCount > 0) { views.shares.setVisibility(View.VISIBLE); views.shares.setText(Integer.toString(resharerCount)); } else { views.shares.setVisibility(View.GONE); } views.interactionsContainer.setVisibility( (plusOneCount > 0 || commentCount > 0 || resharerCount > 0) ? View.VISIBLE : View.GONE); }
From source file:com.chen.mail.utils.NotificationUtils.java
private static void configureLatestEventInfoFromConversation(final Context context, final Account account, final FolderPreferences folderPreferences, final NotificationCompat.Builder notification, final Cursor conversationCursor, final PendingIntent clickIntent, final Intent notificationIntent, final int unreadCount, final int unseenCount, final Folder folder, final long when) { final Resources res = context.getResources(); final String notificationAccount = account.name; LogUtils.i(LOG_TAG, "Showing notification with unreadCount of %d and unseenCount of %d", unreadCount, unseenCount);// w w w . ja va 2 s . c o m String notificationTicker = null; // Boolean indicating that this notification is for a non-inbox label. final boolean isInbox = folder.folderUri.fullUri.equals(account.settings.defaultInbox); // Notification label name for user label notifications. final String notificationLabelName = isInbox ? null : folder.name; if (unseenCount > 1) { // Build the string that describes the number of new messages final String newMessagesString = res.getString(R.string.new_messages, unseenCount); // Use the default notification icon notification .setLargeIcon(getDefaultNotificationIcon(context, folder, true /* multiple new messages */)); // The ticker initially start as the new messages string. notificationTicker = newMessagesString; // The title of the notification is the new messages string notification.setContentTitle(newMessagesString); // TODO(skennedy) Can we remove this check? if (Utils.isRunningJellybeanOrLater()) { // For a new-style notification final int maxNumDigestItems = context.getResources() .getInteger(R.integer.max_num_notification_digest_items); // The body of the notification is the account name, or the label name. notification.setSubText(isInbox ? notificationAccount : notificationLabelName); final NotificationCompat.InboxStyle digest = new NotificationCompat.InboxStyle(notification); int numDigestItems = 0; do { final Conversation conversation = new Conversation(conversationCursor); if (!conversation.read) { boolean multipleUnreadThread = false; // TODO(cwren) extract this pattern into a helper Cursor cursor = null; MessageCursor messageCursor = null; try { final Uri.Builder uriBuilder = conversation.messageListUri.buildUpon(); uriBuilder.appendQueryParameter(UIProvider.LABEL_QUERY_PARAMETER, notificationLabelName); cursor = context.getContentResolver().query(uriBuilder.build(), UIProvider.MESSAGE_PROJECTION, null, null, null); messageCursor = new MessageCursor(cursor); String from = ""; String fromAddress = ""; if (messageCursor.moveToPosition(messageCursor.getCount() - 1)) { final Message message = messageCursor.getMessage(); fromAddress = message.getFrom(); if (fromAddress == null) { fromAddress = ""; } from = getDisplayableSender(fromAddress); } while (messageCursor.moveToPosition(messageCursor.getPosition() - 1)) { final Message message = messageCursor.getMessage(); if (!message.read && !fromAddress.contentEquals(message.getFrom())) { multipleUnreadThread = true; break; } } final SpannableStringBuilder sendersBuilder; if (multipleUnreadThread) { final int sendersLength = res.getInteger(R.integer.swipe_senders_length); sendersBuilder = getStyledSenders(context, conversationCursor, sendersLength, notificationAccount); } else { sendersBuilder = new SpannableStringBuilder(getWrappedFromString(from)); } final CharSequence digestLine = getSingleMessageInboxLine(context, sendersBuilder.toString(), conversation.subject, conversation.snippet); digest.addLine(digestLine); numDigestItems++; } finally { if (messageCursor != null) { messageCursor.close(); } if (cursor != null) { cursor.close(); } } } } while (numDigestItems <= maxNumDigestItems && conversationCursor.moveToNext()); } else { // The body of the notification is the account name, or the label name. notification.setContentText(isInbox ? notificationAccount : notificationLabelName); } } else { // For notifications for a single new conversation, we want to get the information from // the conversation // Move the cursor to the most recent unread conversation seekToLatestUnreadConversation(conversationCursor); final Conversation conversation = new Conversation(conversationCursor); Cursor cursor = null; MessageCursor messageCursor = null; boolean multipleUnseenThread = false; String from = null; try { final Uri uri = conversation.messageListUri.buildUpon() .appendQueryParameter(UIProvider.LABEL_QUERY_PARAMETER, folder.persistentId).build(); cursor = context.getContentResolver().query(uri, UIProvider.MESSAGE_PROJECTION, null, null, null); messageCursor = new MessageCursor(cursor); // Use the information from the last sender in the conversation that triggered // this notification. String fromAddress = ""; if (messageCursor.moveToPosition(messageCursor.getCount() - 1)) { final Message message = messageCursor.getMessage(); fromAddress = message.getFrom(); from = getDisplayableSender(fromAddress); notification.setLargeIcon(getContactIcon(context, from, getSenderAddress(fromAddress), folder)); } // Assume that the last message in this conversation is unread int firstUnseenMessagePos = messageCursor.getPosition(); while (messageCursor.moveToPosition(messageCursor.getPosition() - 1)) { final Message message = messageCursor.getMessage(); final boolean unseen = !message.seen; if (unseen) { firstUnseenMessagePos = messageCursor.getPosition(); if (!multipleUnseenThread && !fromAddress.contentEquals(message.getFrom())) { multipleUnseenThread = true; } } } // TODO(skennedy) Can we remove this check? if (Utils.isRunningJellybeanOrLater()) { // For a new-style notification if (multipleUnseenThread) { // The title of a single conversation is the list of senders. int sendersLength = res.getInteger(R.integer.swipe_senders_length); final SpannableStringBuilder sendersBuilder = getStyledSenders(context, conversationCursor, sendersLength, notificationAccount); notification.setContentTitle(sendersBuilder); // For a single new conversation, the ticker is based on the sender's name. notificationTicker = sendersBuilder.toString(); } else { from = getWrappedFromString(from); // The title of a single message the sender. notification.setContentTitle(from); // For a single new conversation, the ticker is based on the sender's name. notificationTicker = from; } // The notification content will be the subject of the conversation. notification.setContentText(getSingleMessageLittleText(context, conversation.subject)); // The notification subtext will be the subject of the conversation for inbox // notifications, or will based on the the label name for user label // notifications. notification.setSubText(isInbox ? notificationAccount : notificationLabelName); if (multipleUnseenThread) { notification.setLargeIcon(getDefaultNotificationIcon(context, folder, true)); } final NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle( notification); // Seek the message cursor to the first unread message final Message message; if (messageCursor.moveToPosition(firstUnseenMessagePos)) { message = messageCursor.getMessage(); bigText.bigText(getSingleMessageBigText(context, conversation.subject, message)); } else { LogUtils.e(LOG_TAG, "Failed to load message"); message = null; } if (message != null) { final Set<String> notificationActions = folderPreferences.getNotificationActions(account); final int notificationId = getNotificationId(account.getAccountManagerAccount(), folder); NotificationActionUtils.addNotificationActions(context, notificationIntent, notification, account, conversation, message, folder, notificationId, when, notificationActions); } } else { // For an old-style notification // The title of a single conversation notification is built from both the sender // and subject of the new message. notification.setContentTitle( getSingleMessageNotificationTitle(context, from, conversation.subject)); // The notification content will be the subject of the conversation for inbox // notifications, or will based on the the label name for user label // notifications. notification.setContentText(isInbox ? notificationAccount : notificationLabelName); // For a single new conversation, the ticker is based on the sender's name. notificationTicker = from; } } finally { if (messageCursor != null) { messageCursor.close(); } if (cursor != null) { cursor.close(); } } } // Build the notification ticker if (notificationLabelName != null && notificationTicker != null) { // This is a per label notification, format the ticker with that information notificationTicker = res.getString(R.string.label_notification_ticker, notificationLabelName, notificationTicker); } if (notificationTicker != null) { // If we didn't generate a notification ticker, it will default to account name notification.setTicker(notificationTicker); } // Set the number in the notification if (unreadCount > 1) { notification.setNumber(unreadCount); } notification.setContentIntent(clickIntent); }
From source file:com.ichi2.anki2.StudyOptionsFragment.java
private void prepareCongratsView() { mCurrentContentView = CONTENT_CONGRATS; if (!AnkiDroidApp.colIsOpen() || !AnkiDroidApp.getCol().undoAvailable()) { mButtonCongratsUndo.setEnabled(false); mButtonCongratsUndo.setVisibility(View.GONE); } else {//from ww w.ja v a 2 s. c om Resources res = AnkiDroidApp.getAppResources(); mButtonCongratsUndo.setText( res.getString(R.string.studyoptions_congrats_undo, AnkiDroidApp.getCol().undoName(res))); } mTextCongratsMessage.setText(AnkiDroidApp.getCol().getSched().finishedMsg(getActivity())); }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java
private void prepareCongratsView() { mCurrentContentView = CONTENT_CONGRATS; if (!AnkiDroidApp.colIsOpen() || !AnkiDroidApp.getCol().undoAvailable()) { mButtonCongratsUndo.setEnabled(false); mButtonCongratsUndo.setVisibility(View.GONE); } else {// w w w.j a v a2 s .c o m Resources res = AnkiDroidApp.getAppResources(); mButtonCongratsUndo.setText( res.getString(R.string.studyoptions_congrats_undo, AnkiDroidApp.getCol().undoName(res))); } if (AnkiDroidApp.colIsOpen() && !AnkiDroidApp.getCol().getSched().haveBuried()) { mButtonCongratsUnbury.setVisibility(View.GONE); } mTextCongratsMessage.setText(AnkiDroidApp.getCol().getSched().finishedMsg(getActivity())); // Filtered decks must not have a custom study button try { if (AnkiDroidApp.getCol().getDecks().current().getInt("dyn") == 1) { mButtonCongratsCustomStudy.setEnabled(false); mButtonCongratsCustomStudy.setVisibility(View.GONE); } } catch (JSONException e) { throw new RuntimeException(); } }
From source file:com.ichi2.anki2.StudyOptionsFragment.java
private void onPrepareDialog(int id, StyledDialog styledDialog) { Resources res = getResources(); switch (id) { case DIALOG_CUSTOM_STUDY_DETAILS: styledDialog.setTitle(res.getStringArray(R.array.custom_study_options_labels)[mCustomDialogChoice]); switch (mCustomDialogChoice + 1) { case CUSTOM_STUDY_NEW: if (AnkiDroidApp.colIsOpen()) { Collection col = AnkiDroidApp.getCol(); mCustomStudyTextView1.setText(res.getString(R.string.custom_study_new_total_new, col.getSched().totalNewForCurrentDeck())); }/*from ww w. ja v a 2s . com*/ mCustomStudyTextView2.setText(res.getString(R.string.custom_study_new_extend)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendNew", 10))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (AnkiDroidApp.colIsOpen()) { try { int n = Integer.parseInt(mCustomStudyEditText.getText().toString()); AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n) .commit(); Collection col = AnkiDroidApp.getCol(); JSONObject deck = col.getDecks().current(); deck.put("extendNew", n); col.getDecks().save(deck); col.getSched().extendLimits(n, 0); resetAndUpdateValuesFromDeck(); finishCongrats(); } catch (NumberFormatException e) { // ignore non numerical values } catch (JSONException e) { throw new RuntimeException(e); } } } }); break; case CUSTOM_STUDY_REV: if (AnkiDroidApp.colIsOpen()) { Collection col = AnkiDroidApp.getCol(); mCustomStudyTextView1.setText(res.getString(R.string.custom_study_rev_total_rev, col.getSched().totalRevForCurrentDeck())); } mCustomStudyTextView2.setText(res.getString(R.string.custom_study_rev_extend)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendRev", 10))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (AnkiDroidApp.colIsOpen()) { try { int n = Integer.parseInt(mCustomStudyEditText.getText().toString()); AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n) .commit(); Collection col = AnkiDroidApp.getCol(); JSONObject deck = col.getDecks().current(); deck.put("extendRev", n); col.getDecks().save(deck); col.getSched().extendLimits(0, n); resetAndUpdateValuesFromDeck(); finishCongrats(); } catch (NumberFormatException e) { // ignore non numerical values } catch (JSONException e) { throw new RuntimeException(e); } } } }); break; case CUSTOM_STUDY_FORGOT: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_forgotten)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("forgottenDays", 2))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int forgottenDays = Integer .parseInt(((EditText) mCustomStudyEditText).getText().toString()); JSONArray ar = new JSONArray(); try { ar.put(0, 1); } catch (JSONException e) { throw new RuntimeException(e); } createFilteredDeck(ar, new Object[] { String.format(Locale.US, "rated:%d:1", forgottenDays), 9999, Sched.DYN_RANDOM }, false); } }); break; case CUSTOM_STUDY_AHEAD: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_ahead)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("aheadDays", 1))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int days = Integer.parseInt(((EditText) mCustomStudyEditText).getText().toString()); createFilteredDeck(new JSONArray(), new Object[] { String.format(Locale.US, "prop:due<=%d", days), 9999, Sched.DYN_DUE }, true); } }); break; case CUSTOM_STUDY_RANDOM: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_random)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("randomCards", 100))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int randomCards = Integer .parseInt(((EditText) mCustomStudyEditText).getText().toString()); createFilteredDeck(new JSONArray(), new Object[] { "", randomCards, Sched.DYN_RANDOM }, true); } }); break; case CUSTOM_STUDY_PREVIEW: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_preview)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("previewDays", 1))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String previewDays = ((EditText) mCustomStudyEditText).getText().toString(); createFilteredDeck(new JSONArray(), new Object[] { "is:new added:" + previewDays, 9999, Sched.DYN_OLDEST }, false); } }); break; case CUSTOM_STUDY_TAGS: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_tags)); mCustomStudyEditText .setText(AnkiDroidApp.getSharedPrefs(getActivity()).getString("customTags", "")); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String tags = ((EditText) mCustomStudyEditText).getText().toString(); createFilteredDeck(new JSONArray(), new Object[] { "(is:new or is:due) " + tags, 9999, Sched.DYN_RANDOM }, true); } }); break; } } }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java
private void onPrepareDialog(int id, StyledDialog styledDialog) { Resources res = getResources(); switch (id) { case DIALOG_CUSTOM_STUDY_DETAILS: styledDialog.setTitle(res.getStringArray(R.array.custom_study_options_labels)[mCustomDialogChoice]); switch (mCustomDialogChoice + 1) { case CUSTOM_STUDY_NEW: if (AnkiDroidApp.colIsOpen()) { Collection col = AnkiDroidApp.getCol(); mCustomStudyTextView1.setText(res.getString(R.string.custom_study_new_total_new, col.getSched().totalNewForCurrentDeck())); }//from www . ja v a2s.c om mCustomStudyTextView2.setText(res.getString(R.string.custom_study_new_extend)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendNew", 10))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (AnkiDroidApp.colIsOpen()) { try { int n = Integer.parseInt(mCustomStudyEditText.getText().toString()); AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n) .commit(); Collection col = AnkiDroidApp.getCol(); JSONObject deck = col.getDecks().current(); deck.put("extendNew", n); col.getDecks().save(deck); col.getSched().extendLimits(n, 0); resetAndUpdateValuesFromDeck(); finishCongrats(); } catch (NumberFormatException e) { // ignore non numerical values Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false); } catch (JSONException e) { throw new RuntimeException(e); } } } }); break; case CUSTOM_STUDY_REV: if (AnkiDroidApp.colIsOpen()) { Collection col = AnkiDroidApp.getCol(); mCustomStudyTextView1.setText(res.getString(R.string.custom_study_rev_total_rev, col.getSched().totalRevForCurrentDeck())); } mCustomStudyTextView2.setText(res.getString(R.string.custom_study_rev_extend)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendRev", 10))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (AnkiDroidApp.colIsOpen()) { try { int n = Integer.parseInt(mCustomStudyEditText.getText().toString()); AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n) .commit(); Collection col = AnkiDroidApp.getCol(); JSONObject deck = col.getDecks().current(); deck.put("extendRev", n); col.getDecks().save(deck); col.getSched().extendLimits(0, n); resetAndUpdateValuesFromDeck(); finishCongrats(); } catch (NumberFormatException e) { // ignore non numerical values Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false); } catch (JSONException e) { throw new RuntimeException(e); } } } }); break; case CUSTOM_STUDY_FORGOT: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_forgotten)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("forgottenDays", 2))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONArray ar = new JSONArray(); try { int forgottenDays = Integer .parseInt(((EditText) mCustomStudyEditText).getText().toString()); ar.put(0, 1); createFilteredDeck(ar, new Object[] { String.format(Locale.US, "rated:%d:1", forgottenDays), 9999, Sched.DYN_RANDOM }, false); } catch (NumberFormatException e) { // ignore non numerical values Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false); } catch (JSONException e) { throw new RuntimeException(e); } } }); break; case CUSTOM_STUDY_AHEAD: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_ahead)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("aheadDays", 1))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { int days = Integer .parseInt(((EditText) mCustomStudyEditText).getText().toString()); createFilteredDeck(new JSONArray(), new Object[] { String.format(Locale.US, "prop:due<=%d", days), 9999, Sched.DYN_DUE }, true); } catch (NumberFormatException e) { // ignore non numerical values Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false); } } }); break; case CUSTOM_STUDY_RANDOM: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_random)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("randomCards", 100))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { int randomCards = Integer .parseInt(((EditText) mCustomStudyEditText).getText().toString()); createFilteredDeck(new JSONArray(), new Object[] { "", randomCards, Sched.DYN_RANDOM }, true); } catch (NumberFormatException e) { // ignore non numerical values Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false); } } }); break; case CUSTOM_STUDY_PREVIEW: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_preview)); mCustomStudyEditText.setText( Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("previewDays", 1))); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String previewDays = ((EditText) mCustomStudyEditText).getText().toString(); createFilteredDeck(new JSONArray(), new Object[] { "is:new added:" + previewDays, 9999, Sched.DYN_OLDEST }, false); } }); break; case CUSTOM_STUDY_TAGS: mCustomStudyTextView1.setText(""); mCustomStudyTextView2.setText(res.getString(R.string.custom_study_tags)); mCustomStudyEditText .setText(AnkiDroidApp.getSharedPrefs(getActivity()).getString("customTags", "")); styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String tags = ((EditText) mCustomStudyEditText).getText().toString(); createFilteredDeck(new JSONArray(), new Object[] { "(is:new or is:due) " + tags, 9999, Sched.DYN_RANDOM }, true); } }); break; } } }