Class NotificationTarget
java.lang.Object
com.bumptech.glide.request.target.CustomTarget<Bitmap>
com.bumptech.glide.request.target.NotificationTarget
- All Implemented Interfaces:
LifecycleListener,Target<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.
-
Field Summary
Fields inherited from interface com.bumptech.glide.request.target.Target
SIZE_ORIGINAL -
Constructor Summary
ConstructorsConstructorDescriptionNotificationTarget(Context context, int width, int height, int viewId, RemoteViews remoteViews, Notification notification, int notificationId, 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(Context context, int viewId, RemoteViews remoteViews, 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 usesTarget.SIZE_ORIGINALas the target width and height.NotificationTarget(Context context, int viewId, RemoteViews remoteViews, Notification notification, int notificationId, 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 usesTarget.SIZE_ORIGINALas the target width and height. -
Method Summary
Modifier and TypeMethodDescriptionvoidonLoadCleared(Drawable placeholder) A mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.voidonResourceReady(Bitmap resource, Transition<? super Bitmap> transition) The method that will be called when the resource load has finished.Methods inherited from class com.bumptech.glide.request.target.CustomTarget
getRequest, getSize, onDestroy, onLoadFailed, onLoadStarted, onStart, onStop, removeCallback, setRequest
-
Constructor Details
-
NotificationTarget
@RequiresPermission("android.permission.POST_NOTIFICATIONS") public NotificationTarget(Context context, int viewId, RemoteViews remoteViews, 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 usesTarget.SIZE_ORIGINALas 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
@RequiresPermission("android.permission.POST_NOTIFICATIONS") public NotificationTarget(Context context, int viewId, RemoteViews remoteViews, Notification notification, int notificationId, 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 usesTarget.SIZE_ORIGINALas 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 benull.
-
NotificationTarget
@RequiresPermission("android.permission.POST_NOTIFICATIONS") public NotificationTarget(Context context, int width, int height, int viewId, RemoteViews remoteViews, Notification notification, int notificationId, 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 benull.
-
-
Method Details
-
onResourceReady
@RequiresPermission("android.permission.POST_NOTIFICATIONS") public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) Description copied from interface:TargetThe method that will be called when the resource load has finished.This may be called multiple times both within a single load and also across different loads if the
Targetobject is re-used.Within a single load this may be called multiple times for reasons that include:
- The load uses one or more thumbnails. Each time a thumbnail load completes successfully
and no higher priority load has finished, this method will be called with the thumbnail
resource. See
RequestBuilder.thumbnail(com.bumptech.glide.RequestBuilder). - The load is paused and restarted. This can happen automatically in response to
connectivity changes or the Activity / Fragment lifecycle. It can also happen if
RequestManager.pauseRequests()is called manually.
- Parameters:
resource- the loaded resource.
- The load uses one or more thumbnails. Each time a thumbnail load completes successfully
and no higher priority load has finished, this method will be called with the thumbnail
resource. See
-
onLoadCleared
@RequiresPermission("android.permission.POST_NOTIFICATIONS") public void onLoadCleared(@Nullable Drawable placeholder) Description copied from interface:TargetA 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.
-