Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Mar 12, 2022
1 parent d56da5a commit 8ae479f
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void analyticalSelectResults(ArrayList<LocalMedia> result) {
for (LocalMedia media : result) {
if (media.getWidth() == 0 || media.getHeight() == 0) {
if (PictureMimeType.isHasImage(media.getMimeType())) {
MediaExtraInfo imageExtraInfo = MediaUtils.getImageSize(media.getPath());
MediaExtraInfo imageExtraInfo = MediaUtils.getImageSize(this,media.getPath());
media.setWidth(imageExtraInfo.getWidth());
media.setHeight(imageExtraInfo.getHeight());
} else if (PictureMimeType.isHasVideo(media.getMimeType())) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/luck/pictureselector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ public boolean onSelectLimitTips(Context context, PictureSelectionConfig config,
if (limitType == SelectLimitType.SELECT_MAX_VIDEO_SELECT_LIMIT) {
ToastUtils.showToast(context, context.getString(R.string.ps_message_video_max_num, String.valueOf(config.maxVideoSelectNum)));
return true;
} else if (limitType == SelectLimitType.SELECT_NOT_SUPPORT_SELECT_LIMIT) {
ToastUtils.showToast(context, "暂不支持的选择类型");
return true;
}
return false;
}
Expand Down Expand Up @@ -1579,7 +1582,7 @@ private void analyticalSelectResults(ArrayList<LocalMedia> result) {
for (LocalMedia media : result) {
if (media.getWidth() == 0 || media.getHeight() == 0) {
if (PictureMimeType.isHasImage(media.getMimeType())) {
MediaExtraInfo imageExtraInfo = MediaUtils.getImageSize(media.getPath());
MediaExtraInfo imageExtraInfo = MediaUtils.getImageSize(getContext(), media.getPath());
media.setWidth(imageExtraInfo.getWidth());
media.setHeight(imageExtraInfo.getHeight());
} else if (PictureMimeType.isHasVideo(media.getMimeType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.manager.SelectedManager;
import com.luck.picture.lib.style.SelectMainStyle;
import com.luck.picture.lib.utils.AnimUtils;
import com.luck.picture.lib.utils.StyleUtils;
import com.luck.picture.lib.utils.ValueOf;

Expand Down Expand Up @@ -161,6 +162,11 @@ public void onClick(View view) {
if (resultCode == SelectedManager.INVALID) {
return;
}
if (resultCode == SelectedManager.ADD_SUCCESS) {
if (config.isSelectZoomAnim) {
AnimUtils.selectZoom(ivPicture);
}
}
selectedMedia(isSelected(media));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,20 @@ public long getEnterAnimationDuration() {

@Override
public int confirmSelect(LocalMedia currentMedia, boolean isSelected) {
if (PictureSelectionConfig.onSelectFilterListener != null) {
if (PictureSelectionConfig.onSelectFilterListener.onSelectFilter(currentMedia)) {
boolean isSelectLimit = false;
if (PictureSelectionConfig.onSelectLimitTipsListener != null) {
isSelectLimit = PictureSelectionConfig.onSelectLimitTipsListener
.onSelectLimitTips(getContext(), config, SelectLimitType.SELECT_NOT_SUPPORT_SELECT_LIMIT);
}
if (isSelectLimit) {
} else {
ToastUtils.showToast(getContext(), getString(R.string.ps_select_no_support));
}
return SelectedManager.INVALID;
}
}
int checkSelectValidity = isCheckSelectValidity(currentMedia, isSelected);
if (checkSelectValidity != SelectedManager.SUCCESS) {
return SelectedManager.INVALID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.luck.picture.lib.interfaces.OnPermissionsInterceptListener;
import com.luck.picture.lib.interfaces.OnPreviewInterceptListener;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
import com.luck.picture.lib.interfaces.OnSelectFilterListener;
import com.luck.picture.lib.interfaces.OnSelectLimitTipsListener;
import com.luck.picture.lib.language.LanguageConfig;
import com.luck.picture.lib.manager.SelectedManager;
Expand Down Expand Up @@ -248,6 +249,17 @@ public PictureSelectionModel setSelectLimitTipsListener(OnSelectLimitTipsListene
return this;
}

/**
* You need to filter out the content that does not meet the selection criteria
*
* @param listener
* @return
*/
public PictureSelectionModel setSelectFilterListener(OnSelectFilterListener listener) {
PictureSelectionConfig.onSelectFilterListener = listener;
return this;
}

/**
* Do you want to open a foreground service to prevent the system from reclaiming the memory
* of some models due to the use of cameras
Expand Down Expand Up @@ -981,6 +993,14 @@ public PictureSelectionModel isCameraRotateImage(boolean isCameraRotateImage) {
return this;
}

/**
* Zoom animation is required when selecting an asset
*/
public PictureSelectionModel isSelectZoomAnim(boolean isSelectZoomAnim) {
selectionConfig.isSelectZoomAnim = isSelectZoomAnim;
return this;
}

/**
* @param selectedList Select the selected picture set
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.interfaces.OnPermissionsInterceptListener;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
import com.luck.picture.lib.interfaces.OnSelectFilterListener;
import com.luck.picture.lib.interfaces.OnSelectLimitTipsListener;
import com.luck.picture.lib.utils.DoubleUtils;
import com.luck.picture.lib.utils.SdkVersionUtils;
Expand Down Expand Up @@ -205,6 +206,17 @@ public PictureSelectionSystemModel setSelectLimitTipsListener(OnSelectLimitTipsL
return this;
}

/**
* You need to filter out the content that does not meet the selection criteria
*
* @param listener
* @return
*/
public PictureSelectionSystemModel setSelectFilterListener(OnSelectFilterListener listener) {
PictureSelectionConfig.onSelectFilterListener = listener;
return this;
}

/**
* Call the system library to obtain resources
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.luck.picture.lib.interfaces.OnPermissionsInterceptListener;
import com.luck.picture.lib.interfaces.OnPreviewInterceptListener;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
import com.luck.picture.lib.interfaces.OnSelectFilterListener;
import com.luck.picture.lib.interfaces.OnSelectLimitTipsListener;
import com.luck.picture.lib.language.LanguageConfig;
import com.luck.picture.lib.magical.BuildRecycleItemViewParams;
Expand Down Expand Up @@ -110,6 +111,7 @@ public final class PictureSelectionConfig implements Parcelable {
public boolean isOriginalControl;
public boolean isDisplayTimeAxis;
public boolean isFastSlidingSelect;
public boolean isSelectZoomAnim;

public static ImageEngine imageEngine;
public static CompressEngine compressEngine;
Expand All @@ -125,6 +127,7 @@ public final class PictureSelectionConfig implements Parcelable {
public static OnPermissionsInterceptListener onPermissionsEventListener;
public static OnInjectLayoutResourceListener onLayoutResourceListener;
public static OnPreviewInterceptListener onPreviewInterceptListener;
public static OnSelectFilterListener onSelectFilterListener;


protected PictureSelectionConfig(Parcel in) {
Expand Down Expand Up @@ -203,6 +206,7 @@ protected PictureSelectionConfig(Parcel in) {
isOriginalControl = in.readByte() != 0;
isDisplayTimeAxis = in.readByte() != 0;
isFastSlidingSelect = in.readByte() != 0;
isSelectZoomAnim = in.readByte() != 0;
}

@Override
Expand Down Expand Up @@ -282,6 +286,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (isOriginalControl ? 1 : 0));
dest.writeByte((byte) (isDisplayTimeAxis ? 1 : 0));
dest.writeByte((byte) (isFastSlidingSelect ? 1 : 0));
dest.writeByte((byte) (isSelectZoomAnim ? 1 : 0));
}

@Override
Expand Down Expand Up @@ -378,6 +383,7 @@ protected void initDefaultValue() {
isFastSlidingSelect = false;
skipCropList = new ArrayList<>();
sortOrder = "";
isSelectZoomAnim = true;
}


Expand Down Expand Up @@ -421,6 +427,7 @@ public static void destroy() {
PictureSelectionConfig.onLayoutResourceListener = null;
PictureSelectionConfig.onPreviewInterceptListener = null;
PictureSelectionConfig.onSelectLimitTipsListener = null;
PictureSelectionConfig.onSelectFilterListener = null;
PictureThreadUtils.cancel(PictureThreadUtils.getIoPool());
SelectedManager.clearSelectResult();
BuildRecycleItemViewParams.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class SelectLimitType {
public static final int SELECT_MAX_AUDIO_SECOND_SELECT_LIMIT = 10;
public static final int SELECT_MIN_AUDIO_SECOND_SELECT_LIMIT = 11;
public static final int SELECT_MIN_AUDIO_SELECT_LIMIT = 12;
public static final int SELECT_NOT_SUPPORT_SELECT_LIMIT = 13;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.luck.picture.lib.interfaces;

import com.luck.picture.lib.entity.LocalMedia;

/**
* @author:luck
* @date:2022/3/12 9:00 下午
* @describe:OnSelectFilterListener
*/
public interface OnSelectFilterListener {
/**
* You need to filter out the content that does not meet the selection criteria
*
* @param media current select {@link LocalMedia}
* @return the boolean result
*/
boolean onSelectFilter(LocalMedia media);
}
18 changes: 18 additions & 0 deletions selector/src/main/java/com/luck/picture/lib/utils/AnimUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.luck.picture.lib.utils;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

Expand All @@ -11,6 +13,7 @@
*/
public class AnimUtils {
public final static int DURATION = 250;

/**
* 箭头旋转动画
*
Expand All @@ -31,4 +34,19 @@ public static void rotateArrow(ImageView arrow, boolean isFlag) {
objectAnimator.setInterpolator(new LinearInterpolator());
objectAnimator.start();
}

/**
* 缩放动画
*
* @param view
*/
public static void selectZoom(View view) {
AnimatorSet animatorSet = new AnimatorSet();
ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(view, "scaleX", 1.0F, 1.1F, 1.0F);
ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(view, "scaleY", 1.0F, 1.1F, 1.0F);
animatorSet.playTogether(objectAnimatorX, objectAnimatorY);
animatorSet.setDuration(DURATION);
animatorSet.setInterpolator(new LinearInterpolator());
animatorSet.start();
}
}
33 changes: 19 additions & 14 deletions selector/src/main/java/com/luck/picture/lib/utils/MediaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import android.text.TextUtils;
import android.webkit.MimeTypeMap;

import androidx.exifinterface.media.ExifInterface;

import com.luck.picture.lib.app.PictureAppMaster;
import com.luck.picture.lib.basic.PictureContentResolver;
import com.luck.picture.lib.config.PictureMimeType;
Expand Down Expand Up @@ -166,26 +164,31 @@ public static String generateCameraFolderName(String absolutePath) {

/**
* get Local image width or height
* <p>
* Use {@link MediaUtils.getImageSize(Context context, String url)}
*
* @param context
* @param url
* @return
*/
public static MediaExtraInfo getImageSize(Context context, String url) {
@Deprecated
public static MediaExtraInfo getImageSize(String url) {
MediaExtraInfo mediaExtraInfo = new MediaExtraInfo();
ExifInterface exifInterface;
InputStream inputStream;
InputStream inputStream = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
if (PictureMimeType.isContent(url)) {
inputStream = PictureContentResolver.getContentResolverOpenInputStream(context, Uri.parse(url));
exifInterface = new ExifInterface(inputStream);
inputStream = PictureContentResolver.getContentResolverOpenInputStream(PictureAppMaster.getInstance().getAppContext(), Uri.parse(url));
} else {
exifInterface = new ExifInterface(url);
inputStream = new FileInputStream(url);
}
mediaExtraInfo.setWidth(exifInterface.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, ExifInterface.ORIENTATION_NORMAL));
mediaExtraInfo.setHeight(exifInterface.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, ExifInterface.ORIENTATION_NORMAL));
BitmapFactory.decodeStream(inputStream, null, options);
mediaExtraInfo.setWidth(options.outWidth);
mediaExtraInfo.setHeight(options.outHeight);
} catch (Exception e) {
e.printStackTrace();
} finally {
PictureFileUtils.close(inputStream);
}
return mediaExtraInfo;
}
Expand All @@ -196,14 +199,14 @@ public static MediaExtraInfo getImageSize(Context context, String url) {
* @param url
* @return
*/
public static MediaExtraInfo getImageSize(String url) {
public static MediaExtraInfo getImageSize(Context context, String url) {
MediaExtraInfo mediaExtraInfo = new MediaExtraInfo();
InputStream inputStream;
InputStream inputStream = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
if (PictureMimeType.isContent(url)) {
inputStream = PictureContentResolver.getContentResolverOpenInputStream(PictureAppMaster.getInstance().getAppContext(), Uri.parse(url));
inputStream = PictureContentResolver.getContentResolverOpenInputStream(context, Uri.parse(url));
} else {
inputStream = new FileInputStream(url);
}
Expand All @@ -212,6 +215,8 @@ public static MediaExtraInfo getImageSize(String url) {
mediaExtraInfo.setHeight(options.outHeight);
} catch (Exception e) {
e.printStackTrace();
} finally {
PictureFileUtils.close(inputStream);
}
return mediaExtraInfo;
}
Expand Down
1 change: 1 addition & 0 deletions selector/src/main/res/values-ar-rAE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">اختيار الفيديو أقل من %1$d ثوان</string>
<string name="ps_select_audio_max_second">ختيار الصوت أكبر من %1$d ثانية</string>
<string name="ps_select_audio_min_second">اختيار الصوت أقل من %1$d ثوان</string>
<string name="ps_select_no_support">اختيار نوع غير معتمد</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">Video für weniger als %1$d Sekunden auswählen</string>
<string name="ps_select_audio_max_second">Audio für mehr als %1$d Sekunden auswählen</string>
<string name="ps_select_audio_min_second">Audio für weniger als %1$d Sekunden auswählen</string>
<string name="ps_select_no_support">Nicht unterstützter Auswahltyp</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-en-rUS/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@
<string name="ps_select_video_min_second">Select video for less than %1$d s</string>
<string name="ps_select_audio_max_second">Select audio for more than %1$d s</string>
<string name="ps_select_audio_min_second">Select audio for less than %1$d s</string>
<string name="ps_select_no_support">Unsupported selection type</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@
<string name="ps_select_video_min_second">Seleccionar vídeo durante menos de %1$d segundos</string>
<string name="ps_select_audio_max_second">Seleccionar audio durante más de %1$d segundos</string>
<string name="ps_select_audio_min_second">Seleccionar audio durante menos de %1$d segundos</string>
<string name="ps_select_no_support">Tipos de selección no soportados</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-fr-rFR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">Sélectionner la vidéo moins de %1$d secondes</string>
<string name="ps_select_audio_max_second">Sélectionnez audio plus de %1$d secondes</string>
<string name="ps_select_audio_min_second">Sélectionnez audio moins de %1$d secondes</string>
<string name="ps_select_no_support">Type de sélection non pris en charge</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">%1$d秒未満のビデオを選択</string>
<string name="ps_select_audio_max_second">オーディオを%1$d秒以上選択</string>
<string name="ps_select_audio_min_second">オーディオを%1$d秒未満で選択</string>
<string name="ps_select_no_support">サポートされていない選択タイプ</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">%1$d초 미만의 비디오 선택</string>
<string name="ps_select_audio_max_second">%1$d초 이상 오디오 선택</string>
<string name="ps_select_audio_min_second">%1$d초 미만의 오디오 선택</string>
<string name="ps_select_no_support">지원되지 않는 선택 유형</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-pt-rPT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@
<string name="ps_select_video_min_second">Selecionar vídeo por menos de %1$d segundos</string>
<string name="ps_select_audio_max_second">Selecionar áudio por mais de %1$d segundos</string>
<string name="ps_select_audio_min_second">Selecionar áudio por menos de %1$d segundos</string>
<string name="ps_select_no_support">Tipo de selecção não suportado</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-vi-rVN/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@
<string name="ps_select_video_min_second">Chọn đoạn phim ít hơn %1$d giây</string>
<string name="ps_select_audio_max_second">Chọn tiếng lớn hơn %1$d giây</string>
<string name="ps_select_audio_min_second">Chọn tiếng dưới %1$d giây</string>
<string name="ps_select_no_support">Kiểu chọn không được sắp xếp</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">选择视频小于%1$d秒</string>
<string name="ps_select_audio_max_second">选择音频大于%1$d秒</string>
<string name="ps_select_audio_min_second">选择音频小于%1$d秒</string>
<string name="ps_select_no_support">不支持的选择类型</string>
</resources>
1 change: 1 addition & 0 deletions selector/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
<string name="ps_select_video_min_second">選擇視頻小於%1$d秒</string>
<string name="ps_select_audio_max_second">選擇音訊大於%1$d秒</string>
<string name="ps_select_audio_min_second">選擇音訊小於%1$d秒</string>
<string name="ps_select_no_support">不支持的選擇類型</string>
</resources>
Loading

0 comments on commit 8ae479f

Please sign in to comment.