Class NotificationTarget

  • All Implemented Interfaces:
    LifecycleListener, Target<android.graphics.Bitmap>

    public class NotificationTarget
    extends CustomTarget<android.graphics.Bitmap>
    This class is used to display downloaded Bitmap inside an ImageView of a Notification through RemoteViews.

    Note - For cancellation to work correctly, you must pass in the same instance of this class for every subsequent load.

    • Constructor Summary

      Constructors 
      Constructor Description
      NotificationTarget​(android.content.Context context, int width, int height, int viewId, android.widget.RemoteViews remoteViews, android.app.Notification notification, int notificationId, java.lang.String notificationTag)
      Constructor using a Notification object, a notificationId, and a notificationTag to get a handle on the Notification in order to update it.
      NotificationTarget​(android.content.Context context, int viewId, android.widget.RemoteViews remoteViews, android.app.Notification notification, int notificationId)
      Constructor using a Notification object and a notificationId to get a handle on the Notification in order to update it that uses Target.SIZE_ORIGINAL as the target width and height.
      NotificationTarget​(android.content.Context context, int viewId, android.widget.RemoteViews remoteViews, android.app.Notification notification, int notificationId, java.lang.String notificationTag)
      Constructor using a Notification object, a notificationId, and a notificationTag to get a handle on the Notification in order to update it that uses Target.SIZE_ORIGINAL as the target width and height.
    • Constructor Detail

      • NotificationTarget

        public NotificationTarget​(android.content.Context context,
                                  int viewId,
                                  android.widget.RemoteViews remoteViews,
                                  android.app.Notification notification,
                                  int notificationId)
        Constructor using a Notification object and a notificationId to get a handle on the Notification in order to update it that uses Target.SIZE_ORIGINAL as the target width and height.
        Parameters:
        context - Context to use in the AppWidgetManager initialization.
        viewId - The id of the ImageView view that will load the image.
        remoteViews - RemoteViews object which contains the ImageView that will load the bitmap.
        notification - The Notification object that we want to update.
        notificationId - The notificationId of the Notification that we want to load the Bitmap.
      • NotificationTarget

        public NotificationTarget​(android.content.Context context,
                                  int viewId,
                                  android.widget.RemoteViews remoteViews,
                                  android.app.Notification notification,
                                  int notificationId,
                                  java.lang.String notificationTag)
        Constructor using a Notification object, a notificationId, and a notificationTag to get a handle on the Notification in order to update it that uses Target.SIZE_ORIGINAL as the target width and height.
        Parameters:
        context - Context to use in the AppWidgetManager initialization.
        viewId - The id of the ImageView view that will load the image.
        remoteViews - RemoteViews object which contains the ImageView that will load the bitmap.
        notification - The Notification object that we want to update.
        notificationId - The notificationId of the Notification that we want to load the Bitmap.
        notificationTag - The notificationTag of the Notification that we want to load the Bitmap. May be null.
      • NotificationTarget

        public NotificationTarget​(android.content.Context context,
                                  int width,
                                  int height,
                                  int viewId,
                                  android.widget.RemoteViews remoteViews,
                                  android.app.Notification notification,
                                  int notificationId,
                                  java.lang.String notificationTag)
        Constructor using a Notification object, a notificationId, and a notificationTag to get a handle on the Notification in order to update it.
        Parameters:
        context - Context to use in the AppWidgetManager initialization.
        width - Desired width of the bitmap that will be loaded.(Need to be manually put because of RemoteViews limitations.)
        height - Desired height of the bitmap that will be loaded. (Need to be manually put because of RemoteViews limitations.)
        viewId - The id of the ImageView view that will load the image.
        remoteViews - RemoteViews object which contains the ImageView that will load the bitmap.
        notification - The Notification object that we want to update.
        notificationId - The notificationId of the Notification that we want to load the Bitmap.
        notificationTag - The notificationTag of the Notification that we want to load the Bitmap. May be null.
    • Method Detail

      • onResourceReady

        public void onResourceReady​(@NonNull
                                    android.graphics.Bitmap resource,
                                    @Nullable
                                    Transition<? super android.graphics.Bitmap> transition)
        Description copied from interface: Target
        The method that will be called when the resource load has finished.
        Parameters:
        resource - the loaded resource.
      • onLoadCleared

        public void onLoadCleared​(@Nullable
                                  android.graphics.drawable.Drawable placeholder)
        Description copied from interface: Target
        A mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.

        You must ensure that any current Drawable received in Target.onResourceReady(Object, Transition) is no longer used before redrawing the container (usually a View) or changing its visibility.

        Parameters:
        placeholder - The placeholder drawable to optionally show, or null.