Carousel Push

Carousel Push

Carousel Push functionality allows you to show your notification with a slideshow.

Requirements

  • Android SDK 2.0.0+
Before you start, you need to define your receiver in your manifest file.

Defining Custom Receiver

  1. <receiver android:name=".MyReceiver"  
      android:exported="false">   <!-- change NotificationReceiver to .MyReceiver -->
     <intent-filter> 
     ... 
        <action android:name="com.dengage.push.intent.ITEM_CLICK" /> <!-- add this line-->  
        <action android:name="com.dengage.push.intent.CAROUSEL_ITEM_CLICK" /><!-- add this line-->   
     </intent-filter>
     </receiver>

Preparing Custom Layouts

The SDK uses custom layout for the functionality. It means you need to set your layout first in your res folder. At the same time, We prepared 2 pre-build layouts that you can easily use;

  • Landscape
  • Portrait

To use them, Please add den_carousel_landscape.xml or den_carousel_portrait.xml file to your layouts directory.

den_carousel_landscape.xml Note: You will need to change drawable items with yours.

  1. <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android%22
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/den_carousel_collapsed"
            layout="@layout/den_carousel_collapsed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>


        <FrameLayout
            android:id="@+id/den_carousel_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/den_carousel_collapsed"
            android:layout_gravity="center"
            android:paddingLeft="16dp"
            android:paddingRight="16dp">

            <ImageView
                android:id="@+id/den_carousel_landscape_image"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:scaleType="centerCrop"
                android:layout_gravity="center"
                />

            <ImageView
                android:id="@+id/den_carousel_left_image"
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:src="@drawable/ic_carousal_left_arrow"
                android:layout_gravity="start|center_vertical"
                android:scaleType="fitXY"
                android:layout_marginStart="5dp" />

            <ImageView
                android:id="@+id/den_carousel_right_image"
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:src="@drawable/ic_carousal_right_icon"
                android:layout_gravity="end|center_vertical"
                android:scaleType="fitXY"
                android:layout_marginEnd="5dp" />


        </FrameLayout>

        <LinearLayout android:id="@+id/den_carousel_item_title_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_below="@id/den_carousel_frame"
            android:layout_marginTop="5dp"
            >
            <TextView
                android:id="@+id/den_carousel_item_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Item Title"
                />
        </LinearLayout>

        <LinearLayout android:id="@+id/den_carousel_item_description_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_below="@id/den_carousel_item_title_container"
            >
            <TextView
                android:id="@+id/den_carousel_item_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Item Description" />
        </LinearLayout>     
    </RelativeLayout>

den_carousel_portrait.xml Note: You will need to change drawable items with yours.

  1. <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="320dp">

        <include
            android:id="@+id/den_carousel_collapsed"
            layout="@layout/den_carousel_collapsed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <FrameLayout
            android:id="@+id/den_carousel_body_portrait"
            android:layout_width="596dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/den_carousel_collapsed"
            android:layout_gravity="center"
            android:layout_marginBottom="8dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <RelativeLayout
                    android:id="@+id/den_carousel_left_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toStartOf="@+id/den_carousel_portrait_current_container"
                    android:layout_toLeftOf="@+id/den_carousel_portrait_current_container">

                    <ImageView
                        android:id="@+id/den_carousel_portrait_left_image"
                        android:layout_width="192dp"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:scaleType="centerCrop" />

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBottom="@+id/den_carousel_portrait_left_image"
                        android:layout_alignStart="@+id/den_carousel_portrait_left_image"
                        android:layout_alignLeft="@+id/den_carousel_portrait_left_image"
                        android:layout_alignEnd="@+id/den_carousel_portrait_left_image"
                        android:layout_alignRight="@+id/den_carousel_portrait_left_image"
                        android:layout_alignTop="@+id/den_carousel_portrait_left_image"
                        android:background="#BFffffff" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/den_carousel_right_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@+id/den_carousel_portrait_current_container"
                    android:layout_toRightOf="@+id/den_carousel_portrait_current_container">

                    <ImageView
                        android:id="@+id/den_carousel_portrait_right_image"
                        android:layout_width="192dp"
                        android:layout_height="192dp"
                        android:layout_centerInParent="true"
                        android:scaleType="centerCrop" />

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBottom="@+id/den_carousel_portrait_right_image"
                        android:layout_alignStart="@+id/den_carousel_portrait_right_image"
                        android:layout_alignLeft="@+id/den_carousel_portrait_right_image"
                        android:layout_alignEnd="@+id/den_carousel_portrait_right_image"
                        android:layout_alignRight="@+id/den_carousel_portrait_right_image"
                        android:layout_alignTop="@+id/den_carousel_portrait_right_image"
                        android:background="#B0ffffff" />

                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/den_carousel_portrait_current_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/den_carousel_portrait_current_image"
                        android:layout_width="212dp"
                        android:layout_height="192dp"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        android:cropToPadding="true"
                        android:scaleType="centerCrop" />


                </RelativeLayout>

            </RelativeLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp">

                <ImageView
                    android:id="@+id/den_carousel_left_arrow"
                    android:layout_width="44dp"
                    android:layout_height="44dp"
                    android:src="@drawable/ic_carousal_left_arrow"
                    android:layout_gravity="start|center_vertical"
                    android:scaleType="fitXY" />

                <ImageView
                    android:id="@+id/den_carousel_right_arrow"
                    android:layout_width="44dp"
                    android:layout_height="44dp"
                    android:src="@drawable/ic_carousal_right_icon"
                    android:layout_gravity="end|center_vertical"
                    android:scaleType="fitXY" />

            </FrameLayout>

        </FrameLayout>

        <LinearLayout android:id="@+id/den_carousel_item_title_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_below="@id/den_carousel_body_portrait"
            >
            <TextView
                android:id="@+id/den_carousel_item_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Item Title"
                />
        </LinearLayout>

        <LinearLayout android:id="@+id/den_carousel_item_description_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_below="@id/den_carousel_item_title_container"
            >
            <TextView
                android:id="@+id/den_carousel_item_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Item Description" />
        </LinearLayout>
    </RelativeLayout>

The above layout includes den_carousel_collapsed.xml file;

den_carousel_collapsed.xml Note: You will need to change drawable items with yours.

  1. <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android%22
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp">

        <ImageView
            android:id="@+id/den_carousel_image"
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_gravity="top|end"
            android:layout_marginLeft="12dp"
            android:layout_marginStart="12dp"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_launcher_foreground" /> <!-- Your App Icon -->

        <TextView
            android:id="@+id/den_carousel_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toStartOf="@+id/den_carousel_image"
            android:layout_toLeftOf="@id/den_carousel_image"
            android:text="Remote Title"
            android:textSize="15dp"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/den_carousel_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/den_carousel_title"
            android:layout_alignStart="@+id/den_carousel_title"
            android:layout_alignLeft="@+id/den_carousel_title"
            android:layout_alignEnd="@+id/den_carousel_title"
            android:layout_alignRight="@+id/den_carousel_title"
            android:layout_toLeftOf="@id/den_carousel_image"
            android:ellipsize="end"
            android:lineSpacingMultiplier="1.2"
            android:maxLines="1"
            android:text="Remote message"
            android:textSize="14dp"
            android:textColor="@color/colorPrimary"
            android:layout_marginBottom="16dp"/>

    </RelativeLayout>

Please note that you can always edit these layouts or create new one.

Building Notification

To use a custom layout for the notification requires building a message by the developer with the layout.

First, please create your receiver class extends from NotificationReceiver and override the methods below;

  • onRender
  • onReRender
  1. public class MyReceiver extends NotificationReceiver {
        @Override
        protected void onCarouselRender(Context contextIntent intentMessage message) {
        // build carousel message with a custom layout. In this case, we will use dengage_carousel_landscape.xml and dengage_carousel_portrait.xml files.
        }
        @Override
        protected void onCarouselReRender(Context contextIntent intentMessage message) { 
        // Re-build carousel message with a custom layout to slide item next/prev. 
        }
    }

Copy the codes below to your receiver class.

  1. public class MyReceiver extends NotificationReceiver {
        @Override
        protected void onCarouselRender(Context contextIntent intentMessage message) {
            // accessing to carousel items with its own images.
            CarouselItem[] items = message.getCarouselContent();

            // show first image
            Bitmap img = Utils.loadImageFromStorage(items[0].getMediaFileLocation(), items[0].getMediaFileName());
            String itemTitle = items[0].getTitle();  
            String itemDesc = items[0].getDescription();
     
            // set intents (right button, left button, item click)
            Intent itemIntent = getItemClickIntent(intent.getExtras(), context.getPackageName());
            Intent leftIntent = getLeftItemIntent(intent.getExtras(), context.getPackageName());
            Intent rightIntent = getRightItemIntent(intent.getExtras(), context.getPackageName());
            Intent deleteIntent = getDeleteIntent(intent.getExtras(), context.getPackageName());
            Intent contentIntent = getContentIntent(intent.getExtras(), context.getPackageName());
            PendingIntent carouseItemIntent = PendingIntent.getBroadcast(context0,
                    itemIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent carouselLeftIntent = PendingIntent.getBroadcast(context1,
                    leftIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent carouselRightIntent = PendingIntent.getBroadcast(context2,
                    rightIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context4,
                    deleteIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent contentPendingIntent = PendingIntent.getBroadcast(context5,
                    contentIntentPendingIntent.FLAG_UPDATE_CURRENT);

            // set views for layout. please notice that we use den_carousel_landscape.xml file.
            RemoteViews collapsedView = new RemoteViews(context.getPackageName(),       R.layout.den_carousel_collapsed);
            collapsedView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());
            collapsedView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());
            RemoteViews carouselView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_landscape);
            carouselView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());
            carouselView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());
            carouselView.setTextViewText(R.id.den_carousel_item_titleitemTitle);  
            carouselView.setTextViewText(R.id.den_carousel_item_descriptionitemDesc);
            carouselView.setImageViewBitmap(R.id.den_carousel_landscape_imageimg);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_landscape_imagecarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_item_titlecarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_item_descriptioncarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_left_imagecarouselLeftIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_right_imagecarouselRightIntent);

            // create channel
            String channelId = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel notificationChannel = getNotificationChannel();
                createNotificationChannel(contextnotificationChannel);
                channelId = notificationChannel.getId();
            }
            
            // build notification with the layout.
            Notification notification = new NotificationCompat.Builder(contextchannelId)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setCustomContentView(collapsedView)
                    .setCustomBigContentView(carouselView)
                    .setContentIntent(contentPendingIntent)
                    .setDeleteIntent(deletePendingIntent)
                    .build();

            // show notification
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            notificationManager.notify(message.getMessageSource(), message.getMessageId(), notification);
        }

        @Override
        protected void onCarouselReRender(Context contextIntent intentMessage message) {
            // accessing the carousel items with their own images.
            CarouselItem[] items = message.getCarouselContent();
            // find current item to show prev/next items.
            Bundle bundle = intent.getExtras();
            int size = message.getCarouselContent().length;
            String navigation = bundle.getString("navigation""right");
            int current = bundle.getInt("current"0);
            int newIndex = 0;
            if (navigation.equals("right")) {
                newIndex = (current + 1) % size;
            } else {
                newIndex = (current - 1 + size) % size;
            }
            intent.putExtra("current"newIndex);

            // accessing the current item.
            Bitmap img = Utils.loadImageFromStorage(items[newIndex].getMediaFileLocation(), items[newIndex].getMediaFileName());
            String itemTitle = items[newIndex].getTitle();  
            String itemDesc = items[newIndex].getDescription();

            // set intents (right/left button, item click)
            Intent itemIntent = getItemClickIntent(intent.getExtras(), context.getPackageName());
            Intent leftIntent = getLeftItemIntent(intent.getExtras(), context.getPackageName());
            Intent rightIntent = getRightItemIntent(intent.getExtras(), context.getPackageName());
            Intent deleteIntent = getDeleteIntent(intent.getExtras(), context.getPackageName());
            Intent contentIntent = getContentIntent(intent.getExtras(), context.getPackageName());
            PendingIntent carouseItemIntent = PendingIntent.getBroadcast(context0,
                    itemIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent carouselLeftIntent = PendingIntent.getBroadcast(context1,
                    leftIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent carouselRightIntent = PendingIntent.getBroadcast(context2,
                    rightIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context4,
                    deleteIntentPendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent contentPendingIntent = PendingIntent.getBroadcast(context5,
                    contentIntentPendingIntent.FLAG_UPDATE_CURRENT);

            // set views for the layout
            RemoteViews collapsedView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_collapsed);
            collapsedView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());
            collapsedView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());
            RemoteViews carouselView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_landscape);
            carouselView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());
            carouselView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());
            carouselView.setTextViewText(R.id.den_carousel_item_titleitemTitle);  
            carouselView.setTextViewText(R.id.den_carousel_item_descriptionitemDesc);
            carouselView.setImageViewBitmap(R.id.den_carousel_landscape_imageimg);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_landscape_imagecarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_item_titlecarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_item_descriptioncarouseItemIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_left_imagecarouselLeftIntent);
            carouselView.setOnClickPendingIntent(R.id.den_carousel_right_imagecarouselRightIntent);
            
            // create channel
            String channelId = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel notificationChannel = getNotificationChannel();
                createNotificationChannel(contextnotificationChannel);
                channelId = notificationChannel.getId();
            }
            
            // build notification with the layout.
            Notification notification = new NotificationCompat.Builder(contextchannelId)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setCustomContentView(collapsedView)
                    .setCustomBigContentView(carouselView)
                    .setContentIntent(contentPendingIntent)
                    .setDeleteIntent(deletePendingIntent)
                    .build();

            // show notification silently with curent item.
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            notificationManager.notify(message.getMessageSource(), message.getMessageId(), notification);
        }
    }

Copy the codes below to your receiver class.

  1. public class MyReceiver extends NotificationReceiver {  
        @Override  
      protected void onCarouselRender(Context contextIntent intentMessage message) {  
            CarouselItem[] items = message.getCarouselContent();  
     int size = items.length;  
     int current = 0;  
     int left = (current - 1 + size) % size;  
     int right = (current + 1) % size;  
      
      Bitmap imgLeft = Utils.loadImageFromStorage(items[left].getMediaFileLocation(), items[left].getMediaFileName());  
      Bitmap imgCurrent = Utils.loadImageFromStorage(items[current].getMediaFileLocation(), items[current].getMediaFileName());  
      Bitmap imgRight = Utils.loadImageFromStorage(items[right].getMediaFileLocation(), items[right].getMediaFileName());  
      
      String itemTitle = items[current].getTitle();  
      String itemDesc = items[current].getDescription();  
      
      // set intets (right button, left button, item click)  
      Intent itemIntent = getItemClickIntent(intent.getExtras(), context.getPackageName());  
      Intent leftIntent = getLeftItemIntent(intent.getExtras(), context.getPackageName());  
      Intent rightIntent = getRightItemIntent(intent.getExtras(), context.getPackageName());  
      Intent deleteIntent = getDeleteIntent(intent.getExtras(), context.getPackageName());  
      Intent contentIntent = getContentIntent(intent.getExtras(), context.getPackageName());  
      PendingIntent carouseItemIntent = PendingIntent.getBroadcast(context0,  
      itemIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent carouselLeftIntent = PendingIntent.getBroadcast(context1,  
      leftIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent carouselRightIntent = PendingIntent.getBroadcast(context2,  
      rightIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context4,  
      deleteIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent contentPendingIntent = PendingIntent.getBroadcast(context5,  
      contentIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      
      // set views for the layout  
      RemoteViews collapsedView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_collapsed);  
      collapsedView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());  
      collapsedView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());  
      RemoteViews carouselView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_portrait);  
      carouselView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());  
      carouselView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());  
      carouselView.setTextViewText(R.id.den_carousel_item_titleitemTitle);  
      carouselView.setTextViewText(R.id.den_carousel_item_descriptionitemDesc);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_left_imageimgLeft);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_current_imageimgCurrent);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_right_imageimgRight);  
      carouselView.setOnClickPendingIntent(R.id.den_carousel_left_arrowcarouselLeftIntent);  
      carouselView.setOnClickPendingIntent(R.id.den_carousel_portrait_current_imagecarouseItemIntent);  
      carouselView.setOnClickPendingIntent(R.id.den_carousel_item_titlecarouseItemIntent);
      carouselView.setOnClickPendingIntent(R.id.den_carousel_item_descriptioncarouseItemIntent);
      carouselView.setOnClickPendingIntent(R.id.den_carousel_right_arrowcarouselRightIntent);  
      // create channelId  
      String channelId = null;  
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {  
                NotificationChannel notificationChannel = getNotificationChannel();  
      createNotificationChannel(contextnotificationChannel);  
      channelId = notificationChannel.getId();  
      }  
            // set views for the notification  
      Notification notification = new NotificationCompat.Builder(contextchannelId)  
                    .setSmallIcon(R.mipmap.ic_launcher)  
                    .setCustomContentView(collapsedView)  
                    .setCustomBigContentView(carouselView)  
                    .setContentIntent(contentPendingIntent)  
                    .setDeleteIntent(deletePendingIntent)  
                    .build();  
      // show message  
      NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);  
      notificationManager.notify(message.getMessageSource(), message.getMessageId(), notification);  
      }  
      
        @Override  
      protected void onCarouselReRender(Context contextIntent intentMessage message) {  
            CarouselItem[] items = message.getCarouselContent();  
      Bundle bundle = intent.getExtras();  
     int prevIndex = bundle.getInt("current");  
      String navigation = bundle.getString("navigation""right");  
     int size = items.length;  
     int current = 0;  
     if (navigation.equals("right")) {  
                current = (prevIndex + 1) % size;  
      } else {  
                current = (prevIndex - 1 + size) % size;  
      }  
            int right = (current + 1) % size;  
     int left = (current - 1 + size) % size;  
      intent.putExtra("current"current);  
      
      Bitmap imgLeft = Utils.loadImageFromStorage(items[left].getMediaFileLocation(), items[left].getMediaFileName());  
      Bitmap imgCurrent = Utils.loadImageFromStorage(items[current].getMediaFileLocation(), items[current].getMediaFileName());  
      Bitmap imgRight = Utils.loadImageFromStorage(items[right].getMediaFileLocation(), items[right].getMediaFileName());  
      
      String itemTitle = items[current].getTitle();  
      String itemDesc = items[current].getDescription();  
      
      // set intents (next button, rigth button and item click)  
      Intent itemIntent = getItemClickIntent(intent.getExtras(), context.getPackageName());  
      Intent leftIntent = getLeftItemIntent(intent.getExtras(), context.getPackageName());  
      Intent rightIntent = getRightItemIntent(intent.getExtras(), context.getPackageName());  
      Intent deleteIntent = getDeleteIntent(intent.getExtras(), context.getPackageName());  
      Intent contentIntent = getContentIntent(intent.getExtras(), context.getPackageName());  
      PendingIntent carouseItemIntent = PendingIntent.getBroadcast(context0,  
      itemIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent carouselLeftIntent = PendingIntent.getBroadcast(context1,  
      leftIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent carouselRightIntent = PendingIntent.getBroadcast(context2,  
      rightIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context4,  
      deleteIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      PendingIntent contentPendingIntent = PendingIntent.getBroadcast(context5,  
      contentIntentPendingIntent.FLAG_UPDATE_CURRENT);  
      
      // set views for the layout  
      RemoteViews collapsedView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_collapsed);  
      collapsedView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());  
      collapsedView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());  
      RemoteViews carouselView = new RemoteViews(context.getPackageName(), R.layout.den_carousel_portrait);  
      carouselView.setTextViewText(R.id.den_carousel_titlemessage.getTitle());  
      carouselView.setTextViewText(R.id.den_carousel_messagemessage.getMessage());  
      carouselView.setTextViewText(R.id.den_carousel_item_titleitemTitle);  
      carouselView.setTextViewText(R.id.den_carousel_item_descriptionitemDesc);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_left_imageimgLeft);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_current_imageimgCurrent);  
      carouselView.setImageViewBitmap(R.id.den_carousel_portrait_right_imageimgRight);  
      carouselView.setOnClickPendingIntent(R.id.den_carousel_left_arrowcarouselLeftIntent);  
      carouselView.setOnClickPendingIntent(R.id.den_carousel_portrait_current_imagecarouseItemIntent);
      carouselView.setOnClickPendingIntent(R.id.den_carousel_item_titlecarouseItemIntent);
      carouselView.setOnClickPendingIntent(R.id.den_carousel_item_descriptioncarouseItemIntent);
      carouselView.setOnClickPendingIntent(R.id.den_carousel_right_arrowcarouselRightIntent);  
      // create a channel id.  
      String channelId = null;  
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {  
                NotificationChannel notificationChannel = getNotificationChannel();  
      createNotificationChannel(contextnotificationChannel);  
      channelId = notificationChannel.getId();  
      }  
            // set your views for the notification  
      Notification notification = new NotificationCompat.Builder(contextchannelId)  
                    .setSmallIcon(R.mipmap.ic_launcher)  
                    .setCustomContentView(collapsedView)  
                    .setCustomBigContentView(carouselView)  
                    .setContentIntent(contentPendingIntent)  
                    .setDeleteIntent(deletePendingIntent)  
                    .build();  
      // show message again silently with next,prev and current item.  
      notification.flags |= Notification.FLAG_AUTO_CANCEL;  
      notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;  
      NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);  
      notificationManager.notify(message.getMessageSource(), message.getMessageId(), notification);  
      }  
    }


    • Related Articles

    • Carousel Push

      Carousel Push is a notification type which has a different UI than Rich Notification. SDK will handle notification payload and displays UI if it’s a carousel push. Requirements iOS 10 or higher Notification Service Extension Notification Content ...
    • How can I import my previously collected web push tokens?

      Import your previous web push tokens using file import. OR By creating an automation job But, you will not be able to use them to send push notification because for the service worker file to be updated the person should do these steps Remove all ...
    • How can I import my previously collected mobile push tokens?

      Go to "data space" navigation. From the side menu, open the "import" option. Import the previously collected tokens in the master_device table.   OR  Create an automation job to update the table using FTP. Your .csv file should include columns like ...
    • Mobile Push SDK Implementation

      Implementing D·engage's Mobile Push SDK enables you to engage your users by sending mobile push notifications and in-app messages.  Please check the following resources to implement D·engage's Mobile Push SDK: D·engage Android SDK Setup D·engage iOS ...
    • Web Push SDK Implementation

      With D·engage's Web Push SDK you can collect session and event data from your website. You can also use the Web SDK to engage with your users by sending web push notifications.  Please check the following page to implement D·engage's Mobile Push SDK: ...