diff --git a/app/build.gradle b/app/build.gradle index de40baa05..4ede29b32 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,7 +34,6 @@ android { debug { minifyEnabled false - signingConfig signingConfigs.pictureSelectorKey proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } @@ -75,4 +74,5 @@ dependencies { implementation "androidx.camera:camera-camera2:${cfgs.camerax_version}" implementation "com.github.bumptech.glide:glide:${cfgs.glide_version}" implementation "com.squareup.picasso:picasso:${cfgs.picasso_version}" + implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a56bc9054..5e450f7da 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,6 @@ android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:requestLegacyExternalStorage="true" android:supportsRtl="true" android:theme="@style/AppTheme" tools:targetApi="q"> diff --git a/app/src/main/java/com/luck/pictureselector/GlideEngine.java b/app/src/main/java/com/luck/pictureselector/GlideEngine.java index 694d763f4..40943182b 100644 --- a/app/src/main/java/com/luck/pictureselector/GlideEngine.java +++ b/app/src/main/java/com/luck/pictureselector/GlideEngine.java @@ -13,12 +13,16 @@ import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.BitmapImageViewTarget; import com.bumptech.glide.request.target.ImageViewTarget; import com.luck.picture.lib.engine.ImageEngine; import com.luck.picture.lib.listener.OnImageCompleteCallback; import com.luck.picture.lib.tools.MediaUtils; +import com.luck.picture.lib.tools.ScreenUtils; import com.luck.picture.lib.widget.longimage.ImageSource; import com.luck.picture.lib.widget.longimage.ImageViewState; import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView; @@ -211,6 +215,25 @@ public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNul .into(imageView); } + /** + * 加载图片列表图片 + * + * @param context 上下文 + * @param url 图片路径 + * @param imageView 承载图片ImageView + */ + @Override + public void loadGridImageRound(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { + Glide.with(context) + .load(url) + .centerCrop() + .transform(new CenterCrop(),new RoundedCorners(ScreenUtils.dip2px(context,4))) + .into(imageView); + + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + + } + private GlideEngine() { } diff --git a/app/src/main/java/com/luck/pictureselector/GlideRoundTransform.java b/app/src/main/java/com/luck/pictureselector/GlideRoundTransform.java new file mode 100644 index 000000000..cd154a311 --- /dev/null +++ b/app/src/main/java/com/luck/pictureselector/GlideRoundTransform.java @@ -0,0 +1,59 @@ +package com.luck.pictureselector; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.support.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; + +import java.security.MessageDigest; + +/** + * @author yikai + */ +public class GlideRoundTransform extends BitmapTransformation { + private float radius = 0f; + + public GlideRoundTransform(Context context) { + this(context, 4); + } + + public GlideRoundTransform(Context context, int dp) { + this.radius = Resources.getSystem().getDisplayMetrics().density * dp; + } + + @Override + protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { + Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); + return roundCrop(pool, bitmap); + } + + private Bitmap roundCrop(BitmapPool pool, Bitmap source) { + if (source == null) return null; + + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + if (result == null) { + result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + } + + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); + paint.setAntiAlias(true); + RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); + canvas.drawRoundRect(rectF, radius, radius, paint); + return result; + } + + @Override + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { + + } +} diff --git a/app/src/main/java/com/luck/pictureselector/MainActivity.java b/app/src/main/java/com/luck/pictureselector/MainActivity.java index 8b11eafaf..54bc489ee 100644 --- a/app/src/main/java/com/luck/pictureselector/MainActivity.java +++ b/app/src/main/java/com/luck/pictureselector/MainActivity.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.graphics.Canvas; @@ -27,6 +28,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; @@ -395,6 +397,20 @@ public void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView. // 注册广播 BroadcastManager.getInstance(getContext()).registerReceiver(broadcastReceiver, BroadcastAction.ACTION_DELETE_PREVIEW_POSITION); + + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction("com.newsclapper.picture"); + LocalReceiver localReceiver = new LocalReceiver(); + //注册本地广播监听器 + LocalBroadcastManager.getInstance(this).registerReceiver(localReceiver, intentFilter); + + } + + class LocalReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + ArrayList result = intent.getParcelableArrayListExtra("LOCAL_MEDIA_LIST"); + } } /** @@ -427,6 +443,13 @@ private void clearCache() { public void onAddPicClick() { boolean mode = cb_mode.isChecked(); if (mode) { + + List filterMimeType = new ArrayList<>(); + filterMimeType.add("video/mp4"); + filterMimeType.add("video/mov"); + filterMimeType.add("image/jpeg"); + filterMimeType.add("image/png"); + // 进入相册 以下是例子:不需要的api可以不写 PictureSelector.create(MainActivity.this) .openGallery(chooseMode)// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio() @@ -449,10 +472,12 @@ public void onAddPicClick() { //.setButtonFeatures(CustomCameraView.BUTTON_STATE_BOTH)// 设置自定义相机按钮状态 .maxSelectNum(maxSelectNum)// 最大图片选择数量 .minSelectNum(1)// 最小选择数量 - .maxVideoSelectNum(1) // 视频最大选择数量 + .maxVideoSelectNum(maxSelectNum) // 视频最大选择数量 //.minVideoSelectNum(1)// 视频最小选择数量 //.closeAndroidQChangeVideoWH(!SdkVersionUtils.checkedAndroid_Q())// 关闭在AndroidQ下获取图片或视频宽高相反自动转换 .imageSpanCount(4)// 每行显示个数 + .selectCountText("yikai") + .isCloseActivity(false) .isReturnEmpty(false)// 未选择数据时点击按钮是否可以返回 .closeAndroidQChangeWH(true)//如果图片有旋转角度则对换宽高,默认为true .closeAndroidQChangeVideoWH(!SdkVersionUtils.checkedAndroid_Q())// 如果视频有旋转角度则对换宽高,默认为false @@ -814,9 +839,6 @@ public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { chooseMode = PictureMimeType.ofAudio(); cb_preview_audio.setVisibility(View.VISIBLE); break; - case R.id.rb_system: - language = -1; - break; case R.id.rb_jpan: language = LanguageConfig.JAPAN; break; @@ -835,9 +857,6 @@ public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { case R.id.rb_fr: language = LanguageConfig.FRANCE; break; - case R.id.rb_spanish: - language = LanguageConfig.SPANISH; - break; case R.id.rb_crop_default: aspect_ratio_x = 0; aspect_ratio_y = 0; @@ -1257,9 +1276,9 @@ private PictureParameterStyle getWeChatStyle() { // 是否开启类似QQ相册带数字选择风格 mPictureParameterStyle.isOpenCheckNumStyle = true; // 状态栏背景色 - mPictureParameterStyle.pictureStatusBarColor = Color.parseColor("#393a3e"); + mPictureParameterStyle.pictureStatusBarColor = Color.parseColor("#ffffff"); // 相册列表标题栏背景色 - mPictureParameterStyle.pictureTitleBarBackgroundColor = Color.parseColor("#393a3e"); + mPictureParameterStyle.pictureTitleBarBackgroundColor = Color.parseColor("#ffffff"); // 相册父容器背景色 mPictureParameterStyle.pictureContainerBackgroundColor = ContextCompat.getColor(getContext(), R.color.app_color_black); // 相册列表标题栏右侧上拉箭头 diff --git a/app/src/main/java/com/luck/pictureselector/PicassoEngine.java b/app/src/main/java/com/luck/pictureselector/PicassoEngine.java index 46ffd810c..b25411627 100644 --- a/app/src/main/java/com/luck/pictureselector/PicassoEngine.java +++ b/app/src/main/java/com/luck/pictureselector/PicassoEngine.java @@ -267,6 +267,11 @@ public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNul } } + @Override + public void loadGridImageRound(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { + + } + private PicassoEngine() { } diff --git a/app/src/main/java/com/luck/pictureselector/SimpleActivity.java b/app/src/main/java/com/luck/pictureselector/SimpleActivity.java index a3c23c420..16f67f132 100644 --- a/app/src/main/java/com/luck/pictureselector/SimpleActivity.java +++ b/app/src/main/java/com/luck/pictureselector/SimpleActivity.java @@ -1,14 +1,26 @@ package com.luck.pictureselector; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; +import com.luck.picture.lib.PictureSelector; +import com.luck.picture.lib.config.PictureConfig; +import com.luck.picture.lib.config.PictureMimeType; +import com.luck.picture.lib.language.LanguageConfig; +import com.luck.picture.lib.listener.OnResultCallbackListener; +import com.yalantis.ucrop.util.ScreenUtils; +import com.yalantis.ucrop.view.widget.CustomLoadingDialog; + +import java.util.ArrayList; +import java.util.List; + public class SimpleActivity extends AppCompatActivity implements View.OnClickListener { - private Button btn_activity, btn_fragment; + private Button btn_activity, btn_fragment, btn_dialog, clapper,videoImage; @Override protected void onCreate(Bundle savedInstanceState) { @@ -16,8 +28,13 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_other); btn_activity = findViewById(R.id.btn_activity); btn_fragment = findViewById(R.id.btn_fragment); + btn_dialog = findViewById(R.id.btn_dialog); + clapper = findViewById(R.id.clapper); btn_activity.setOnClickListener(this); btn_fragment.setOnClickListener(this); + btn_dialog.setOnClickListener(this); + clapper.setOnClickListener(this); + } @Override @@ -28,6 +45,57 @@ public void onClick(View v) { break; case R.id.btn_fragment: startActivity(new Intent(SimpleActivity.this, PhotoFragmentActivity.class)); + break; + case R.id.btn_dialog: + View view = getLayoutInflater().inflate(R.layout.ucrop_dialog_loading, null); + CustomLoadingDialog mMyDialog = new CustomLoadingDialog(this, + ScreenUtils.dip2px(this,228), + ScreenUtils.dip2px(this,108), + view, + R.style.ucrop_DialogStyle); + mMyDialog.setCancelable(true); + mMyDialog.show(); + break; + case R.id.clapper: + List filterMimeType = new ArrayList(); + filterMimeType.add("video/mp4"); + filterMimeType.add("video/quicktime"); + filterMimeType.add("image/jpeg"); + filterMimeType.add("image/jpg"); + filterMimeType.add("image/png"); + //upload + PictureSelector.create(this) + .openGallery(PictureMimeType.ofVideo()) + .isWeChatStyle(true) + .imageEngine(GlideEngine.createGlideEngine()) + .isWithVideoImage(true) + .theme(R.style.picture_WeChat_style) + .setLanguage(LanguageConfig.ENGLISH) + .maxVideoSelectNum(35) + .isMaxSelectEnabledMask(true) + .isOnlyVideo(false) + .isPreviewVideo(false) + .selectionMode(PictureConfig.MULTIPLE) + .isSingleDirectReturn(false) + .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + .isCamera(false) + .maxSelectNum(35) + .videoMinSecond(6) + .setFilterMimeType(filterMimeType) + .isShowPreView(false) + .forResult(new OnResultCallbackListener(){ + + @Override + public void onResult(List result) { + + } + + @Override + public void onCancel() { + + } + }); + break; default: break; diff --git a/app/src/main/res/layout/activity_other.xml b/app/src/main/res/layout/activity_other.xml index 27f9298be..a9242d1e2 100644 --- a/app/src/main/res/layout/activity_other.xml +++ b/app/src/main/res/layout/activity_other.xml @@ -21,4 +21,25 @@ android:layout_marginTop="10dp" android:text="Fragment" android:textAllCaps="false" /> + + +