Permalink
Browse files

✨ Update Glide to v4

  • Loading branch information...
esafirm committed Sep 11, 2017
1 parent 25fa231 commit d5969807e5bccdbb5d2798a150a7ef39073a44e5
@@ -1,5 +1,3 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
@@ -22,6 +20,7 @@ ext {
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
@@ -31,7 +31,9 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:glide:4.1.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.1.1'
final supportLibraryVersion = '25.3.1'
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
@@ -2,17 +2,18 @@
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.esafirm.imagepicker.R;
public class DefaultImageLoader implements ImageLoader {
@Override
public void loadImage(String path, ImageView imageView, ImageType imageType) {
Glide.with(imageView.getContext())
GlideApp.with(imageView.getContext())
.load(path)
.placeholder(imageType == ImageType.FOLDER ? R.drawable.folder_placeholder : R.drawable.image_placeholder)
.error(imageType == ImageType.FOLDER ? R.drawable.folder_placeholder : R.drawable.image_placeholder)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView);
}
}
@@ -0,0 +1,7 @@
package com.esafirm.imagepicker.features.imageloader;
import com.bumptech.glide.module.AppGlideModule;
@com.bumptech.glide.annotation.GlideModule
public class GlideModule extends AppGlideModule {
}
@@ -7,7 +7,7 @@ android {
buildToolsVersion sdk.buildTools
defaultConfig {
minSdkVersion sdk.minSdik
minSdkVersion sdk.minSdk
targetSdkVersion sdk.targetSdk
versionCode 1
versionName "1.0"
@@ -2,16 +2,19 @@
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
import com.esafirm.imagepicker.features.imageloader.GlideApp;
import com.esafirm.imagepicker.features.imageloader.ImageLoader;
import com.esafirm.imagepicker.features.imageloader.ImageType;
public class GrayscaleImageLoader implements ImageLoader {
@Override
public void loadImage(String path, ImageView imageView, ImageType imageType) {
Glide.with(imageView.getContext())
GlideApp.with(imageView.getContext())
.asBitmap()
.load(path)
.bitmapTransform(new GrayscaleTransformation(imageView.getContext()))
.transition(BitmapTransitionOptions.withCrossFade())
.transform(new GrayscaleTransformation())
.into(imageView);
}
}
@@ -1,57 +1,45 @@
package com.esafirm.sample;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
public class GrayscaleTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
public class GrayscaleTransformation extends BitmapTransformation {
public GrayscaleTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
}
public GrayscaleTransformation(BitmapPool pool) {
mBitmapPool = pool;
}
private static final String ID = "GrayscaleTransformation()";
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int width = source.getWidth();
int height = source.getHeight();
Bitmap.Config config = toTransform.getConfig() != null
? toTransform.getConfig()
: Bitmap.Config.ARGB_8888;
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Bitmap bitmap = pool.get(width, height, config);
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override
public String getId() {
return "GrayscaleTransformation()";
public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID.getBytes());
}
}

0 comments on commit d596980

Please sign in to comment.