99import android .content .pm .PackageManager ;
1010import android .net .Uri ;
1111import android .os .Bundle ;
12+ import android .os .Handler ;
13+ import android .os .Looper ;
1214import android .support .v4 .app .NotificationCompat ;
15+ import android .widget .RemoteViews ;
1316
14- import java . util . Date ;
17+ import com . squareup . picasso . Picasso ;
1518
1619/**
1720 *
2023public class IterableNotification extends NotificationCompat .Builder {
2124 static final String TAG = "IterableNotification" ;
2225 private boolean isGhostPush ;
26+ private String imageUrl ;
2327 int requestCode ;
2428 IterableNotificationData iterableNotificationData ;
2529
2630 protected IterableNotification (Context context ) {
2731 super (context );
2832 }
2933
34+ /**
35+ * Combine all of the options that have been set and return a new {@link Notification}
36+ * object.
37+ */
38+ public Notification build () {
39+ final Notification notification = super .build ();
40+
41+ final int iconId = android .R .id .icon ;
42+ final int bigIconId = mContext .getResources ().getIdentifier ("android:id/big_picture" , null , null );
43+
44+ Handler handler = new Handler (Looper .getMainLooper ());
45+ handler .post (new Runnable () {
46+ @ Override
47+ public void run () {
48+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN && imageUrl != null ) {
49+ final RemoteViews bigContentView = notification .bigContentView ;
50+ try {
51+ Class picassoClass = Class .forName (IterableConstants .PICASSO_CLASS );
52+ if (picassoClass != null ) {
53+ Picasso .with (mContext ).load (imageUrl ).into (bigContentView , bigIconId , requestCode , notification );
54+ }
55+ } catch (ClassNotFoundException e ) {
56+ IterableLogger .w (TAG , "ClassNotFoundException: Check that picasso is added " +
57+ "to the build dependencies" , e );
58+ }
59+ }
60+ }
61+ });
62+ return notification ;
63+ }
64+
3065 /**
3166 * Creates and returns an instance of IterableNotification.
3267 * @param context
@@ -40,13 +75,15 @@ public static IterableNotification createNotification(Context context, Bundle ex
4075 String notificationBody = null ;
4176 String soundName = null ;
4277 String messageId = null ;
78+ String pushImage = null ;
4379
4480 IterableNotification notificationBuilder = new IterableNotification (context );
4581
4682 if (extras .containsKey (IterableConstants .ITERABLE_DATA_KEY )) {
4783 applicationName = extras .getString (IterableConstants .ITERABLE_DATA_TITLE , applicationName );
4884 notificationBody = extras .getString (IterableConstants .ITERABLE_DATA_BODY );
4985 soundName = extras .getString (IterableConstants .ITERABLE_DATA_SOUND );
86+ pushImage = extras .getString (IterableConstants .ITERABLE_DATA_PUSH_IMAGE );
5087
5188 String iterableData = extras .getString (IterableConstants .ITERABLE_DATA_KEY );
5289 notificationBuilder .iterableNotificationData = new IterableNotificationData (iterableData );
@@ -66,10 +103,20 @@ public static IterableNotification createNotification(Context context, Bundle ex
66103 .setTicker (applicationName ).setWhen (0 )
67104 .setAutoCancel (true )
68105 .setContentTitle (applicationName )
69- .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ))
70106 .setPriority (Notification .PRIORITY_HIGH )
71107 .setContentText (notificationBody );
72108
109+ if (pushImage != null ) {
110+ notificationBuilder .imageUrl = pushImage ;
111+ notificationBuilder .setContentText (notificationBody )
112+ .setStyle (new NotificationCompat .BigPictureStyle ()
113+ .setBigContentTitle (applicationName )
114+ .setSummaryText (notificationBody )
115+ );
116+ } else {
117+ notificationBuilder .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ));
118+ }
119+
73120 if (soundName != null ) {
74121 //Removes the file type from the name
75122 String [] soundFile = soundName .split ("\\ ." );
@@ -142,6 +189,7 @@ private static int getIconId(Context context) {
142189 try {
143190 ApplicationInfo info = context .getPackageManager ().getApplicationInfo (context .getPackageName (), PackageManager .GET_META_DATA );
144191 iconId = info .metaData .getInt (IterableConstants .NOTIFICATION_ICON_NAME , 0 );
192+ IterableLogger .d (TAG , "iconID: " + info .metaData .get (IterableConstants .NOTIFICATION_ICON_NAME ));
145193 } catch (PackageManager .NameNotFoundException e ) {
146194 e .printStackTrace ();
147195 }
0 commit comments