@Override public boolean onLoadFailed(GlideException e, Object model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); view.setLayerType(ImageView.LAYER_TYPE_NONE, null); return false; }
@Override public boolean onResourceReady(PictureDrawable resource, Object model, Target<PictureDrawable> target, DataSource dataSource, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); return false; }
private void displayVideoThumbnail(ViewHolder h, Video v) { Glide.with(h.mThumbnail.getContext()) .load(v.getThumbnailUrl()) .centerCrop() .crossFade() .into(new ImageViewTarget<GlideDrawable>(h.mThumbnail) { @Override protected void setResource(GlideDrawable resource) { view.setImageDrawable(resource); } public void onLoadFailed(Exception e, Drawable errorDrawable) { view.setImageResource(R.drawable.ic_photo_grey600_48dp); } }); }
@Override public boolean onException( Exception e, GlideUrl uri, Target<GlideDrawable> target, boolean isFirstResource ) { OkHttpProgressGlideModule.forget(uri.toStringUrl()); if (!(target instanceof ImageViewTarget)) { return false; } ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView(); ThemedReactContext context = (ThemedReactContext) view.getContext(); RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); int viewId = view.getId(); eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, new WritableNativeMap()); eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap()); return false; }
@Override public boolean onResourceReady( GlideDrawable resource, GlideUrl uri, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource ) { if (!(target instanceof ImageViewTarget)) { return false; } ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView(); ThemedReactContext context = (ThemedReactContext) view.getContext(); RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); int viewId = view.getId(); eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_EVENT, new WritableNativeMap()); eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap()); return false; }
private void load(int position) { Glide.with(this).load(testPhoto.get(position)) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageViewTarget<Bitmap>(photoView) { @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { super.onLoadFailed(e, errorDrawable); Toast.makeText(TestPhotoViewActivity.this, "load fail", Toast.LENGTH_SHORT).show(); } @Override protected void setResource(Bitmap resource) { getView().setImageBitmap(resource); } }); }
@Override public void showAvatar(String avatarUrl) { this.avatarUrl=avatarUrl; Glide.with(getContext()) .load(avatarUrl) .asBitmap() .priority(Priority.IMMEDIATE) .into(new ImageViewTarget<Bitmap>(avatar) { @Override protected void setResource(Bitmap resource) { avatar.setImageBitmap(resource); avatar.post(()->{ media.post(()->{ View blank = adapter.getBlank(); ViewGroup.LayoutParams params = blank.getLayoutParams(); params.height = followers.getTop()+followers.getHeight() +2*getResources().getDimensionPixelOffset(R.dimen.spacing_large); blank.setLayoutParams(params); }); media.setVisibility(View.INVISIBLE); getActivity().supportStartPostponedEnterTransition(); presenter.start(id); }); } }); }
@Override public View instantiateItem(ViewGroup container, int position) { View view=inflater.inflate(R.layout.adapter_album,container,false); ImageView image= ButterKnife.findById(view,R.id.image); Glide.with(container.getContext()) .load(albums.get(position).getArtworkUrl()) .asBitmap() .priority(Priority.IMMEDIATE) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(new ImageViewTarget<Bitmap>(image) { @Override protected void setResource(Bitmap resource) { image.setImageBitmap(resource); if (position == current && !isLoaded) { isLoaded = true; if (callback != null) { callback.onTransitionImageLoaded(image,resource); } } } }); container.addView(view); return view; }
public void showArt(String artUrl){ if(!TextUtils.equals(lastArtUrl,artUrl)) { lastArtUrl=artUrl; Glide.with(getContext()) .load(artUrl) .asBitmap() .priority(Priority.IMMEDIATE) .into(new ImageViewTarget<Bitmap>(smallImage) { @Override protected void setResource(Bitmap resource) { smallImage.setImageBitmap(resource); smallImage.post(()->{ Blurry.with(getContext()) .async(bitmap->{ background.setImageDrawable(bitmap); getActivity().supportStartPostponedEnterTransition(); }) .from(resource) .into(background); }); } }); } }
@Override public void showPlaylistArt(String artUrl) { if(!loaded) { loaded=true; Glide.with(getContext()) .load(artUrl) .asBitmap() .priority(Priority.IMMEDIATE) .into(new ImageViewTarget<Bitmap>(playlistArt) { @Override protected void setResource(Bitmap resource) { final int imageHeight=playlistArt.getHeight(); playlistArt.setImageBitmap(resource); parent.setStaticOffset(imageHeight); parent.setOffset(imageHeight); toggle.setStaticOffset(imageHeight- toggle.getHeight()/2); toggle.setOffset(imageHeight- toggle.getHeight()/2); toggle.setMinOffset(ViewCompat.getMinimumHeight(playlistArt)- toggle.getHeight()/2); tracks.addOnScrollListener(listener); tracks.setOnFlingListener(flingListener); new Palette.Builder(resource).generate(PlaylistFragment.this::applyPalette); getActivity().supportStartPostponedEnterTransition(); } }); } }
@Override public void onBindViewHolder(final ViewHolder holder, int position) { if(!(sponsorItemArrayList.get(position).sponsor_name.isEmpty())){ holder.sponsorname.setText(sponsorItemArrayList.get(position).sponsor_name); } if(!(sponsorItemArrayList.get(position).image_id==null)){ // holder.sponsorimage.setImageResource(sponsorItemArrayList.get(position).image_id); Glide.with(context).load(sponsorItemArrayList.get(position).image_id).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).into(new ImageViewTarget<Bitmap>(holder.sponsorimage) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable drawable= RoundedBitmapDrawableFactory.create(context.getResources(),resource); drawable.setCircular(false); holder.sponsorimage.setImageDrawable(drawable); } }); } }
@Override protected void convert(final BaseAdapterHelper helper, T item, int position) { final RadioImageView story_img = (RadioImageView) helper.getView(R.id.story_img); TextView story_title = helper.getTextView(R.id.story_item_title); story_title.setText(item.getStory_title()); Glide.with(helper.itemView.getContext()) .load(item.getImgUrl()) // //设置占位图或者加载错误图: // .placeholder(R.drawable.ic_sun_smile) // .error(R.drawable.ic_cloud_sad) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageViewTarget<GlideDrawable>(story_img) { @Override protected void setResource(GlideDrawable resource) { story_img.setOriginalSize(resource.getIntrinsicWidth(), resource.getIntrinsicHeight()); story_img.setImageDrawable(resource); } }); helper.itemView.setTag(position); }
private void initData() { if (mPlayBean!=null){ livePlayerPresenterImpl.enterRoom(mPlayBean.uid); } Glide.with(this) .load(mPlayBean.love_cover) .into(new ImageViewTarget<GlideDrawable>(bgImg) { @Override protected void setResource(GlideDrawable resource) { bgImg.setImageDrawable(resource); Blurry.with(VerFullLiveUI.this) .animate() .radius(10) .sampling(8) .capture(bgImg) .into(bgImg); } }); }
@Override public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) { Glide.with(activity) .load("file://" + path) .placeholder(defaultDrawable) .error(defaultDrawable) .override(width, height) .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡 .skipMemoryCache(true) //.centerCrop() .into(new ImageViewTarget<GlideDrawable>(imageView) { @Override protected void setResource(GlideDrawable resource) { imageView.setImageDrawable(resource); } @Override public void setRequest(Request request) { } }); }
protected void loadAndCompressImage(String url, ImageView view) { getRequestManager() .load(url) .downloadOnly(new ImageViewTarget<File>(view) { @Override protected void setResource(File resource) { Bitmap bitmap = ImageUtils.resizeBitmap(resource, view.getWidth(), view.getHeight()); view.setImageBitmap(bitmap); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); ButterKnife.bind(this); final AnimatedViewPager pager= ButterKnife.findById(this,R.id.pager); final ImageView background=ButterKnife.findById(this,R.id.scrolling_background); int[] screenSize=screenSize(); for(ImageView element:sharedElements){ @ColorRes int color=element.getId()!=R.id.logo?R.color.white_transparent:R.color.color_logo_log_in; DrawableCompat.setTint(element.getDrawable(), ContextCompat.getColor(this,color)); } //load a very big image and resize it, so it fits our needs Glide.with(this) .load(R.drawable.busy) .asBitmap() .override(screenSize[0]*2,screenSize[1]) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(new ImageViewTarget<Bitmap>(background) { @Override protected void setResource(Bitmap resource) { background.setImageBitmap(resource); background.post(()->{ //we need to scroll to the very left edge of the image //fire the scale animation background.scrollTo(-background.getWidth()/2,0); ObjectAnimator xAnimator=ObjectAnimator.ofFloat(background,View.SCALE_X,4f,background.getScaleX()); ObjectAnimator yAnimator=ObjectAnimator.ofFloat(background,View.SCALE_Y,4f,background.getScaleY()); AnimatorSet set=new AnimatorSet(); set.playTogether(xAnimator,yAnimator); set.setDuration(getResources().getInteger(R.integer.duration)); set.start(); }); pager.post(()->{ AuthAdapter adapter = new AuthAdapter(getSupportFragmentManager(), pager, background, sharedElements); pager.setAdapter(adapter); }); } }); }
@Override public void onBindViewHolder(final ComicViewHolder holder, int position) { Comic comic = comics.get(position); holder.cardView.setVisibility(View.GONE); Glide.with(holder.cardView.getContext()) .fromString() .asBitmap() .transcode(new PaletteBitmap.PaletteBitmapTranscoder(holder.cardView.getContext()), PaletteBitmap.class) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .load(comic.getCoverPath()) .into(new ImageViewTarget<PaletteBitmap>(holder.imageViewCover) { @Override protected void setResource(PaletteBitmap resource) { super.view.setImageBitmap(resource.bitmap); holder.cardView.setCardBackgroundColor( Prefs.with(holder.cardView.getContext()).readBoolean(Constants.KEY_PREFERENCES_THEME) ? resource.palette.getMutedColor(Color.WHITE) : resource.palette.getLightMutedColor(Color.WHITE)); Palette.Swatch swatch = Prefs.with(holder.cardView.getContext()).readBoolean(Constants.KEY_PREFERENCES_THEME) ? resource.palette.getMutedSwatch() : resource.palette.getLightMutedSwatch(); holder.imageViewDate.setColorFilter(swatch == null ? Color.DKGRAY : swatch.getTitleTextColor(), PorterDuff.Mode.SRC_IN); holder.imageViewPages.setColorFilter(swatch == null ? Color.DKGRAY : swatch.getTitleTextColor(), PorterDuff.Mode.SRC_IN); holder.cardView.setVisibility(View.VISIBLE); holder.textViewTitle.setTextColor(swatch == null ? Color.DKGRAY : swatch.getTitleTextColor()); holder.textViewPages.setTextColor(swatch == null ? Color.DKGRAY : swatch.getTitleTextColor()); holder.textViewTimeStamp.setTextColor(swatch == null ? Color.DKGRAY : swatch.getTitleTextColor()); } }); holder.textViewTitle.setText(comic.getTitle()); holder.textViewPages.setText(holder.textViewPages.getContext().getString(R.string.page_of, comic.getCurrentPage(), comic.getNumPages())); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy"); String date = simpleDateFormat.format(comic.getAddedTimeStamp()); holder.textViewTimeStamp.setText(date); }
@Override public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) { Glide.with(activity) .load("file://" + path) .placeholder(defaultDrawable) .error(defaultDrawable) .override(width, height) .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡 .skipMemoryCache(true) //.centerCrop() .into(new ImageViewTarget<GlideDrawable>(imageView) { @Override protected void setResource(GlideDrawable resource) { imageView.setImageDrawable(resource); } @Override public void setRequest(Request request) { imageView.setTag(mTag, request); } @Override public Request getRequest() { return (Request) imageView.getTag(mTag); } }) ; }
@Override public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) { Glide.with(activity) .load("file://" + path) .placeholder(defaultDrawable) .error(defaultDrawable) .override(width, height) .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡 .skipMemoryCache(true) //.centerCrop() .into(new ImageViewTarget<GlideDrawable>(imageView) { @Override protected void setResource(GlideDrawable resource) { imageView.setImageDrawable(resource); } @Override public void setRequest(Request request) { imageView.setTag(R.id.adapter_item_tag_key,request); } @Override public Request getRequest() { return (Request) imageView.getTag(R.id.adapter_item_tag_key); } }); }
@Override public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_NONE, null); } return false; }
@Override public boolean onResourceReady(PictureDrawable resource, T model, Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); } return false; }
@Override protected void convert(BaseAdapterHelper helper, final Items item, int position) { final RadioImageView story_img = (RadioImageView) helper.getView(R.id.story_img); TextView story_title = helper.getTextView(R.id.story_item_title); story_title.setText(item.getName()); Glide.with(helper.itemView.getContext()) .load(item.getPictures().getImg()) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageViewTarget<GlideDrawable>(story_img) { @Override protected void setResource(GlideDrawable resource) { story_img.setOriginalSize(resource.getIntrinsicWidth(), resource.getIntrinsicHeight()); story_img.setImageDrawable(resource); } }); helper.itemView.setTag(position); helper.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("title", item.getName()); intent.setClass(context, M3u8VideoActivity.class); intent.putExtra("type", VideoApi.TYPE_XM); intent.putExtra("roomid", item.getId()); context.startActivity(intent); } }); }
@Override public boolean onException (Exception e, Object model, Target target, boolean isFirstResource) { ImageView view = (( ImageViewTarget<?> ) target).getView( ); if ( Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT ) { view.setLayerType( ImageView.LAYER_TYPE_NONE, null ); } return false; }
@Override public boolean onResourceReady (PictureDrawable resource, T model, Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageView view = (( ImageViewTarget<?> ) target).getView( ); if ( Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT ) { view.setLayerType( ImageView.LAYER_TYPE_SOFTWARE, null ); } return false; }
@Override public boolean onException(Exception e, Uri model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_NONE, null); } return false; }
@Override public boolean onResourceReady(PictureDrawable resource, Uri model, Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); } return false; }
public static void hybridImplementation(String u, final ImageView target, Context context, final Runnable callback) { if (u.contains(".gif")) { Glide.with(context).asGif().load(u) .apply(getOpt()) .into(new ImageViewTarget<GifDrawable>(target) { @Override protected void setResource(GifDrawable resource) { target.setImageDrawable(resource); callback.run(); } }); } else { picassoImplementation(u, target, context, callback); } }
@Override public boolean onResourceReady(PictureDrawable resource, T model , Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); } return false; }
@Override public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_NONE, null); } e.printStackTrace(); return false; }
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageViewTarget<GlideDrawable> image_target = (ImageViewTarget<GlideDrawable>)target; Drawable current = image_target.getCurrentDrawable(); if (last != null) { TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{current, resource}); transitionDrawable.setCrossFadeEnabled(true); transitionDrawable.startTransition(1000); image_target.setDrawable(transitionDrawable); } last = resource; return true; }
@Override public void onBindViewHolder(final ViewHolder holder, final int position) { String imageUrl = "http://image.tmdb.org/t/p/w185/" + mMovieList.get(position).getPoster();//+mImageList.get(position); String backDropPath= "http://image.tmdb.org/t/p/w342/" + mMovieList.get(position).getBackdrop(); //mImageListBackDrop.get(position); if(mMovieList.get(position).getPosterUrl(this.mAct) !=null || mMovieList.get(position).getBackdropUrl(this.mAct) !=null) { glideRequest .load(backDropPath) .diskCacheStrategy( DiskCacheStrategy.RESULT) //Storing only compressed images for saving disk space (Disc Cache) .into(new ImageViewTarget<PaletteBitmap>(holder.getImageView()) { @Override protected void setResource(PaletteBitmap resource) { super.view.setImageBitmap(resource.bitmap); holder.setDarkColor(resource.palette.getDarkVibrantColor(defaultColor)); holder.setLightColor(resource.palette.getDarkMutedColor(defaultColor)); holder.getCardView().setCardBackgroundColor(holder.getDarkColor()); holder.getTitleView().setTextColor(ContextCompat.getColor(mAct, android.R.color.white)); } }); Glide.with(mAct) .load(imageUrl) .diskCacheStrategy(DiskCacheStrategy.RESULT) .centerCrop() .crossFade() .into(holder.getmRoundedImageView()); } else { //if json data contains nothing Glide.clear(holder.getImageView()); Glide.clear(holder.getmRoundedImageView()); holder.getImageView().setVisibility(View.GONE); holder.getmRoundedImageView().setVisibility(View.GONE); } holder.getTitleView().setText(mMovieList.get(position).getTitle()); holder.getTitleView().setTextSize(15); if(mMovieList.get(position).getUserRating()!=null && mMovieList.get(position).getUserRating() !="0"){ holder.getRatingValue().setText(mMovieList.get(position).getUserRating()); holder.getmIcon().setImageResource(R.mipmap.ic_stars_white_18dp); }else{ holder.getRatingValue().setText("Rating not available."); holder.getmIcon().setVisibility(View.GONE); } holder.getCardView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(getItemClickListener != null) { getItemClickListener.getItemDetails(mMovieList.get(position).getId(), mMovieList.get(position).getBackdrop(), mMovieList.get(position).getTitle(), holder.getDarkColor(), holder.getLightColor()); } } }); }