From 1b8bc084c476e131b3fa9f9fb573bccf3e56f952 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 4 Jul 2024 23:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 20 +- .../com/xypower/mpapp/BridgeActivity.java | 8 +- .../java/com/xypower/mpapp/BridgeService.java | 236 ++++++++++++++++++ 3 files changed, 249 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/xypower/mpapp/BridgeService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ca222124..5355f78d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,7 +54,7 @@ - + @@ -74,6 +74,7 @@ + + @@ -94,17 +98,11 @@ - + android:screenOrientation="landscape" /> - + android:screenOrientation="landscape" /> 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(); + } else { + FileUtils.ensureParentDirectoryExisted(path); + } + + 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"); + int channel = intent.getIntExtra("channel", 1); + int cameraId = intent.getIntExtra("cameraId", -1); + int quality = intent.getIntExtra("quality", 0); + int width = intent.getIntExtra("width", 1280); + int height = intent.getIntExtra("height", 720); + int duration = intent.getIntExtra("duration", 15); + int orientation = intent.getIntExtra("orientation", 0); + long videoId = System.currentTimeMillis() / 1000; + + String leftTopOsd = intent.getStringExtra("leftTopOsd"); + String rightTopOsd = intent.getStringExtra("rightTopOsd"); + String rightBottomOsd = intent.getStringExtra("rightBottomOsd"); + String leftBottomOsd = intent.getStringExtra("leftBottomOsd"); + + if (cameraId == -1) { + cameraId = channel - 1; + } + + Intent recordingIntent = MicroPhotoService.makeRecordingIntent(getApplicationContext(), + cameraId, videoId, duration, width, height, quality, orientation, + leftTopOsd, rightTopOsd, rightBottomOsd, leftBottomOsd); + + mVideoFilePath = path; + mAutoClose = false; + + recordingIntent.putExtra("ActivityResult", true); + // startActivityForResult(recordingIntent, REQUEST_CODE_RECORDING); + } + } + + if (mAutoClose) { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + Log.i(TAG, "BridgeActivity will finish automatically"); + stopSelf(); + } + }, 200); + } + + return super.onStartCommand(intent, flags, startId); + } + + /** + * 服务销毁时的回调 + */ + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + +} \ No newline at end of file