下面列出了怎么用com.bumptech.glide.request.RequestFutureTarget的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns a future that can be used to do a blocking get on a background thread.
*
* @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be overridden by
* {@link #override * (int, int)} if previously called.
* @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be overridden by
* {@link #override * (int, int)}} if previously called).
*
* @see Glide#clear(FutureTarget)
*
* @return An {@link FutureTarget} that can be used to obtain the
* resource in a blocking manner.
*/
public FutureTarget<TranscodeType> into(int width, int height) {
final RequestFutureTarget<ModelType, TranscodeType> target =
new RequestFutureTarget<ModelType, TranscodeType>(glide.getMainHandler(), width, height);
// TODO: Currently all loads must be started on the main thread...
glide.getMainHandler().post(new Runnable() {
@Override
public void run() {
if (!target.isCancelled()) {
into(target);
}
}
});
return target;
}
/**
* 更新通知
*/
private void updateNotification() {
final int dimen = DensityUtil.dp2px(this, 128);
Glide.with(this)
.asBitmap()
.load(cover)
.into(new RequestFutureTarget<Bitmap>(dimen, dimen) {
@Override
public synchronized void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
showNotification(resource);
}
@Override
public synchronized void onLoadFailed(@Nullable Drawable errorDrawable) {
showNotification(BitmapFactory.decodeResource(getResources(), R.drawable.img_cover_default));
}
});
}
private void updateNotification() {
final String coverUrl = bookShelfBean == null ? null : bookShelfBean.getBookInfoBean().getRealCoverUrl();
final int dimen = DensityUtil.dp2px(this, 128);
Glide.with(this)
.asBitmap()
.load(coverUrl)
.into(new RequestFutureTarget<Bitmap>(dimen, dimen) {
@Override
public synchronized void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
showNotification(resource);
}
@Override
public synchronized void onLoadFailed(@Nullable Drawable errorDrawable) {
showNotification(BitmapFactory.decodeResource(getResources(), R.drawable.img_cover_default));
}
});
}