Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Apr 8, 2021
1 parent a2674a8 commit 8717879
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 51 deletions.
10 changes: 5 additions & 5 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ ext {

//open version control
androidSupportVersion : "27.0.2",
version_recyclerview : "1.1.0",
version_recyclerview : "1.2.0",
version_appcompat : "1.2.0",
localbroadcastmanager : "1.0.0",

camerax_view : "1.0.0-alpha22",
camerax_version : "1.1.0-alpha02",
camerax_view : "1.0.0-alpha23",
camerax_version : "1.1.0-alpha03",
camera_core_version : "1.0.0-beta03",
experimental_version : "1.1.0-rc01",
experimental_version : "1.1.0",
futures_version : "1.1.0",

// ucrop
androidx_appcompat_version : "1.2.0",
androidx_exifinterface_version: "1.3.2",
androidx_transition_version : "1.3.1",
androidx_transition_version : "1.4.0",

// okio
okio_version : "2.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract class PictureBaseActivity extends AppCompatActivity {
protected int colorPrimary, colorPrimaryDark;
protected PictureLoadingDialog mLoadingDialog;
protected List<LocalMedia> selectionMedias;
protected Handler mHandler;
protected Handler mHandler = new Handler(Looper.getMainLooper());
protected View container;
/**
* if there more
Expand Down Expand Up @@ -153,7 +153,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (isRequestedOrientation()) {
setNewRequestedOrientation();
}
mHandler = new Handler(Looper.getMainLooper());
initConfig();
if (isImmersive()) {
immersive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,9 +1239,7 @@ private void AudioDialog(final String path) {
mTvPlayPause = audioDialog.findViewById(R.id.tv_PlayPause);
mTvStop = audioDialog.findViewById(R.id.tv_Stop);
mTvQuit = audioDialog.findViewById(R.id.tv_Quit);
if (mHandler != null) {
mHandler.postDelayed(() -> initPlayer(path), 30);
}
mHandler.postDelayed(() -> initPlayer(path), 30);
mTvPlayPause.setOnClickListener(new AudioOnClick(path));
mTvStop.setOnClickListener(new AudioOnClick(path));
mTvQuit.setOnClickListener(new AudioOnClick(path));
Expand All @@ -1262,9 +1260,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});
audioDialog.setOnDismissListener(dialog -> {
if (mHandler != null) {
mHandler.removeCallbacks(mRunnable);
}
mHandler.removeCallbacks(mRunnable);
new Handler().postDelayed(() -> stop(path), 30);
try {
if (audioDialog != null
Expand All @@ -1275,9 +1271,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
e.printStackTrace();
}
});
if (mHandler != null) {
mHandler.post(mRunnable);
}
mHandler.post(mRunnable);
audioDialog.show();
}
}
Expand All @@ -1291,9 +1285,7 @@ public void run() {
musicSeekBar.setProgress(mediaPlayer.getCurrentPosition());
musicSeekBar.setMax(mediaPlayer.getDuration());
mTvMusicTotal.setText(DateUtils.formatDurationTime(mediaPlayer.getDuration()));
if (mHandler != null) {
mHandler.postDelayed(mRunnable, 200);
}
mHandler.postDelayed(mRunnable, 200);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -1341,18 +1333,16 @@ public void onClick(View v) {
stop(path);
}
if (id == R.id.tv_Quit) {
if (mHandler != null) {
mHandler.postDelayed(() -> stop(path), 30);
try {
if (audioDialog != null
&& audioDialog.isShowing()) {
audioDialog.dismiss();
}
} catch (Exception e) {
e.printStackTrace();
mHandler.postDelayed(() -> stop(path), 30);
try {
if (audioDialog != null
&& audioDialog.isShowing()) {
audioDialog.dismiss();
}
mHandler.removeCallbacks(mRunnable);
} catch (Exception e) {
e.printStackTrace();
}
mHandler.removeCallbacks(mRunnable);
}
}
}
Expand All @@ -1376,9 +1366,7 @@ private void playAudio() {
playOrPause();
}
if (!isPlayAudio) {
if (mHandler != null) {
mHandler.post(mRunnable);
}
mHandler.post(mRunnable);
isPlayAudio = true;
}
}
Expand Down Expand Up @@ -2393,7 +2381,7 @@ protected void onDestroy() {
animation.cancel();
animation = null;
}
if (mediaPlayer != null && mHandler != null) {
if (mediaPlayer != null) {
mHandler.removeCallbacks(mRunnable);
mediaPlayer.release();
mediaPlayer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.luck.picture.lib.tools.SdkVersionUtils;
import com.luck.picture.lib.tools.StringUtils;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -273,7 +275,7 @@ private File compressReal(Context context, InputStreamProvider path) throws IOEx
}

private File compressRealLocalMedia(Context context, InputStreamProvider path) throws Exception {
File result = null;
File result;
LocalMedia media = path.getMedia();
String newPath = media.isCut() && !TextUtils.isEmpty(media.getCutPath()) ? media.getCutPath() : media.getRealPath();
String suffix = Checker.SINGLE.extSuffix(media.getMimeType());
Expand All @@ -296,24 +298,28 @@ private File compressRealLocalMedia(Context context, InputStreamProvider path) t
} else {
String androidQToPath = AndroidQTransformUtils.copyPathToAndroidQ(context, path.getPath(),
media.getWidth(), media.getHeight(), media.getMimeType(), filename);
if (androidQToPath != null) {
result = new File(androidQToPath);
}
result = new File(androidQToPath);
}
} else {
result = new File(newPath);
}
} else {
boolean isCompress = Checker.SINGLE.needCompressToLocalMedia(mLeastCompressSize, newPath);
if (mCompressionPredicate.apply(newPath) && isCompress) {
// 压缩
result = new Engine(path, outFile, focusAlpha, compressQuality).compress();
} else {
if (isCompress) {
// 压缩
result = new Engine(path, outFile, focusAlpha, compressQuality).compress();
} else {
result = new File(newPath);
// 这种情况判断一下,如果是小于设置的图片压缩阀值,再Android 10以上做下拷贝的处理
if (SdkVersionUtils.checkedAndroid_Q()) {
String newFilePath = media.isCut() ? media.getCutPath() :
AndroidQTransformUtils.copyPathToAndroidQ(context,
path.getPath(), media.getWidth(), media.getHeight(), media.getMimeType(), filename);
result = new File(TextUtils.isEmpty(newFilePath) ? newPath : newFilePath);
} else {
result = new File(newPath);
}
}
}
}
Expand All @@ -324,27 +330,32 @@ private File compressRealLocalMedia(Context context, InputStreamProvider path) t
String newFilePath = media.isCut() ? media.getCutPath() :
AndroidQTransformUtils.copyPathToAndroidQ(context,
path.getPath(), media.getWidth(), media.getHeight(), media.getMimeType(), filename);
if (newFilePath != null) {
result = new File(newFilePath);
}
result = new File(TextUtils.isEmpty(newFilePath) ? newPath : newFilePath);
} else {
result = new File(newPath);
}
} else {
boolean isCompress = Checker.SINGLE.needCompressToLocalMedia(mLeastCompressSize, newPath);
if (isCompress) {
// 压缩
result = new Engine(path, outFile, focusAlpha, compressQuality).compress();
} else {
result = new File(newPath);
// 这种情况判断一下,如果是小于设置的图片压缩阀值,再Android 10以上做下拷贝的处理
if (SdkVersionUtils.checkedAndroid_Q()) {
String newFilePath = media.isCut() ? media.getCutPath() :
AndroidQTransformUtils.copyPathToAndroidQ(context,
path.getPath(), media.getWidth(), media.getHeight(), media.getMimeType(), filename);
result = new File(TextUtils.isEmpty(newFilePath) ? newPath : newFilePath);
} else {
result = new File(newPath);
}
}
}
}
return result;
}

@Override
public boolean handleMessage(Message msg) {
public boolean handleMessage(@NotNull Message msg) {
if (mCompressListener == null) return false;

switch (msg.what) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;

import com.luck.picture.lib.config.PictureSelectionConfig;

import java.io.File;
import java.io.OutputStream;
import java.util.Objects;
Expand Down Expand Up @@ -54,7 +50,7 @@ public static String copyPathToAndroidQ(Context ctx, String url, int width, int
PictureFileUtils.close(inBuffer);
}
}
return null;
return "";
}

/**
Expand Down

0 comments on commit 8717879

Please sign in to comment.