Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Added support of HTML tags to title, message and summary text. (#892)
Browse files Browse the repository at this point in the history
* Added support of HTML tags to title, message and summary text.

* Bugfix for NullPointerException

* Remove debug console output
  • Loading branch information
waptaxi authored and macdonst committed May 26, 2016
1 parent 92576a2 commit 37d5666
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;

import com.google.android.gms.gcm.GcmListenerService;
Expand Down Expand Up @@ -236,8 +237,8 @@ public void createNotification(Context context, Bundle extras) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString(TITLE))
.setTicker(extras.getString(TITLE))
.setContentTitle(fromHtml(extras.getString(TITLE)))
.setTicker(fromHtml(extras.getString(TITLE)))
.setContentIntent(contentIntent)
.setAutoCancel(true);

Expand Down Expand Up @@ -411,7 +412,7 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat
if(STYLE_INBOX.equals(style)) {
setNotification(notId, message);

mBuilder.setContentText(message);
mBuilder.setContentText(fromHtml(message));

ArrayList<String> messageList = messageMap.get(notId);
Integer sizeList = messageList.size();
Expand All @@ -423,19 +424,19 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat
stacking = stacking.replace("%n%", sizeListMessage);
}
NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle()
.setBigContentTitle(extras.getString(TITLE))
.setSummaryText(stacking);
.setBigContentTitle(fromHtml(extras.getString(TITLE)))
.setSummaryText(fromHtml(stacking));

for (int i = messageList.size() - 1; i >= 0; i--) {
notificationInbox.addLine(Html.fromHtml(messageList.get(i)));
notificationInbox.addLine(fromHtml(messageList.get(i)));
}

mBuilder.setStyle(notificationInbox);
} else {
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
if (message != null) {
bigText.bigText(message);
bigText.setBigContentTitle(extras.getString(TITLE));
bigText.bigText(fromHtml(message));
bigText.setBigContentTitle(fromHtml(extras.getString(TITLE)));
mBuilder.setStyle(bigText);
}
}
Expand All @@ -444,11 +445,11 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat

NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle();
bigPicture.bigPicture(getBitmapFromURL(extras.getString(PICTURE)));
bigPicture.setBigContentTitle(extras.getString(TITLE));
bigPicture.setSummaryText(extras.getString(SUMMARY_TEXT));
bigPicture.setBigContentTitle(fromHtml(extras.getString(TITLE)));
bigPicture.setSummaryText(fromHtml(extras.getString(SUMMARY_TEXT)));

mBuilder.setContentTitle(extras.getString(TITLE));
mBuilder.setContentText(message);
mBuilder.setContentTitle(fromHtml(extras.getString(TITLE)));
mBuilder.setContentText(fromHtml(message));

mBuilder.setStyle(bigPicture);
} else {
Expand All @@ -457,14 +458,14 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();

if (message != null) {
mBuilder.setContentText(Html.fromHtml(message));
mBuilder.setContentText(fromHtml(message));

bigText.bigText(message);
bigText.setBigContentTitle(extras.getString(TITLE));
bigText.bigText(fromHtml(message));
bigText.setBigContentTitle(fromHtml(extras.getString(TITLE)));

String summaryText = extras.getString(SUMMARY_TEXT);
if (summaryText != null) {
bigText.setSummaryText(summaryText);
bigText.setSummaryText(fromHtml(summaryText));
}

mBuilder.setStyle(bigText);
Expand Down Expand Up @@ -631,4 +632,11 @@ private int parseInt(String value, Bundle extras) {

return retval;
}

private Spanned fromHtml(String source) {
if (source != null)
return Html.fromHtml(source);
else
return null;
}
}

0 comments on commit 37d5666

Please sign in to comment.