Browse Source

Support for big-text and inbox style on Android

Sebastián Katzer 8 years ago
parent
commit
d85f6af16b

+ 45 - 0
src/android/notification/Builder.java

@@ -117,12 +117,57 @@ public class Builder {
             builder.setSmallIcon(options.getIcon());
         }
 
+        applyStyle(builder);
         applyDeleteReceiver(builder);
         applyContentReceiver(builder);
 
         return new Notification(context, options, builder);
     }
 
+    /**
+     * Find out and set the notification style.
+     *
+     * @param builder Local notification builder instance
+     */
+    private void applyStyle(NotificationCompat.Builder builder) {
+        String summary = options.getSummary();
+        String text    = options.getText();
+
+        if (summary == null && text == null)
+            return;
+
+        if (text.contains("\n")) {
+            NotificationCompat.InboxStyle style =
+                    new NotificationCompat.InboxStyle(builder)
+                            .setBigContentTitle(options.getTitle());
+
+            if (summary != null) {
+                style.setSummaryText(summary);
+            }
+
+            for (String line : text.split("\n")) {
+                style.addLine(line);
+            }
+
+            builder.setStyle(style);
+            return;
+        }
+
+        if (summary == null && text.length() < 45)
+            return;
+
+        NotificationCompat.BigTextStyle style =
+                new NotificationCompat.BigTextStyle(builder)
+                        .setBigContentTitle(options.getTitle())
+                        .bigText(text);
+
+        if (summary != null) {
+            style.setSummaryText(summary);
+        }
+
+        builder.setStyle(style);
+    }
+
     /**
      * Set intent to handle the delete event. Will clean up some persisted
      * preferences.

+ 7 - 0
src/android/notification/Options.java

@@ -444,6 +444,13 @@ public class Options {
                 .optBoolean("indeterminate", false);
     }
 
+    /**
+     * The summary for inbox style notifications.
+     */
+    String getSummary() {
+        return options.optString("summary");
+    }
+
     /**
      * Gets the raw trigger spec as provided by the user.
      */

+ 0 - 3
src/android/notification/util/AssetUtil.java

@@ -27,7 +27,6 @@ import android.content.res.AssetManager;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.media.RingtoneManager;
 import android.net.Uri;
 import android.os.StrictMode;
 import android.util.Log;
@@ -43,8 +42,6 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.UUID;
 
-import static android.media.RingtoneManager.TYPE_NOTIFICATION;
-
 /**
  * Util class to map unified asset URIs to native URIs. URIs like file:///
  * map to absolute paths while file:// point relatively to the www folder

+ 2 - 1
www/local-notification-util.js

@@ -51,6 +51,7 @@ exports.applyPlatformSpecificOptions = function () {
 
     switch (device.platform) {
     case 'Android':
+        defaults.summary    = undefined;
         defaults.icon       = 'res://icon';
         defaults.smallIcon  = undefined;
         defaults.sticky     = false;
@@ -83,7 +84,7 @@ exports.mergeWithDefaults = function (options) {
         options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
     }
 
-    if (options.autoClear !== true && options.sticky) {
+    if (options.autoClear !== true && options.ongoing) {
         options.autoClear = false;
     }