Glidev4 Integration

ChandraSaiMohan bhupathi
2 min readAug 17, 2020

What is Glide ?

Glide is a fast and efficient image loading library for Android focused on smooth scrolling. Glide offers an easy to use API, a performant and extensible resource decoding pipeline and automatic resource pooling.

Features:

•Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.

•By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google’s Volley project or Square’s OkHttp library instead.

Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

Glide uses a simple fluent API that allows users to make most requests in a single line:

Code sample:

Glide.with(fragment).load(url).into(imageView);

Glide integration in Android project:

Step 1:

Requirements:

Glide v4 requires Android Ice Cream Sandwich (API level 14) or higher.

Step 2:

Dependencies:

Add the below dependencies in module level build.gradle

dependencies{

implementation ‘com.github.bumptech.glide:glide:4.11.0’

annotationProcessor ‘com.github.bumptech.glide:compiler:4.11.0’

}

Step 3:

Create an empty class that extends AppGlideModule annotated with

@GlideModule in order to Glidev4 APIs as below :

@GlideModule

public class GiftListGlideModule extends AppGlideModule {

}

Step 4:

Downloading image from remote URL:

Use GlideApp.with() API to access image from remote URL as below code sample:

GlideApp.with(ctx)

.asBitmap()

.load(url)

.into(new CustomTarget<Bitmap>(){

@Override

public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

if(resource!=null){

//Set the received bitmap to imageView as per requirement

}

@Override

public void onLoadCleared(@Nullable Drawable placeholder) {

Log.writeInfo(LOG_TAG + “ onLoadCleared() “);

}

@Override

public void onLoadFailed(@Nullable Drawable errorDrawable) {

super.onLoadFailed(errorDrawable);

Log.writeInfo(LOG_TAG + “onLoadFailed() “);

}

});

References:

https://bumptech.github.io/glide/doc/getting-started.html

https://guides.codepath.com/android/Displaying-Images-with-the-Glide-Library#:~:text=Glide%20is%20an%20Image%20Loader,and%20handles%20image%20loading%2Fcaching

https://medium.com/@nuhkocaa/manage-all-your-glides-in-a-single-class-with-glidemodule-on-android-4856ee4983a1

--

--