|
|
|
@ -1,19 +1,27 @@
|
|
|
|
|
package com.xypower.mpapp;
|
|
|
|
|
|
|
|
|
|
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Base64;
|
|
|
|
|
|
|
|
|
|
import com.xypower.common.FileUtils;
|
|
|
|
|
import com.xypower.common.JSONUtils;
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
import com.xypower.mpapp.v2.Camera2VideoActivity;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
|
|
public class BridgeActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
@ -92,14 +100,58 @@ public class BridgeActivity extends AppCompatActivity {
|
|
|
|
|
String path = intent.getStringExtra("path");
|
|
|
|
|
int channel = intent.getIntExtra("channel", 1);
|
|
|
|
|
int preset = intent.getIntExtra("preset", 0xFF);
|
|
|
|
|
boolean usb = intent.getBooleanExtra("usb", false);
|
|
|
|
|
int cameraId = intent.getIntExtra("cameraId", -1);
|
|
|
|
|
|
|
|
|
|
int width = intent.getIntExtra("width", 0);
|
|
|
|
|
int height = intent.getIntExtra("height", 0);
|
|
|
|
|
|
|
|
|
|
String leftTopOsd = intent.getStringExtra("leftTopOsd");
|
|
|
|
|
String rightTopOsd = intent.getStringExtra("rightTopOsd");
|
|
|
|
|
String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
|
|
|
|
|
String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
|
|
|
|
|
|
|
|
|
|
String appPath = MicroPhotoContext.buildMpAppDir(getApplicationContext());
|
|
|
|
|
File configFile = new File(appPath);
|
|
|
|
|
configFile = new File(configFile, "data/channels/" + Integer.toString(channel) + ".json");
|
|
|
|
|
|
|
|
|
|
File tmpConfigFile = new File(appPath);
|
|
|
|
|
tmpConfigFile = new File(tmpConfigFile, "tmp/" + Integer.toString(channel) + "-" + Long.toString(System.currentTimeMillis()) + ".json");
|
|
|
|
|
|
|
|
|
|
if (configFile.exists()) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
FileUtils.copyFile(configFile, tmpConfigFile);
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject configJson = JSONUtils.loadJson(tmpConfigFile.getAbsolutePath());
|
|
|
|
|
try {
|
|
|
|
|
if (configJson == null) {
|
|
|
|
|
configJson = new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
if (width > 0) {
|
|
|
|
|
configJson.put("resolutionCX", width);
|
|
|
|
|
}
|
|
|
|
|
if (height > 0) {
|
|
|
|
|
configJson.put("resolutionCY", height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject osdJson = configJson.getJSONObject("osd");
|
|
|
|
|
if (osdJson == null) {
|
|
|
|
|
osdJson = configJson.put("osd", new JSONObject());
|
|
|
|
|
}
|
|
|
|
|
osdJson.put("leftTop", TextUtils.isEmpty(leftTopOsd) ? "" : leftTopOsd);
|
|
|
|
|
osdJson.put("rightTop", TextUtils.isEmpty(rightTopOsd) ? "" : rightTopOsd);
|
|
|
|
|
osdJson.put("rightBottom", TextUtils.isEmpty(rightBottomOsd) ? "" : rightBottomOsd);
|
|
|
|
|
osdJson.put("leftBottom", TextUtils.isEmpty(leftBottomOsd) ? "" : leftBottomOsd);
|
|
|
|
|
|
|
|
|
|
JSONUtils.saveJson(tmpConfigFile.getAbsolutePath(), configJson);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.delete();
|
|
|
|
@ -107,7 +159,10 @@ public class BridgeActivity extends AppCompatActivity {
|
|
|
|
|
FileUtils.ensureParentDirectoryExisted(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MicroPhotoService.takePhoto(channel, preset, cameraId, usb, path, leftTopOsd, rightTopOsd, rightBottomOsd, leftBottomOsd);
|
|
|
|
|
MicroPhotoService.takePhoto(channel, preset, true, tmpConfigFile.getAbsolutePath(), path);
|
|
|
|
|
if (tmpConfigFile.exists()) {
|
|
|
|
|
tmpConfigFile.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(action, ACTION_RECORDING)) {
|
|
|
|
|
String path = intent.getStringExtra("path");
|
|
|
|
|