@Override @CheckResult @SafeVarargs @SuppressWarnings("varargs") public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<TranscodeType>... arg0) { return (GlideRequest<TranscodeType>) super.thumbnail(arg0); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view); Glide.with(this) .load(R.raw.large_giphy_logo) .into(giphyLogoView); RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list); LinearLayoutManager layoutManager = new LinearLayoutManager(this); gifList.setLayoutManager(layoutManager); RequestBuilder<Drawable> gifItemRequest = Glide.with(this).asDrawable(); ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>(); adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider); gifList.setAdapter(adapter); RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, 4); gifList.addOnScrollListener(preloader); }
private void setupUserAvatar(AppCompatImageView avatar, Me.ProfileImage image) { int flag = CalendarUtils.festivalFlag(); if (2 == flag) { avatar.setImageResource(R.mipmap.new_year_round); } else if (1 == flag) { avatar.setImageResource(R.mipmap.new_year_dog2); } else { if (null == image) { avatar.setImageResource(R.mipmap.bg_dark_avatar_male_big_normal); } else { RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(getActivity()) .asBitmap() .load(image.large) .error(R.mipmap.bg_dark_avatar_male_big_normal) .placeholder(R.mipmap.bg_dark_avatar_male_big_normal) .diskCacheStrategy(DiskCacheStrategy.ALL) .fallback(R.mipmap.bg_dark_avatar_male_big_normal); bitmapRequestBuilder.into(avatar); } } }
public static void showImage(Activity activity, ImageView imageView, String image, Drawable placeholder, boolean anim) { RequestOptions requestOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL); RequestBuilder<Drawable> builder = Glide.with(activity) .load(image); if (placeholder != null) { requestOptions.placeholder(placeholder); //设置占位图片 } if (!anim) { requestOptions.dontAnimate(); } builder.apply(requestOptions); builder.into(imageView); }
@BindingAdapter({"url", "thumbUrl", "manager", "show"}) public static void loadImage(LargeImageView largeImageView, String url, @Nullable String thumbUrl, DownloadPreferencesManager manager, boolean show) { if (!show || TextUtils.isEmpty(url)) { return; } Context context = largeImageView.getContext(); RequestBuilder<File> builder = Glide.with(context) .download(new ForcePassUrl(url)); //avatar signature if (manager != null && Api.isAvatarUrl(url)) { builder = builder.apply(new RequestOptions() .signature(manager.getAvatarCacheInvalidationIntervalSignature())); } builder.into(new LargeImageViewTarget(largeImageView) { @Override public void onLoadFailed(@Nullable Drawable errorDrawable) { if (thumbUrl != null) { loadImage(largeImageView, thumbUrl, null, manager, show); } else { super.onLoadFailed(errorDrawable); } } }); }
private void startImageGetterViewTarget(RequestBuilder<Drawable> glideRequestBuilder, ImageGetterViewTarget imageGetterViewTarget, boolean emoticon) { Single.just(glideRequestBuilder) .subscribeOn(AndroidSchedulers.mainThread()) .to(imageGetterScoper) .subscribe(builder -> { if (emoticon) { imageGetterViewTarget.mDrawable.setWidthTargetSize(emoticonSize); imageGetterViewTarget.mDrawable.setHeightTargetSize(emoticonSize); } else { //Big image scale to fit width imageGetterViewTarget.mDrawable.setTriggerSize(200); if (mTextView.getWidth() > 0) { imageGetterViewTarget.mDrawable.setWidthTargetSize(mTextView.getWidth()); } } builder.into(imageGetterViewTarget); }, L::report); }
public void loadAsPath(final String path, final int width, final int height, final int maskId, final String ext) { if (TextUtils.isEmpty(path)) { loadAsResource(R.drawable.nim_image_default, maskId); return; } setBlendDrawable(maskId); RequestBuilder builder; if (ImageUtil.isGif(ext)) { builder = Glide.with(getContext().getApplicationContext()).asGif().load(new File(path)); } else { RequestOptions options = new RequestOptions() .override(width, height) .fitCenter() .placeholder(R.drawable.nim_image_default) .error(R.drawable.nim_image_default); builder = Glide.with(getContext().getApplicationContext()) .asBitmap() .apply(options) .load(new File(path)) ; } builder.into(this); }
@Override @Nullable public RequestBuilder getPreloadRequestBuilder(IconDataParcelable iconData) { GlideRequest request; if(!showThumbs) { request = GlideApp.with(fragment).asDrawable().fitCenter().load(iconData.image); } else { if (iconData.type == IconDataParcelable.IMAGE_FROMFILE) { request = GlideApp.with(fragment).asDrawable().centerCrop().load(iconData.path).fallback(iconData.image); } else { request = GlideApp.with(fragment).asDrawable().centerCrop().load(iconData.image); } } return request; }
public static void loadFlickrThumb(Photo photo, ImageView image) { final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(photo.getThumbnailUrl()) .apply(options) .transition(DrawableTransitionOptions.with(TRANSITION_FACTORY)); Glide.with(image).load(photo.getMediumUrl()) .apply(options) .thumbnail(thumbRequest) .into(image); }
public static void loadFlickrFull(Photo photo, ImageView image, LoadingListener listener) { final String photoUrl = photo.getLargeSize() == null ? photo.getMediumUrl() : photo.getLargeUrl(); final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(photo.getThumbnailUrl()) .apply(options); Glide.with(image) .load(photoUrl) .apply(new RequestOptions().apply(options).placeholder(image.getDrawable())) .thumbnail(thumbRequest) .listener(new RequestListenerWrapper<>(listener)) .into(image); }
/** * Loads thumbnail and then replaces it with full image. */ public static void loadFull(ImageView image, int imageId, int thumbId) { // We don't want Glide to crop or resize our image final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.NONE) .override(Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(thumbId) .apply(options); Glide.with(image) .load(imageId) .apply(options) .thumbnail(thumbRequest) .into(image); }
@Override public RequestBuilder<Drawable> getPreloadRequestBuilder(MediaStoreData item) { MediaStoreSignature signature = new MediaStoreSignature(item.mimeType, item.dateModified, item.orientation); return requestBuilder .clone() .signature(signature) .load(item.uri); }
private static RequestBuilder<Bitmap> getRequestBuilder( RequestManager requestManager, int width, int height) { return requestManager .asBitmap() .apply( diskCacheStrategyOf(DiskCacheStrategy.NONE) .skipMemoryCache(true) .override(width, height)); }
@SuppressWarnings("unchecked") @Before public void setUp() { MockitoAnnotations.initMocks(this); when(handler.obtainMessage(anyInt(), isA(DelayTarget.class))).thenReturn(mock(Message.class)); firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); ByteBuffer byteBuffer = ByteBuffer.allocate(10); when(gifDecoder.getData()).thenReturn(byteBuffer); requestBuilder = mock(RequestBuilder.class, new ReturnsSelfAnswer()); loader = createGifFrameLoader(handler); }
@Override public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> arg0) { return (GlideRequest<TranscodeType>) super.error(arg0); }
public Bitmap test(RequestBuilder<Bitmap> request) throws ExecutionException, InterruptedException { Bitmap result = request .submit() .get(); if (writeNewExpected()) { writeBitmap(result); } Bitmap expected = decodeExpected(); BitmapSubject.assertThat(result).sameAs(expected); return result; }
@NonNull @Override public RequestBuilder<GifDrawable> getPreloadRequestBuilder(MediaStoreData item) { MediaStoreSignature signature = new MediaStoreSignature(item.mimeType, item.dateModified, item.orientation); return requestBuilder .clone() .signature(signature) .load(item.uri); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view); GlideApp.with(this) .load(R.raw.large_giphy_logo) .into(giphyLogoView); RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list); LinearLayoutManager layoutManager = new LinearLayoutManager(this); gifList.setLayoutManager(layoutManager); RequestBuilder<Drawable> gifItemRequest = GlideApp.with(this) .asDrawable(); ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>(); adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider); gifList.setAdapter(adapter); RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(GlideApp.with(this), adapter, preloadSizeProvider, 4); gifList.addOnScrollListener(preloader); gifList.setRecyclerListener(new RecyclerListener() { @Override public void onViewRecycled(ViewHolder holder) { // This is an optimization to reduce the memory usage of RecyclerView's recycled view pool // and good practice when using Glide with RecyclerView. GifViewHolder gifViewHolder = (GifViewHolder) holder; GlideApp.with(MainActivity.this).clear(gifViewHolder.gifView); } }); }
private static RequestBuilder<Bitmap> getRequestBuilder( RequestManager requestManager, int width, int height) { return requestManager .asBitmap() .apply( diskCacheStrategyOf(DiskCacheStrategy.NONE) .useAnimationPool(true) .skipMemoryCache(true) .override(width, height)); }
private void setupData(Photos.User user) { if (null == getActivity()) return; mColorIcon = ContextCompat.getDrawable(getActivity(), R.mipmap.ic_fiber_manual_record_white_18dp); mUserTxt.setText(getString(R.string.by_photo, user.name)); setTranslate(mUserTxt, DELAY * 4); try { Date createdAt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-HH:mm", Locale.getDefault()).parse(mPhotos.created_at); mTitleTxt.setText(getString(R.string.shoot_at, new PrettyTime().format(createdAt))); } catch (ParseException e) { Timber.e(e); } RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(getActivity()) .asBitmap() .load(user.profile_image.large) .error(R.mipmap.bg_dark_avatar_male_big_normal) .placeholder(R.mipmap.bg_dark_avatar_male_big_normal) .diskCacheStrategy(DiskCacheStrategy.ALL) .fallback(R.mipmap.bg_dark_avatar_male_big_normal); bitmapRequestBuilder.into(new CircularBitmapImageViewTarget(getActivity(), mUserAvatar)); RxView.clicks(mUserAvatar).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { if (null != mPhotos && null != mPhotos.user) { Request request = new Request(UserFragment.class); request.putExtra(UserFragment.EXTRA_USER_NAME_KEY, mPhotos.user.username); request.putExtra(UserFragment.EXTRA_NIKE_NAME_KEY, mPhotos.user.name); startFragment(request); } } }); setTranslate(mUserTxt, DELAY * 4); setTranslate(mUserTxt, DELAY * 5); }
/** * Reference : https://medium.com/fueled-android/data-binding-adapter-write-bind-repeat-50e9c64fe806 * Bind Glide with an ImageView. * * @param view the ImageView to bind to Glide. * @param src The URL of the image to load. * @param placeholder The placeholder icon. * @param error The error icon. * @param blurValue The blur radius value between 1 and 25. * @param cropCircle Crop the image in a circle of not. */ @SuppressWarnings("unchecked") @android.databinding.BindingAdapter(value = {"src", "placeholder", "error", "blur", "cropCircle"}, requireAll = false) public void setImageUrl(ImageView view, String src, Drawable placeholder, Drawable error, int blurValue, boolean cropCircle) { Context ctx = view.getContext(); RequestOptions options = new RequestOptions(); RequestBuilder<Drawable> glideBuilder = requestManager.load(src); if (placeholder != null) { options.placeholder(placeholder); } if (error != null) { options.error(error); } if (blurValue > 0) { options.transform(new BlurTransformation(ctx, blurValue)); } if (cropCircle) { options.circleCrop(); } glideBuilder .apply(options) .into(view); }
public GlideManager(Builder builder){ RequestOptions options = new RequestOptions() .placeholder(builder.placeresid); if (builder.eroorresid != 0){ options.error(builder.eroorresid); } switch (builder.type){ case BITMAP_SCAN_CENTERN: options.centerCrop(); break; case BITMAP_SCAN_FIT: options.fitCenter(); break; default: break; } if (builder.setCircleCrop){ options.circleCrop(); } if (builder.radius != 0){ options.transform(new RoundedCorners(builder.radius)); } RequestBuilder requestBuilder = null; requestBuilder = Glide.with(builder.context).load(builder.source); if (builder.animtime > 0){ requestBuilder.transition(new DrawableTransitionOptions().crossFade(builder.animtime)); } requestBuilder.apply(options) .listener(new LoadListener()) .into(builder.imageView); }
public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, Drawable holderDrawable, Drawable errorDrawable, ImageView targetIv , RequestListener callback) { RequestBuilder requestBuilder = loadImageRequest(context, picUrl); RequestOptions options = new RequestOptions(); if (newWidth > 0 && newHeight > 0) { options.override(newWidth,newHeight).centerCrop(); } else{ // loadRequest.fit(); } if (holderDrawable != null) { options.placeholder(holderDrawable); } else{ // loadRequest.noPlaceholder(); } if (errorDrawable != null) { options.error(errorDrawable); } options.dontAnimate(); if (callback != null) { requestBuilder.listener(callback); } requestBuilder.apply(options) .into(targetIv); }
@Override public void onBindViewHolder(final SearchViewHolder holder, int position) { if (position < mShowList.size()) { RequestBuilder<Drawable> request = Glide.with(mActivity) .load(mShowList.get(position).getRes()); if (mLessAnim) { request.apply(RequestOptions.noAnimation()); } request.into(holder.icon); RxView.clicks(holder.itemView) .filter(click -> !sLock) .subscribe(click -> { sLock = true; new Handler().postDelayed(() -> sLock = false, 1000); if (mCustomPicker) { holder.itemView.setOnClickListener(view -> { mActivity.setResult(Activity.RESULT_OK, new Intent().putExtra("icon res", mShowList.get(holder.getAdapterPosition()) .getRes())); mActivity.finish(); }); } else { showIconDialog( holder.icon, mShowList.get(holder.getAdapterPosition())); } }, Timber::e); } }
public GifAdapter(Activity activity, RequestBuilder<Drawable> requestBuilder, ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider) { this.activity = activity; this.requestBuilder = requestBuilder; this.preloadSizeProvider = preloadSizeProvider; }
@Override public RequestBuilder<Drawable> getPreloadRequestBuilder(Api.GifResult item) { return requestBuilder.load(item); }