public void showWhenPictureReady (final int id) { Glide.with(getCenter().getContext()).load(url) .asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { Log.v(TAG, "showWhenPictureReady onResourceReady"); bigPicture(resource).show(id); } @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { super.onLoadFailed(e, errorDrawable); getCenter().show(id); Log.v(TAG, "showWhenPictureReady onLoadFailed " + e.getMessage()); } }); }
private void setImgBackGround() { String[] images = getResources().getStringArray(R.array.splash_background); int position = new Random().nextInt(images.length - 1) % (images.length); Glide.with(this) .load(images[position]) .into(mImgBackGround); String path = SpUtil.getString(this, "path"); Glide.with(this) .load(path) .asBitmap() .error(R.drawable.def_avatar) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { mCircleImageView.setImageBitmap(resource); } }); //设置图像的透明度 AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f); animation.setDuration(800); mCircleImageView.startAnimation(animation); animation.setAnimationListener(this); }
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View contentView = inflater.inflate(R.layout.fragment_image_preview, container, false); final ImageView imageView = (ImageView) contentView.findViewById(R.id.preview_image); final PhotoViewAttacher mAttacher = new PhotoViewAttacher(imageView); Glide.with(container.getContext()) .load(new File(getArguments().getString(PATH))) .asBitmap() .into(new SimpleTarget<Bitmap>(480, 800) { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { imageView.setImageBitmap(resource); mAttacher.update(); } }); mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { @Override public void onViewTap(View view, float x, float y) { ImagePreviewActivity activity = (ImagePreviewActivity) getActivity(); activity.switchBarVisibility(); } }); return contentView; }
@Override protected void initEventAndData() { setToolBar(toolBar,""); mRealmHelper = App.getAppComponent().realmHelper(); Intent intent = getIntent(); url = intent.getExtras().getString(Constants.IT_GANK_GRIL_URL); id = intent.getExtras().getString(Constants.IT_GANK_GRIL_ID); if (url != null) { Glide.with(mContext).load(url).asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { bitmap = resource; ivGirlDetail.setImageBitmap(resource); mAttacher = new PhotoViewAttacher(ivGirlDetail); } }); } }
private DetailsOverviewRow setupDetailsOverviewRow(Object event) { final DetailsOverviewRow row = new DetailsOverviewRow(event); String thumbUrl; if (event instanceof Event) { thumbUrl = ((Event) event).getThumbUrl(); } else { thumbUrl = ((Room) event).getThumb(); } Glide.with(getActivity()) .load(thumbUrl) .asBitmap() .into(new SimpleTarget<Bitmap>(DETAIL_THUMB_WIDTH, DETAIL_THUMB_HEIGHT) { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { row.setImageBitmap(getActivity(), resource); } @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { // super.onLoadFailed(e, errorDrawable); row.setImageDrawable(getResources().getDrawable(DEFAULT_DRAWABLE)); } }); return row; }
private void loadImageView() { final String url = getArguments().getString(ARGUMENTS_IMAGE); Glide.with(this).downloadOnly().load(url) /* todo replace error icon */ .apply(new RequestOptions().error(R.mipmap.qq_refresh_success)) .into(new SimpleTarget<File>() { @Override public void onResourceReady(File resource, Transition<? super File> transition) { mImageView.setImage(ImageSource.uri(Uri.fromFile(resource))); } @Override public void onLoadFailed(@Nullable Drawable errorDrawable) { super.onLoadFailed(errorDrawable); } }); }
/** * 更新通知 */ public void onUpdateMusicNotification(MusicBean bean, boolean isplay){ Log.e(TAG,"更新通知--歌曲名称:"+ bean.getSongname()+"--isplay:"+isplay); if (null == bean) return; //更新歌曲名称 remoteViews.setTextViewText(R.id.tv_song_name,(bean.getSongname() == null ? "" : bean.getSongname())); //更新歌手名字 remoteViews.setTextViewText(R.id.tv_singer,(bean.getSingername() == null ? "" : bean.getSingername())); //更新歌曲图片 Glide.with(context).load(bean.getAlbumpic_big()).asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { remoteViews.setImageViewBitmap(R.id.img_song, resource); } }); //更新播放状态:播放或者暂停 if (isplay){ remoteViews.setImageViewResource(R.id.img_play,R.mipmap.play); }else { remoteViews.setImageViewResource(R.id.img_play,R.mipmap.pause); } onCreateMusicNotification();//弹出更新的通知 }
@Override protected void initEventAndData() { setToolBar(toolBar,""); mRealmHelper = App.getAppComponent().realmHelper(); Intent intent = getIntent(); url = intent.getExtras().getString("url"); id = intent.getExtras().getString("id"); if (url != null) { Glide.with(mContext).load(url).asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { bitmap = resource; ivGirlDetail.setImageBitmap(resource); mAttacher = new PhotoViewAttacher(ivGirlDetail); } }); } }
@Test public void removeFromManagers_afterRequestManagerRemoved_clearsRequest() { target = requestManager.load(mockUri("content://uri")).into(new SimpleTarget<Drawable>() { @Override public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { // Do nothing. } }); Request request = Preconditions.checkNotNull(target.getRequest()); requestManager.onDestroy(); requestManager.clear(target); assertThat(target.getRequest()).isNull(); assertThat(request.isCancelled()).isTrue(); }
private void getUserProfile() { mUserService.me() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(u -> { mUserName.setText(u.getUsername()); mAvatarView.setAvatarOfUser(u); mReputation.setText(u.getReputation()); mPost.setText(u.getPostcount()); mFollowing.setText(String.valueOf(u.getFollowingCount())); mFollower.setText(String.valueOf(u.getFollowerCount())); mLoginTime.setText(DateTimeFormatter.format(Long.parseLong(u.getLastonline()))); mRegTime.setText(DateTimeFormatter.format(Long.parseLong(u.getJoindate()))); mProfileViews.setText(u.getProfileviews()); mEmail.setText(u.getEmail()); GlideApp.with(UserProfileActivity.this) .load(NodeBBService.url(u.getCoverUrl())) .into(new SimpleTarget<Drawable>() { @Override public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { mHeaderView.setBackground(resource); } }); }); }
private void renderImage(Object image, final ImageView imageView){ GlideApp.with(mContext) .asBitmap() .load(image) .placeholder(R.drawable.iconerror) .error(R.drawable.iconerror) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(final Bitmap resource, Transition<? super Bitmap> transition) { int valueWidth = (int) mContext.getResources().getDimension(R.dimen.book_cover_width); int valueHeight = (int) mContext.getResources().getDimension(R.dimen.book_cover_height); final Bitmap scaledBitmap = Bitmap.createScaledBitmap(resource, valueWidth, valueHeight, true); imageView.setImageBitmap(resource); imageView.invalidate(); } }); }
protected void updateBackground(String uri) { int width = mMetrics.widthPixels; int height = mMetrics.heightPixels; Glide.with(getActivity()) .load(uri) .centerCrop() .error(mDefaultBackground) .into(new SimpleTarget<GlideDrawable>(width, height) { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mBackgroundManager.setDrawable(resource); } }); mBackgroundTimer.cancel(); }
@Override public void onActivityResult(int reqCode, int resultCode, final Intent data) { super.onActivityResult(reqCode, resultCode, data); Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped")); if (data == null || resultCode != Activity.RESULT_OK) return; switch (reqCode) { case PICK_CONTACT: List<String> selected = data.getStringArrayListExtra("contacts"); for (String contact : selected) { final Recipient recipient = RecipientFactory.getRecipientsFromString(this, contact, false).getPrimaryRecipient(); if (recipient != null) addSelectedContacts(recipient); } break; case Crop.REQUEST_PICK: new Crop(data.getData()).output(outputFile).asSquare().start(this); break; case Crop.REQUEST_CROP: Glide.with(this).load(Crop.getOutput(data)).asBitmap() .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.NONE) .centerCrop().override(AVATAR_SIZE, AVATAR_SIZE) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { setAvatar(Crop.getOutput(data), resource); } }); } }
@Override public void onBindViewHolder(final ContributorAdapter.ViewHolder holder, int position) { ContributorData contributor = contributors.get(position); Glide.with(holder.imageView.getContext()).asBitmap().load(contributor.imageUrl).into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { holder.imageView.setImageBitmap(resource); } }); holder.textView.setText(contributor.name); holder.itemView.setTag(contributor); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (view.getTag() != null && view.getTag() instanceof ContributorData) view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(((ContributorData) view.getTag()).url))); } }); }
@Override public void loadArtWork(long artistId) { LogUtils.i(TAG, "loadArtWork"); if (mView != null) { Glide.with(mView.getContext()).asBitmap().load(String.valueOf(artistId)) .into(new SimpleTarget<Bitmap>() { @Override public void onLoadFailed(Drawable errorDrawable) { super.onLoadFailed(errorDrawable); if (mView != null) { mView.showArtwork(errorDrawable); } } @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { if (mView != null) { mView.showArtwork(resource); } } }); } }
@Override public void loadAlbum(long albumID) { if (mView != null) { Glide.with(mView.getContext()).asBitmap() .load(Utils.getAlbumArtUri(albumID)) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { if (mView != null) { mView.showAlbum(resource); } } @Override public void onLoadFailed(Drawable errorDrawable) { super.onLoadFailed(errorDrawable); if (mView != null) { mView.showAlbum(errorDrawable); } } }); } }
private void initializeBackground(Movie data) { mDetailsBackground.enableParallax(); Glide.with(getActivity()) .load(data.getBackgroundImageUrl()) .asBitmap() .centerCrop() .error(R.drawable.default_background) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) { mDetailsBackground.setCoverBitmap(bitmap); mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size()); } }); }
private void setupUIElements() { Glide.with(getActivity()) .load(mConference.getLogoUrl()) .centerCrop() .error(mDefaultBackground) .into(new SimpleTarget<GlideDrawable>(432, 243) { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { setBadgeDrawable(resource); } }); setTitle(mConference.getTitle()); // Badge, when set, takes precedent // over title setHeadersState(HEADERS_ENABLED); setHeadersTransitionOnBackEnabled(true); // set fastLane (or headers) background color setBrandColor(getResources().getColor(R.color.fastlane_background)); // set search icon color setSearchAffordanceColor(getResources().getColor(R.color.search_opaque)); }
private void setCoverImage(User user) { if (user == null || TextUtils.isEmpty(user.getCoverUrl()) || user.getCoverUrl().equals("/assets/images/cover-default.png")) { mDefaultCover.setVisibility(View.VISIBLE); mShadow.setVisibility(View.GONE); mHeaderView.setBackgroundColor(ThemeColorManagerCompat.getColorPrimary()); } else { mDefaultCover.setVisibility(View.GONE); mShadow.setVisibility(View.VISIBLE); GlideApp.with(getContext()) .load(NodeBB.BASE_URL + user.getCoverUrl()) .diskCacheStrategy(DiskCacheStrategy.NONE) .into(new SimpleTarget<Drawable>() { @Override public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { mHeaderView.setBackground(resource); } }); } }
@Override public Object instantiateItem(ViewGroup container, final int position) { final View view = LayoutInflater.from(context) .inflate(R.layout.page_image_item_preview, container, false); final ViewHolder viewHolder = new ViewHolder(view); ViewCompat.setTransitionName(viewHolder.photoView, images.get(position).getUrl()); Glide.with(context) .load(images.get(position).getUrl()) .dontTransform() .dontAnimate() .into(new SimpleTarget<GlideDrawable>() { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { viewHolder.photoView.setImageDrawable(resource); startPostponedEnterTransition(position); } }); container.addView(viewHolder.itemView); return viewHolder; }
private void updateMetadata(final Movie movie) { final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder(); String title = movie.getTitle().replace("_", " -"); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, movie.getDescription()); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, movie.getCardImageUrl()); // And at minimum the title and artist for legacy support metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, movie.getStudio()); Glide.with(this) .load(Uri.parse(movie.getCardImageUrl())) .asBitmap() .into(new SimpleTarget<Bitmap>(500, 500) { @Override public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mSession.setMetadata(metadataBuilder.build()); } }); }
@Override public void onBindViewHolder(final XianViewHolder holder, int position) { final XianduItem item = xiandus.get(position); holder.rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { WebUtils.openInternal(context, item.getUrl()); } }); holder.tv_name.setText(String.format("%s. %s", position + 1, item.getName())); holder.tv_info.setText(item.getUpdateTime() + " • " + item.getFrom()); Glide.with(context).load(item.getIcon()).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.iv.setImageDrawable(circularBitmapDrawable); } }); }
public static void savePicture(final Context context, final String folder, final String url){ Glide.with(context).load(url).asBitmap().toBytes().into(new SimpleTarget<byte[]>() { @Override public void onResourceReady(byte[] bytes, GlideAnimation<? super byte[]> glideAnimation) { try { String name = url.substring(url.lastIndexOf('/')); File targetFile = new File(folder, name); if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs(); if (targetFile.exists()) { targetFile.delete(); } targetFile.createNewFile(); FileOutputStream output = new FileOutputStream(targetFile); output.write(bytes); output.close(); Toast.makeText(context, "图片已成功保存到"+targetFile.getAbsolutePath(), Toast.LENGTH_SHORT).show(); return; } catch (Exception e) { e.printStackTrace(); } Toast.makeText(context, "图片保存失败", Toast.LENGTH_SHORT).show(); } }); }
@Override public void onGranted() { Glide.with(context).load(url).into(new SimpleTarget<Drawable>() { @Override public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { String path = String.format("%s/Android/data/%s/", Environment.getExternalStorageDirectory(), AppUtils.getAppPackageName()); String filename = TimeUtils.getNowString() + ".png"; boolean ok = ImageUtils.save(ImageUtils.drawable2Bitmap(resource), path + filename, Bitmap.CompressFormat.PNG); if (ok) { ToastUtils.showShort(R.string.success); } else { ToastUtils.showShort(R.string.error); } } }); }
@Override protected void initData() { super.initData(); mPath = getIntent().getStringExtra("image"); getImageLoader() .load(mPath) .downloadOnly(new SimpleTarget<File>() { @Override public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) { if (isDestroyed()) return; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(resource.getPath(), options); int w = options.outWidth; int sw = Util.getScreenWidth(LargeImageActivity.this); float scale = (float) sw / (float) w; mImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM); mImageView.setImage(ImageSource.uri(Uri.fromFile(resource)), new ImageViewState(scale, new PointF(0, 0), net.oschina.app.improve.utils.BitmapUtil.readPictureDegree(mPath))); mImageSave.setVisibility(View.VISIBLE); mLoading.stop(); mLoading.setVisibility(View.GONE); } }); }
private void replaceImage(final String imageName) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; File imageFile = new File(mView.getActivity().getExternalFilesDir(mNoteId).getPath() + "/" + imageName); BitmapFactory.decodeFile(imageFile.getPath(), options); int imageRequestWidth = getRequestImeWidth(); int imageRequestHeight = setNeedHeight(options); Glide.with(mView.getActivity()) .load(imageFile) .asBitmap() .override(imageRequestWidth, imageRequestHeight) .fitCenter() .priority(Priority.HIGH) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { mView.replaceImage(imageName, resource); } }); }
private void displayImage() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // 对图片进行设置 但不形成示例,不耗费内存 BitmapFactory.decodeFile(mImageFile.getPath(), options); int imageRequestWidth = getRequestImeWidth(); int imageRequestHeight = getRequestImeHeight(options); Logger.d("width " + imageRequestWidth + " height:" + imageRequestHeight); Logger.d("bitmap1 width " + options.outWidth + " height:" + options.outHeight); Glide.with(mView.getActivity()) .load(mImageFile) .asBitmap() .override(imageRequestWidth, imageRequestHeight) // 设置大小 .fitCenter() // 不按照比例 .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { //根据Bitmap对象创建ImageSpan对象 Logger.d("bitmap width:" + resource.getWidth() + " height:" + resource.getHeight()); mView.insertImage(mImageName, resource); } }); }
public static void loadBitmap(Context context, String url, final OnLoadBitmapCallback callback) { Glide.with(context).load(url).asBitmap() .dontAnimate() .placeholder(R.drawable.ic_place_holder_small) .error(R.drawable.ic_error_small) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { callback.loadBitmap(resource); } }); }
@Override public Drawable getDrawable(String source) { final RichTextView tv = weakRef.get(); final LevelListDrawable mDrawable = new LevelListDrawable(); Glide.with(tv.getContext()).load(source).asBitmap().placeholder(R.drawable.ic_placeholder).into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { if (width == 0) { tv.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); width = tv.getWidth(); } BitmapDrawable d = new BitmapDrawable(resource); mDrawable.addLevel(1, 1, d); int imageWidth; int imageHeight; //小图只需略微扩大,大图则宽度铺满 if (resource.getHeight() < 50 || resource.getWidth() < 50) { imageWidth = (int) (resource.getWidth() * zoomFactor); imageHeight = (int) (resource.getHeight() * zoomFactor); } else { imageWidth = width; double ratio = (double) resource.getHeight() / (double) resource.getWidth(); imageHeight = (int) (ratio * width); } mDrawable.setBounds(0, 0, imageWidth, imageHeight); mDrawable.setLevel(1); tv.invalidate(); tv.setText(tv.getText()); } }); return mDrawable; }
private void setupDetailsOverviewRow() { Log.d(TAG, "doInBackground: " + mSelectedMovie.toString()); final DetailsOverviewRow row = new DetailsOverviewRow(mSelectedMovie); row.setImageDrawable(getResources().getDrawable(R.drawable.default_background)); int width = Utils.convertDpToPixel(getActivity() .getApplicationContext(), DETAIL_THUMB_WIDTH); int height = Utils.convertDpToPixel(getActivity() .getApplicationContext(), DETAIL_THUMB_HEIGHT); Glide.with(getActivity()) .load(mSelectedMovie.getCardImageUrl()) .centerCrop() .error(R.drawable.default_background) .into(new SimpleTarget<GlideDrawable>(width, height) { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { Log.d(TAG, "details overview card image url ready: " + resource); row.setImageDrawable(resource); mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size()); } }); row.addAction(new Action(ACTION_WATCH_TRAILER, getResources().getString( R.string.watch_trailer_1), getResources().getString(R.string.watch_trailer_2))); row.addAction(new Action(ACTION_RENT, getResources().getString(R.string.rent_1), getResources().getString(R.string.rent_2))); row.addAction(new Action(ACTION_BUY, getResources().getString(R.string.buy_1), getResources().getString(R.string.buy_2))); mAdapter.add(row); }
@Override public void loadImage(String url,final ImageView iv) { Glide.with(iv.getContext()) .load(url) .into(new SimpleTarget<Drawable>(200, 200) { @Override public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { iv.setImageDrawable(resource); } }); }
public void showWhenPictureReady (final String tag, final int id) { Glide.with(getCenter().getContext()).load(url) .asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { bigPicture(resource).show(tag, id); } }); }
@Override public void loadNet(Context context, String url, Options options, final LoadCallback callback) { DrawableTypeRequest request = getRequestManager(context).load(url); if (options == null) options = Options.defaultOptions(); if (options.loadingResId != Options.RES_NONE) { request.placeholder(options.loadingResId); } if (options.loadErrorResId != Options.RES_NONE) { request.error(options.loadErrorResId); } request.diskCacheStrategy(DiskCacheStrategy.SOURCE) .crossFade() .into(new SimpleTarget<GlideBitmapDrawable>() { @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { super.onLoadFailed(e, errorDrawable); if (callback != null) { callback.onLoadFailed(e); } } @Override public void onResourceReady(GlideBitmapDrawable resource, GlideAnimation<? super GlideBitmapDrawable> glideAnimation) { if (resource != null && resource.getBitmap() != null) { if (callback != null) { callback.onLoadReady(resource.getBitmap()); } } } }); }
protected void updateBackground(String uri) { Glide.with(getActivity()) .load(uri) .centerCrop() .error(mDefaultBackground) .into(new SimpleTarget<GlideDrawable>(mMetrics.widthPixels, mMetrics.heightPixels) { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mBackgroundManager.setDrawable(resource); } }); }