Java Code Examples for androidx.core.app.NotificationCompat#InboxStyle
The following examples show how to use
androidx.core.app.NotificationCompat#InboxStyle .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KaliumMessagingService.java From natrium-android-wallet with BSD 2-Clause "Simplified" License | 6 votes |
private NotificationCompat.InboxStyle getStyleForNotification(String messageBody) { NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(); SharedPreferences sharedPref = getSharedPreferences("NotificationData", 0); Map<String, String> notificationMessages = (Map<String, String>) sharedPref.getAll(); Map<String, String> myNewHashMap = new HashMap<>(); for (Map.Entry<String, String> entry : notificationMessages.entrySet()) { myNewHashMap.put(entry.getKey(), entry.getValue()); } inbox.addLine(messageBody); for (Map.Entry<String, String> message : myNewHashMap.entrySet()) { inbox.addLine(message.getValue()); } inbox.setBigContentTitle(this.getResources().getString(R.string.app_name)) .setSummaryText(getString(R.string.notificaiton_header_suplement)); return inbox; }
Example 2
Source File: EventProcessor.java From android-app with GNU General Public License v3.0 | 6 votes |
@Subscribe(sticky = true) public void onDownloadFileStartedEvent(DownloadFileStartedEvent event) { Log.d(TAG, "onDownloadFileStartedEvent() started"); Context context = getContext(); String formatString = event.getRequest().getDownloadFormat().toString(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID_DOWNLOADING_ARTICLES) .setContentTitle(context.getString(R.string.downloadAsFilePathStart)) .setContentText(context.getString(R.string.downloadAsFileProgress, formatString)) .setSmallIcon(R.drawable.ic_file_download_24dp) .setOngoing(true); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle( context.getString(R.string.downloadAsFileProgressDetail, event.getArticle().getTitle().replaceAll("[^a-zA-Z0-9.-]", " "), formatString)); notificationBuilder.setStyle(inboxStyle); getNotificationManager().notify(TAG, NOTIFICATION_ID_DOWNLOAD_FILE_ONGOING, notificationBuilder.setProgress(1, 0, true).build()); }
Example 3
Source File: NotificationManager.java From QuickDevFramework with Apache License 2.0 | 6 votes |
/** * set inbox data style for notification * @param builder builder * @param title title * @param summaryText summary * @param lines multiline text list * */ public static NotificationCompat.Builder setInboxMessages(NotificationCompat.Builder builder, String title, String summaryText, List<String> lines) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(title); if (!TextUtils.isEmpty(summaryText)) { inboxStyle.setSummaryText(summaryText); } for (String line : lines) { inboxStyle.addLine(line); } builder.setStyle(inboxStyle); return builder; }
Example 4
Source File: FileDownloaderExecutor.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable private NotificationCompat.InboxStyle buildInboxStyle(@Nullable List<String> titleList, float process) { if (titleList != null) { NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(); inbox.setBigContentTitle(context.getString(R.string.feedback_downloading)); inbox.setSummaryText(((int) process) + "%"); for (int i = 0; i < titleList.size(); i ++) { if (i < 7) { inbox.addLine(titleList.get(i)); } else { inbox.addLine("..."); break; } } return inbox; } else { return null; } }
Example 5
Source File: NotificationHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
private Notification buildProgressNotification(Context c, boolean timeChanged) { int process = (int) (100.0 * soFar / total); NotificationCompat.Builder builder = new NotificationCompat.Builder(c); builder.setSmallIcon(getIconResId(timeChanged)); builder.setContentTitle(c.getString(R.string.feedback_downloading)); builder.setSubText(process + "%"); builder.setProgress(100, process, false); NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(); for (int i = 0; i < titleList.size(); i ++) { inbox.addLine(titleList.get(i)); } builder.setStyle(inbox); Intent intent = IntentHelper.getDownloadManageActivityIntent(c); PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); return builder.build(); }
Example 6
Source File: NotificationChannel.java From Shipr-Community-Android with GNU General Public License v3.0 | 5 votes |
private void Notify() { Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); final PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) Calendar.getInstance().getTimeInMillis(), intent, 0); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(channel_Id + " channel"); for (int i = (messages.size() > 5 ? messages.size() - 5 : 0); i < messages.size(); i++) { DeveloperMessage message = messages.get(i); String line = message.getName() + ":\t" + message.getText(); inboxStyle.addLine(line); } int count = messages.size(); String summary = count + (count > 1 ? " new messages" : " new message"); inboxStyle.setSummaryText(summary); //Todo: change the small icon with an xml icon NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channel_Id) .setSmallIcon(R.mipmap.ic_launcher) //Todo: change the small icon with an xml icon .setStyle(inboxStyle) .setContentIntent(pendingIntent) .setContentTitle(channel_Id + " channel") .setContentText(summary); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { android.app.NotificationChannel notificationChannel = new android.app.NotificationChannel(channel_Id, "Maker Toolbox", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(notificationChannel); } notificationManager.notify(id, builder.build()); }
Example 7
Source File: NotificationHelper.java From Gander with Apache License 2.0 | 5 votes |
public synchronized void show(HttpTransaction transaction, boolean stickyNotification) { HttpTransactionUIHelper httpTransactionUIHelper = new HttpTransactionUIHelper(transaction); addToBuffer(httpTransactionUIHelper); if (!BaseGanderActivity.isInForeground()) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, CHANNEL_ID) .setContentIntent(PendingIntent.getActivity(mContext, 0, Gander.getLaunchIntent(mContext), 0)) .setLocalOnly(true) .setSmallIcon(R.drawable.gander_ic_notification_white_24dp) .setColor(ContextCompat.getColor(mContext, R.color.gander_colorPrimary)) .setOngoing(stickyNotification) .setContentTitle(mContext.getString(R.string.gander_notification_title)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); int count = 0; for (int i = TRANSACTION_BUFFER.size() - 1; i >= 0; i--) { if (count < BUFFER_SIZE) { if (count == 0) { builder.setContentText(getNotificationText(TRANSACTION_BUFFER.valueAt(i))); } inboxStyle.addLine(getNotificationText(TRANSACTION_BUFFER.valueAt(i))); } count++; } builder.setAutoCancel(true); builder.setStyle(inboxStyle); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { builder.setSubText(String.valueOf(TRANSACTION_COUNT)); } else { builder.setNumber(TRANSACTION_COUNT); } builder.addAction(getDismissAction()); builder.addAction(getClearAction()); mNotificationManager.notify(NOTIFICATION_ID, builder.build()); } }
Example 8
Source File: TimerService.java From Alarmio with Apache License 2.0 | 5 votes |
@Nullable private Notification getNotification() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) notificationManager.createNotificationChannel(new NotificationChannel(Alarmio.NOTIFICATION_CHANNEL_TIMERS, "Timers", NotificationManager.IMPORTANCE_LOW)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String string = ""; for (TimerData timer : timers) { if (!timer.isSet()) continue; String time = FormatUtils.formatMillis(timer.getRemainingMillis()); time = time.substring(0, time.length() - 3); inboxStyle.addLine(time); string += "/" + time + "/"; } if (notificationString != null && notificationString.equals(string)) return null; notificationString = string; Intent intent = new Intent(this, MainActivity.class); if (timers.size() == 1) intent.putExtra(TimerReceiver.EXTRA_TIMER_ID, 0); return new NotificationCompat.Builder(this, Alarmio.NOTIFICATION_CHANNEL_TIMERS) .setSmallIcon(R.drawable.ic_timer_notification) .setContentTitle(getString(R.string.title_set_timer)) .setContentText("") .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)) .setStyle(inboxStyle) .build(); }
Example 9
Source File: EventProcessor.java From android-app with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onDownloadFileFinishedEvent(DownloadFileFinishedEvent event) { Log.d(TAG, "onDownloadFileFinishedEvent() started"); ActionResult result = event.getResult(); if(result == null || result.isSuccess()) { Context context = getContext(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = WallabagFileProvider.getUriForFile(context, event.getFile()); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension( event.getRequest().getDownloadFormat().toString().toLowerCase(Locale.US)); intent.setDataAndType(uri, mimeType); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID_DOWNLOADING_ARTICLES) .setContentTitle(context.getString(R.string.downloadAsFileArticleDownloaded)) .setContentText(context.getString(R.string.downloadAsFileTouchToOpen)) .setSmallIcon(R.drawable.ic_file_download_24dp) .setContentIntent(contentIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle( context.getString(R.string.downloadAsFileArticleDownloadedDetail, event.getArticle().getTitle().replaceAll("[^a-zA-Z0-9.-]", " "))); notificationBuilder.setStyle(inboxStyle); getNotificationManager().notify(TAG, NOTIFICATION_ID_DOWNLOAD_FILE_ONGOING, notificationBuilder.build()); } else { getNotificationManager().cancel(TAG, NOTIFICATION_ID_DOWNLOAD_FILE_ONGOING); } }
Example 10
Source File: MultipleRecipientNotificationBuilder.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public Notification build() { if (privacy.isDisplayMessage() || privacy.isDisplayContact()) { NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); for (CharSequence body : messageBodies) { style.addLine(trimToDisplayLength(body)); } setStyle(style); } return super.build(); }
Example 11
Source File: FileDownloaderExecutor.java From Mysplash with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void run() { List<String> titleList = new ArrayList<>(); AtomicLong total = new AtomicLong(); AtomicLong soFar = new AtomicLong(); int process; AtomicInteger size = new AtomicInteger(); FileDownloader.getImpl().startForeground( NotificationHelper.NOTIFICATION_DOWNLOADING_ID, builder.build() ); while (isRunning()) { titleList.clear(); total.set(0); soFar.set(0); lockableTaskList.read(list -> { size.set(innerListenerList.size()); if (size.get() != 0) { for (TaskDownloadListener l : innerListenerList) { titleList.add(l.task.getNotificationTitle()); total.addAndGet(l.total); soFar.addAndGet(l.soFar); } } }); if (size.get() == 0) { break; } process = (int) Math.max(0, Math.min(100, 100.0 * soFar.get() / total.get())); NotificationCompat.InboxStyle inboxStyle = buildInboxStyle(titleList, process); builder.setSubText(process + "%"); builder.setProgress(100, process, false); builder.setStyle(inboxStyle); NotificationHelper.sendDownloadingNotification(context, builder.build()); SystemClock.sleep(1000); } FileDownloader.getImpl().stopForeground(true); NotificationHelper.removeDownloadingNotification(context); }
Example 12
Source File: DownloadService.java From EhViewer with Apache License 2.0 | 4 votes |
@Override public void onFinish(DownloadInfo info) { if (mNotifyManager == null) { return; } if (null != mDownloadingDelay) { mDownloadingDelay.cancel(); } ensureDownloadedBuilder(); boolean finish = info.state == DownloadInfo.STATE_FINISH; long gid = info.gid; int index = sItemStateArray.indexOfKey(gid); if (index < 0) { // Not contain sItemStateArray.put(gid, finish); sItemTitleArray.put(gid, EhUtils.getSuitableTitle(info)); sDownloadedCount++; if (finish) { sFinishedCount++; } else { sFailedCount++; } } else { // Contain boolean oldFinish = sItemStateArray.valueAt(index); sItemStateArray.put(gid, finish); sItemTitleArray.put(gid, EhUtils.getSuitableTitle(info)); if (oldFinish && !finish) { sFinishedCount--; sFailedCount++; } else if (!oldFinish && finish) { sFinishedCount++; sFailedCount--; } } String text; boolean needStyle; if (sFinishedCount != 0 && sFailedCount == 0) { if (sFinishedCount == 1) { if (sItemTitleArray.size() >= 1) { text = getString(R.string.stat_download_done_line_succeeded, sItemTitleArray.valueAt(0)); } else { Log.d("TAG", "WTF, sItemTitleArray is null"); text = getString(R.string.error_unknown); } needStyle = false; } else { text = getString(R.string.stat_download_done_text_succeeded, sFinishedCount); needStyle = true; } } else if (sFinishedCount == 0 && sFailedCount != 0) { if (sFailedCount == 1) { if (sItemTitleArray.size() >= 1) { text = getString(R.string.stat_download_done_line_failed, sItemTitleArray.valueAt(0)); } else { Log.d("TAG", "WTF, sItemTitleArray is null"); text = getString(R.string.error_unknown); } needStyle = false; } else { text = getString(R.string.stat_download_done_text_failed, sFailedCount); needStyle = true; } } else { text = getString(R.string.stat_download_done_text_mix, sFinishedCount, sFailedCount); needStyle = true; } NotificationCompat.InboxStyle style; if (needStyle) { style = new NotificationCompat.InboxStyle(); style.setBigContentTitle(getString(R.string.stat_download_done_title)); SparseJBArray stateArray = sItemStateArray; SparseJLArray<String> titleArray = sItemTitleArray; for (int i = 0, n = stateArray.size(); i < n; i++) { long id = stateArray.keyAt(i); boolean fin = stateArray.valueAt(i); String title = titleArray.get(id); if (title == null) { continue; } style.addLine(getString(fin ? R.string.stat_download_done_line_succeeded : R.string.stat_download_done_line_failed, title)); } } else { style = null; } mDownloadedBuilder.setContentText(text) .setStyle(style) .setWhen(System.currentTimeMillis()) .setNumber(sDownloadedCount); mDownloadedDelay.show(); checkStopSelf(); }
Example 13
Source File: DeviceAdminReceiver.java From android-testdpc with Apache License 2.0 | 4 votes |
private static void updatePasswordConstraintNotification(Context context) { final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( Context.DEVICE_POLICY_SERVICE); final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); if (!dpm.isProfileOwnerApp(context.getPackageName()) && !dpm.isDeviceOwnerApp(context.getPackageName())) { // Only try to update the notification if we are a profile or device owner. return; } final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final ArrayList<CharSequence> problems = new ArrayList<>(); if (!dpm.isActivePasswordSufficient()) { problems.add(context.getText(R.string.password_not_compliant_title)); } if (um.hasUserRestriction(UserManager.DISALLOW_UNIFIED_PASSWORD) && Util.isManagedProfileOwner(context) && isUsingUnifiedPassword(context)) { problems.add(context.getText(R.string.separate_challenge_required_title)); } if (!problems.isEmpty()) { final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); style.setBigContentTitle( context.getText(R.string.set_new_password_notification_content)); for (final CharSequence problem : problems) { style.addLine(problem); } final NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context); warn.setOngoing(true) .setSmallIcon(R.drawable.ic_launcher) .setStyle(style) .setContentIntent(PendingIntent.getActivity(context, /*requestCode*/ -1, new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /*flags*/ 0)); nm.notify(CHANGE_PASSWORD_NOTIFICATION_ID, warn.getNotification()); } else { nm.cancel(CHANGE_PASSWORD_NOTIFICATION_ID); } }
Example 14
Source File: DeviceAdminReceiver.java From android-testdpc with Apache License 2.0 | 4 votes |
@TargetApi(VERSION_CODES.O) // @Override public void onPasswordFailed(Context context, Intent intent, UserHandle user) { if (!Process.myUserHandle().equals(user)) { // This password failure was on another user, for example a parent profile. Ignore it. return; } DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService( Context.DEVICE_POLICY_SERVICE); /* * Post a notification to show: * - how many wrong passwords have been entered; * - how many wrong passwords need to be entered for the device to be wiped. */ int attempts = devicePolicyManager.getCurrentFailedPasswordAttempts(); int maxAttempts = devicePolicyManager.getMaximumFailedPasswordsForWipe(null); String title = context.getResources().getQuantityString( R.plurals.password_failed_attempts_title, attempts, attempts); ArrayList<Date> previousFailedAttempts = getFailedPasswordAttempts(context); Date date = new Date(); previousFailedAttempts.add(date); Collections.sort(previousFailedAttempts, Collections.<Date>reverseOrder()); try { saveFailedPasswordAttempts(context, previousFailedAttempts); } catch (IOException e) { Log.e(TAG, "Unable to save failed password attempts", e); } String content = maxAttempts == 0 ? context.getString(R.string.password_failed_no_limit_set) : context.getResources().getQuantityString( R.plurals.password_failed_attempts_content, maxAttempts, maxAttempts); NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context); warn.setSmallIcon(R.drawable.ic_launcher) .setTicker(title) .setContentTitle(title) .setContentText(content) .setContentIntent(PendingIntent.getActivity(context, /* requestCode */ -1, new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /* flags */ 0)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(title); final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(); for(Date d : previousFailedAttempts) { inboxStyle.addLine(dateFormat.format(d)); } warn.setStyle(inboxStyle); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(PASSWORD_FAILED_NOTIFICATION_ID, warn.build()); }
Example 15
Source File: MageApplication.java From mage-android with Apache License 2.0 | 4 votes |
public void createNotification() { boolean tokenExpired = UserUtility.getInstance(getApplicationContext()).isTokenExpired(); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, LoginActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(LoginActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); String noticationMsg = tokenExpired ? "Your token has expired, please tap to login." : "You are currently logged into MAGE."; Notification accountNotification = new NotificationCompat.Builder(this, MAGE_NOTIFICATION_CHANNEL_ID) .setOngoing(true) .setSortKey("1") .setContentTitle("MAGE") .setContentText(noticationMsg) .setGroup(MAGE_NOTIFICATION_GROUP) .setContentIntent(resultPendingIntent) .setSmallIcon(R.drawable.ic_wand_white_50dp) .addAction(R.drawable.ic_power_settings_new_white_24dp, "Logout", getLogoutPendingIntent()) .build(); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle() .addLine(noticationMsg) .setBigContentTitle("MAGE"); if (isReportingLocation()) { style.addLine("MAGE is currently reporting your location."); } // This summary notification supports "grouping" on versions older that Android.N Notification summaryNotification = new NotificationCompat.Builder(this, MAGE_NOTIFICATION_CHANNEL_ID) .setGroupSummary(true) .setGroup(MAGE_NOTIFICATION_GROUP) .setContentTitle("MAGE") .setContentText(noticationMsg) .setSmallIcon(R.drawable.ic_wand_white_50dp) .setStyle(style) .setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_power_settings_new_white_24dp, "Logout", getLogoutPendingIntent()) .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(MAGE_ACCOUNT_NOTIFICATION_ID, accountNotification); notificationManager.notify(MAGE_SUMMARY_NOTIFICATION_ID, summaryNotification); }
Example 16
Source File: QiscusPushNotificationUtil.java From qiscus-sdk-android with Apache License 2.0 | 4 votes |
private static void pushNotification(Context context, QiscusComment comment, QiscusPushNotificationMessage pushNotificationMessage, Bitmap largeIcon) { String notificationChannelId = Qiscus.getApps().getPackageName() + ".qiscus.sdk.notification.channel"; if (BuildVersionUtil.isOreoOrHigher()) { NotificationChannel notificationChannel = new NotificationChannel(notificationChannelId, "Chat", NotificationManager.IMPORTANCE_HIGH); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.createNotificationChannel(notificationChannel); } } PendingIntent pendingIntent; Intent openIntent = new Intent(context, QiscusPushNotificationClickReceiver.class); openIntent.putExtra("data", comment); pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()), openIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, notificationChannelId); notificationBuilder.setContentTitle(pushNotificationMessage.getRoomName()) .setContentIntent(pendingIntent) .setContentText(pushNotificationMessage.getMessage()) .setTicker(pushNotificationMessage.getMessage()) .setSmallIcon(Qiscus.getChatConfig().getNotificationSmallIcon()) .setLargeIcon(largeIcon) .setColor(ContextCompat.getColor(context, Qiscus.getChatConfig().getInlineReplyColor())) .setGroup("CHAT_NOTIF_" + comment.getRoomId()) .setAutoCancel(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (Qiscus.getChatConfig().isEnableReplyNotification() && isNougatOrHigher()) { String getRepliedTo = pushNotificationMessage.getRoomName(); RemoteInput remoteInput = new RemoteInput.Builder(KEY_NOTIFICATION_REPLY) .setLabel(QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase())) .build(); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send, QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase()), pendingIntent) .addRemoteInput(remoteInput) .build(); notificationBuilder.addAction(replyAction); } boolean cancel = false; if (Qiscus.getChatConfig().getNotificationBuilderInterceptor() != null) { cancel = !Qiscus.getChatConfig().getNotificationBuilderInterceptor() .intercept(notificationBuilder, comment); } if (cancel) { return; } NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); List<QiscusPushNotificationMessage> notifItems = QiscusCacheManager.getInstance() .getMessageNotifItems(comment.getRoomId()); if (notifItems == null) { notifItems = new ArrayList<>(); } int notifSize = 5; if (notifItems.size() < notifSize) { notifSize = notifItems.size(); } if (notifItems.size() > notifSize) { inboxStyle.addLine("......."); } int start = notifItems.size() - notifSize; for (int i = start; i < notifItems.size(); i++) { inboxStyle.addLine(notifItems.get(i).getMessage()); } inboxStyle.setSummaryText(QiscusTextUtil.getString(R.string.qiscus_notif_count, notifItems.size())); notificationBuilder.setStyle(inboxStyle); if (notifSize <= 3) { notificationBuilder.setPriority(Notification.PRIORITY_HIGH); } QiscusAndroidUtil.runOnUIThread(() -> NotificationManagerCompat.from(context) .notify(QiscusNumberUtil.convertToInt(comment.getRoomId()), notificationBuilder.build())); }
Example 17
Source File: RefreshJobService.java From mimi-reader with Apache License 2.0 | 4 votes |
private Pair<ChanThread, Integer> processPosts(ThreadRegistryModel model, ChanThread thread, NotificationCompat.InboxStyle style) { if (model != null && model.getUnreadCount() > 0) { final String hasUnread = getResources().getQuantityString(R.plurals.has_unread_plural, model.getUnreadCount(), model.getUnreadCount()); final String notificationTitle = "/" + model.getBoardName() + "/" + model.getThreadId() + " " + hasUnread; style.addLine(notificationTitle); int repliesToYou = -1; if (model.getUserPosts() != null && model.getUserPosts().size() > 0) { if (thread == null) { return Pair.create(ChanThread.empty(), -1); } final ChanThread currentThread = ProcessThreadTask.processThread( thread.getPosts(), model.getUserPosts(), model.getBoardName(), model.getThreadId() ); final int pos = model.getLastReadPosition() < model.getThreadSize() ? model.getLastReadPosition() : model.getThreadSize(); if (currentThread != null && currentThread.getPosts() != null) { repliesToYou = 0; for (int i = pos; i < currentThread.getPosts().size(); i++) { final ChanPost post = currentThread.getPosts().get(i); if (LOG_DEBUG) { Log.d(LOG_TAG, "post id=" + post.getNo()); } if (post.getRepliesTo() != null && post.getRepliesTo().size() > 0) { for (Long l : model.getUserPosts()) { final String s = String.valueOf(l); if (LOG_DEBUG) { Log.d(LOG_TAG, "Checking post id " + s); } if (post.getRepliesTo().indexOf(s) >= 0) { if (LOG_DEBUG) { Log.d(LOG_TAG, "Found reply to " + s); } repliesToYou++; userPosts++; } } } } } return new Pair<>(currentThread, repliesToYou); } } return Pair.create(ChanThread.empty(), -1); }
Example 18
Source File: DownloadService.java From MHViewer with Apache License 2.0 | 4 votes |
@Override public void onFinish(DownloadInfo info) { if (mNotifyManager == null) { return; } if (null != mDownloadingDelay) { mDownloadingDelay.cancel(); } ensureDownloadedBuilder(); boolean finish = info.state == DownloadInfo.STATE_FINISH; String gid = info.gid; int index = (Integer)sItemStateArray.get(gid); if (index < 0) { // Not contain sItemStateArray.put(gid, finish); sItemTitleArray.put(gid, EhUtils.getSuitableTitle(info)); sDownloadedCount++; if (finish) { sFinishedCount++; } else { sFailedCount++; } } else { // Contain boolean oldFinish = (Boolean)sItemStateArray.get(index); sItemStateArray.put(gid, finish); sItemTitleArray.put(gid, EhUtils.getSuitableTitle(info)); if (oldFinish && !finish) { sFinishedCount--; sFailedCount++; } else if (!oldFinish && finish) { sFinishedCount++; sFailedCount--; } } String text; boolean needStyle; if (sFinishedCount != 0 && sFailedCount == 0) { if (sFinishedCount == 1) { if (sItemTitleArray.size() >= 1) { text = getString(R.string.stat_download_done_line_succeeded, sItemTitleArray.get(0)); } else { Log.d("TAG", "WTF, sItemTitleArray is null"); text = getString(R.string.error_unknown); } needStyle = false; } else { text = getString(R.string.stat_download_done_text_succeeded, sFinishedCount); needStyle = true; } } else if (sFinishedCount == 0 && sFailedCount != 0) { if (sFailedCount == 1) { if (sItemTitleArray.size() >= 1) { text = getString(R.string.stat_download_done_line_failed, sItemTitleArray.get(0)); } else { Log.d("TAG", "WTF, sItemTitleArray is null"); text = getString(R.string.error_unknown); } needStyle = false; } else { text = getString(R.string.stat_download_done_text_failed, sFailedCount); needStyle = true; } } else { text = getString(R.string.stat_download_done_text_mix, sFinishedCount, sFailedCount); needStyle = true; } NotificationCompat.InboxStyle style; if (needStyle) { style = new NotificationCompat.InboxStyle(); style.setBigContentTitle(getString(R.string.stat_download_done_title)); HashMap stateArray = sItemStateArray; HashMap<String,String> titleArray = sItemTitleArray; for (int i = 0, n = stateArray.size(); i < n; i++) { long id = (Long)stateArray.get(i); boolean fin = (Boolean)stateArray.get(i); String title = titleArray.get(id); if (title == null) { continue; } style.addLine(getString(fin ? R.string.stat_download_done_line_succeeded : R.string.stat_download_done_line_failed, title)); } } else { style = null; } mDownloadedBuilder.setContentText(text) .setStyle(style) .setWhen(System.currentTimeMillis()) .setNumber(sDownloadedCount); mDownloadedDelay.show(); checkStopSelf(); }