下面列出了怎么用com.bumptech.glide.request.target.NotificationTarget的API类实例代码及写法,或者点击链接到github查看源代码。
private void testNotification() {
final RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.remoteview_notification);
rv.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.ic_launcher);
rv.setTextViewText(R.id.remoteview_notification_headline, "Headline");
rv.setTextViewText(R.id.remoteview_notification_short_message, "Short Message");
// build notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Content Title")
.setContentText("Content Text")
.setContent(rv)
.setPriority(NotificationCompat.PRIORITY_MIN);
final Notification notification = mBuilder.build();
// set big content view for newer androids
if (Build.VERSION.SDK_INT >= 16) {
notification.bigContentView = rv;
}
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, notification);
NotificationTarget notificationTarget = new NotificationTarget(this, rv, R.id.remoteview_notification_icon, notification, NOTIFICATION_ID);
Glide.with(this.getApplicationContext())// safer!
.load(eatFoodyImages[3]).asBitmap().into(notificationTarget);
}
public NotificationTarget loadImageToNotification(NotificationTarget notificationTarget,
String url) {
Context context = weakContext.get();
if (context != null) {
return Glide.with(context.getApplicationContext())
.asBitmap()
.load(url)
.apply(getRequestOptions())
.into(notificationTarget);
} else {
Log.e(TAG, "::loadImageToNotification() Context is null");
}
return notificationTarget;
}
private void loadImage(Context context, int notificationId, Notification notification, String url,
RemoteViews expandedView, @IdRes int viewId) {
NotificationTarget notificationTarget =
new NotificationTarget(context, viewId, expandedView, notification, notificationId);
ImageLoader.with(context)
.loadImageToNotification(notificationTarget, url);
}
public DefaultNotificationPanel(Context mContext, MediaItem playableMediaItem) {
super(mContext, playableMediaItem);
this.currentState = UniversalPlayer.State.PLAYING;
this.nBuilder = new NotificationCompat.Builder(mContext);
this.nBuilder.setContentTitle(playableMediaItem.getName());
this.nBuilder.setContentInfo(playableMediaItem.getName());
this.nBuilder.setContentText(playableMediaItem.getName());
this.nBuilder.setSmallIcon(R.drawable.ic_pause_white);
this.nBuilder.setAutoCancel(false);
this.nBuilder.setOngoing(true);
Intent intentOpen = new Intent(mContext, ActivityPlayer.class);
PendingIntent piOpen = PendingIntent.getActivity(mContext, 0, intentOpen, 0);
this.nBuilder.setContentIntent(piOpen);
this.nBuilder.setOngoing(false);
this.remoteView = new RemoteViews(mContext.getPackageName(), R.layout.player_notification);
this.remoteView.setTextViewText(R.id.tvPlayerTitleNtBar, playableMediaItem.getName());
this.remoteView.setTextViewText(R.id.tvPlayerSubTitleNtBar, playableMediaItem.getSubHeader());
setListeners();
this.nBuilder.setContent(remoteView);
Notification notification = nBuilder.build();
this.nManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
this.nManager.notify(NOTIFICATION_ID, notification);
if (playableMediaItem.getCoverImageUrl() != null) {
Glide.with(mContext)
.load(playableMediaItem.getCoverImageUrl())
.asBitmap()
.into(new NotificationTarget(
mContext,
remoteView,
R.id.imgPlayerNtBar,
notification,
NOTIFICATION_ID));
} else {
final LetterBitmap letterBitmap = new LetterBitmap(mContext);
Bitmap letterTile = letterBitmap.getLetterTile(playableMediaItem.getName(), playableMediaItem.getName(), COVER_IMAGE_SIZE, COVER_IMAGE_SIZE);
remoteView.setImageViewBitmap(R.id.imgPlayerNtBar, letterTile);
this.nManager.notify(NOTIFICATION_ID, notification);
}
}
private void loadImageNotification() {
// create RemoteViews
final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remoteview_notification);
remoteViews.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.future_studio_launcher);
remoteViews.setTextViewText(R.id.remoteview_notification_headline, "Headline");
remoteViews.setTextViewText(R.id.remoteview_notification_short_message, "Short Message");
remoteViews.setTextColor(R.id.remoteview_notification_headline, context.getResources().getColor( android.R.color.black));
remoteViews.setTextColor(R.id.remoteview_notification_short_message, context.getResources().getColor(android.R.color.black));
// build notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.future_studio_launcher)
.setContentTitle("Content Title")
.setContentText("Content Text")
.setContent(remoteViews)
.setPriority( NotificationCompat.PRIORITY_MIN);
final Notification notification = mBuilder.build();
// set big content view for newer androids
if (android.os.Build.VERSION.SDK_INT >= 16) {
notification.bigContentView = remoteViews;
}
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, notification);
notificationTarget = new NotificationTarget(
context,
remoteViews,
R.id.remoteview_notification_icon,
notification,
NOTIFICATION_ID);
Glide
.with( context.getApplicationContext() ) // safer!
.load( eatFoodyImages[3] )
.asBitmap()
.into( notificationTarget );
}