From 81d46306ee6522f84363be5f2a55f15ac220268b Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 10 Jul 2024 16:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=E9=80=9A=E9=81=932?= =?UTF-8?q?=E4=B8=BB=E5=8A=A8=E6=8B=8D=E4=B8=80=E5=BC=A0=E7=85=A7=E7=89=87?= =?UTF-8?q?=E5=B9=B6=E6=8A=9B=E5=BC=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/mpapp/MainActivity.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java index d34dec90..e3c05688 100644 --- a/app/src/main/java/com/xypower/mpapp/MainActivity.java +++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java @@ -38,11 +38,15 @@ import android.widget.Toast; import com.dev.devapi.api.SysApi; import com.xypower.common.CameraUtils; +import com.xypower.common.FilesUtils; +import com.xypower.common.JSONUtils; import com.xypower.common.MicroPhotoContext; import com.xypower.mpapp.databinding.ActivityMainBinding; import com.xypower.mpapp.utils.RandomReader; +import org.json.JSONObject; + import java.io.File; import java.lang.reflect.Method; import java.text.SimpleDateFormat; @@ -245,6 +249,13 @@ public class MainActivity extends AppCompatActivity { binding.logs.setText(""); MicroPhotoContext.AppConfig curAppConfig = retrieveAndSaveAppConfig(); + TakeAndThrowPhoto(2, 0xFF); + try { + Thread.sleep(20); + } catch (Exception ex) { + ex.printStackTrace(); + } + startMicroPhotoService(MainActivity.this.getApplicationContext(), appConfig, mMessenger); binding.btnStartServ.setEnabled(false); @@ -602,6 +613,26 @@ public class MainActivity extends AppCompatActivity { } } + protected void TakeAndThrowPhoto(int channel, int preset) { + String appPath = MicroPhotoContext.buildMpAppDir(getApplicationContext()); + File configFile = new File(appPath); + configFile = new File(configFile, "data/channels/" + Integer.toString(channel) + ".json"); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + Date dt = new Date(); + + File tmpPath = new File(appPath, "tmp"); + if (!tmpPath.exists()) { + tmpPath.mkdirs(); + } + File photoFile = new File(tmpPath, "IMG-" + Integer.toString(channel) + "-" + sdf.format(dt) + ".jpg"); + if (photoFile.exists()) { + photoFile.delete(); + } + + MicroPhotoService.takePhoto(channel, preset, true, configFile.getAbsolutePath(), photoFile.getAbsolutePath()); + } + @Override protected void onResume() { // call the superclass method first