!23 fix: 修改拍照数量过多时,数据保存过慢的问题
Merge pull request !23 from 肖岩/founchBranch
This commit is contained in:
commit
1b47add5bf
@ -80,6 +80,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -125,7 +126,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
private int radioPicture = 0;
|
private int radioPicture = 0;
|
||||||
private int videoIndex = -1;
|
private int videoIndex = -1;
|
||||||
private int startVideoIndex = -1;
|
private int startVideoIndex = -1;
|
||||||
private int webp=1;
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
private SimpleDateFormat formatter;
|
private SimpleDateFormat formatter;
|
||||||
private Handler handler = new Handler(new Handler.Callback() {
|
private Handler handler = new Handler(new Handler.Callback() {
|
||||||
@ -327,7 +327,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
result.toFile(file, new FileCallback() {
|
result.toFile(file, new FileCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onFileReady(@Nullable File file) {
|
public void onFileReady(@Nullable File file) {
|
||||||
UserApplication.fixedThreadPool.execute(new Jpg2WebpRunnable(result, file));
|
UserApplication.fixedThreadPool.execute(new Jpg2WebpRunnable(/*result, */file, 0));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -348,41 +348,56 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
layoutParamsMap.height = dm.widthPixels / 3;
|
layoutParamsMap.height = dm.widthPixels / 3;
|
||||||
layoutParamsMap.width = dm.heightPixels / 3;
|
layoutParamsMap.width = dm.heightPixels / 3;
|
||||||
tvMapView.setLayoutParams(layoutParamsMap);
|
tvMapView.setLayoutParams(layoutParamsMap);
|
||||||
|
timerTask = new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (radioPicture == 1) {
|
||||||
|
camera.takePicture();
|
||||||
|
} else {
|
||||||
|
Message message = new Message();
|
||||||
|
message.what = 0x101;
|
||||||
|
handler.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Jpg2WebpRunnable implements Runnable {
|
class Jpg2WebpRunnable implements Runnable {
|
||||||
private PictureResult pictureResult;
|
// private PictureResult pictureResult;
|
||||||
private File file;
|
private File file;
|
||||||
|
private int count; // 该转换执行次数,如果连续3次执行失败,则不再转换
|
||||||
|
|
||||||
public Jpg2WebpRunnable(PictureResult pictureResult, File file) {
|
public Jpg2WebpRunnable(/*PictureResult pictureResult, */File file, int count) {
|
||||||
this.pictureResult = pictureResult;
|
// this.pictureResult = pictureResult;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (file.exists() && file != null) {
|
if (file.exists() && file != null) {
|
||||||
initWeb(file);
|
initWeb(file, count);
|
||||||
runOnUiThread(new Runnable() {
|
if (count<=0) { // 不是重新转换webp流程
|
||||||
@SuppressLint("SetTextI18n")
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@SuppressLint("SetTextI18n")
|
||||||
public void run() {
|
@Override
|
||||||
if (PicturesActivity.this != null) {
|
public void run() {
|
||||||
if (file.exists()) {
|
if (PicturesActivity.this != null) {
|
||||||
initMarkerPaper();
|
if (file.exists()) {
|
||||||
initMarker();
|
initMarker();
|
||||||
videoIndex = Integer.parseInt(file.getName().replace(".webp", ""));
|
videoIndex = Integer.parseInt(file.getName().replace(".webp", ""));
|
||||||
finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp";
|
finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp";
|
||||||
tvTitle.setText("保存成功:" + (videoIndex + 1));
|
tvTitle.setText("保存成功:" + (videoIndex + 1));
|
||||||
}
|
}
|
||||||
if (radioPicture == 1 && handler != null) {
|
if (radioPicture == 1 && handler != null) {
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
message.what = 0x103;
|
message.what = 0x103;
|
||||||
handler.sendMessage(message);
|
handler.sendMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
isBack = false;
|
isBack = false;
|
||||||
if (isOration) {
|
if (isOration) {
|
||||||
@ -402,28 +417,26 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWeb(File file) {
|
private void initWeb(File file, int count) {
|
||||||
if (webp==3){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
count++;
|
||||||
WebPNative webPNative = new WebPNative();
|
WebPNative webPNative = new WebPNative();
|
||||||
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||||
webPNative.encodeRGBA(bitmap, file.getPath(), 90);
|
webPNative.encodeRGBA(bitmap, file.getPath(), 90);
|
||||||
if (!bitmap.isRecycled()) {
|
if (!bitmap.isRecycled()) {
|
||||||
bitmap.recycle();
|
bitmap.recycle();
|
||||||
}
|
}
|
||||||
webp=1;
|
initMarkerPaper();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// 如果是写入txt记录失败,上传失败记录
|
||||||
|
UMCrashManager.reportCrash(this,e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
UMCrashManager.reportCrash(this,e);
|
UMCrashManager.reportCrash(this,e);
|
||||||
handler.postDelayed(new Runnable() {
|
if (count<3) { // 当尝试次数小于3次,则加入转换队列,尝试重新转换
|
||||||
@Override
|
UserApplication.fixedThreadPool.execute(new Jpg2WebpRunnable(/*result, */file, count));
|
||||||
public void run() {
|
}
|
||||||
webp++;
|
|
||||||
initWeb(file);
|
|
||||||
}
|
|
||||||
}, 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,12 +816,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
UMCrash.generateCustomLog(e, "自定义");
|
UMCrash.generateCustomLog(e, "自定义");
|
||||||
handler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
initMarkerPaper();
|
|
||||||
}
|
|
||||||
}, 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,18 +931,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
|||||||
if (timer == null) {
|
if (timer == null) {
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
}
|
}
|
||||||
timerTask = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (radioPicture == 1) {
|
|
||||||
camera.takePicture();
|
|
||||||
} else {
|
|
||||||
Message message = new Message();
|
|
||||||
message.what = 0x101;
|
|
||||||
handler.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (radioPicture == 1) {
|
if (radioPicture == 1) {
|
||||||
timer.schedule(timerTask, 0);
|
timer.schedule(timerTask, 0);
|
||||||
} else if (radioPicture == 2) {
|
} else if (radioPicture == 2) {
|
||||||
|
@ -47,7 +47,7 @@ public class UserApplication extends Application {
|
|||||||
initOkGo();
|
initOkGo();
|
||||||
TalentLocationUtils.getInstance(this).startLocation(this);
|
TalentLocationUtils.getInstance(this).startLocation(this);
|
||||||
//创建一个线程池
|
//创建一个线程池
|
||||||
fixedThreadPool = Executors.newFixedThreadPool(5);
|
fixedThreadPool = Executors.newSingleThreadExecutor(); // 使用单线程线程池
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserApplication getUserApplication() {
|
public static UserApplication getUserApplication() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user