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+ final RemoteViews contentView = notification .contentView ;
49+ //Picasso.with(mContext).load(imageUrl).into(contentView, iconId, requestCode, notification);
50+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN ) {
51+ final RemoteViews bigContentView = notification .bigContentView ;
52+ Picasso .with (mContext ).load (imageUrl ).into (bigContentView , bigIconId , requestCode , notification );
53+ }
54+ }
55+ });
56+ return notification ;
57+ }
58+
3059 /**
3160 * Creates and returns an instance of IterableNotification.
3261 * @param context
@@ -40,13 +69,15 @@ public static IterableNotification createNotification(Context context, Bundle ex
4069 String notificationBody = null ;
4170 String soundName = null ;
4271 String messageId = null ;
72+ String pushImage = null ;
4373
4474 IterableNotification notificationBuilder = new IterableNotification (context );
4575
4676 if (extras .containsKey (IterableConstants .ITERABLE_DATA_KEY )) {
4777 applicationName = extras .getString (IterableConstants .ITERABLE_DATA_TITLE , applicationName );
4878 notificationBody = extras .getString (IterableConstants .ITERABLE_DATA_BODY );
4979 soundName = extras .getString (IterableConstants .ITERABLE_DATA_SOUND );
80+ pushImage = extras .getString (IterableConstants .ITERABLE_DATA_PUSH_IMAGE );
5081
5182 String iterableData = extras .getString (IterableConstants .ITERABLE_DATA_KEY );
5283 notificationBuilder .iterableNotificationData = new IterableNotificationData (iterableData );
@@ -66,10 +97,20 @@ public static IterableNotification createNotification(Context context, Bundle ex
6697 .setTicker (applicationName ).setWhen (0 )
6798 .setAutoCancel (true )
6899 .setContentTitle (applicationName )
69- .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ))
70100 .setPriority (Notification .PRIORITY_HIGH )
71101 .setContentText (notificationBody );
72102
103+ if (pushImage != null ) {
104+ notificationBuilder .imageUrl = pushImage ;
105+ notificationBuilder .setContentText (notificationBody )
106+ .setStyle (new NotificationCompat .BigPictureStyle ()
107+ .setBigContentTitle (applicationName )
108+ .setSummaryText (notificationBody )
109+ );
110+ } else {
111+ notificationBuilder .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ));
112+ }
113+
73114 if (soundName != null ) {
74115 //Removes the file type from the name
75116 String [] soundFile = soundName .split ("\\ ." );
@@ -142,6 +183,7 @@ private static int getIconId(Context context) {
142183 try {
143184 ApplicationInfo info = context .getPackageManager ().getApplicationInfo (context .getPackageName (), PackageManager .GET_META_DATA );
144185 iconId = info .metaData .getInt (IterableConstants .NOTIFICATION_ICON_NAME , 0 );
186+ IterableLogger .d (TAG , "iconID: " + info .metaData .get (IterableConstants .NOTIFICATION_ICON_NAME ));
145187 } catch (PackageManager .NameNotFoundException e ) {
146188 e .printStackTrace ();
147189 }
0 commit comments