Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int APP_IS_RUNNING_NOTIFICATION_ID = 6;
- ...
- notificationManager.notify(APP_IS_RUNNING_NOTIFICATION_ID, buildAppIsRunningNotificationForOverstayEnabled());
- private Notification buildAppIsRunningNotificationForOverstayEnabled() {
- long timeValue = overstayManager.calculateRemainingTimeMillis();
- String notificationText = timeValue >= 0
- ? context.getString(R.string.overstay_notification_text)
- : context.getString(R.string.overstay_notification_text_time_over);
- String remainingTime = timeValue >= 0
- ? LongExtensionsKt.toHHmmssString(timeValue)
- : context.getString(R.string.empty);
- CharSequence notificationTitle;
- if(timeValue >= TimeUnit.MINUTES.toMillis(15))
- notificationTitle = Html.fromHtml(context.getString(R.string.overstay_remaining_time_title, remainingTime));
- else if(timeValue >= 0)
- notificationTitle = Html.fromHtml(context.getString(R.string.overstay_remaining_time_title_under_15, remainingTime));
- else
- notificationTitle = context.getString(R.string.overstay_remaining_time_title_timer_over);
- RemoteViews remoteViews = new RemoteViews(context.getPackageName(), timeValue >= TimeUnit.MINUTES.toMillis(15)
- ? R.layout.custom_notification_with_action_overstay
- : R.layout.custom_notification_with_action_overstay_under_15_min);
- remoteViews.setTextViewText(R.id.title, notificationTitle);
- remoteViews.setTextViewText(R.id.text, notificationText);
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
- .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.parkanizer_small_logo_new))
- .setSmallIcon(R.drawable.notify_white)
- .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
- .setContent(remoteViews)
- .setTicker(notificationText)
- .setAutoCancel(false)
- .setOngoing(true)
- .setPriority(Notification.PRIORITY_MAX)
- .setContentIntent(returnToAppPendingIntent);
- if(overstayManager.shouldPlayNotificationSound())
- notificationBuilder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.parkanizer_notification_positive));
- Notification notification = notificationBuilder.build();
- hideSmallIcon(notification);
- Log.d("NOTIF", "CREATED");
- return notification;
- }
Advertisement
Add Comment
Please, Sign In to add comment