diff app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java @ 457:105815cce146 stable-1.9.3-3

minimum version android 5, target and compile version api 28
author Carl Byington <carl@five-ten-sg.com>
date Tue, 29 Jan 2019 11:21:57 -0800
parents d29cce60f393
children 3afdeb535e9f
line wrap: on
line diff
--- a/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Sat Nov 10 12:18:05 2018 -0800
+++ b/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Tue Jan 29 11:21:57 2019 -0800
@@ -29,6 +29,7 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.Color;
+import android.graphics.BitmapFactory;
 
 /**
  * @author Kenny Root
@@ -43,56 +44,48 @@
         return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
     }
 
-    protected Notification newNotification(Context context) {
-        Notification notification = new Notification();
-        notification.icon = R.drawable.notification_icon;
-        notification.when = System.currentTimeMillis();
-        return notification;
-    }
-
     protected Notification newActivityNotification(Context context, HostBean host) {
-        Notification notification = newNotification(context);
+        int rgb;
+        if (HostDatabase.COLOR_RED.equals(host.getColor()))
+            rgb = Color.RED;
+        else if (HostDatabase.COLOR_GREEN.equals(host.getColor()))
+            rgb = Color.GREEN;
+        else if (HostDatabase.COLOR_BLUE.equals(host.getColor()))
+            rgb = Color.BLUE;
+        else
+            rgb = Color.WHITE;
         Resources res = context.getResources();
-        String contentText = res.getString(
-                                 R.string.notification_text, host.getNickname());
         Intent notificationIntent = new Intent(context, ConsoleActivity.class);
-        notificationIntent.setAction(Intent.ACTION_VIEW);
-        notificationIntent.setData(host.getUri());
-        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
-                                      notificationIntent, 0);
-        notification.setLatestEventInfo(context, res.getString(R.string.app_name), contentText, contentIntent);
-        notification.flags = Notification.FLAG_AUTO_CANCEL;
-        notification.flags |= Notification.DEFAULT_LIGHTS;
-
-        if (HostDatabase.COLOR_RED.equals(host.getColor()))
-            notification.ledARGB = Color.RED;
-        else if (HostDatabase.COLOR_GREEN.equals(host.getColor()))
-            notification.ledARGB = Color.GREEN;
-        else if (HostDatabase.COLOR_BLUE.equals(host.getColor()))
-            notification.ledARGB = Color.BLUE;
-        else
-            notification.ledARGB = Color.WHITE;
-
-        notification.ledOnMS = 300;
-        notification.ledOffMS = 1000;
-        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
+        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+        Notification notification = new Notification.Builder(context)
+            .setContentTitle(res.getString(R.string.app_name))
+            .setContentText(res.getString(R.string.notification_text, host.getNickname()))
+            .setContentIntent(contentIntent)
+            .setWhen(System.currentTimeMillis())
+            .setSmallIcon(R.drawable.notification_icon)
+            .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon))
+            .setLights(rgb, 300, 1000)
+            .build();
+        notification.flags |= Notification.FLAG_AUTO_CANCEL;
         return notification;
     }
 
     protected Notification newRunningNotification(Context context) {
-        Notification notification = newNotification(context);
-        notification.flags = Notification.FLAG_ONGOING_EVENT
-                             | Notification.FLAG_NO_CLEAR;
-        notification.when = 0;
-        notification.contentIntent = PendingIntent.getActivity(context,
-                                     ONLINE_NOTIFICATION,
-                                     new Intent(context, ConsoleActivity.class), 0);
         Resources res = context.getResources();
-        notification.setLatestEventInfo(context,
-                                        res.getString(R.string.app_name),
-                                        res.getString(R.string.app_is_running),
-                                        notification.contentIntent);
+        Intent notificationIntent = new Intent(context, ConsoleActivity.class);
+        PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0);
+        Notification notification = new Notification.Builder(context)
+            .setContentTitle(res.getString(R.string.app_name))
+            .setContentText(res.getString(R.string.app_is_running))
+            .setContentIntent(contentIntent)
+            .setWhen(0)
+            .setOngoing(true)
+            .setSmallIcon(R.drawable.notification_icon)
+            .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon))
+            .build();
+        notification.flags |= Notification.FLAG_NO_CLEAR;
         return notification;
+
     }
 
     public void showActivityNotification(Service context, HostBean host) {