Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Dec 7, 2019
1 parent 1549d8f commit e7e22cb
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 122 deletions.
41 changes: 33 additions & 8 deletions app/src/main/java/com/luck/pictureselector/GlideEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,34 @@
*/
public class GlideEngine implements ImageEngine {

/**
* 加载图片
*
* @param context
* @param url
* @param imageView
*/
@Override
public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
Glide.with(context).load(url).into(imageView);
}

/**
* 加载相册目录
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadFolderAsBitmapImage(@NonNull Context context, @NonNull String url,
@NonNull ImageView imageView, int placeholderId) {
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
Glide.with(context)
.asBitmap()
.override(180, 180)
.centerCrop()
.sizeMultiplier(0.5f)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(placeholderId)
.placeholder(R.drawable.picture_icon_placeholder)
.load(url)
.into(new BitmapImageViewTarget(imageView) {
@Override
Expand All @@ -49,6 +62,13 @@ protected void setResource(Bitmap resource) {
}


/**
* 加载gif
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadAsGifImage(@NonNull Context context, @NonNull String url,
@NonNull ImageView imageView) {
Expand All @@ -58,16 +78,21 @@ public void loadAsGifImage(@NonNull Context context, @NonNull String url,
.into(imageView);
}

/**
* 加载图片列表图片
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadAsBitmapGridImage(@NonNull Context context, @NonNull String url,
@NonNull ImageView imageView, int placeholderId) {
public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
Glide.with(context)
.asBitmap()
.load(url)
.override(200, 200)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(placeholderId)
.load(url)
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
}

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/luck/pictureselector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ protected void onCreate(Bundle savedInstanceState) {
// animationStyle.activityPreviewEnterAnimation = R.anim.picture_anim_up_in;
// animationStyle.activityPreviewExitAnimation = R.anim.picture_anim_down_out;
PictureSelector.create(MainActivity.this)
//.themeStyle(themeId) // xml设置主题
.setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
.themeStyle(themeId) // xml设置主题
//.setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
//.setPictureWindowAnimationStyle(animationStyle)// 自定义页面启动动画
.isNotPreviewDownload(true)// 预览图片长按是否可以下载
.loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎,必传项
Expand Down Expand Up @@ -192,6 +192,7 @@ public void onAddPicClick() {
.maxSelectNum(maxSelectNum)// 最大图片选择数量
.minSelectNum(1)// 最小选择数量
.imageSpanCount(4)// 每行显示个数
//.isAndroidQTransform(false)// 是否需要处理Android Q 拷贝至应用沙盒的操作,只针对compress(false); && enableCrop(false);有效,默认处理
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)// 设置相册Activity方向,不设置默认使用系统
.isOriginalImageControl(cb_original.isChecked())// 是否显示原图控制按钮,如果设置为true则用户可以自由选择是否使用原图,压缩、裁剪功能将会失效
//.cameraFileName("test.png") // 重命名拍照文件名、注意这个只在使用相机时可以使用,如果使用相机又开启了压缩或裁剪 需要配合压缩和裁剪文件名api
Expand All @@ -202,7 +203,7 @@ public void onAddPicClick() {
.isSingleDirectReturn(cb_single_back.isChecked())// 单选模式下是否直接返回,PictureConfig.SINGLE模式下有效
.previewImage(cb_preview_img.isChecked())// 是否可预览图片
.previewVideo(cb_preview_video.isChecked())// 是否可预览视频
//.querySpecifiedFormatSuffix(PictureMimeType.ofPNG())// 查询指定后缀格式资源
//.querySpecifiedFormatSuffix(PictureMimeType.ofJPEG())// 查询指定后缀格式资源
.enablePreviewAudio(cb_preview_audio.isChecked()) // 是否可播放音频
.isCamera(cb_isCamera.isChecked())// 是否显示拍照按钮
.isZoomAnim(true)// 图片列表点击 缩放效果 默认true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
Expand Down Expand Up @@ -310,12 +309,16 @@ protected void compressImage(final List<LocalMedia> result) {
.loadMediaData(result)
.setTargetDir(config.compressSavePath)
.setCompressQuality(config.compressQuality)
.setFocusAlpha(config.focusAlpha)
.setRenameListener(filePath -> config.renameCompressFileName)
.ignoreBy(config.minimumCompressSize).get();
// 线程切换
mHandler.sendMessage(mHandler.obtainMessage(MSG_ASY_COMPRESSION_RESULT_SUCCESS,
new Object[]{result, files}));
} catch (Exception e) {
BroadcastManager.getInstance(getApplicationContext())
.action(BroadcastAction.ACTION_CLOSE_PREVIEW).broadcast();
onResult(result);
e.printStackTrace();
}
});
Expand All @@ -325,6 +328,7 @@ protected void compressImage(final List<LocalMedia> result) {
.ignoreBy(config.minimumCompressSize)
.setCompressQuality(config.compressQuality)
.setTargetDir(config.compressSavePath)
.setFocusAlpha(config.focusAlpha)
.setRenameListener(filePath -> config.renameCompressFileName)
.setCompressListener(new OnCompressListener() {
@Override
Expand Down Expand Up @@ -615,7 +619,7 @@ protected void onResult(List<LocalMedia> images) {
if (isAndroidQ && !isVideo) {
showCompressDialog();
}
if (isAndroidQ) {
if (isAndroidQ && config.isAndroidQTransform) {
onResultToAndroidAsy(images);
} else {
dismissCompressDialog();
Expand Down
Loading

0 comments on commit e7e22cb

Please sign in to comment.