Commit 27207957 by 郑娜伟

picture 支持fresco

parent ebacb6f2
......@@ -31,6 +31,7 @@ dependencies {
compileOnly 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compileOnly 'com.github.bumptech.glide:glide:3.8.0'
compileOnly 'com.squareup.picasso:picasso:2.5.2'
compileOnly 'com.facebook.fresco:fresco:2.6.0'
api 'com.sobot.chat:sobotsupport-glidev4:2.0'
}
......
......@@ -27,8 +27,10 @@ public class SobotBitmapUtil {
sImageLoader = new SobotPicassoImageLoader();
} else if (isClassExists("com.nostra13.universalimageloader.core.ImageLoader")) {
sImageLoader = new SobotUILImageLoader();
} else if (isClassExists("com.facebook.drawee.backends.pipeline.Fresco")) {
sImageLoader = new SobotFrescoImageLoader();
} else {
throw new RuntimeException("必须在(Glide、Picasso、universal-image-loader)中选择一个图片加载库添加依赖,或者检查是否添加了相应的混淆配置");
throw new RuntimeException("必须在(Glide、Picasso、universal-image-loader、Fresco)中选择一个图片加载库添加依赖,或者检查是否添加了相应的混淆配置");
}
}
}
......@@ -74,7 +76,7 @@ public class SobotBitmapUtil {
@SuppressWarnings("deprecation")
public static Bitmap compress(String filePath, Context context, boolean isCamera) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || isCamera) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || isCamera) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;// 设置后decode图片不会返回一个bitmap对象,但是会将图片的信息封装到Options中
BitmapFactory.decodeFile(filePath, options);
......
package com.sobot.pictureframe;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.facebook.common.executors.UiThreadImmediateExecutorService;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.sobot.chat.imageloader.SobotImageLoader;
public class SobotFrescoImageLoader extends SobotImageLoader {
@Override
public void displayImage(Context context, final ImageView imageView, final String path, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
if (width > 0 && height > 0) {
builder.setResizeOptions(new ResizeOptions(width, height));
}
ImageRequest imageRequest = builder.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
BaseBitmapDataSubscriber subscriber = new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// if (listener != null) {
new AsyncTask<Bitmap, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Bitmap... params) {
Bitmap bitmap = params[0];
Bitmap result = null;
if (bitmap != null && !bitmap.isRecycled()) {
result = bitmap.copy(Bitmap.Config.RGB_565, false);
}
return result;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
// listener.onLoadComplete(bitmap);
imageView.setImageBitmap(bitmap);
} else {
// listener.onLoadFailed(null);
}
}
}.execute(bitmap);
}
@Override
public void onFailureImpl(DataSource dataSource) {
// if (listener != null) {
// listener.onLoadFailed(dataSource.getFailureCause());
// }
}
};
dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
@Override
public void displayImage(Context context, final ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment