Skip to content

Commit

Permalink
Merge branch 'sqli-ImageBigStyle'
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed May 2, 2016
2 parents e837848 + 663104a commit bf774e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build/
npm-debug.log
system-notification.iml
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ Add a timestamp pertaining to the notification (usually the time the event occur
**bigText (`string`)**
Set the text to be shown when the user expand the notification.

**bigStyleImageBase64 (`string`)**
Set the image in base64 to be shown when the user expand the notification. if bigText is not null, it have priority over bigStyleImageBase64.

**subText (`string`)**
Set the third line of text in the platform notification template. Note that it cannot be used with `progress`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.neson.react.notification;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.SystemClock;
import android.app.PendingIntent;
Expand All @@ -22,6 +24,7 @@

import android.support.v7.app.NotificationCompat;
import android.text.Html;
import android.util.Base64;
import android.util.Log;
import android.graphics.Color;

Expand Down Expand Up @@ -173,11 +176,33 @@ public android.app.Notification build() {
notificationBuilder.setShowWhen(true);
}

// if bigText is not null, it have priority over bigStyleImageBase64
if (attributes.bigText != null) {
notificationBuilder
.setStyle(new android.support.v7.app.NotificationCompat.BigTextStyle()
.bigText(attributes.bigText));
}
else if (attributes.bigStyleImageBase64 != null) {

Bitmap bigPicture = null;

try {

Log.i("ReactSystemNotification", "start to convert bigStyleImageBase64 to bitmap");
// Convert base64 image to Bitmap
byte[] bitmapAsBytes = Base64.decode(attributes.bigStyleImageBase64.getBytes(), Base64.DEFAULT);
bigPicture = BitmapFactory.decodeByteArray(bitmapAsBytes, 0, bitmapAsBytes.length);
Log.i("ReactSystemNotification", "finished to convert bigStyleImageBase64 to bitmap");

} catch (Exception e) {
Log.e("ReactSystemNotification", "Error when converting base 64 to Bitmap" + e.getStackTrace());
}

if (bigPicture != null) {
notificationBuilder
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPicture));
}
}

if (attributes.color != null) {
notificationBuilder.setColor(Color.parseColor(attributes.color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.Iterator;

import com.facebook.react.bridge.WritableNativeMap;
import com.google.gson.Gson;

public class NotificationAttributes {
Expand Down Expand Up @@ -46,6 +48,7 @@ public class NotificationAttributes {
public String tickerText;
public Long when;
public String bigText;
public String bigStyleImageBase64;
public String subText;
public Integer progress;
public String color;
Expand Down Expand Up @@ -128,6 +131,7 @@ public void loadFromReadableMap(ReadableMap readableMap) {
if (readableMap.hasKey("tickerText")) tickerText = readableMap.getString("tickerText");
if (readableMap.hasKey("when")) when = Long.parseLong(readableMap.getString("when"));
if (readableMap.hasKey("bigText")) bigText = readableMap.getString("bigText");
if (readableMap.hasKey("bigStyleImageBase64")) bigStyleImageBase64 = readableMap.getString("bigStyleImageBase64");
if (readableMap.hasKey("subText")) subText = readableMap.getString("subText");
if (readableMap.hasKey("progress")) progress = readableMap.getInt("progress");
if (readableMap.hasKey("color")) color = readableMap.getString("color");
Expand Down Expand Up @@ -191,6 +195,7 @@ public ReadableMap asReadableMap() {
if (tickerText != null) writableMap.putString("tickerText", tickerText);
if (when != null) writableMap.putString("when", Long.toString(when));
if (bigText != null) writableMap.putString("bigText", bigText);
if (bigStyleImageBase64 != null) writableMap.putString("bigStyleImageBase64", bigStyleImageBase64);
if (subText != null) writableMap.putString("subText", subText);
if (progress != null) writableMap.putInt("progress", progress);
if (color != null) writableMap.putString("color", color);
Expand Down

0 comments on commit bf774e9

Please sign in to comment.