Java Code Examples for com.bumptech.glide.load.resource.drawable.GlideDrawable

The following examples show how to use com.bumptech.glide.load.resource.drawable.GlideDrawable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Silence   Source File: ZoomingImageView.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setImageViewUri(MasterSecret masterSecret, Uri uri) {
  subsamplingImageView.setVisibility(View.GONE);
  imageView.setVisibility(View.VISIBLE);

  Glide.with(getContext())
       .load(new DecryptableUri(masterSecret, uri))
       .diskCacheStrategy(DiskCacheStrategy.NONE)
       .dontTransform()
       .dontAnimate()
       .into(new GlideDrawableImageViewTarget(imageView) {
         @Override protected void setResource(GlideDrawable resource) {
           super.setResource(resource);
           imageViewAttacher.update();
         }
       });
}
 
Example 2
public void showCirImage(String url, final ImageView image) {
    if (url == null || url.isEmpty() || "".equals(url)) {
        image.setImageResource(R.mipmap.defeat_person_img);
        return;
    }
    Glide.with(getApplicationContext())
            .load(url)
            .error(R.mipmap.ic_launcher_round)
            .into(new SimpleTarget<GlideDrawable>() { // 加上这段代码 可以解决
                @Override
                public void onResourceReady(GlideDrawable resource,
                                            GlideAnimation<? super GlideDrawable> glideAnimation) {
                    image.setImageDrawable(resource); //显示图片
                }
            });
}
 
Example 3
Source Project: glide-support   Source File: TestFragment.java    License: The Unlicense 6 votes vote down vote up
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
	super.onViewCreated(view, savedInstanceState);
	listView.setAdapter(new SimpleUrlAdapter(Glide.with(this), Arrays.asList(
			// original url, already url-encoded
			URL_BASE + "s%C3%BCt%C3%A9s+1146.jpg", 
			// parse url-encoded url and toString encodes it again
			Uri.parse(URL_BASE + "s%C3%BCt%C3%A9s+1146.jpg").toString(),
			// raw url, nothing is escaped "sütés"
			Uri.decode(URL_BASE + "s%C3%BCt%C3%A9s+1146.jpg"),
			// illegally decoded url, utf-8 is not parsed properly
			URL_BASE + "sütés+1146.jpg"
	)) {
		@Override protected void load(Context context, RequestManager glide, String url, ImageView imageView) {
			glide.load(url).listener(new LoggingListener<String, GlideDrawable>()).into(imageView);
		}
	});
}
 
Example 4
Source Project: BuildingForAndroidTV   Source File: MainFragment.java    License: MIT License 6 votes vote down vote up
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();
}
 
Example 5
Source Project: YiZhi   Source File: ImageBrowseActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 加载gif
 */
private void loadGif() {
    Glide.with(ImageBrowseActivity.this)
            .load(mImageUrl)
            .fitCenter()
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(new GlideDrawableImageViewTarget(pvPic) {
                @Override
                public void onResourceReady(GlideDrawable resource, GlideAnimation<?
                        super GlideDrawable> animation) {
                    super.onResourceReady(resource, animation);
                    //在这里添加一些图片加载完成的操作
                    pbPicBrowse.setVisibility(View.GONE);
                }
            });
}
 
Example 6
Source Project: AndroidModulePattern   Source File: ImageUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 显示加载进度
 *
 * @param path       图片地址
 * @param mImageView 图片控件
 * @param loadView   加载view
 */
public static void loadImageWithProgress(String path, final ImageView mImageView, final View loadView, int errorRes) {
    Glide.with(mImageView.getContext()).load(path).error(errorRes).into(new GlideDrawableImageViewTarget(mImageView) {
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
            super.onResourceReady(resource, animation);
            loadView.setVisibility(View.GONE);
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            super.onLoadFailed(e, errorDrawable);
            loadView.setVisibility(View.GONE);
        }
    });
}
 
Example 7
Source Project: hintcase   Source File: FullHintActivity.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
private ImageView getGifLoadedUsingGlide() {
    ImageView animatedImageView = new ImageView(getActivity());
    animatedImageView.setMaxHeight(900);
    Glide.with(getActivity())
            .load(R.drawable.animated_image)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .thumbnail(Glide.with(getActivity())
                    .load(R.drawable.animated_image)
                    .asBitmap()
                    .transcode(new BitmapToGlideDrawableTranscoder(getActivity()), GlideDrawable.class)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
            )
            .into(animatedImageView);
    return animatedImageView;
}
 
Example 8
Source Project: androidtestdebug   Source File: AddNoteFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void showImagePreview(@NonNull String imageUrl) {
    checkState(!TextUtils.isEmpty(imageUrl), "imageUrl cannot be null or empty!");
    mImageThumbnail.setVisibility(View.VISIBLE);

    // The image is loaded in a different thread so in order to UI-test this, an idling resource
    // is used to specify when the app is idle.
    EspressoIdlingResource.increment(); // App is busy until further notice.

    // This app uses Glide for image loading
    Glide.with(this)
            .load(imageUrl)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .into(new GlideDrawableImageViewTarget(mImageThumbnail) {
                @Override
                public void onResourceReady(GlideDrawable resource,
                                            GlideAnimation<? super GlideDrawable> animation) {
                    super.onResourceReady(resource, animation);
                    EspressoIdlingResource.decrement(); // Set app as idle.
                }
            });
}
 
Example 9
Source Project: glide-support   Source File: TestFragment_Single.java    License: The Unlicense 6 votes vote down vote up
@Override protected void load(final Context context) throws Exception {
	String url = "http://www.kizoa.com/img/e8nZC.gif";
	Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.github_1261_nine_to_five);
	if (drawable instanceof Animatable) {
		((Animatable)drawable).stop();
		((Animatable)drawable).start();
	}
	Glide
			.with(this)
			.load(url)
			.placeholder(drawable)
			.crossFade(3000)
			.skipMemoryCache(true) // make sure the image is reloaded so the placeholder has a chance
			.diskCacheStrategy(DiskCacheStrategy.SOURCE)
			.bitmapTransform(DelayTransformation.<Bitmap>create(2000)) // debug lengthen decode to see placeholder
			.listener(new LoggingListener<String, GlideDrawable>())
			.into(new LoggingTarget<>(new GlideDrawableImageViewTarget(imageView)))
	;
}
 
Example 10
Source Project: TvAppRepo   Source File: MainFragment.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 11
Source Project: Anecdote   Source File: CustomImageView.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public File saveImage(){

    Drawable drawable = getDrawable();
    Bitmap bitmap = null;

    if(drawable instanceof BitmapDrawable){
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof GlideDrawable){
        bitmap = ((GlideBitmapDrawable)drawable.getCurrent()).getBitmap();
    }

    File output = new ImageSaver(getContext())
            .setExternal(true)
            .setDirectoryName(Configuration.DOWNLOAD_FOLDER)
            .setFileName(getContext().getString(R.string.app_name) + "-" + System.currentTimeMillis() + ".jpg")
            .save(bitmap);

    if(output != null){
        return output;
    }
    return null;
}
 
Example 12
Source Project: GankMeizhi   Source File: ViewerFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onException(Exception e,
                           String model,
                           Target<GlideDrawable> target,
                           boolean isFirstResource) {
    maybeStartPostponedEnterTransition();
    return true;
}
 
Example 13
Source Project: giffun   Source File: SquaringDrawable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Drawable mutate() {
    if (!mutated && super.mutate() == this) {
        wrapped = (GlideDrawable) wrapped.mutate();
        state = new State(state);
        mutated = true;
    }
    return this;
}
 
Example 14
Source Project: RichText   Source File: ImageTargetGif.java    License: MIT License 5 votes vote down vote up
@Override
public void onResourceReady(GifDrawable resource, GlideAnimation<? super GifDrawable> glideAnimation) {
    if (!activityIsAlive()) {
        return;
    }
    DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
    if (drawableWrapper == null) {
        return;
    }
    holder.setImageState(ImageHolder.ImageState.READY);
    gifDrawableSoftReference = new SoftReference<>(resource);
    Bitmap first = resource.getFirstFrame();
    holder.setSize(first.getWidth(), first.getHeight());
    drawableWrapper.setDrawable(resource);
    if (rect != null) {
        drawableWrapper.setBounds(rect);
    } else {
        if (!config.autoFix && config.imageFixCallback != null) {
            config.imageFixCallback.onImageReady(holder, first.getWidth(), first.getHeight());
        }
        if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
            int width = getRealWidth();
            int height = (int) ((float) first.getHeight() * width / first.getWidth());
            drawableWrapper.setBounds(0, 0, width, height);
        } else {
            drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
        }
        if (holder.isAutoPlay()) {
            resource.setCallback(this);
            resource.start();
            resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
        }
    }
    resetText();
    loadDone();
}
 
Example 15
Source Project: BuildingForAndroidTV   Source File: PlaybackOverlayFragment.java    License: MIT License 5 votes vote down vote up
protected void updateVideoImage(String uri) {
    Glide.with(getActivity())
            .load(uri)
            .centerCrop()
            .into(new SimpleTarget<GlideDrawable>(CARD_WIDTH, CARD_HEIGHT) {
                @Override
                public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                    mPlaybackControlsRow.setImageDrawable(resource);
                    mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
                }
            });
}
 
Example 16
Source Project: glide-support   Source File: TestFragment.java    License: The Unlicense 5 votes vote down vote up
@Override protected void load2(Context context, ImageView imageView) throws Exception {
		Glide
				.with(this)
				.load(url)
				.diskCacheStrategy(DiskCacheStrategy.RESULT)
				.listener(new LoggingListener<String, GlideDrawable>("second"))
				.dontAnimate()
				.dontTransform()
//				.transcoder(new GifBitmapWrapperDrawableTranscoder(new GlideBitmapDrawableTranscoder(context)) {
//					@Override public Resource<GlideDrawable> transcode(Resource<GifBitmapWrapper> toTranscode) {
//						try {
//							Thread.sleep(3000);
//						} catch (InterruptedException e) {
//							e.printStackTrace();
//						}
//						return super.transcode(toTranscode);
//					}
//				})
				.override(360, 360)
				.thumbnail(Glide
						.with(this)
						.load(url)
						.diskCacheStrategy(DiskCacheStrategy.RESULT)
						.listener(new LoggingListener<String, GlideDrawable>("second-thumb"))
						.animate(android.R.anim.fade_in)
						.override(72, 72)
				)
				.into(imageView)
		;
	}
 
Example 17
Source Project: giffun   Source File: DrawableRequestBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DrawableRequestBuilder<ModelType> thumbnail(
        GenericRequestBuilder<?, ?, ?, GlideDrawable> thumbnailRequest) {
    super.thumbnail(thumbnailRequest);
    return this;
}
 
Example 18
Source Project: glide-support   Source File: TestFragment.java    License: The Unlicense 5 votes vote down vote up
@Override protected void load2(Context context, ImageView imageView) throws Exception {
	Glide
			.with(this)
			.load("http://facebook.github.io/stetho/static/logo.png")
			.listener(new LoggingListener<String, GlideDrawable>())
			.into(imageView)
	;
}
 
Example 19
Source Project: ImageLoadPK   Source File: GlideHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
    Log.w(TAG, "onException: ", e);
    Log.d(TAG, "onException: " + model);
    Log.d(TAG, "onException: " + target.getRequest().isRunning());
    return false;
}
 
Example 20
Source Project: giffun   Source File: DrawableRequestBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DrawableRequestBuilder<ModelType> listener(
        RequestListener<? super ModelType, GlideDrawable> requestListener) {
    super.listener(requestListener);
    return this;
}
 
Example 21
Source Project: glide-support   Source File: TestFragment.java    License: The Unlicense 5 votes vote down vote up
@Override protected void load(Context context) {
	SyncLoadImageViewTarget target = Glide
			.with(this)
			.load("http://placehold.it/1600x900/ff0000/00ff00&text=image")
			.diskCacheStrategy(DiskCacheStrategy.ALL)
			.placeholder(R.drawable.glide_placeholder)
			.listener(new LoggingListener<String, GlideDrawable>())
			.into(new SyncLoadImageViewTarget(imageView));

	Log.d("isLoaded", target.isLoaded() + "");
	if (!target.isLoaded()) {
		//Glide.clear(target); NOT CLEARING ANYMORE
	}
}
 
Example 22
private void loadImageViewTarget() {
    viewTarget = new ViewTarget<FutureStudioView, GlideDrawable>( customView ) {
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
            this.view.setImage( resource.getCurrent() );
        }
    };

    Glide
            .with( context.getApplicationContext() ) // safer!
            .load( eatFoodyImages[2] )
            .into( viewTarget );
}
 
Example 23
Source Project: Phonograph   Source File: SongGlideRequest.java    License: GNU General Public License v3.0 5 votes vote down vote up
public DrawableRequestBuilder<GlideDrawable> build() {
    //noinspection unchecked
    return createBaseRequest(requestManager, song, ignoreMediaStore)
            .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
            .error(DEFAULT_ERROR_IMAGE)
            .animate(DEFAULT_ANIMATION)
            .signature(createSignature(song));
}
 
Example 24
Source Project: glide-support   Source File: TestFragment.java    License: The Unlicense 5 votes vote down vote up
@Override protected void load(Context context) throws Exception {
	Glide
			.with(context)
			.load(R.drawable.glide)
			.diskCacheStrategy(DiskCacheStrategy.NONE) // necessary only because I'm loading an APK resource
			.skipMemoryCache(true) // remove in production, this is just there so it's reproducible quickly
			.placeholder(R.drawable.glide_placeholder)
			// delay to see what's going on, in normal usage replace this with .fitCenter()
			.transform(new FitCenter(context), new DelayBitmapTransformation(1000))
			.animate(new PaddingAnimationFactory<>(new DrawableCrossFadeFactory<GlideDrawable>(2000)))
			.into(imageView)
	;
}
 
Example 25
Source Project: Camera2   Source File: GlideFilmstripManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a small thumbnail sized image that has the same bounds as the
 * media store thumbnail images.
 * <p>
 * If the Uri points at an animated gif, the gif will not play.
 */
public GenericRequestBuilder<Uri, ?, ?, GlideDrawable> loadMediaStoreThumb(Uri uri, Key key)
{
    Size size = clampSize(MEDIASTORE_THUMB_SIZE, MAXIMUM_SMOOTH_PIXELS, getMaxImageDisplaySize());
    return mTinyImageBuilder
            .clone()
            .load(uri)
            .signature(key)
            // This attempts to ensure we load the cached media store version.
            .override(size.width(), size.height());
}
 
Example 26
Source Project: Camera2   Source File: GlideFilmstripManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create very tiny thumbnail request that should complete as fast
 * as possible.
 * <p>
 * If the Uri points at an animated gif, the gif will not play.
 */
public GenericRequestBuilder<Uri, ?, ?, GlideDrawable> loadTinyThumb(Uri uri, Key key)
{
    Size size = clampSize(TINY_THUMB_SIZE, MAXIMUM_SMOOTH_PIXELS, getMaxImageDisplaySize());
    return mTinyImageBuilder
            .clone()
            .load(uri)
            .signature(key)
            .override(size.width(), size.height());
}
 
Example 27
public DrawableRequestBuilder<GlideDrawable> build() {
    //noinspection unchecked
    return createBaseRequest(requestManager, song, ignoreMediaStore)
            .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
            .error(DEFAULT_ERROR_IMAGE)
            .animate(DEFAULT_ANIMATION)
            .signature(createSignature(song));
}
 
Example 28
public DrawableRequestBuilder<GlideDrawable> build() {
    //noinspection unchecked
    return createBaseRequest(requestManager, artist, noCustomImage)
            .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
            .error(DEFAULT_ERROR_IMAGE)
            .animate(DEFAULT_ANIMATION)
            .priority(Priority.LOW)
            .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
            .signature(createSignature(artist));
}
 
Example 29
Source Project: Jockey   Source File: AlbumItemViewModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onResourceReady(GlideDrawable resource,
                            GlideAnimation<? super GlideDrawable> glideAnimation) {

    Drawable start = mTarget.get();

    if (start != null) {
        setDrawableWithFade(start, resource);
    } else {
        setDrawable(resource);
    }
}
 
Example 30
public void showImage(String url, final ImageView image) {
    Glide.with(getApplicationContext()).load(url).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher)
            .into(new SimpleTarget<GlideDrawable>() { // 加上这段代码 可以解决
                @Override
                public void onResourceReady(GlideDrawable resource,
                                            GlideAnimation<? super GlideDrawable> glideAnimation) {
                    image.setImageDrawable(resource); //显示图片
                }
            });
}