From 91ebf6e29118f85e94603d4fb91131c87d60ae1f Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Mon, 29 Nov 2021 13:55:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=BF=9E=E6=8B=8D?= =?UTF-8?q?=E9=97=B4=E9=9A=941=E7=A7=92=E6=97=B6=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=99=BD=E5=B1=8F=E7=85=A7=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=A8=E5=B1=80=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=E5=A4=84=E7=90=86jpg=E8=BD=ACwebp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outdoor/activity/PicturesActivity.java | 93 ++++++++++++------- 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java index 26d0b1f..67a2f0a 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java @@ -87,6 +87,8 @@ import java.util.List; import java.util.Objects; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE; import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER; @@ -306,42 +308,12 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen } File file = new File(finalVideoPath); initMarkerPaper(); - Runnable runnable = new Runnable() { + result.toFile(file, new FileCallback() { @Override - public void run() { - result.toFile(file, new FileCallback() { - @Override - public void onFileReady(@Nullable File file) { - if (file!=null&&file.exists()){ - WebPNative webPNative = new WebPNative(); - Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); - webPNative.encodeRGBA(bitmap, file.getPath(), 90); - runOnUiThread(new Runnable() { - @SuppressLint("SetTextI18n") - @Override - public void run() { - if (file.exists()) { - initMarker(); - videoIndex = Integer.parseInt(file.getName().replace(".webp", "")); - finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp"; - tvTitle.setText("保存成功:" + (videoIndex + 1)); - } - if (radioPicture == 1) { - Message message = new Message(); - message.what = 0x103; - handler.sendMessage(message); - } - } - }); - if (!bitmap.isRecycled()) { - bitmap.recycle(); - } - } - } - }); + public void onFileReady(@Nullable File file) { + UserApplication.fixedThreadPool.execute(new Jpg2WebpRunnable(result, file)); } - }; - UserApplication.fixedThreadPool.submit(runnable); + }); } else { isBack = false; if (isOration) { @@ -362,6 +334,59 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen tvMapView.setLayoutParams(layoutParamsMap); } + class Jpg2WebpRunnable implements Runnable { + private PictureResult pictureResult; + private File file; + + public Jpg2WebpRunnable(PictureResult pictureResult,File file) { + this.pictureResult = pictureResult; + this.file = file; + } + + @Override + public void run() { + if (file.exists() && file != null) { + WebPNative webPNative = new WebPNative(); + Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); + webPNative.encodeRGBA(bitmap, file.getPath(), 90); + if (!bitmap.isRecycled()) { + bitmap.recycle(); + } + runOnUiThread(new Runnable() { + @Override + public void run() { + if (file.exists()) { + initMarker(); + videoIndex = Integer.parseInt(file.getName().replace(".webp", "")); + finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp"; + tvTitle.setText("保存成功:" + (videoIndex + 1)); + } + if (radioPicture == 1) { + Message message = new Message(); + message.what = 0x103; + handler.sendMessage(message); + } + } + }); + } else { + isBack = false; + if (isOration) { + stopTimer(); + } + if (radioPicture != 1) { + capturePicture.setText("开始采集"); + } + capturePicture.setChecked(false); + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(PicturesActivity.this, "源文件不存在", Toast.LENGTH_SHORT).show(); + } + }); + } + } + } + private void initLine() { if (geoWkt != null) { String geo = Geohash.getInstance().decode(geoWkt);