From 931abfd2619e35c89927b1b9949d1d8c768d81c5 Mon Sep 17 00:00:00 2001 From: HuXiaobai <1203747102@qq.com> Date: Tue, 20 Nov 2018 14:24:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Crop=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 +++++++---------- .../xiaobai/photoselector/MainActivity.java | 19 +++++++++++-------- .../example/media/activity/MediaActivity.java | 1 + .../com/example/media/utils/GlideUtils.java | 13 ++++++++++--- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d53ce1a..5b78dfc 100644 --- a/README.md +++ b/README.md @@ -62,15 +62,12 @@ allprojects { * @param resultCode * @param data */ - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - //具体重写这行代码即可 - List mediaList = MediaSelector.resultMediaFile(data); + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); - if (mediaList != null && mediaList.size() > 0) { - mData.addAll(0, mediaList); - mDataAdapter.notifyDataSetChanged(); + if (resultCode == Contast.CODE_RESULT_MEDIA && requestCode == Contast.CODE_REQUEST_MEDIA) { + List mediaList = MediaSelector.resultMediaFile(data); - } - } \ No newline at end of file + } + } \ No newline at end of file diff --git a/app/src/main/java/com/hu/xiaobai/photoselector/MainActivity.java b/app/src/main/java/com/hu/xiaobai/photoselector/MainActivity.java index 9f4fb87..180657f 100644 --- a/app/src/main/java/com/hu/xiaobai/photoselector/MainActivity.java +++ b/app/src/main/java/com/hu/xiaobai/photoselector/MainActivity.java @@ -13,6 +13,7 @@ import com.example.media.MediaSelector; import com.example.media.OnRecyclerItemClickListener; import com.example.media.bean.MediaSelectorFile; +import com.example.media.resolver.Contast; import java.util.ArrayList; import java.util.List; @@ -70,7 +71,7 @@ public void itemClick(@NonNull View view, int position) { mediaOptions.isCompress = true; mediaOptions.maxChooseMedia = 1; mediaOptions.isCrop = true; - // mediaOptions.themeColor = R.color.colorAccent; + // mediaOptions.themeColor = R.color.colorAccent; MediaSelector.with(MainActivity.this).setMediaOptions(mediaOptions).openMediaActivity(); } @@ -88,15 +89,17 @@ public void itemClick(@NonNull View view, int position) { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - List mediaList = MediaSelector.resultMediaFile(data); - if (mediaList != null && mediaList.size() > 0) { - mData.addAll(0, mediaList); - mDataAdapter.notifyDataSetChanged(); - for (int i = 0; i < mediaList.size(); i++) { - Log.w("onActivityResult----", mediaList.get(i).filePath + mediaList.get(i).folderPath); - } + if (resultCode == Contast.CODE_RESULT_MEDIA && requestCode == Contast.CODE_REQUEST_MEDIA) { + List mediaList = MediaSelector.resultMediaFile(data); + if (mediaList != null && mediaList.size() > 0) { + mData.addAll(0, mediaList); + mDataAdapter.notifyDataSetChanged(); + for (int i = 0; i < mediaList.size(); i++) { + Log.w("onActivityResult----", mediaList.get(i).filePath + mediaList.get(i).folderPath); + } + } } } diff --git a/media/src/main/java/com/example/media/activity/MediaActivity.java b/media/src/main/java/com/example/media/activity/MediaActivity.java index c4e5cc4..bb671af 100644 --- a/media/src/main/java/com/example/media/activity/MediaActivity.java +++ b/media/src/main/java/com/example/media/activity/MediaActivity.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; +import android.graphics.ImageDecoder; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Parcelable; diff --git a/media/src/main/java/com/example/media/utils/GlideUtils.java b/media/src/main/java/com/example/media/utils/GlideUtils.java index c0838a0..6efee8f 100644 --- a/media/src/main/java/com/example/media/utils/GlideUtils.java +++ b/media/src/main/java/com/example/media/utils/GlideUtils.java @@ -6,17 +6,24 @@ import android.widget.ImageView; import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory; +import com.bumptech.glide.module.AppGlideModule; import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.Target; import com.example.media.R; public class GlideUtils { public static void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { - RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.icon_image_background).error(R.mipmap.icon_image_background); + RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.icon_image_background).error(R.mipmap.icon_image_background) + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); Glide.with(context).asBitmap().apply(options).load(url).into(imageView); } public static void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView, boolean isCenterCrop) { - RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_image_background).error(R.mipmap.icon_image_background); + RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_image_background) + .error(R.mipmap.icon_image_background).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); if (isCenterCrop) { options = options.centerCrop(); } else { @@ -26,7 +33,7 @@ public static void loadImage(@NonNull Context context, @NonNull String url, @Non } public static void loadImage(@NonNull Context context, @DrawableRes int resId, @NonNull ImageView imageView) { - RequestOptions options = new RequestOptions().centerInside().placeholder(R.mipmap.icon_image_background).error(R.mipmap.icon_image_background); + RequestOptions options = new RequestOptions().centerInside().placeholder(R.mipmap.icon_image_background).error(R.mipmap.icon_image_background).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); Glide.with(context).asBitmap().apply(options).load(resId).into(imageView); }