Guest User

Untitled

a guest
Nov 3rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. public static int APP_IS_RUNNING_NOTIFICATION_ID = 6;
  2. ...
  3. notificationManager.notify(APP_IS_RUNNING_NOTIFICATION_ID, buildAppIsRunningNotificationForOverstayEnabled());
  4.  
  5. private Notification buildAppIsRunningNotificationForOverstayEnabled() {
  6.  
  7.         long timeValue = overstayManager.calculateRemainingTimeMillis();
  8.  
  9.         String notificationText = timeValue >= 0
  10.             ? context.getString(R.string.overstay_notification_text)
  11.             : context.getString(R.string.overstay_notification_text_time_over);
  12.  
  13.         String remainingTime = timeValue >= 0
  14.                 ? LongExtensionsKt.toHHmmssString(timeValue)
  15.                 : context.getString(R.string.empty);
  16.  
  17.         CharSequence notificationTitle;
  18.  
  19.         if(timeValue >= TimeUnit.MINUTES.toMillis(15))
  20.             notificationTitle = Html.fromHtml(context.getString(R.string.overstay_remaining_time_title, remainingTime));
  21.         else if(timeValue >= 0)
  22.             notificationTitle = Html.fromHtml(context.getString(R.string.overstay_remaining_time_title_under_15, remainingTime));
  23.         else
  24.             notificationTitle = context.getString(R.string.overstay_remaining_time_title_timer_over);
  25.  
  26.         RemoteViews remoteViews = new RemoteViews(context.getPackageName(), timeValue >= TimeUnit.MINUTES.toMillis(15)
  27.                 ? R.layout.custom_notification_with_action_overstay
  28.                 : R.layout.custom_notification_with_action_overstay_under_15_min);
  29.         remoteViews.setTextViewText(R.id.title, notificationTitle);
  30.         remoteViews.setTextViewText(R.id.text, notificationText);
  31.  
  32.         NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
  33.                 .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.parkanizer_small_logo_new))
  34.                 .setSmallIcon(R.drawable.notify_white)
  35.                 .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
  36.                 .setContent(remoteViews)
  37.                 .setTicker(notificationText)
  38.                 .setAutoCancel(false)
  39.                 .setOngoing(true)
  40.                 .setPriority(Notification.PRIORITY_MAX)
  41.                 .setContentIntent(returnToAppPendingIntent);
  42.  
  43.         if(overstayManager.shouldPlayNotificationSound())
  44.             notificationBuilder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.parkanizer_notification_positive));
  45.  
  46.         Notification notification = notificationBuilder.build();
  47.         hideSmallIcon(notification);
  48.  
  49.         Log.d("NOTIF", "CREATED");
  50.         return notification;
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment