Compare commits
52 Commits
9eb8d1cc37
...
linfeng/de
| Author | SHA1 | Date | |
|---|---|---|---|
| 8570486798 | |||
| 208920dfea | |||
| 88d8dfda04 | |||
| d39d85cd99 | |||
| c01ce1dca0 | |||
| 25ac9c4c35 | |||
| a3a02e623f | |||
| 7a654d54f0 | |||
| de2aacca90 | |||
| cf1c2d7d0e | |||
| 13cb3bfd7b | |||
| bcd2162cd7 | |||
| 41fcd730f0 | |||
| 7ab03dd912 | |||
| 29cfbdf8c4 | |||
| 7031765b4d | |||
| 942d15e54c | |||
| 6b168ccd62 | |||
| 551d10dec4 | |||
| e1446337e9 | |||
| 26098114d2 | |||
| 1e08b70c39 | |||
| e821bd68a7 | |||
| 9c21915bf7 | |||
| 1221b16c7f | |||
| 54738d53f9 | |||
| 4d83f38960 | |||
| 36da37c6c0 | |||
| 0183bd9a6d | |||
| 016aad49b7 | |||
| a39fcdb929 | |||
| 0a2cfe27ac | |||
| d598b36449 | |||
| c0aa2db6db | |||
| 0d06975313 | |||
| f6440ea8b7 | |||
| 1e936bfc12 | |||
| 4c5bf22638 | |||
| e387dfad0a | |||
| 846c6a8edb | |||
| f49d208042 | |||
| 124b4c1882 | |||
| 7c342c4477 | |||
| dfbdbbdb66 | |||
| 1b404525d2 | |||
| 77d9c35592 | |||
| 5ddcb95358 | |||
| 02c1c87b46 | |||
| 66435302b3 | |||
| 250f21a2b8 | |||
| 8f9f3a9779 | |||
| fb61e28e2f |
7
.gitignore
vendored
@@ -11,12 +11,15 @@
|
|||||||
.svn/
|
.svn/
|
||||||
.swiftpm/
|
.swiftpm/
|
||||||
migrate_working_dir/
|
migrate_working_dir/
|
||||||
|
.vscode
|
||||||
|
pubspec.lock
|
||||||
# IntelliJ related
|
# IntelliJ related
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
.idea/
|
.idea/
|
||||||
|
.cursor
|
||||||
|
Podfile.lock
|
||||||
|
|
||||||
# The .vscode folder contains launch configuration and tasks you configure in
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
# VS Code which you may wish to be included in version control, so this line
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
@@ -43,3 +46,5 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
/android/.kotlin
|
||||||
|
|
||||||
|
|||||||
34
README.en.md
@@ -13,22 +13,22 @@ A production-ready Flutter quick-start template extracted from real-world projec
|
|||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
| Category | Package | Purpose |
|
| Category | Package | Purpose |
|
||||||
|---|---|---|
|
| ----------------- | -------------------- | --------------------------------------- |
|
||||||
| State Management | flutter_riverpod | Compile-safe, testable state management |
|
| State Management | flutter_riverpod | Compile-safe, testable state management |
|
||||||
| Networking | dio | HTTP client with interceptor chain |
|
| Networking | dio | HTTP client with interceptor chain |
|
||||||
| Local Cache | shared_preferences | Key-value persistence |
|
| Local Cache | shared_preferences | Key-value persistence |
|
||||||
| Network Monitor | connectivity_plus | Real-time connectivity tracking |
|
| Network Monitor | connectivity_plus | Real-time connectivity tracking |
|
||||||
| Permissions | permission_handler | Runtime permission requests |
|
| Permissions | permission_handler | Runtime permission requests |
|
||||||
| Screen Adaptation | flutter_screenutil | Design-dimension-based layout |
|
| Screen Adaptation | flutter_screenutil | Design-dimension-based layout |
|
||||||
| Image Loading | cached_network_image | Network image caching |
|
| Image Loading | cached_network_image | Network image caching |
|
||||||
| SVG | flutter_svg | SVG rendering |
|
| SVG | flutter_svg | SVG rendering |
|
||||||
| Pull to Refresh | pull_to_refresh | Refresh and load-more |
|
| Pull to Refresh | pull_to_refresh | Refresh and load-more |
|
||||||
| Loading HUD | flutter_easyloading | Toast and loading indicator |
|
| Loading HUD | flutter_easyloading | Toast and loading indicator |
|
||||||
| Device Info | device_info_plus | Device metadata |
|
| Device Info | device_info_plus | Device metadata |
|
||||||
| Package Info | package_info_plus | App version info |
|
| Package Info | package_info_plus | App version info |
|
||||||
| URL Launcher | url_launcher | Open external URLs |
|
| URL Launcher | url_launcher | Open external URLs |
|
||||||
| Linting | flutter_lints | Recommended Dart lint rules |
|
| Linting | flutter_lints | Recommended Dart lint rules |
|
||||||
|
|
||||||
## Directory Structure
|
## Directory Structure
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ lib/
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd flutter-template
|
cd record-tool
|
||||||
flutter pub get
|
flutter pub get
|
||||||
flutter analyze
|
flutter analyze
|
||||||
flutter test
|
flutter test
|
||||||
|
|||||||
34
README.md
@@ -13,22 +13,22 @@
|
|||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
| 类别 | 依赖 | 用途 |
|
| 类别 | 依赖 | 用途 |
|
||||||
|---|---|---|
|
| -------- | -------------------- | -------------------------- |
|
||||||
| 状态管理 | flutter_riverpod | 编译安全、可测试的状态管理 |
|
| 状态管理 | flutter_riverpod | 编译安全、可测试的状态管理 |
|
||||||
| 网络请求 | dio | HTTP 客户端,支持拦截器链 |
|
| 网络请求 | dio | HTTP 客户端,支持拦截器链 |
|
||||||
| 本地缓存 | shared_preferences | KV 持久化存储 |
|
| 本地缓存 | shared_preferences | KV 持久化存储 |
|
||||||
| 网络监听 | connectivity_plus | 实时网络状态监测 |
|
| 网络监听 | connectivity_plus | 实时网络状态监测 |
|
||||||
| 权限申请 | permission_handler | 运行时权限请求 |
|
| 权限申请 | permission_handler | 运行时权限请求 |
|
||||||
| 屏幕适配 | flutter_screenutil | 设计稿尺寸适配 |
|
| 屏幕适配 | flutter_screenutil | 设计稿尺寸适配 |
|
||||||
| 图片加载 | cached_network_image | 网络图片缓存 |
|
| 图片加载 | cached_network_image | 网络图片缓存 |
|
||||||
| SVG | flutter_svg | SVG 渲染 |
|
| SVG | flutter_svg | SVG 渲染 |
|
||||||
| 下拉刷新 | pull_to_refresh | 下拉刷新 / 上拉加载 |
|
| 下拉刷新 | pull_to_refresh | 下拉刷新 / 上拉加载 |
|
||||||
| 加载提示 | flutter_easyloading | Toast 和 loading |
|
| 加载提示 | flutter_easyloading | Toast 和 loading |
|
||||||
| 设备信息 | device_info_plus | 设备元数据 |
|
| 设备信息 | device_info_plus | 设备元数据 |
|
||||||
| 应用信息 | package_info_plus | 版本号等应用信息 |
|
| 应用信息 | package_info_plus | 版本号等应用信息 |
|
||||||
| 链接跳转 | url_launcher | 外部 URL 打开 |
|
| 链接跳转 | url_launcher | 外部 URL 打开 |
|
||||||
| 代码规范 | flutter_lints | Dart 推荐 lint 规则 |
|
| 代码规范 | flutter_lints | Dart 推荐 lint 规则 |
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ lib/
|
|||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd flutter-template
|
cd record-tool
|
||||||
flutter pub get
|
flutter pub get
|
||||||
flutter analyze
|
flutter analyze
|
||||||
flutter test
|
flutter test
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
id("kotlin-android")
|
// The Flutter Gradle Plugin must be applied after the Android Gradle plugin.
|
||||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
|
||||||
id("dev.flutter.flutter-gradle-plugin")
|
id("dev.flutter.flutter-gradle-plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val appPackageName = "com.dronex.rec"
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.example.flutter_template"
|
namespace = appPackageName
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
ndkVersion = flutter.ndkVersion
|
ndkVersion = flutter.ndkVersion
|
||||||
|
|
||||||
@@ -15,13 +16,8 @@ android {
|
|||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
applicationId = appPackageName
|
||||||
applicationId = "com.example.flutter_template"
|
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
@@ -39,6 +35,23 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
val cameraxVersion = "1.4.1"
|
||||||
|
implementation("androidx.camera:camera-core:$cameraxVersion")
|
||||||
|
implementation("androidx.camera:camera-camera2:$cameraxVersion")
|
||||||
|
implementation("androidx.camera:camera-lifecycle:$cameraxVersion")
|
||||||
|
implementation("androidx.camera:camera-video:$cameraxVersion")
|
||||||
|
implementation("androidx.camera:camera-view:$cameraxVersion")
|
||||||
|
implementation("androidx.lifecycle:lifecycle-service:2.8.7")
|
||||||
|
implementation("androidx.core:core-ktx:1.15.0")
|
||||||
|
}
|
||||||
|
|
||||||
flutter {
|
flutter {
|
||||||
source = "../.."
|
source = "../.."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
|
||||||
the Flutter tool needs it to communicate with the running application
|
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
|
||||||
-->
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,6 +1,26 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.dronex.rec">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
android:maxSdkVersion="28" />
|
||||||
|
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.camera"
|
||||||
|
android:required="true" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="flutter_template"
|
android:label="飞行极控录像工作台"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
@@ -12,34 +32,29 @@
|
|||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
|
||||||
the Android process has started. This theme is visible to the user
|
|
||||||
while the Flutter UI initializes. After that, this theme continues
|
|
||||||
to determine the Window background behind the Flutter UI. -->
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="io.flutter.embedding.android.NormalTheme"
|
android:name="io.flutter.embedding.android.NormalTheme"
|
||||||
android:resource="@style/NormalTheme"
|
android:resource="@style/NormalTheme"
|
||||||
/>
|
/>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<!-- Don't delete the meta-data below.
|
|
||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
<service
|
||||||
|
android:name=".recording.RecordingForegroundService"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="camera|microphone" />
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
</application>
|
</application>
|
||||||
<!-- Required to query activities that can process text, see:
|
|
||||||
https://developer.android.com/training/package-visibility and
|
|
||||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
|
||||||
|
|
||||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
<action android:name="android.intent.action.PROCESS_TEXT" />
|
||||||
<data android:mimeType="text/plain"/>
|
<data android:mimeType="text/plain" />
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
</manifest>
|
</manifest>
|
||||||
10
android/app/src/main/kotlin/com/dronex/rec/AppConstants.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.dronex.rec
|
||||||
|
|
||||||
|
object AppConstants {
|
||||||
|
const val PACKAGE_NAME = "com.dronex.rec"
|
||||||
|
const val PLATFORM_INFO_CHANNEL = "$PACKAGE_NAME/platform_info"
|
||||||
|
const val RECORDING_METHOD_CHANNEL = "$PACKAGE_NAME/recording"
|
||||||
|
const val RECORDING_EVENT_CHANNEL = "$PACKAGE_NAME/recording_events"
|
||||||
|
const val RECORDING_ACTION_START = "$PACKAGE_NAME.recording.START"
|
||||||
|
const val RECORDING_ACTION_STOP = "$PACKAGE_NAME.recording.STOP"
|
||||||
|
}
|
||||||
146
android/app/src/main/kotlin/com/dronex/rec/MainActivity.kt
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package com.dronex.rec
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.os.BatteryManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Environment
|
||||||
|
import android.os.StatFs
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import com.dronex.rec.recording.RecordingPlatformHandler
|
||||||
|
import com.dronex.rec.recording.RecordingPreviewFactory
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
|
class MainActivity : FlutterActivity() {
|
||||||
|
private var platformHandler: RecordingPlatformHandler? = null
|
||||||
|
private var platformInfoChannel: MethodChannel? = null
|
||||||
|
|
||||||
|
var recordingPreviewView: PreviewView? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
super.configureFlutterEngine(flutterEngine)
|
||||||
|
flutterEngine.platformViewsController.registry.registerViewFactory(
|
||||||
|
"recording-camera-preview",
|
||||||
|
RecordingPreviewFactory(this),
|
||||||
|
)
|
||||||
|
|
||||||
|
platformInfoChannel =
|
||||||
|
MethodChannel(
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
AppConstants.PLATFORM_INFO_CHANNEL,
|
||||||
|
)
|
||||||
|
.also { channel ->
|
||||||
|
channel.setMethodCallHandler { call, result ->
|
||||||
|
when (call.method) {
|
||||||
|
"packageInfo" -> result.success(packageInfoMap())
|
||||||
|
"deviceInfo" -> result.success(deviceInfoMap())
|
||||||
|
"deviceHealth" -> result.success(deviceHealthMap())
|
||||||
|
else -> result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
platformHandler =
|
||||||
|
RecordingPlatformHandler(
|
||||||
|
this,
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attachRecordingPreview(previewView: PreviewView) {
|
||||||
|
recordingPreviewView = previewView
|
||||||
|
}
|
||||||
|
|
||||||
|
fun detachRecordingPreview(previewView: PreviewView? = null) {
|
||||||
|
if (previewView == null || recordingPreviewView === previewView) {
|
||||||
|
recordingPreviewView = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
platformInfoChannel?.setMethodCallHandler(null)
|
||||||
|
platformInfoChannel = null
|
||||||
|
platformHandler?.dispose()
|
||||||
|
platformHandler = null
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun packageInfoMap(): Map<String, String> {
|
||||||
|
val packageInfo =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
packageManager.getPackageInfo(
|
||||||
|
packageName,
|
||||||
|
android.content.pm.PackageManager.PackageInfoFlags.of(0),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION") packageManager.getPackageInfo(packageName, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
val appName = applicationInfo.loadLabel(packageManager)?.toString().orEmpty()
|
||||||
|
val versionCode =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
packageInfo.longVersionCode.toString()
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION") packageInfo.versionCode.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapOf(
|
||||||
|
"appName" to appName,
|
||||||
|
"packageName" to packageName,
|
||||||
|
"version" to packageInfo.versionName.orEmpty(),
|
||||||
|
"buildNumber" to versionCode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deviceInfoMap(): Map<String, Any> {
|
||||||
|
val flags = applicationInfo.flags
|
||||||
|
val isEmulator =
|
||||||
|
Build.FINGERPRINT.startsWith("generic") ||
|
||||||
|
Build.FINGERPRINT.startsWith("unknown") ||
|
||||||
|
Build.MODEL.contains("google_sdk") ||
|
||||||
|
Build.MODEL.contains("Emulator") ||
|
||||||
|
Build.MODEL.contains("Android SDK built for x86") ||
|
||||||
|
Build.MANUFACTURER.contains("Genymotion") ||
|
||||||
|
Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic") ||
|
||||||
|
Build.PRODUCT == "google_sdk" ||
|
||||||
|
flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 &&
|
||||||
|
Build.HARDWARE.contains("ranchu")
|
||||||
|
|
||||||
|
return mapOf(
|
||||||
|
"platform" to "android",
|
||||||
|
"brand" to Build.BRAND,
|
||||||
|
"model" to Build.MODEL,
|
||||||
|
"systemVersion" to Build.VERSION.RELEASE,
|
||||||
|
"sdkInt" to Build.VERSION.SDK_INT,
|
||||||
|
"isPhysicalDevice" to !isEmulator,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deviceHealthMap(): Map<String, Any?> {
|
||||||
|
val batteryLevelPercent = readBatteryLevelPercent()
|
||||||
|
val storageAvailablePercent = readStorageAvailablePercent()
|
||||||
|
return mapOf(
|
||||||
|
"batteryLevelPercent" to batteryLevelPercent,
|
||||||
|
"storageAvailablePercent" to storageAvailablePercent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readBatteryLevelPercent(): Int? {
|
||||||
|
val batteryManager = getSystemService(Context.BATTERY_SERVICE) as? BatteryManager
|
||||||
|
?: return null
|
||||||
|
val level =
|
||||||
|
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
|
return if (level in 0..100) level else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readStorageAvailablePercent(): Double {
|
||||||
|
val stat = StatFs(Environment.getDataDirectory().path)
|
||||||
|
val totalBytes = stat.totalBytes
|
||||||
|
if (totalBytes <= 0L) return 100.0
|
||||||
|
val availableBytes = stat.availableBytes
|
||||||
|
return availableBytes.toDouble() / totalBytes.toDouble() * 100.0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.provider.Settings
|
||||||
|
|
||||||
|
object BatteryOptimizationHelper {
|
||||||
|
fun isIgnoringOptimizations(context: Context): Boolean {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true
|
||||||
|
val manager = context.getSystemService(PowerManager::class.java) ?: return true
|
||||||
|
return manager.isIgnoringBatteryOptimizations(context.packageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openSettings(context: Context) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
|
||||||
|
|
||||||
|
val intent =
|
||||||
|
Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||||
|
data = Uri.parse("package:${context.packageName}")
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intent.resolveActivity(context.packageManager) != null) {
|
||||||
|
context.startActivity(intent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val fallback =
|
||||||
|
Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).apply {
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
}
|
||||||
|
context.startActivity(fallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
|
|
||||||
|
object DoNotDisturbHelper {
|
||||||
|
private var savedInterruptionFilter: Int? = null
|
||||||
|
|
||||||
|
fun hasAccess(context: Context): Boolean {
|
||||||
|
val manager = context.getSystemService(NotificationManager::class.java)
|
||||||
|
return manager?.isNotificationPolicyAccessGranted == true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openAccessSettings(context: Context) {
|
||||||
|
val intent =
|
||||||
|
Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS).apply {
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
}
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enable(context: Context): Boolean {
|
||||||
|
val manager = context.getSystemService(NotificationManager::class.java) ?: return false
|
||||||
|
if (!manager.isNotificationPolicyAccessGranted) return false
|
||||||
|
|
||||||
|
if (savedInterruptionFilter == null) {
|
||||||
|
savedInterruptionFilter = manager.currentInterruptionFilter
|
||||||
|
}
|
||||||
|
manager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disable(context: Context) {
|
||||||
|
val manager = context.getSystemService(NotificationManager::class.java) ?: return
|
||||||
|
if (!manager.isNotificationPolicyAccessGranted) return
|
||||||
|
|
||||||
|
val previous = savedInterruptionFilter ?: NotificationManager.INTERRUPTION_FILTER_ALL
|
||||||
|
manager.setInterruptionFilter(previous)
|
||||||
|
savedInterruptionFilter = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun areNotificationsEnabled(context: Context): Boolean {
|
||||||
|
return NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,588 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.hardware.camera2.CameraCharacteristics
|
||||||
|
import android.hardware.camera2.CameraManager
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.camera.camera2.interop.Camera2CameraInfo
|
||||||
|
import androidx.camera.core.Camera
|
||||||
|
import androidx.camera.core.CameraSelector
|
||||||
|
import androidx.camera.core.Preview
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
|
import androidx.camera.video.Quality
|
||||||
|
import androidx.camera.video.QualitySelector
|
||||||
|
import androidx.camera.video.Recorder
|
||||||
|
import androidx.camera.video.Recording
|
||||||
|
import androidx.camera.video.VideoCapture
|
||||||
|
import androidx.camera.video.VideoRecordEvent
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import kotlin.math.atan
|
||||||
|
import java.util.concurrent.Executor
|
||||||
|
|
||||||
|
class RecordingCameraController(
|
||||||
|
private val appContext: Context,
|
||||||
|
) {
|
||||||
|
private val mainExecutor: Executor = ContextCompat.getMainExecutor(appContext)
|
||||||
|
|
||||||
|
private var cameraProvider: ProcessCameraProvider? = null
|
||||||
|
private var preview: Preview? = null
|
||||||
|
private var videoCapture: VideoCapture<Recorder>? = null
|
||||||
|
private var camera: Camera? = null
|
||||||
|
private var mainCameraId: String? = null
|
||||||
|
private var ultraWideCameraId: String? = null
|
||||||
|
private var ultraWideZoomRatio: Float = DEFAULT_ULTRA_WIDE_ZOOM_RATIO
|
||||||
|
private var currentLensMode: LensMode = LensMode.MAIN
|
||||||
|
private var activeRecording: Recording? = null
|
||||||
|
private var boundLifecycleOwner: LifecycleOwner? = null
|
||||||
|
private var currentZoomRatio: Float = 1f
|
||||||
|
|
||||||
|
var status: RecordingStatus = RecordingStatus(RecordingState.IDLE)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var statusListener: ((RecordingStatus) -> Unit)? = null
|
||||||
|
|
||||||
|
private var recordingStartedAt: Long = 0L
|
||||||
|
private var latestOutputPath: String? = null
|
||||||
|
private var pendingStopCallback: ((String?) -> Unit)? = null
|
||||||
|
|
||||||
|
fun bindPreview(
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
previewView: PreviewView,
|
||||||
|
onReady: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val future = ProcessCameraProvider.getInstance(appContext)
|
||||||
|
future.addListener(
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
val provider = future.get()
|
||||||
|
cameraProvider = provider
|
||||||
|
boundLifecycleOwner = lifecycleOwner
|
||||||
|
|
||||||
|
preview =
|
||||||
|
Preview.Builder().build().also {
|
||||||
|
it.surfaceProvider = previewView.surfaceProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
val recorder =
|
||||||
|
Recorder.Builder()
|
||||||
|
.setQualitySelector(QualitySelector.from(Quality.HD))
|
||||||
|
.build()
|
||||||
|
videoCapture = VideoCapture.withOutput(recorder)
|
||||||
|
|
||||||
|
discoverBackCameras(provider)
|
||||||
|
bindUseCases(provider, lifecycleOwner, selectorForCurrentLensMode())
|
||||||
|
applyCurrentZoom()
|
||||||
|
|
||||||
|
updateStatus(RecordingStatus(RecordingState.PREVIEWING))
|
||||||
|
onReady(true)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "bindPreview failed", error)
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.ERROR,
|
||||||
|
message = error.message,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
onReady(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mainExecutor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebindForRecording(
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
previewView: PreviewView,
|
||||||
|
onReady: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val provider = cameraProvider
|
||||||
|
if (provider == null) {
|
||||||
|
bindPreview(lifecycleOwner, previewView, onReady)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
boundLifecycleOwner === lifecycleOwner &&
|
||||||
|
preview != null &&
|
||||||
|
videoCapture != null
|
||||||
|
) {
|
||||||
|
onReady(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
boundLifecycleOwner = lifecycleOwner
|
||||||
|
bindUseCases(provider, lifecycleOwner, selectorForCurrentLensMode())
|
||||||
|
applyCurrentZoom()
|
||||||
|
onReady(true)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "rebindForRecording failed", error)
|
||||||
|
onReady(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startRecording(
|
||||||
|
withAudio: Boolean,
|
||||||
|
displayName: String?,
|
||||||
|
onStarted: (Boolean, String?) -> Unit,
|
||||||
|
) {
|
||||||
|
val capture = videoCapture
|
||||||
|
if (capture == null || boundLifecycleOwner == null) {
|
||||||
|
onStarted(false, "Camera not ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeRecording != null) {
|
||||||
|
onStarted(false, "Already recording")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val outputOptions =
|
||||||
|
RecordingOutputFactory.buildMediaStoreOutputOptions(
|
||||||
|
appContext,
|
||||||
|
displayName,
|
||||||
|
)
|
||||||
|
latestOutputPath = null
|
||||||
|
|
||||||
|
val pending =
|
||||||
|
capture.output.prepareRecording(appContext, outputOptions).apply {
|
||||||
|
if (withAudio) {
|
||||||
|
val granted =
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
appContext,
|
||||||
|
android.Manifest.permission.RECORD_AUDIO,
|
||||||
|
) == android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||||
|
if (granted) {
|
||||||
|
withAudioEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recordingStartedAt = System.currentTimeMillis()
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.RECORDING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
activeRecording =
|
||||||
|
pending.start(mainExecutor) { event ->
|
||||||
|
when (event) {
|
||||||
|
is VideoRecordEvent.Start -> Unit
|
||||||
|
is VideoRecordEvent.Finalize -> {
|
||||||
|
activeRecording = null
|
||||||
|
if (event.hasError()) {
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.ERROR,
|
||||||
|
message = event.cause?.message
|
||||||
|
?: "Recording failed",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
latestOutputPath = event.outputResults.outputUri.toString()
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.PREVIEWING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
elapsedMillis =
|
||||||
|
System.currentTimeMillis() -
|
||||||
|
recordingStartedAt,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val stopCallback = pendingStopCallback
|
||||||
|
pendingStopCallback = null
|
||||||
|
stopCallback?.invoke(latestOutputPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onStarted(true, latestOutputPath ?: "recording")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopRecording(onStopped: (String?) -> Unit) {
|
||||||
|
val recording = activeRecording
|
||||||
|
if (recording == null) {
|
||||||
|
onStopped(latestOutputPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingStopCallback = onStopped
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.STOPPING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
recording.stop()
|
||||||
|
activeRecording = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun zoomCapabilitiesMap(): Map<String, Any> {
|
||||||
|
val zoomState = camera?.cameraInfo?.zoomState?.value
|
||||||
|
val logicalMin = zoomState?.minZoomRatio ?: 1f
|
||||||
|
// 兜底两路超广角来源:独立超广角镜头(0.6) 与 逻辑相机原生 <1.0 变焦范围,取更小者。
|
||||||
|
val minZoom =
|
||||||
|
if (hasUltraWideCamera()) {
|
||||||
|
minOf(ultraWideZoomRatio, logicalMin)
|
||||||
|
} else {
|
||||||
|
logicalMin
|
||||||
|
}
|
||||||
|
val maxZoom = zoomState?.maxZoomRatio ?: 3f
|
||||||
|
val zoom =
|
||||||
|
if (currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
ultraWideZoomRatio
|
||||||
|
} else {
|
||||||
|
(zoomState?.zoomRatio ?: currentZoomRatio).coerceIn(minZoom, maxZoom)
|
||||||
|
}
|
||||||
|
currentZoomRatio = zoom
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"zoomCapabilities hasUltraWide=${hasUltraWideCamera()} logicalMin=$logicalMin " +
|
||||||
|
"ultraWideZoomRatio=$ultraWideZoomRatio minZoom=$minZoom maxZoom=$maxZoom zoom=$zoom",
|
||||||
|
)
|
||||||
|
return mapOf(
|
||||||
|
"zoomRatio" to zoom.toDouble(),
|
||||||
|
"minZoomRatio" to minZoom.toDouble(),
|
||||||
|
"maxZoomRatio" to maxZoom.toDouble(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setZoomRatio(
|
||||||
|
ratio: Double,
|
||||||
|
onComplete: (Boolean, Map<String, Any>, String?) -> Unit,
|
||||||
|
) {
|
||||||
|
val boundCamera = camera
|
||||||
|
if (boundCamera == null) {
|
||||||
|
val clamped =
|
||||||
|
if (ratio < 1.0 && hasUltraWideCamera()) {
|
||||||
|
ultraWideZoomRatio
|
||||||
|
} else {
|
||||||
|
ratio.toFloat().coerceAtLeast(1f)
|
||||||
|
}
|
||||||
|
currentZoomRatio = clamped
|
||||||
|
onComplete(true, zoomCapabilitiesMap(), null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ratio < 1.0 && hasUltraWideCamera()) {
|
||||||
|
switchToUltraWide(onComplete)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
switchToMainAndZoom(ratio, onComplete)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val zoomState = boundCamera.cameraInfo.zoomState.value
|
||||||
|
val minZoom = zoomState?.minZoomRatio ?: 1f
|
||||||
|
val maxZoom = zoomState?.maxZoomRatio ?: clampedMaxZoom()
|
||||||
|
val nextZoom = ratio.toFloat().coerceIn(minZoom, maxZoom)
|
||||||
|
currentZoomRatio = nextZoom
|
||||||
|
|
||||||
|
val future = boundCamera.cameraControl.setZoomRatio(nextZoom)
|
||||||
|
future.addListener(
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
future.get()
|
||||||
|
onComplete(true, zoomCapabilitiesMap(), null)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "setZoomRatio failed", error)
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), error.message)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mainExecutor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbind() {
|
||||||
|
activeRecording?.stop()
|
||||||
|
activeRecording = null
|
||||||
|
cameraProvider?.unbindAll()
|
||||||
|
cameraProvider = null
|
||||||
|
preview = null
|
||||||
|
videoCapture = null
|
||||||
|
camera = null
|
||||||
|
boundLifecycleOwner = null
|
||||||
|
currentLensMode = LensMode.MAIN
|
||||||
|
currentZoomRatio = 1f
|
||||||
|
ultraWideZoomRatio = DEFAULT_ULTRA_WIDE_ZOOM_RATIO
|
||||||
|
updateStatus(RecordingStatus(RecordingState.IDLE))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun elapsedMillis(): Long {
|
||||||
|
if (status.state != RecordingState.RECORDING) return 0L
|
||||||
|
return System.currentTimeMillis() - recordingStartedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateStatus(next: RecordingStatus) {
|
||||||
|
status = next
|
||||||
|
statusListener?.invoke(next)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyCurrentZoom() {
|
||||||
|
val boundCamera = camera ?: return
|
||||||
|
if (currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
currentZoomRatio = ultraWideZoomRatio
|
||||||
|
boundCamera.cameraControl.setZoomRatio(1f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val zoomState = boundCamera.cameraInfo.zoomState.value
|
||||||
|
val minZoom = zoomState?.minZoomRatio ?: 1f
|
||||||
|
val maxZoom = zoomState?.maxZoomRatio ?: clampedMaxZoom()
|
||||||
|
currentZoomRatio = currentZoomRatio.coerceIn(minZoom, maxZoom)
|
||||||
|
boundCamera.cameraControl.setZoomRatio(currentZoomRatio)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clampedMaxZoom(): Float {
|
||||||
|
return camera?.cameraInfo?.zoomState?.value?.maxZoomRatio ?: 3f
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun discoverBackCameras(provider: ProcessCameraProvider) {
|
||||||
|
if (mainCameraId == null) {
|
||||||
|
mainCameraId = cameraIdForSelector(provider, CameraSelector.DEFAULT_BACK_CAMERA)
|
||||||
|
}
|
||||||
|
val ultraWideCamera = findUltraWideCamera(provider, mainCameraId)
|
||||||
|
ultraWideCameraId = ultraWideCamera?.cameraId
|
||||||
|
ultraWideZoomRatio = ultraWideCamera?.zoomRatio ?: DEFAULT_ULTRA_WIDE_ZOOM_RATIO
|
||||||
|
if (ultraWideCamera == null && currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
currentLensMode = LensMode.MAIN
|
||||||
|
currentZoomRatio = 1f
|
||||||
|
}
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"mainCameraId=$mainCameraId ultraWideCameraId=$ultraWideCameraId " +
|
||||||
|
"ultraWideZoomRatio=$ultraWideZoomRatio",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cameraIdForSelector(
|
||||||
|
provider: ProcessCameraProvider,
|
||||||
|
selector: CameraSelector,
|
||||||
|
): String? {
|
||||||
|
return try {
|
||||||
|
val infos = selector.filter(provider.availableCameraInfos)
|
||||||
|
infos.firstOrNull()?.let { Camera2CameraInfo.from(it).cameraId }
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.w(TAG, "cameraIdForSelector failed", error)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun findUltraWideCamera(
|
||||||
|
provider: ProcessCameraProvider,
|
||||||
|
excludedCameraId: String?,
|
||||||
|
): UltraWideCamera? {
|
||||||
|
val manager = appContext.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||||
|
val candidates =
|
||||||
|
manager.cameraIdList
|
||||||
|
.mapNotNull { cameraId -> backCameraProfile(manager, cameraId) }
|
||||||
|
.filter { it.cameraId != excludedCameraId }
|
||||||
|
.filter { provider.hasCameraSafely(selectorForCameraId(it.cameraId)) }
|
||||||
|
.sortedWith(
|
||||||
|
compareByDescending<CameraProfile> { it.horizontalFov }
|
||||||
|
.thenBy { it.minFocalLength },
|
||||||
|
)
|
||||||
|
|
||||||
|
val mainProfile = excludedCameraId?.let { backCameraProfile(manager, it) }
|
||||||
|
val widest = candidates.firstOrNull() ?: return null
|
||||||
|
val candidatesDesc =
|
||||||
|
candidates.joinToString { "id=${it.cameraId} fov=${it.horizontalFov} focal=${it.minFocalLength}" }
|
||||||
|
val mainDesc =
|
||||||
|
mainProfile?.let { "id=${it.cameraId} fov=${it.horizontalFov} focal=${it.minFocalLength}" }
|
||||||
|
Log.d(TAG, "ultraWide candidates=[$candidatesDesc] main=$mainDesc")
|
||||||
|
if (mainProfile == null) {
|
||||||
|
return UltraWideCamera(widest.cameraId, DEFAULT_ULTRA_WIDE_ZOOM_RATIO)
|
||||||
|
}
|
||||||
|
|
||||||
|
val meaningfullyWider =
|
||||||
|
widest.horizontalFov > mainProfile.horizontalFov * ULTRA_WIDE_FOV_FACTOR ||
|
||||||
|
widest.minFocalLength < mainProfile.minFocalLength * ULTRA_WIDE_FOCAL_FACTOR
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"ultraWide decision widest=${widest.cameraId} meaningfullyWider=$meaningfullyWider " +
|
||||||
|
"(fovFactor=$ULTRA_WIDE_FOV_FACTOR focalFactor=$ULTRA_WIDE_FOCAL_FACTOR)",
|
||||||
|
)
|
||||||
|
if (!meaningfullyWider) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return UltraWideCamera(widest.cameraId, DEFAULT_ULTRA_WIDE_ZOOM_RATIO)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun backCameraProfile(
|
||||||
|
manager: CameraManager,
|
||||||
|
cameraId: String,
|
||||||
|
): CameraProfile? {
|
||||||
|
return try {
|
||||||
|
val characteristics = manager.getCameraCharacteristics(cameraId)
|
||||||
|
val facing = characteristics.get(CameraCharacteristics.LENS_FACING)
|
||||||
|
if (facing != CameraCharacteristics.LENS_FACING_BACK) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val focalLengths =
|
||||||
|
characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)
|
||||||
|
?: return null
|
||||||
|
val physicalSize =
|
||||||
|
characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)
|
||||||
|
?: return null
|
||||||
|
val minFocalLength = focalLengths.minOrNull() ?: return null
|
||||||
|
val horizontalFov =
|
||||||
|
2.0 * atan((physicalSize.width / (2.0f * minFocalLength)).toDouble())
|
||||||
|
CameraProfile(cameraId, minFocalLength, horizontalFov)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.w(TAG, "backCameraProfile failed for cameraId=$cameraId", error)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectorForCurrentLensMode(): CameraSelector {
|
||||||
|
val cameraId =
|
||||||
|
if (currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
ultraWideCameraId
|
||||||
|
} else {
|
||||||
|
mainCameraId
|
||||||
|
}
|
||||||
|
return if (cameraId != null) {
|
||||||
|
selectorForCameraId(cameraId)
|
||||||
|
} else {
|
||||||
|
CameraSelector.DEFAULT_BACK_CAMERA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectorForCameraId(cameraId: String): CameraSelector {
|
||||||
|
return CameraSelector.Builder()
|
||||||
|
.addCameraFilter { cameraInfos ->
|
||||||
|
cameraInfos.filter { Camera2CameraInfo.from(it).cameraId == cameraId }
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindUseCases(
|
||||||
|
provider: ProcessCameraProvider,
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
selector: CameraSelector,
|
||||||
|
) {
|
||||||
|
val boundPreview = preview ?: throw IllegalStateException("Preview is not ready")
|
||||||
|
val boundVideoCapture =
|
||||||
|
videoCapture ?: throw IllegalStateException("Video capture is not ready")
|
||||||
|
provider.unbindAll()
|
||||||
|
camera =
|
||||||
|
provider.bindToLifecycle(
|
||||||
|
lifecycleOwner,
|
||||||
|
selector,
|
||||||
|
boundPreview,
|
||||||
|
boundVideoCapture,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun switchToUltraWide(
|
||||||
|
onComplete: (Boolean, Map<String, Any>, String?) -> Unit,
|
||||||
|
) {
|
||||||
|
val ultraWideId = ultraWideCameraId
|
||||||
|
if (ultraWideId == null) {
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), "Ultra-wide camera is unavailable")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (currentLensMode == LensMode.ULTRA_WIDE) {
|
||||||
|
currentZoomRatio = ultraWideZoomRatio
|
||||||
|
onComplete(true, zoomCapabilitiesMap(), null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (activeRecording != null) {
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), "Cannot switch physical camera while recording")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val provider = cameraProvider
|
||||||
|
val lifecycleOwner = boundLifecycleOwner
|
||||||
|
if (provider == null || lifecycleOwner == null) {
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), "Camera is not ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
currentLensMode = LensMode.ULTRA_WIDE
|
||||||
|
currentZoomRatio = ultraWideZoomRatio
|
||||||
|
bindUseCases(provider, lifecycleOwner, selectorForCameraId(ultraWideId))
|
||||||
|
applyCurrentZoom()
|
||||||
|
onComplete(true, zoomCapabilitiesMap(), null)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "switchToUltraWide failed", error)
|
||||||
|
currentLensMode = LensMode.MAIN
|
||||||
|
currentZoomRatio = 1f
|
||||||
|
try {
|
||||||
|
bindUseCases(provider, lifecycleOwner, selectorForCurrentLensMode())
|
||||||
|
applyCurrentZoom()
|
||||||
|
} catch (restoreError: Exception) {
|
||||||
|
Log.e(TAG, "restore main camera after ultra-wide failure failed", restoreError)
|
||||||
|
}
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun switchToMainAndZoom(
|
||||||
|
ratio: Double,
|
||||||
|
onComplete: (Boolean, Map<String, Any>, String?) -> Unit,
|
||||||
|
) {
|
||||||
|
if (activeRecording != null) {
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), "Cannot switch physical camera while recording")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val provider = cameraProvider
|
||||||
|
val lifecycleOwner = boundLifecycleOwner
|
||||||
|
if (provider == null || lifecycleOwner == null) {
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), "Camera is not ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
currentLensMode = LensMode.MAIN
|
||||||
|
currentZoomRatio = ratio.toFloat().coerceAtLeast(1f)
|
||||||
|
bindUseCases(provider, lifecycleOwner, selectorForCurrentLensMode())
|
||||||
|
setZoomRatio(ratio, onComplete)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "switchToMainAndZoom failed", error)
|
||||||
|
onComplete(false, zoomCapabilitiesMap(), error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasUltraWideCamera(): Boolean {
|
||||||
|
return ultraWideCameraId != null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ProcessCameraProvider.hasCameraSafely(selector: CameraSelector): Boolean {
|
||||||
|
return try {
|
||||||
|
hasCamera(selector)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum class LensMode {
|
||||||
|
MAIN,
|
||||||
|
ULTRA_WIDE,
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class CameraProfile(
|
||||||
|
val cameraId: String,
|
||||||
|
val minFocalLength: Float,
|
||||||
|
val horizontalFov: Double,
|
||||||
|
)
|
||||||
|
|
||||||
|
private data class UltraWideCamera(
|
||||||
|
val cameraId: String,
|
||||||
|
val zoomRatio: Float,
|
||||||
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "RecordingCamera"
|
||||||
|
private const val DEFAULT_ULTRA_WIDE_ZOOM_RATIO = 0.6f
|
||||||
|
// 适度放宽判定宽容度,覆盖更多机型(更小的 FOV/焦距差异也视为超广角)。
|
||||||
|
private const val ULTRA_WIDE_FOV_FACTOR = 1.04
|
||||||
|
private const val ULTRA_WIDE_FOCAL_FACTOR = 0.96
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.os.PowerManager
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.LifecycleService
|
||||||
|
import com.dronex.rec.AppConstants
|
||||||
|
import com.dronex.rec.MainActivity
|
||||||
|
|
||||||
|
class RecordingForegroundService : LifecycleService() {
|
||||||
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
instance = this
|
||||||
|
createNotificationChannel()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
super.onStartCommand(intent, flags, startId)
|
||||||
|
when (intent?.action) {
|
||||||
|
AppConstants.RECORDING_ACTION_START -> {
|
||||||
|
acquireWakeLock()
|
||||||
|
val notification = buildNotification("正在录制")
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
startForeground(
|
||||||
|
NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
foregroundServiceTypes(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
}
|
||||||
|
isRunning = true
|
||||||
|
}
|
||||||
|
AppConstants.RECORDING_ACTION_STOP -> {
|
||||||
|
releaseWakeLock()
|
||||||
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
isRunning = false
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
releaseWakeLock()
|
||||||
|
isRunning = false
|
||||||
|
if (instance === this) {
|
||||||
|
instance = null
|
||||||
|
}
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
|
super.onBind(intent)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun acquireWakeLock() {
|
||||||
|
if (wakeLock?.isHeld == true) return
|
||||||
|
val manager = getSystemService(PowerManager::class.java) ?: return
|
||||||
|
wakeLock =
|
||||||
|
manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
|
||||||
|
setReferenceCounted(false)
|
||||||
|
acquire(4 * 60 * 60 * 1000L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun releaseWakeLock() {
|
||||||
|
wakeLock?.let {
|
||||||
|
if (it.isHeld) {
|
||||||
|
it.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wakeLock = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createNotificationChannel() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||||
|
val channel =
|
||||||
|
NotificationChannel(
|
||||||
|
CHANNEL_ID,
|
||||||
|
"录制服务",
|
||||||
|
NotificationManager.IMPORTANCE_LOW,
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
description = "保持相机录制在后台与息屏时继续运行"
|
||||||
|
setShowBadge(false)
|
||||||
|
}
|
||||||
|
val manager = getSystemService(NotificationManager::class.java)
|
||||||
|
manager?.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun foregroundServiceTypes(): Int {
|
||||||
|
var types = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
|
||||||
|
if (hasRecordAudioPermission()) {
|
||||||
|
types = types or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
|
||||||
|
}
|
||||||
|
return types
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasRecordAudioPermission(): Boolean {
|
||||||
|
return ContextCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
android.Manifest.permission.RECORD_AUDIO,
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNotification(content: String): Notification {
|
||||||
|
val launchIntent =
|
||||||
|
Intent(this, MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
|
}
|
||||||
|
val pendingIntent =
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
this,
|
||||||
|
0,
|
||||||
|
launchIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
)
|
||||||
|
|
||||||
|
return NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
|
.setContentTitle("录制进行中")
|
||||||
|
.setContentText(content)
|
||||||
|
.setSmallIcon(android.R.drawable.presence_video_online)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setContentIntent(pendingIntent)
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CHANNEL_ID = "recording_foreground"
|
||||||
|
const val NOTIFICATION_ID = 1001
|
||||||
|
private const val WAKE_LOCK_TAG = "record_tool:recording_wake_lock"
|
||||||
|
|
||||||
|
@Volatile var isRunning: Boolean = false
|
||||||
|
|
||||||
|
@Volatile var instance: RecordingForegroundService? = null
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
val intent =
|
||||||
|
Intent(context, RecordingForegroundService::class.java).apply {
|
||||||
|
action = AppConstants.RECORDING_ACTION_START
|
||||||
|
}
|
||||||
|
ContextCompatStart.startForegroundService(context, intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
val intent =
|
||||||
|
Intent(context, RecordingForegroundService::class.java).apply {
|
||||||
|
action = AppConstants.RECORDING_ACTION_STOP
|
||||||
|
}
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ContextCompatStart {
|
||||||
|
fun startForegroundService(context: Context, intent: Intent) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.MediaStore
|
||||||
|
import androidx.camera.video.MediaStoreOutputOptions
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
object RecordingOutputFactory {
|
||||||
|
private const val RELATIVE_PATH = "Movies/飞行极控录像工作台"
|
||||||
|
private const val MIME_TYPE = "video/mp4"
|
||||||
|
|
||||||
|
fun buildMediaStoreOutputOptions(
|
||||||
|
context: Context,
|
||||||
|
displayName: String?,
|
||||||
|
): MediaStoreOutputOptions {
|
||||||
|
val fileName = resolveFileName(displayName)
|
||||||
|
val contentValues =
|
||||||
|
ContentValues().apply {
|
||||||
|
put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
|
||||||
|
put(MediaStore.MediaColumns.MIME_TYPE, MIME_TYPE)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
put(MediaStore.Video.Media.RELATIVE_PATH, RELATIVE_PATH)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MediaStoreOutputOptions.Builder(
|
||||||
|
context.contentResolver,
|
||||||
|
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||||
|
)
|
||||||
|
.setContentValues(contentValues)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveFileName(displayName: String?): String {
|
||||||
|
val trimmed = displayName?.trim().orEmpty()
|
||||||
|
if (trimmed.isNotEmpty()) {
|
||||||
|
return if (trimmed.lowercase(Locale.US).endsWith(".mp4")) {
|
||||||
|
trimmed
|
||||||
|
} else {
|
||||||
|
"$trimmed.mp4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
|
||||||
|
return "REC_$timestamp.mp4"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
|
import com.dronex.rec.AppConstants
|
||||||
|
import com.dronex.rec.MainActivity
|
||||||
|
import io.flutter.plugin.common.BinaryMessenger
|
||||||
|
import io.flutter.plugin.common.EventChannel
|
||||||
|
import io.flutter.plugin.common.MethodCall
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
|
class RecordingPlatformHandler(
|
||||||
|
private val activity: MainActivity,
|
||||||
|
messenger: BinaryMessenger,
|
||||||
|
) : MethodChannel.MethodCallHandler, EventChannel.StreamHandler {
|
||||||
|
private val methodChannel = MethodChannel(messenger, AppConstants.RECORDING_METHOD_CHANNEL)
|
||||||
|
private val eventChannel = EventChannel(messenger, AppConstants.RECORDING_EVENT_CHANNEL)
|
||||||
|
|
||||||
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
|
private var eventSink: EventChannel.EventSink? = null
|
||||||
|
private var elapsedTicker: Runnable? = null
|
||||||
|
|
||||||
|
private val controller by lazy { RecordingSession.controller(activity.applicationContext) }
|
||||||
|
|
||||||
|
init {
|
||||||
|
methodChannel.setMethodCallHandler(this)
|
||||||
|
eventChannel.setStreamHandler(this)
|
||||||
|
controller.statusListener = { status ->
|
||||||
|
mainHandler.post { eventSink?.success(status.toMap()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun dispose() {
|
||||||
|
stopElapsedTicker()
|
||||||
|
methodChannel.setMethodCallHandler(null)
|
||||||
|
eventChannel.setStreamHandler(null)
|
||||||
|
controller.statusListener = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||||
|
when (call.method) {
|
||||||
|
"initializePreview" -> initializePreview(result)
|
||||||
|
"startRecording" -> {
|
||||||
|
val withAudio = call.argument<Boolean>("withAudio") ?: true
|
||||||
|
val enableDnd = call.argument<Boolean>("enableDoNotDisturb") ?: true
|
||||||
|
val displayName = call.argument<String>("displayName")
|
||||||
|
startRecording(withAudio, enableDnd, displayName, result)
|
||||||
|
}
|
||||||
|
"stopRecording" -> stopRecording(result)
|
||||||
|
"getZoomCapabilities" -> result.success(controller.zoomCapabilitiesMap())
|
||||||
|
"setZoomRatio" -> {
|
||||||
|
val ratio = call.argument<Double>("zoomRatio") ?: 1.0
|
||||||
|
setZoomRatio(ratio, result)
|
||||||
|
}
|
||||||
|
"disposePreview" -> {
|
||||||
|
controller.unbind()
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
"hasNotificationPolicyAccess" -> result.success(DoNotDisturbHelper.hasAccess(activity))
|
||||||
|
"openNotificationPolicySettings" -> {
|
||||||
|
DoNotDisturbHelper.openAccessSettings(activity)
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
"enableDoNotDisturb" -> result.success(DoNotDisturbHelper.enable(activity))
|
||||||
|
"disableDoNotDisturb" -> {
|
||||||
|
DoNotDisturbHelper.disable(activity)
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
"isIgnoringBatteryOptimizations" ->
|
||||||
|
result.success(BatteryOptimizationHelper.isIgnoringOptimizations(activity))
|
||||||
|
"openBatteryOptimizationSettings" -> {
|
||||||
|
BatteryOptimizationHelper.openSettings(activity)
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
"setImmersiveMode" -> {
|
||||||
|
val enabled = call.argument<Boolean>("enabled") ?: false
|
||||||
|
setImmersiveMode(enabled)
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
"getStatus" -> result.success(controller.status.toMap())
|
||||||
|
"isForegroundServiceRunning" -> result.success(RecordingForegroundService.isRunning)
|
||||||
|
else -> result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initializePreview(result: MethodChannel.Result) {
|
||||||
|
val previewView = activity.recordingPreviewView
|
||||||
|
if (previewView == null) {
|
||||||
|
result.error("NO_PREVIEW", "Camera preview is not attached", null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.bindPreview(activity, previewView) { ready ->
|
||||||
|
mainHandler.post {
|
||||||
|
if (ready) {
|
||||||
|
result.success(controller.status.toMap())
|
||||||
|
} else {
|
||||||
|
result.error("PREVIEW_FAILED", "Failed to bind camera preview", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startRecording(
|
||||||
|
withAudio: Boolean,
|
||||||
|
enableDnd: Boolean,
|
||||||
|
displayName: String?,
|
||||||
|
result: MethodChannel.Result,
|
||||||
|
) {
|
||||||
|
val previewView = activity.recordingPreviewView
|
||||||
|
if (previewView == null) {
|
||||||
|
result.error("NO_PREVIEW", "Camera preview is not attached", null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordingSession.startForeground(activity)
|
||||||
|
|
||||||
|
fun beginCapture() {
|
||||||
|
if (enableDnd && DoNotDisturbHelper.hasAccess(activity)) {
|
||||||
|
DoNotDisturbHelper.enable(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.startRecording(withAudio, displayName) { started, message ->
|
||||||
|
mainHandler.post {
|
||||||
|
if (started) {
|
||||||
|
startElapsedTicker()
|
||||||
|
result.success(
|
||||||
|
mapOf(
|
||||||
|
"outputPath" to message,
|
||||||
|
"status" to controller.status.toMap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
RecordingSession.stopForeground(activity)
|
||||||
|
DoNotDisturbHelper.disable(activity)
|
||||||
|
result.error("START_FAILED", message, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebindAndCapture() {
|
||||||
|
val lifecycleOwner = RecordingForegroundService.instance ?: activity
|
||||||
|
controller.rebindForRecording(lifecycleOwner, previewView) { ready ->
|
||||||
|
if (ready) {
|
||||||
|
beginCapture()
|
||||||
|
} else {
|
||||||
|
RecordingSession.stopForeground(activity)
|
||||||
|
result.error("REBIND_FAILED", "Failed to bind camera for recording", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RecordingForegroundService.instance != null) {
|
||||||
|
rebindAndCapture()
|
||||||
|
} else {
|
||||||
|
mainHandler.post { rebindAndCapture() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopRecording(result: MethodChannel.Result) {
|
||||||
|
stopElapsedTicker()
|
||||||
|
controller.stopRecording { path ->
|
||||||
|
RecordingSession.stopForeground(activity)
|
||||||
|
DoNotDisturbHelper.disable(activity)
|
||||||
|
val previewView = activity.recordingPreviewView
|
||||||
|
if (previewView == null) {
|
||||||
|
mainHandler.post { deliverStopResult(result, path) }
|
||||||
|
return@stopRecording
|
||||||
|
}
|
||||||
|
controller.rebindForRecording(activity, previewView) { _ ->
|
||||||
|
mainHandler.post { deliverStopResult(result, path) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setZoomRatio(ratio: Double, result: MethodChannel.Result) {
|
||||||
|
controller.setZoomRatio(ratio) { success, capabilities, message ->
|
||||||
|
mainHandler.post {
|
||||||
|
if (success) {
|
||||||
|
result.success(capabilities)
|
||||||
|
} else {
|
||||||
|
result.error("ZOOM_FAILED", message ?: "Failed to set camera zoom", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deliverStopResult(result: MethodChannel.Result, path: String?) {
|
||||||
|
val fileSaved = path != null && controller.status.state != RecordingState.ERROR
|
||||||
|
val payload =
|
||||||
|
mutableMapOf<String, Any?>(
|
||||||
|
"outputPath" to path,
|
||||||
|
"status" to controller.status.toMap(),
|
||||||
|
"fileSaved" to fileSaved,
|
||||||
|
)
|
||||||
|
if (!fileSaved) {
|
||||||
|
payload["fileErrorMessage"] = controller.status.message ?: "保存到文件夹失败"
|
||||||
|
}
|
||||||
|
result.success(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setImmersiveMode(enabled: Boolean) {
|
||||||
|
val window = activity.window
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, !enabled)
|
||||||
|
val insetsController = WindowInsetsControllerCompat(window, window.decorView)
|
||||||
|
if (enabled) {
|
||||||
|
insetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
|
insetsController.systemBarsBehavior =
|
||||||
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
} else {
|
||||||
|
insetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startElapsedTicker() {
|
||||||
|
stopElapsedTicker()
|
||||||
|
elapsedTicker =
|
||||||
|
object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
if (controller.status.state == RecordingState.RECORDING) {
|
||||||
|
eventSink?.success(
|
||||||
|
controller
|
||||||
|
.status
|
||||||
|
.copy(
|
||||||
|
elapsedMillis =
|
||||||
|
controller.elapsedMillis(),
|
||||||
|
)
|
||||||
|
.toMap(),
|
||||||
|
)
|
||||||
|
mainHandler.postDelayed(this, 1000L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.also { mainHandler.post(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopElapsedTicker() {
|
||||||
|
elapsedTicker?.let { mainHandler.removeCallbacks(it) }
|
||||||
|
elapsedTicker = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
|
||||||
|
eventSink = events
|
||||||
|
events?.success(controller.status.toMap())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCancel(arguments: Any?) {
|
||||||
|
eventSink = null
|
||||||
|
stopElapsedTicker()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import com.dronex.rec.MainActivity
|
||||||
|
import io.flutter.plugin.common.StandardMessageCodec
|
||||||
|
import io.flutter.plugin.platform.PlatformView
|
||||||
|
import io.flutter.plugin.platform.PlatformViewFactory
|
||||||
|
|
||||||
|
class RecordingPreviewFactory(
|
||||||
|
private val activity: MainActivity,
|
||||||
|
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
||||||
|
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
|
||||||
|
return RecordingPreviewPlatformView(activity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingPreviewPlatformView(
|
||||||
|
private val activity: MainActivity,
|
||||||
|
) : PlatformView {
|
||||||
|
val previewView: PreviewView =
|
||||||
|
PreviewView(activity).apply {
|
||||||
|
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
|
||||||
|
scaleType = PreviewView.ScaleType.FILL_CENTER
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
activity.attachRecordingPreview(previewView)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(): View = previewView
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
activity.detachRecordingPreview(previewView)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.lifecycle.LifecycleService
|
||||||
|
|
||||||
|
object RecordingSession {
|
||||||
|
private var cameraController: RecordingCameraController? = null
|
||||||
|
|
||||||
|
fun controller(context: Context): RecordingCameraController {
|
||||||
|
return cameraController
|
||||||
|
?: RecordingCameraController(context.applicationContext).also {
|
||||||
|
cameraController = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun release() {
|
||||||
|
cameraController?.unbind()
|
||||||
|
cameraController = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startForeground(context: Context) {
|
||||||
|
RecordingForegroundService.start(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopForeground(context: Context) {
|
||||||
|
RecordingForegroundService.stop(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun recordingLifecycleOwner(): LifecycleService? = RecordingForegroundService.instance
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.dronex.rec.recording
|
||||||
|
|
||||||
|
enum class RecordingState {
|
||||||
|
IDLE,
|
||||||
|
PREVIEWING,
|
||||||
|
RECORDING,
|
||||||
|
STOPPING,
|
||||||
|
ERROR,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class RecordingStatus(
|
||||||
|
val state: RecordingState,
|
||||||
|
val outputPath: String? = null,
|
||||||
|
val elapsedMillis: Long = 0L,
|
||||||
|
val message: String? = null,
|
||||||
|
) {
|
||||||
|
fun toMap(): Map<String, Any?> =
|
||||||
|
mapOf(
|
||||||
|
"state" to state.name.lowercase(),
|
||||||
|
"outputPath" to outputPath,
|
||||||
|
"elapsedMillis" to elapsedMillis,
|
||||||
|
"message" to message,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.flutter_template
|
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
|
||||||
|
|
||||||
class MainActivity : FlutterActivity()
|
|
||||||
BIN
android/app/src/main/res/drawable-nodpi/startup_background.png
Normal file
|
After Width: | Height: | Size: 262 KiB |
@@ -1,12 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Modify this file to customize your launch splash screen -->
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="?android:colorBackground" />
|
<item>
|
||||||
|
|
||||||
<!-- You can insert your own image assets here -->
|
|
||||||
<!-- <item>
|
|
||||||
<bitmap
|
<bitmap
|
||||||
android:gravity="center"
|
android:gravity="fill"
|
||||||
android:src="@mipmap/launch_image" />
|
android:src="@drawable/startup_background" />
|
||||||
</item> -->
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Modify this file to customize your launch splash screen -->
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="@android:color/white" />
|
<item>
|
||||||
|
|
||||||
<!-- You can insert your own image assets here -->
|
|
||||||
<!-- <item>
|
|
||||||
<bitmap
|
<bitmap
|
||||||
android:gravity="center"
|
android:gravity="fill"
|
||||||
android:src="@mipmap/launch_image" />
|
android:src="@drawable/startup_background" />
|
||||||
</item> -->
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 24 KiB |
@@ -1,7 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
|
||||||
the Flutter tool needs it to communicate with the running application
|
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
|
||||||
-->
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
</manifest>
|
|
||||||
663
android/build/reports/problems/problems-report.html
Normal file
@@ -1,3 +1,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=1G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
|
# This builtInKotlin flag was added automatically by Flutter migrator
|
||||||
|
android.builtInKotlin=false
|
||||||
|
# This newDsl flag was added automatically by Flutter migrator
|
||||||
|
android.newDsl=false
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ pluginManagement {
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||||
id("com.android.application") version "8.9.1" apply false
|
id("com.android.application") version "8.11.1" apply false
|
||||||
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
|
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
include(":app")
|
include(":app")
|
||||||
|
|||||||
BIN
assets/images/image_copy.png
Normal file
|
After Width: | Height: | Size: 795 B |
BIN
assets/images/image_delete.png
Normal file
|
After Width: | Height: | Size: 1011 B |
BIN
assets/images/image_dialog_bg.png
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
assets/images/image_logo.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/images/image_vs.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
1
build-apk-split.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flutter build apk --release --split-per-abi
|
||||||
1
build-apk.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flutter build apk --release
|
||||||
19
buildServer.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "xcode build server",
|
||||||
|
"version": "1.3.0",
|
||||||
|
"bspVersion": "2.2.0",
|
||||||
|
"languages": [
|
||||||
|
"c",
|
||||||
|
"cpp",
|
||||||
|
"objective-c",
|
||||||
|
"objective-cpp",
|
||||||
|
"swift"
|
||||||
|
],
|
||||||
|
"argv": [
|
||||||
|
"/opt/homebrew/bin/xcode-build-server"
|
||||||
|
],
|
||||||
|
"workspace": "/Users/ZhuanZ/Documents/gdfw/record-tool/ios/Runner.xcworkspace",
|
||||||
|
"build_root": "/Users/ZhuanZ/Library/Developer/Xcode/DerivedData/Runner-ckjfuyjdkgumnpbnnftroxddsppq",
|
||||||
|
"scheme": "Runner",
|
||||||
|
"kind": "xcode"
|
||||||
|
}
|
||||||
7
clean.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
flutter clean
|
||||||
|
flutter pub get
|
||||||
|
rm -rf ios/Pods
|
||||||
|
rm -rf ios/Podfile.lock
|
||||||
|
cd ios
|
||||||
|
pod install
|
||||||
|
cd ..
|
||||||
3
devtools_options.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -20,7 +20,5 @@
|
|||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>MinimumOSVersion</key>
|
|
||||||
<string>13.0</string>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}"
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}"
|
||||||
|
|||||||
35
ios/Podfile
@@ -39,5 +39,40 @@ end
|
|||||||
post_install do |installer|
|
post_install do |installer|
|
||||||
installer.pods_project.targets.each do |target|
|
installer.pods_project.targets.each do |target|
|
||||||
flutter_additional_ios_build_settings(target)
|
flutter_additional_ios_build_settings(target)
|
||||||
|
|
||||||
|
target.build_configurations.each do |config|
|
||||||
|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
|
||||||
|
'$(inherited)',
|
||||||
|
'PERMISSION_CAMERA=1',
|
||||||
|
'PERMISSION_MICROPHONE=1',
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
pods_runner_dir = File.join(
|
||||||
|
installer.sandbox.root,
|
||||||
|
'Target Support Files',
|
||||||
|
'Pods-Runner'
|
||||||
|
)
|
||||||
|
Dir.glob(File.join(pods_runner_dir, 'Pods-Runner.*.xcconfig')).each do |config_path|
|
||||||
|
config = File.read(config_path)
|
||||||
|
config.gsub!(
|
||||||
|
'FRAMEWORK_SEARCH_PATHS = $(inherited)',
|
||||||
|
'FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}"'
|
||||||
|
)
|
||||||
|
File.write(config_path, config)
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.glob(File.join(pods_runner_dir, 'Pods-Runner-frameworks-*input-files.xcfilelist')).each do |file_list_path|
|
||||||
|
file_list = File.read(file_list_path)
|
||||||
|
file_list.gsub!('${BUILT_PRODUCTS_DIR}/', '${PODS_CONFIGURATION_BUILD_DIR}/')
|
||||||
|
File.write(file_list_path, file_list)
|
||||||
|
end
|
||||||
|
|
||||||
|
frameworks_script = File.join(pods_runner_dir, 'Pods-Runner-frameworks.sh')
|
||||||
|
if File.exist?(frameworks_script)
|
||||||
|
script = File.read(frameworks_script)
|
||||||
|
script.gsub!('${BUILT_PRODUCTS_DIR}/', '${PODS_CONFIGURATION_BUILD_DIR}/')
|
||||||
|
File.write(frameworks_script, script)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
PODS:
|
PODS:
|
||||||
- connectivity_plus (0.0.1):
|
- connectivity_plus (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- device_info_plus (0.0.1):
|
|
||||||
- Flutter
|
|
||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
- package_info_plus (0.4.5):
|
- permission_handler_apple (9.4.8):
|
||||||
- Flutter
|
|
||||||
- path_provider_foundation (0.0.1):
|
|
||||||
- Flutter
|
|
||||||
- FlutterMacOS
|
|
||||||
- permission_handler_apple (9.3.0):
|
|
||||||
- Flutter
|
- Flutter
|
||||||
- shared_preferences_foundation (0.0.1):
|
- shared_preferences_foundation (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
@@ -22,10 +15,7 @@ PODS:
|
|||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
|
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
|
||||||
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
|
|
||||||
- Flutter (from `Flutter`)
|
- Flutter (from `Flutter`)
|
||||||
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
|
|
||||||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
|
||||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||||
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
|
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
|
||||||
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
|
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
|
||||||
@@ -34,14 +24,8 @@ DEPENDENCIES:
|
|||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
connectivity_plus:
|
connectivity_plus:
|
||||||
:path: ".symlinks/plugins/connectivity_plus/ios"
|
:path: ".symlinks/plugins/connectivity_plus/ios"
|
||||||
device_info_plus:
|
|
||||||
:path: ".symlinks/plugins/device_info_plus/ios"
|
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: Flutter
|
:path: Flutter
|
||||||
package_info_plus:
|
|
||||||
:path: ".symlinks/plugins/package_info_plus/ios"
|
|
||||||
path_provider_foundation:
|
|
||||||
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
|
||||||
permission_handler_apple:
|
permission_handler_apple:
|
||||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||||
shared_preferences_foundation:
|
shared_preferences_foundation:
|
||||||
@@ -53,15 +37,12 @@ EXTERNAL SOURCES:
|
|||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7dd
|
connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7dd
|
||||||
device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbe
|
|
||||||
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
|
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
|
||||||
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
|
permission_handler_apple: 92d754bbaa7361d436db2d6c3c1c2a0fdcec462e
|
||||||
path_provider_foundation: bb55f6dbba17d0dccd6737fe6f7f34fbd0376880
|
|
||||||
permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d
|
|
||||||
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
||||||
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
|
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
|
||||||
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
|
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
|
||||||
|
|
||||||
PODFILE CHECKSUM: 3c63482e143d1b91d2d2560aee9fb04ecc74ac7e
|
PODFILE CHECKSUM: 858401fbd980bedce6ecd2f9b429bf271f11f74b
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
64BC3B3C75FABAA128C4FE7A /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D84231833EC084C45F76D9A0 /* Pods_RunnerTests.framework */; };
|
64BC3B3C75FABAA128C4FE7A /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D84231833EC084C45F76D9A0 /* Pods_RunnerTests.framework */; };
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
||||||
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6AA1C86CE710449CC3E8FCD /* Pods_Runner.framework */; };
|
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6AA1C86CE710449CC3E8FCD /* Pods_Runner.framework */; };
|
||||||
|
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */; };
|
||||||
|
8E5D9D9E2C69000100F10002 /* PlatformInfoPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */; };
|
||||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
||||||
@@ -52,6 +54,8 @@
|
|||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||||
|
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingPlugin.swift; sourceTree = "<group>"; };
|
||||||
|
8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformInfoPlugin.swift; sourceTree = "<group>"; };
|
||||||
95C6AC1536EA3DBA2D369C55 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
|
95C6AC1536EA3DBA2D369C55 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
||||||
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
||||||
@@ -97,7 +101,6 @@
|
|||||||
DFA822DC4965C5AFAFF6BB41 /* Pods-RunnerTests.release.xcconfig */,
|
DFA822DC4965C5AFAFF6BB41 /* Pods-RunnerTests.release.xcconfig */,
|
||||||
99DBE6263F70650B13C33EAC /* Pods-RunnerTests.profile.xcconfig */,
|
99DBE6263F70650B13C33EAC /* Pods-RunnerTests.profile.xcconfig */,
|
||||||
);
|
);
|
||||||
name = Pods;
|
|
||||||
path = Pods;
|
path = Pods;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
@@ -160,6 +163,8 @@
|
|||||||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
|
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
|
||||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
||||||
|
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */,
|
||||||
|
8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */,
|
||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
||||||
);
|
);
|
||||||
path = Runner;
|
path = Runner;
|
||||||
@@ -198,8 +203,8 @@
|
|||||||
97C146EC1CF9000F007C117D /* Resources */,
|
97C146EC1CF9000F007C117D /* Resources */,
|
||||||
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
||||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
||||||
CD126DA202245CE8BB749787 /* [CP] Embed Pods Frameworks */,
|
7858230D5ADC7A99F778CB03 /* [CP] Embed Pods Frameworks */,
|
||||||
62D3774184B6C76B8E34C8C2 /* [CP] Copy Pods Resources */,
|
99E9790F23C2D0C0B51A6C19 /* [CP] Copy Pods Resources */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
@@ -331,21 +336,21 @@
|
|||||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
62D3774184B6C76B8E34C8C2 /* [CP] Copy Pods Resources */ = {
|
7858230D5ADC7A99F778CB03 /* [CP] Embed Pods Frameworks */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
);
|
);
|
||||||
inputFileListPaths = (
|
inputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||||
);
|
);
|
||||||
name = "[CP] Copy Pods Resources";
|
name = "[CP] Embed Pods Frameworks";
|
||||||
outputFileListPaths = (
|
outputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
|
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||||
@@ -363,21 +368,21 @@
|
|||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
||||||
};
|
};
|
||||||
CD126DA202245CE8BB749787 /* [CP] Embed Pods Frameworks */ = {
|
99E9790F23C2D0C0B51A6C19 /* [CP] Copy Pods Resources */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
);
|
);
|
||||||
inputFileListPaths = (
|
inputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
|
||||||
);
|
);
|
||||||
name = "[CP] Embed Pods Frameworks";
|
name = "[CP] Copy Pods Resources";
|
||||||
outputFileListPaths = (
|
outputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
@@ -396,6 +401,8 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
||||||
|
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */,
|
||||||
|
8E5D9D9E2C69000100F10002 /* PlatformInfoPlugin.swift in Sources */,
|
||||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@@ -488,16 +495,22 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
|
CODE_SIGN_STYLE = Manual;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
DEVELOPMENT_TEAM = 35634V629S;
|
DEVELOPMENT_TEAM = "";
|
||||||
|
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = MT26BPCKF6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.dronex.rec;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "dev-profile-dronex";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
@@ -513,7 +526,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -531,7 +544,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -547,7 +560,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -671,16 +684,22 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
|
CODE_SIGN_STYLE = Manual;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
DEVELOPMENT_TEAM = 35634V629S;
|
DEVELOPMENT_TEAM = "";
|
||||||
|
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = MT26BPCKF6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.dronex.rec;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "dev-profile-dronex";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -694,16 +713,22 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
|
CODE_SIGN_STYLE = Manual;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
DEVELOPMENT_TEAM = 35634V629S;
|
DEVELOPMENT_TEAM = "";
|
||||||
|
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = MT26BPCKF6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.dronex.rec;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "dev-profile-dronex";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
|
|||||||
@@ -1,10 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1510"
|
LastUpgradeVersion = "1510"
|
||||||
version = "1.3">
|
version = "1.7">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
buildImplicitDependencies = "YES">
|
buildImplicitDependencies = "YES">
|
||||||
|
<PreActions>
|
||||||
|
<ExecutionAction
|
||||||
|
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
|
||||||
|
<ActionContent
|
||||||
|
title = "Run Prepare Flutter Framework Script"
|
||||||
|
scriptText = "/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" prepare ">
|
||||||
|
<EnvironmentBuildable>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "97C146ED1CF9000F007C117D"
|
||||||
|
BuildableName = "Runner.app"
|
||||||
|
BlueprintName = "Runner"
|
||||||
|
ReferencedContainer = "container:Runner.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</EnvironmentBuildable>
|
||||||
|
</ActionContent>
|
||||||
|
</ExecutionAction>
|
||||||
|
</PreActions>
|
||||||
<BuildActionEntries>
|
<BuildActionEntries>
|
||||||
<BuildActionEntry
|
<BuildActionEntry
|
||||||
buildForTesting = "YES"
|
buildForTesting = "YES"
|
||||||
@@ -52,7 +70,7 @@
|
|||||||
</Testables>
|
</Testables>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Release"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
|
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
|
||||||
|
|||||||
@@ -2,12 +2,21 @@ import Flutter
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@main
|
@main
|
||||||
@objc class AppDelegate: FlutterAppDelegate {
|
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
||||||
override func application(
|
override func application(
|
||||||
_ application: UIApplication,
|
_ application: UIApplication,
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
GeneratedPluginRegistrant.register(with: self)
|
|
||||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
|
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||||
|
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "RecordingPlugin") {
|
||||||
|
RecordingPlugin.register(with: registrar)
|
||||||
|
}
|
||||||
|
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "PlatformInfoPlugin") {
|
||||||
|
PlatformInfoPlugin.register(with: registrar)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 295 B After Width: | Height: | Size: 976 B |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 20 KiB |
13
ios/Runner/Assets.xcassets/StartupBackground.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "startup_background.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
ios/Runner/Assets.xcassets/StartupBackground.imageset/startup_background.png
vendored
Normal file
|
After Width: | Height: | Size: 262 KiB |
@@ -16,13 +16,15 @@
|
|||||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
|
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" image="StartupBackground" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
|
||||||
</imageView>
|
</imageView>
|
||||||
</subviews>
|
</subviews>
|
||||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="1a2-6s-vTC"/>
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="1a2-6s-vTC"/>
|
||||||
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="4X2-HB-R7a"/>
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="4X2-HB-R7a"/>
|
||||||
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="E8f-e3-JEx"/>
|
||||||
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="trailing" secondItem="Ze5-6b-2t3" secondAttribute="trailing" id="rwG-Bh-0uU"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</view>
|
</view>
|
||||||
</viewController>
|
</viewController>
|
||||||
@@ -32,6 +34,6 @@
|
|||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
<resources>
|
<resources>
|
||||||
<image name="LaunchImage" width="168" height="185"/>
|
<image name="StartupBackground" width="750" height="1624"/>
|
||||||
</resources>
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="24412" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||||
|
<device id="retina6_12" orientation="portrait" appearance="light"/>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="iOS"/>
|
<deployment identifier="iOS"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24405"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<scenes>
|
<scenes>
|
||||||
<!--Flutter View Controller-->
|
<!--Flutter View Controller-->
|
||||||
@@ -14,13 +16,28 @@
|
|||||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
||||||
</layoutGuides>
|
</layoutGuides>
|
||||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
<subviews>
|
||||||
|
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" image="StartupBackground" translatesAutoresizingMaskIntoConstraints="NO" id="YQm-Ov-qw7">
|
||||||
|
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||||
|
</imageView>
|
||||||
|
</subviews>
|
||||||
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstItem="YQm-Ov-qw7" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="7pp-OK-Dgk"/>
|
||||||
|
<constraint firstItem="YQm-Ov-qw7" firstAttribute="bottom" secondItem="8bC-Xf-vdC" secondAttribute="bottom" id="Hbf-gY-rbf"/>
|
||||||
|
<constraint firstItem="YQm-Ov-qw7" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="WPc-7k-20p"/>
|
||||||
|
<constraint firstItem="YQm-Ov-qw7" firstAttribute="trailing" secondItem="8bC-Xf-vdC" secondAttribute="trailing" id="w1G-WA-3QR"/>
|
||||||
|
</constraints>
|
||||||
</view>
|
</view>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
<point key="canvasLocation" x="139" y="122"/>
|
||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
|
<resources>
|
||||||
|
<image name="StartupBackground" width="750" height="1624"/>
|
||||||
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||||
|
<true/>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Flutter Template</string>
|
<string>飞行极控录像工作台</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -13,7 +15,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>flutter_template</string>
|
<string>飞行极控录像工作台</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
@@ -24,6 +26,37 @@
|
|||||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>需要访问相机以显示预览并录制视频。</string>
|
||||||
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
<string>需要访问麦克风以录制视频声音;未授权时将静音录制。</string>
|
||||||
|
<key>UIFileSharingEnabled</key>
|
||||||
|
<true/>
|
||||||
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
|
<true/>
|
||||||
|
<key>UIApplicationSceneManifest</key>
|
||||||
|
<dict>
|
||||||
|
<key>UIApplicationSupportsMultipleScenes</key>
|
||||||
|
<false/>
|
||||||
|
<key>UISceneConfigurations</key>
|
||||||
|
<dict>
|
||||||
|
<key>UIWindowSceneSessionRoleApplication</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>UISceneClassName</key>
|
||||||
|
<string>UIWindowScene</string>
|
||||||
|
<key>UISceneConfigurationName</key>
|
||||||
|
<string>flutter</string>
|
||||||
|
<key>UISceneDelegateClassName</key>
|
||||||
|
<string>FlutterSceneDelegate</string>
|
||||||
|
<key>UISceneStoryboardFile</key>
|
||||||
|
<string>Main</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||||
|
<true/>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>LaunchScreen</string>
|
<string>LaunchScreen</string>
|
||||||
<key>UIMainStoryboardFile</key>
|
<key>UIMainStoryboardFile</key>
|
||||||
@@ -41,9 +74,5 @@
|
|||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
</array>
|
||||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
|
||||||
<true/>
|
|
||||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
97
ios/Runner/PlatformInfoPlugin.swift
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import Flutter
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
||||||
|
static func register(with registrar: FlutterPluginRegistrar) {
|
||||||
|
let channel = FlutterMethodChannel(
|
||||||
|
name: "com.dronex.rec/platform_info",
|
||||||
|
binaryMessenger: registrar.messenger()
|
||||||
|
)
|
||||||
|
let plugin = PlatformInfoPlugin()
|
||||||
|
registrar.addMethodCallDelegate(plugin, channel: channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||||
|
switch call.method {
|
||||||
|
case "packageInfo":
|
||||||
|
result(packageInfoMap())
|
||||||
|
case "deviceInfo":
|
||||||
|
result(deviceInfoMap())
|
||||||
|
case "deviceHealth":
|
||||||
|
result(deviceHealthMap())
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func packageInfoMap() -> [String: String] {
|
||||||
|
let bundle = Bundle.main
|
||||||
|
return [
|
||||||
|
"appName": displayName(bundle: bundle),
|
||||||
|
"packageName": bundle.bundleIdentifier ?? "",
|
||||||
|
"version": bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "",
|
||||||
|
"buildNumber": bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deviceHealthMap() -> [String: Any?] {
|
||||||
|
let device = UIDevice.current
|
||||||
|
device.isBatteryMonitoringEnabled = true
|
||||||
|
|
||||||
|
var batteryLevelPercent: Int?
|
||||||
|
let batteryLevel = device.batteryLevel
|
||||||
|
if batteryLevel >= 0 {
|
||||||
|
batteryLevelPercent = Int((batteryLevel * 100).rounded())
|
||||||
|
}
|
||||||
|
|
||||||
|
var storageAvailablePercent = 100.0
|
||||||
|
if let attrs = try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory()),
|
||||||
|
let free = attrs[.systemFreeSize] as? NSNumber,
|
||||||
|
let total = attrs[.systemSize] as? NSNumber,
|
||||||
|
total.doubleValue > 0 {
|
||||||
|
storageAvailablePercent = free.doubleValue / total.doubleValue * 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"batteryLevelPercent": batteryLevelPercent,
|
||||||
|
"storageAvailablePercent": storageAvailablePercent,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deviceInfoMap() -> [String: Any] {
|
||||||
|
let device = UIDevice.current
|
||||||
|
return [
|
||||||
|
"platform": "ios",
|
||||||
|
"brand": device.systemName,
|
||||||
|
"model": machineIdentifier(),
|
||||||
|
"systemVersion": device.systemVersion,
|
||||||
|
"isPhysicalDevice": !isSimulator(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func displayName(bundle: Bundle) -> String {
|
||||||
|
if let displayName = bundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
|
||||||
|
return displayName
|
||||||
|
}
|
||||||
|
return bundle.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
private func isSimulator() -> Bool {
|
||||||
|
#if targetEnvironment(simulator)
|
||||||
|
return true
|
||||||
|
#else
|
||||||
|
return false
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private func machineIdentifier() -> String {
|
||||||
|
var systemInfo = utsname()
|
||||||
|
uname(&systemInfo)
|
||||||
|
let mirror = Mirror(reflecting: systemInfo.machine)
|
||||||
|
let identifier = mirror.children.reduce(into: "") { value, element in
|
||||||
|
guard let byte = element.value as? Int8, byte != 0 else { return }
|
||||||
|
value.append(String(UnicodeScalar(UInt8(byte))))
|
||||||
|
}
|
||||||
|
return identifier
|
||||||
|
}
|
||||||
|
}
|
||||||
722
ios/Runner/RecordingPlugin.swift
Normal file
@@ -0,0 +1,722 @@
|
|||||||
|
import AVFoundation
|
||||||
|
import Flutter
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
private enum RecordingState: String {
|
||||||
|
case idle
|
||||||
|
case previewing
|
||||||
|
case recording
|
||||||
|
case stopping
|
||||||
|
case error
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct RecordingStatus {
|
||||||
|
let state: RecordingState
|
||||||
|
let outputPath: String?
|
||||||
|
let elapsedMillis: Int
|
||||||
|
let message: String?
|
||||||
|
|
||||||
|
init(
|
||||||
|
state: RecordingState,
|
||||||
|
outputPath: String? = nil,
|
||||||
|
elapsedMillis: Int = 0,
|
||||||
|
message: String? = nil
|
||||||
|
) {
|
||||||
|
self.state = state
|
||||||
|
self.outputPath = outputPath
|
||||||
|
self.elapsedMillis = elapsedMillis
|
||||||
|
self.message = message
|
||||||
|
}
|
||||||
|
|
||||||
|
func toMap() -> [String: Any] {
|
||||||
|
var map: [String: Any] = [
|
||||||
|
"state": state.rawValue,
|
||||||
|
"elapsedMillis": elapsedMillis,
|
||||||
|
]
|
||||||
|
if let outputPath {
|
||||||
|
map["outputPath"] = outputPath
|
||||||
|
}
|
||||||
|
if let message {
|
||||||
|
map["message"] = message
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class RecordingPreviewView: UIView {
|
||||||
|
override class var layerClass: AnyClass {
|
||||||
|
AVCaptureVideoPreviewLayer.self
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewLayer: AVCaptureVideoPreviewLayer {
|
||||||
|
layer as! AVCaptureVideoPreviewLayer
|
||||||
|
}
|
||||||
|
|
||||||
|
override init(frame: CGRect) {
|
||||||
|
super.init(frame: frame)
|
||||||
|
previewLayer.videoGravity = .resizeAspectFill
|
||||||
|
backgroundColor = .black
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
super.init(coder: coder)
|
||||||
|
previewLayer.videoGravity = .resizeAspectFill
|
||||||
|
backgroundColor = .black
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class RecordingPreviewPlatformView: NSObject, FlutterPlatformView {
|
||||||
|
private let previewView: RecordingPreviewView
|
||||||
|
|
||||||
|
init(frame: CGRect) {
|
||||||
|
previewView = RecordingPreviewView(frame: frame)
|
||||||
|
super.init()
|
||||||
|
RecordingCameraController.shared.attach(previewView: previewView)
|
||||||
|
}
|
||||||
|
|
||||||
|
func view() -> UIView {
|
||||||
|
previewView
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
RecordingCameraController.shared.detach(previewView: previewView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class RecordingPreviewFactory: NSObject, FlutterPlatformViewFactory {
|
||||||
|
func create(
|
||||||
|
withFrame frame: CGRect,
|
||||||
|
viewIdentifier viewId: Int64,
|
||||||
|
arguments args: Any?
|
||||||
|
) -> FlutterPlatformView {
|
||||||
|
RecordingPreviewPlatformView(frame: frame)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
|
||||||
|
FlutterStandardMessageCodec.sharedInstance()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class RecordingCameraController: NSObject, AVCaptureFileOutputRecordingDelegate {
|
||||||
|
static let shared = RecordingCameraController()
|
||||||
|
|
||||||
|
private let session = AVCaptureSession()
|
||||||
|
private let sessionQueue = DispatchQueue(label: "recording.camera.session")
|
||||||
|
private let movieOutput = AVCaptureMovieFileOutput()
|
||||||
|
|
||||||
|
private weak var previewView: RecordingPreviewView?
|
||||||
|
private var videoInput: AVCaptureDeviceInput?
|
||||||
|
private var audioInput: AVCaptureDeviceInput?
|
||||||
|
private var configured = false
|
||||||
|
private var latestOutputPath: String?
|
||||||
|
private var latestFileSaved = true
|
||||||
|
private var latestFileErrorMessage: String?
|
||||||
|
private var pendingDisplayName: String?
|
||||||
|
private var recordingStartedAt: Date?
|
||||||
|
private var elapsedTimer: Timer?
|
||||||
|
private var pendingStopResult: FlutterResult?
|
||||||
|
private var currentZoomRatio: CGFloat = 1.0
|
||||||
|
|
||||||
|
private(set) var status = RecordingStatus(state: .idle) {
|
||||||
|
didSet {
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.statusListener?(self.currentStatusMap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var statusListener: (([String: Any]) -> Void)?
|
||||||
|
|
||||||
|
func attach(previewView: RecordingPreviewView) {
|
||||||
|
let bindPreview = { [weak self, weak previewView] in
|
||||||
|
guard let self, let previewView else { return }
|
||||||
|
self.previewView = previewView
|
||||||
|
previewView.previewLayer.session = self.session
|
||||||
|
}
|
||||||
|
if Thread.isMainThread {
|
||||||
|
bindPreview()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async(execute: bindPreview)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func detach(previewView: RecordingPreviewView) {
|
||||||
|
let unbindPreview = { [weak self, weak previewView] in
|
||||||
|
guard let self, let previewView else { return }
|
||||||
|
if self.previewView === previewView {
|
||||||
|
previewView.previewLayer.session = nil
|
||||||
|
self.previewView = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if Thread.isMainThread {
|
||||||
|
unbindPreview()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async(execute: unbindPreview)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func initializePreview(result: @escaping FlutterResult) {
|
||||||
|
guard let previewView else {
|
||||||
|
result(
|
||||||
|
FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
previewView.previewLayer.session = session
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
|
do {
|
||||||
|
try self.configureSession(withAudio: self.isMicrophoneAuthorized())
|
||||||
|
if !self.session.isRunning {
|
||||||
|
self.session.startRunning()
|
||||||
|
}
|
||||||
|
self.updateStatus(RecordingStatus(state: .previewing))
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(self.currentStatusMap())
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
self.updateStatus(RecordingStatus(state: .error, message: error.localizedDescription))
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(
|
||||||
|
FlutterError(
|
||||||
|
code: "PREVIEW_FAILED",
|
||||||
|
message: error.localizedDescription,
|
||||||
|
details: nil
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func startRecording(withAudio: Bool, displayName: String?, result: @escaping FlutterResult) {
|
||||||
|
guard previewView != nil else {
|
||||||
|
result(
|
||||||
|
FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
|
do {
|
||||||
|
try self.configureSession(withAudio: withAudio && self.isMicrophoneAuthorized())
|
||||||
|
if !self.session.isRunning {
|
||||||
|
self.session.startRunning()
|
||||||
|
}
|
||||||
|
|
||||||
|
guard !self.movieOutput.isRecording else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(FlutterError(code: "START_FAILED", message: "Already recording", details: nil))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pendingDisplayName = displayName
|
||||||
|
self.latestFileSaved = true
|
||||||
|
self.latestFileErrorMessage = nil
|
||||||
|
let outputURL = try self.createOutputURL(displayName: displayName)
|
||||||
|
self.latestOutputPath = outputURL.path
|
||||||
|
self.recordingStartedAt = Date()
|
||||||
|
self.updateStatus(RecordingStatus(state: .recording, outputPath: outputURL.path))
|
||||||
|
self.movieOutput.startRecording(to: outputURL, recordingDelegate: self)
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.startElapsedTimer()
|
||||||
|
result([
|
||||||
|
"outputPath": outputURL.path,
|
||||||
|
"status": self.currentStatusMap(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
self.updateStatus(RecordingStatus(state: .error, message: error.localizedDescription))
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(
|
||||||
|
FlutterError(
|
||||||
|
code: "START_FAILED",
|
||||||
|
message: error.localizedDescription,
|
||||||
|
details: nil
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopRecording(result: @escaping FlutterResult) {
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
|
guard self.movieOutput.isRecording else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
var payload: [String: Any] = [
|
||||||
|
"outputPath": self.latestOutputPath as Any,
|
||||||
|
"status": self.currentStatusMap(),
|
||||||
|
"fileSaved": self.latestFileSaved,
|
||||||
|
]
|
||||||
|
if !self.latestFileSaved {
|
||||||
|
payload["fileErrorMessage"] =
|
||||||
|
self.latestFileErrorMessage ?? "保存到文件夹失败"
|
||||||
|
}
|
||||||
|
result(payload)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pendingStopResult = result
|
||||||
|
self.updateStatus(RecordingStatus(state: .stopping, outputPath: self.latestOutputPath))
|
||||||
|
self.movieOutput.stopRecording()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func disposePreview(result: @escaping FlutterResult) {
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
|
if self.movieOutput.isRecording {
|
||||||
|
self.movieOutput.stopRecording()
|
||||||
|
}
|
||||||
|
if self.session.isRunning {
|
||||||
|
self.session.stopRunning()
|
||||||
|
}
|
||||||
|
self.session.beginConfiguration()
|
||||||
|
for input in self.session.inputs {
|
||||||
|
self.session.removeInput(input)
|
||||||
|
}
|
||||||
|
for output in self.session.outputs {
|
||||||
|
self.session.removeOutput(output)
|
||||||
|
}
|
||||||
|
self.session.commitConfiguration()
|
||||||
|
self.videoInput = nil
|
||||||
|
self.audioInput = nil
|
||||||
|
self.currentZoomRatio = 1.0
|
||||||
|
self.configured = false
|
||||||
|
self.updateStatus(RecordingStatus(state: .idle))
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.stopElapsedTimer()
|
||||||
|
result(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func currentStatusMap() -> [String: Any] {
|
||||||
|
if status.state == .recording {
|
||||||
|
return RecordingStatus(
|
||||||
|
state: .recording,
|
||||||
|
outputPath: latestOutputPath,
|
||||||
|
elapsedMillis: elapsedMillis()
|
||||||
|
).toMap()
|
||||||
|
}
|
||||||
|
return status.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
func zoomCapabilities(result: @escaping FlutterResult) {
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
let capabilities = self.currentZoomCapabilitiesMap()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(capabilities)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setZoomRatio(_ ratio: CGFloat, result: @escaping FlutterResult) {
|
||||||
|
sessionQueue.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
guard let device = self.videoInput?.device else {
|
||||||
|
self.currentZoomRatio = max(1.0, ratio)
|
||||||
|
let capabilities = self.currentZoomCapabilitiesMap()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(capabilities)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
// 入参是显示倍率(1.0x = 主摄),按 S 基准换算回设备 zoomFactor。
|
||||||
|
let baseline = self.mainBaselineFactor(for: device)
|
||||||
|
let nextZoom = self.clampedZoomRatio(ratio * baseline, for: device)
|
||||||
|
try device.lockForConfiguration()
|
||||||
|
device.videoZoomFactor = nextZoom
|
||||||
|
device.unlockForConfiguration()
|
||||||
|
self.currentZoomRatio = nextZoom
|
||||||
|
let capabilities = self.currentZoomCapabilitiesMap()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(capabilities)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(
|
||||||
|
FlutterError(
|
||||||
|
code: "ZOOM_FAILED",
|
||||||
|
message: error.localizedDescription,
|
||||||
|
details: nil
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileOutput(
|
||||||
|
_ output: AVCaptureFileOutput,
|
||||||
|
didFinishRecordingTo outputFileURL: URL,
|
||||||
|
from connections: [AVCaptureConnection],
|
||||||
|
error: Error?
|
||||||
|
) {
|
||||||
|
let stopResult = pendingStopResult
|
||||||
|
pendingStopResult = nil
|
||||||
|
|
||||||
|
if let error {
|
||||||
|
latestFileSaved = false
|
||||||
|
latestFileErrorMessage = error.localizedDescription
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
state: .error, outputPath: latestOutputPath, message: error.localizedDescription))
|
||||||
|
finishStopRecording(stopResult: stopResult)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
latestFileSaved = true
|
||||||
|
latestFileErrorMessage = nil
|
||||||
|
latestOutputPath = outputFileURL.path
|
||||||
|
guard FileManager.default.fileExists(atPath: outputFileURL.path) else {
|
||||||
|
latestFileSaved = false
|
||||||
|
latestFileErrorMessage = "录制文件未生成"
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
state: .error,
|
||||||
|
outputPath: latestOutputPath,
|
||||||
|
message: latestFileErrorMessage
|
||||||
|
)
|
||||||
|
)
|
||||||
|
finishStopRecording(stopResult: stopResult)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
state: .previewing,
|
||||||
|
outputPath: latestOutputPath,
|
||||||
|
elapsedMillis: elapsedMillis()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
finishStopRecording(stopResult: stopResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func finishStopRecording(stopResult: FlutterResult?) {
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.stopElapsedTimer()
|
||||||
|
var payload: [String: Any] = [
|
||||||
|
"outputPath": self.latestOutputPath as Any,
|
||||||
|
"status": self.currentStatusMap(),
|
||||||
|
"fileSaved": self.latestFileSaved,
|
||||||
|
]
|
||||||
|
if !self.latestFileSaved {
|
||||||
|
payload["fileErrorMessage"] =
|
||||||
|
self.latestFileErrorMessage ?? "保存到文件夹失败,请检查文件保存权限"
|
||||||
|
}
|
||||||
|
stopResult?(payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func configureSession(withAudio: Bool) throws {
|
||||||
|
if configured {
|
||||||
|
try configureAudioInput(enabled: withAudio)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let videoDevice = Self.preferredVideoDevice() else {
|
||||||
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 1,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "No camera device available"])
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextVideoInput = try AVCaptureDeviceInput(device: videoDevice)
|
||||||
|
|
||||||
|
session.beginConfiguration()
|
||||||
|
session.sessionPreset = .high
|
||||||
|
|
||||||
|
guard session.canAddInput(nextVideoInput) else {
|
||||||
|
session.commitConfiguration()
|
||||||
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 2,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "Cannot add camera input"])
|
||||||
|
}
|
||||||
|
session.addInput(nextVideoInput)
|
||||||
|
videoInput = nextVideoInput
|
||||||
|
|
||||||
|
guard session.canAddOutput(movieOutput) else {
|
||||||
|
session.commitConfiguration()
|
||||||
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 3,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "Cannot add movie output"])
|
||||||
|
}
|
||||||
|
session.addOutput(movieOutput)
|
||||||
|
session.commitConfiguration()
|
||||||
|
|
||||||
|
configured = true
|
||||||
|
// 默认以主摄(显示 1.0x)开场:虚拟多摄设备里主摄对应的 zoomFactor 是 S。
|
||||||
|
currentZoomRatio = mainBaselineFactor(for: videoDevice)
|
||||||
|
try applyCurrentZoom()
|
||||||
|
try configureAudioInput(enabled: withAudio)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 优先选用包含超广角的虚拟多摄设备,使 minAvailableVideoZoomFactor 能低于主摄(从而支持 0.6x)。
|
||||||
|
private static func preferredVideoDevice() -> AVCaptureDevice? {
|
||||||
|
let preferredTypes: [AVCaptureDevice.DeviceType] = [
|
||||||
|
.builtInTripleCamera,
|
||||||
|
.builtInDualWideCamera,
|
||||||
|
.builtInWideAngleCamera,
|
||||||
|
]
|
||||||
|
for type in preferredTypes {
|
||||||
|
if let device = AVCaptureDevice.default(type, for: .video, position: .back) {
|
||||||
|
return device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AVCaptureDevice.default(for: .video)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 虚拟多摄设备中「主摄(显示 1.0x)」对应的设备 zoomFactor 基准 S。
|
||||||
|
/// 取 ultra-wide → wide 的切换点;非虚拟设备无切换点时返回 1.0(向后兼容)。
|
||||||
|
private func mainBaselineFactor(for device: AVCaptureDevice) -> CGFloat {
|
||||||
|
if let first = device.virtualDeviceSwitchOverVideoZoomFactors.first {
|
||||||
|
let value = CGFloat(truncating: first)
|
||||||
|
if value > 0 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1.0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func currentZoomCapabilitiesMap() -> [String: Any] {
|
||||||
|
guard let device = videoInput?.device else {
|
||||||
|
return [
|
||||||
|
"zoomRatio": Double(currentZoomRatio),
|
||||||
|
"minZoomRatio": 1.0,
|
||||||
|
"maxZoomRatio": 3.0,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设备 zoomFactor 以 S 为基准换算成 App 使用的「显示倍率」(1.0x = 主摄)。
|
||||||
|
let baseline = mainBaselineFactor(for: device)
|
||||||
|
let minZoom = device.minAvailableVideoZoomFactor
|
||||||
|
let maxZoom = device.maxAvailableVideoZoomFactor
|
||||||
|
let zoom = clampedZoomRatio(device.videoZoomFactor, for: device)
|
||||||
|
currentZoomRatio = zoom
|
||||||
|
return [
|
||||||
|
"zoomRatio": Double(zoom / baseline),
|
||||||
|
"minZoomRatio": Double(minZoom / baseline),
|
||||||
|
"maxZoomRatio": Double(maxZoom / baseline),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func applyCurrentZoom() throws {
|
||||||
|
guard let device = videoInput?.device else { return }
|
||||||
|
let nextZoom = clampedZoomRatio(currentZoomRatio, for: device)
|
||||||
|
try device.lockForConfiguration()
|
||||||
|
device.videoZoomFactor = nextZoom
|
||||||
|
device.unlockForConfiguration()
|
||||||
|
currentZoomRatio = nextZoom
|
||||||
|
}
|
||||||
|
|
||||||
|
private func clampedZoomRatio(_ ratio: CGFloat, for device: AVCaptureDevice) -> CGFloat {
|
||||||
|
min(max(ratio, device.minAvailableVideoZoomFactor), device.maxAvailableVideoZoomFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func configureAudioInput(enabled: Bool) throws {
|
||||||
|
session.beginConfiguration()
|
||||||
|
defer { session.commitConfiguration() }
|
||||||
|
|
||||||
|
if let audioInput {
|
||||||
|
session.removeInput(audioInput)
|
||||||
|
self.audioInput = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard enabled else { return }
|
||||||
|
guard let audioDevice = AVCaptureDevice.default(for: .audio) else { return }
|
||||||
|
|
||||||
|
let nextAudioInput = try AVCaptureDeviceInput(device: audioDevice)
|
||||||
|
if session.canAddInput(nextAudioInput) {
|
||||||
|
session.addInput(nextAudioInput)
|
||||||
|
audioInput = nextAudioInput
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func isMicrophoneAuthorized() -> Bool {
|
||||||
|
AVCaptureDevice.authorizationStatus(for: .audio) == .authorized
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createOutputURL(displayName: String?) throws -> URL {
|
||||||
|
let baseURL = try FileManager.default.url(
|
||||||
|
for: .documentDirectory,
|
||||||
|
in: .userDomainMask,
|
||||||
|
appropriateFor: nil,
|
||||||
|
create: true
|
||||||
|
)
|
||||||
|
let recordingsURL = baseURL.appendingPathComponent("recordings", isDirectory: true)
|
||||||
|
try FileManager.default.createDirectory(at: recordingsURL, withIntermediateDirectories: true)
|
||||||
|
|
||||||
|
let fileName = Self.resolveFileName(displayName: displayName)
|
||||||
|
return uniqueOutputURL(in: recordingsURL, preferredFileName: fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func uniqueOutputURL(in directoryURL: URL, preferredFileName: String) -> URL {
|
||||||
|
let preferredURL = directoryURL.appendingPathComponent(preferredFileName)
|
||||||
|
guard !FileManager.default.fileExists(atPath: preferredURL.path) else {
|
||||||
|
let fileExtension = preferredURL.pathExtension
|
||||||
|
let baseName = preferredURL.deletingPathExtension().lastPathComponent
|
||||||
|
let timestamp = Self.fileNameDateFormatter.string(from: Date())
|
||||||
|
|
||||||
|
var index = 0
|
||||||
|
while true {
|
||||||
|
let suffix = index == 0 ? timestamp : "\(timestamp)_\(index)"
|
||||||
|
let nextName = fileExtension.isEmpty
|
||||||
|
? "\(baseName)_\(suffix)"
|
||||||
|
: "\(baseName)_\(suffix).\(fileExtension)"
|
||||||
|
let nextURL = directoryURL.appendingPathComponent(nextName)
|
||||||
|
if !FileManager.default.fileExists(atPath: nextURL.path) {
|
||||||
|
return nextURL
|
||||||
|
}
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return preferredURL
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func resolveFileName(displayName: String?) -> String {
|
||||||
|
let trimmed = displayName?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
|
if !trimmed.isEmpty {
|
||||||
|
let lower = trimmed.lowercased()
|
||||||
|
if lower.hasSuffix(".mov") || lower.hasSuffix(".mp4") {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
return "\(trimmed).mov"
|
||||||
|
}
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
formatter.dateFormat = "yyyyMMdd_HHmmss"
|
||||||
|
return "REC_\(formatter.string(from: Date())).mov"
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let fileNameDateFormatter: DateFormatter = {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
formatter.dateFormat = "yyyyMMdd_HHmmss"
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
|
|
||||||
|
private func updateStatus(_ next: RecordingStatus) {
|
||||||
|
status = next
|
||||||
|
}
|
||||||
|
|
||||||
|
private func elapsedMillis() -> Int {
|
||||||
|
guard let recordingStartedAt else { return 0 }
|
||||||
|
return max(0, Int(Date().timeIntervalSince(recordingStartedAt) * 1000))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func startElapsedTimer() {
|
||||||
|
stopElapsedTimer()
|
||||||
|
elapsedTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
|
||||||
|
guard let self, self.status.state == .recording else { return }
|
||||||
|
self.statusListener?(self.currentStatusMap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopElapsedTimer() {
|
||||||
|
elapsedTimer?.invalidate()
|
||||||
|
elapsedTimer = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum RecordingChannelNames {
|
||||||
|
static let packageName = "com.dronex.rec"
|
||||||
|
static let method = "\(packageName)/recording"
|
||||||
|
static let events = "\(packageName)/recording_events"
|
||||||
|
}
|
||||||
|
|
||||||
|
final class RecordingPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
|
||||||
|
private let controller = RecordingCameraController.shared
|
||||||
|
private var eventSink: FlutterEventSink?
|
||||||
|
|
||||||
|
static func register(with registrar: FlutterPluginRegistrar) {
|
||||||
|
let plugin = RecordingPlugin()
|
||||||
|
let messenger = registrar.messenger()
|
||||||
|
|
||||||
|
registrar.register(RecordingPreviewFactory(), withId: "recording-camera-preview")
|
||||||
|
|
||||||
|
let methodChannel = FlutterMethodChannel(
|
||||||
|
name: RecordingChannelNames.method,
|
||||||
|
binaryMessenger: messenger
|
||||||
|
)
|
||||||
|
registrar.addMethodCallDelegate(plugin, channel: methodChannel)
|
||||||
|
|
||||||
|
let eventChannel = FlutterEventChannel(
|
||||||
|
name: RecordingChannelNames.events,
|
||||||
|
binaryMessenger: messenger
|
||||||
|
)
|
||||||
|
eventChannel.setStreamHandler(plugin)
|
||||||
|
|
||||||
|
plugin.controller.statusListener = { [weak plugin] status in
|
||||||
|
plugin?.eventSink?(status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||||
|
switch call.method {
|
||||||
|
case "initializePreview":
|
||||||
|
controller.initializePreview(result: result)
|
||||||
|
case "startRecording":
|
||||||
|
let args = call.arguments as? [String: Any]
|
||||||
|
let withAudio = args?["withAudio"] as? Bool ?? true
|
||||||
|
let displayName = args?["displayName"] as? String
|
||||||
|
controller.startRecording(withAudio: withAudio, displayName: displayName, result: result)
|
||||||
|
case "stopRecording":
|
||||||
|
controller.stopRecording(result: result)
|
||||||
|
case "getZoomCapabilities":
|
||||||
|
controller.zoomCapabilities(result: result)
|
||||||
|
case "setZoomRatio":
|
||||||
|
let args = call.arguments as? [String: Any]
|
||||||
|
let ratio = args?["zoomRatio"] as? Double ?? 1.0
|
||||||
|
controller.setZoomRatio(CGFloat(ratio), result: result)
|
||||||
|
case "disposePreview":
|
||||||
|
controller.disposePreview(result: result)
|
||||||
|
case "getStatus":
|
||||||
|
result(controller.currentStatusMap())
|
||||||
|
case "hasNotificationPolicyAccess":
|
||||||
|
result(true)
|
||||||
|
case "openNotificationPolicySettings":
|
||||||
|
result(nil)
|
||||||
|
case "enableDoNotDisturb":
|
||||||
|
result(false)
|
||||||
|
case "disableDoNotDisturb":
|
||||||
|
result(nil)
|
||||||
|
case "isIgnoringBatteryOptimizations":
|
||||||
|
result(true)
|
||||||
|
case "openBatteryOptimizationSettings":
|
||||||
|
result(nil)
|
||||||
|
case "setImmersiveMode":
|
||||||
|
result(nil)
|
||||||
|
case "isForegroundServiceRunning":
|
||||||
|
result(false)
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink)
|
||||||
|
-> FlutterError?
|
||||||
|
{
|
||||||
|
eventSink = events
|
||||||
|
events(controller.currentStatusMap())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func onCancel(withArguments arguments: Any?) -> FlutterError? {
|
||||||
|
eventSink = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,50 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:flutter_template/app/config/app_config.dart';
|
|
||||||
import 'package:flutter_template/app/router/app_navigator.dart';
|
|
||||||
import 'package:flutter_template/app/theme/app_theme.dart';
|
|
||||||
import 'package:flutter_template/features/demo/demo_page.dart';
|
|
||||||
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||||||
|
import 'package:recording_tool/app/config/app_config.dart';
|
||||||
|
import 'package:recording_tool/app/router/app_navigator.dart';
|
||||||
|
import 'package:recording_tool/app/theme/app_theme.dart';
|
||||||
|
import 'package:recording_tool/features/recording/pages/page_record.dart';
|
||||||
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
|
|
||||||
class FlutterTemplateApp extends StatelessWidget {
|
class FlutterTemplateApp extends ConsumerStatefulWidget {
|
||||||
const FlutterTemplateApp({super.key});
|
const FlutterTemplateApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<FlutterTemplateApp> createState() => _FlutterTemplateAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FlutterTemplateAppState extends ConsumerState<FlutterTemplateApp>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
ref.read(recordingViewModelProvider.notifier).getClipboardContent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
|
ref.read(recordingViewModelProvider.notifier).getClipboardContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ScreenUtilInit(
|
return ScreenUtilInit(
|
||||||
designSize: const Size(375, 812),
|
designSize: AppConfig.designSize,
|
||||||
minTextAdapt: true,
|
minTextAdapt: true,
|
||||||
splitScreenMode: true,
|
splitScreenMode: true,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
@@ -43,8 +73,8 @@ class FlutterTemplateApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
home: RefreshConfiguration(
|
home: RefreshConfiguration(
|
||||||
enableLoadingWhenNoData: false,
|
enableLoadingWhenNoData: false,
|
||||||
headerTriggerDistance: 80,
|
headerTriggerDistance: 80.h,
|
||||||
child: const DemoPage(),
|
child: const RecordingPage(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_template/app/app.dart';
|
import 'package:recording_tool/app/app.dart';
|
||||||
import 'package:flutter_template/app/config/app_config.dart';
|
import 'package:recording_tool/app/config/app_config.dart';
|
||||||
import 'package:flutter_template/core/cache/app_storage.dart';
|
import 'package:recording_tool/core/cache/app_storage.dart';
|
||||||
import 'package:flutter_template/core/logging/app_logger.dart';
|
import 'package:recording_tool/core/logging/app_logger.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||||
|
|
||||||
class AppBootstrapper {
|
class AppBootstrapper {
|
||||||
AppBootstrapper._();
|
AppBootstrapper._();
|
||||||
@@ -18,12 +20,31 @@ class AppBootstrapper {
|
|||||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
|
|
||||||
await AppStorage.init();
|
await AppStorage.init();
|
||||||
final packageInfo = await PackageInfo.fromPlatform();
|
|
||||||
|
|
||||||
AppConfig.configure(environment: environment, packageInfo: packageInfo);
|
AppConfig.configure(environment: environment);
|
||||||
|
|
||||||
AppLogger.debug('App started in ${AppConfig.current.environment.name}');
|
AppLogger.debug('App started in ${AppConfig.current.environment.name}');
|
||||||
|
|
||||||
runApp(const ProviderScope(child: FlutterTemplateApp()));
|
runApp(const ProviderScope(child: FlutterTemplateApp()));
|
||||||
|
|
||||||
|
// Load native package metadata after the first frame can render.
|
||||||
|
// Awaiting MethodChannel calls before runApp() can stall the Android
|
||||||
|
// splash screen on some devices.
|
||||||
|
unawaited(_loadPackageInfo(environment));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _loadPackageInfo(AppEnvironment environment) async {
|
||||||
|
try {
|
||||||
|
final packageInfo = await AppPlatformInfo.packageInfo().timeout(
|
||||||
|
const Duration(seconds: 8),
|
||||||
|
);
|
||||||
|
AppConfig.configure(environment: environment, packageInfo: packageInfo);
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
AppLogger.debug(
|
||||||
|
'Native packageInfo unavailable',
|
||||||
|
error: error,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||||
|
|
||||||
enum AppEnvironment { dev, staging, prod }
|
enum AppEnvironment { dev, staging, prod }
|
||||||
|
|
||||||
@@ -18,13 +19,14 @@ class AppConfig {
|
|||||||
AppConfig._();
|
AppConfig._();
|
||||||
|
|
||||||
static late EnvironmentValues current;
|
static late EnvironmentValues current;
|
||||||
static PackageInfo? packageInfo;
|
static AppPackageInfo? packageInfo;
|
||||||
|
|
||||||
static const appName = 'Flutter Template';
|
static const appName = '飞行极控录像工作台';
|
||||||
|
static const designSize = Size(375, 812);
|
||||||
|
|
||||||
static void configure({
|
static void configure({
|
||||||
required AppEnvironment environment,
|
required AppEnvironment environment,
|
||||||
PackageInfo? packageInfo,
|
AppPackageInfo? packageInfo,
|
||||||
}) {
|
}) {
|
||||||
AppConfig.packageInfo = packageInfo;
|
AppConfig.packageInfo = packageInfo;
|
||||||
current = switch (environment) {
|
current = switch (environment) {
|
||||||
@@ -35,12 +37,12 @@ class AppConfig {
|
|||||||
),
|
),
|
||||||
AppEnvironment.staging => const EnvironmentValues(
|
AppEnvironment.staging => const EnvironmentValues(
|
||||||
environment: AppEnvironment.staging,
|
environment: AppEnvironment.staging,
|
||||||
baseUrl: 'https://staging.example.com/api',
|
baseUrl: 'https://example.com/api',
|
||||||
enableNetworkLog: true,
|
enableNetworkLog: true,
|
||||||
),
|
),
|
||||||
AppEnvironment.prod => const EnvironmentValues(
|
AppEnvironment.prod => const EnvironmentValues(
|
||||||
environment: AppEnvironment.prod,
|
environment: AppEnvironment.prod,
|
||||||
baseUrl: 'https://api.example.com',
|
baseUrl: 'https://example.com/api',
|
||||||
enableNetworkLog: false,
|
enableNetworkLog: false,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ class AppNavigator {
|
|||||||
barrierDismissible: dismissible,
|
barrierDismissible: dismissible,
|
||||||
transitionDuration: duration,
|
transitionDuration: duration,
|
||||||
reverseTransitionDuration: duration,
|
reverseTransitionDuration: duration,
|
||||||
pageBuilder: (_, __, ___) => page,
|
pageBuilder: (_, _, _) => page,
|
||||||
transitionsBuilder: (_, animation, __, child) {
|
transitionsBuilder: (_, animation, _, child) {
|
||||||
return FadeTransition(opacity: animation, child: child);
|
return FadeTransition(opacity: animation, child: child);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
class AppTheme {
|
class AppTheme {
|
||||||
AppTheme._();
|
AppTheme._();
|
||||||
@@ -32,20 +33,20 @@ class AppTheme {
|
|||||||
),
|
),
|
||||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
minimumSize: const Size(88, 44),
|
minimumSize: Size(88.w, 44.h),
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
textButtonTheme: TextButtonThemeData(
|
textButtonTheme: TextButtonThemeData(
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
outlinedButtonTheme: OutlinedButtonThemeData(
|
outlinedButtonTheme: OutlinedButtonThemeData(
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
minimumSize: const Size(88, 44),
|
minimumSize: Size(88.w, 44.h),
|
||||||
side: const BorderSide(color: border),
|
side: const BorderSide(color: border),
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -71,10 +72,10 @@ class AppTheme {
|
|||||||
class AppSpacing {
|
class AppSpacing {
|
||||||
AppSpacing._();
|
AppSpacing._();
|
||||||
|
|
||||||
static const double xs = 4;
|
static double get xs => 4.r;
|
||||||
static const double sm = 8;
|
static double get sm => 8.r;
|
||||||
static const double md = 12;
|
static double get md => 12.r;
|
||||||
static const double lg = 16;
|
static double get lg => 16.r;
|
||||||
static const double xl = 24;
|
static double get xl => 24.r;
|
||||||
static const double xxl = 32;
|
static double get xxl => 32.r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_template/core/network/api_exception.dart';
|
import 'package:recording_tool/core/network/api_exception.dart';
|
||||||
import 'package:flutter_template/core/network/api_response.dart';
|
import 'package:recording_tool/core/network/api_response.dart';
|
||||||
import 'package:flutter_template/core/network/http_method.dart';
|
import 'package:recording_tool/core/network/http_method.dart';
|
||||||
|
|
||||||
typedef JsonParser<T> = T Function(dynamic json);
|
typedef JsonParser<T> = T Function(dynamic json);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_template/app/config/app_config.dart';
|
import 'package:recording_tool/app/config/app_config.dart';
|
||||||
import 'package:flutter_template/core/cache/app_storage.dart';
|
import 'package:recording_tool/core/cache/app_storage.dart';
|
||||||
import 'package:flutter_template/core/cache/storage_keys.dart';
|
import 'package:recording_tool/core/cache/storage_keys.dart';
|
||||||
import 'package:flutter_template/core/utils/device_utils.dart';
|
import 'package:recording_tool/core/utils/device_utils.dart';
|
||||||
|
|
||||||
class HeaderInterceptor extends Interceptor {
|
class HeaderInterceptor extends Interceptor {
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_template/core/network/network_state.dart';
|
import 'package:recording_tool/core/network/network_state.dart';
|
||||||
|
|
||||||
class NetworkMonitor {
|
class NetworkMonitor {
|
||||||
final _controller = StreamController<NetworkState>.broadcast();
|
final _controller = StreamController<NetworkState>.broadcast();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_template/core/network/network_monitor.dart';
|
import 'package:recording_tool/core/network/network_monitor.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_manager.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_manager.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_request.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_request.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class OfflineQueueInterceptor extends Interceptor {
|
class OfflineQueueInterceptor extends Interceptor {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_template/core/logging/app_logger.dart';
|
import 'package:recording_tool/core/logging/app_logger.dart';
|
||||||
import 'package:flutter_template/core/network/network_monitor.dart';
|
import 'package:recording_tool/core/network/network_monitor.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_state.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_state.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_storage.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_storage.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_request.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_request.dart';
|
||||||
|
|
||||||
class OfflineQueueManager {
|
class OfflineQueueManager {
|
||||||
OfflineQueueManager({
|
OfflineQueueManager({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter_template/core/cache/app_storage.dart';
|
import 'package:recording_tool/core/cache/app_storage.dart';
|
||||||
import 'package:flutter_template/core/cache/storage_keys.dart';
|
import 'package:recording_tool/core/cache/storage_keys.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_request.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_request.dart';
|
||||||
|
|
||||||
class OfflineQueueStorage {
|
class OfflineQueueStorage {
|
||||||
Future<List<OfflineRequest>> loadQueue() async {
|
Future<List<OfflineRequest>> loadQueue() async {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_template/app/config/app_config.dart';
|
import 'package:recording_tool/app/config/app_config.dart';
|
||||||
import 'package:flutter_template/core/network/api_client.dart';
|
import 'package:recording_tool/core/network/api_client.dart';
|
||||||
import 'package:flutter_template/core/network/header_interceptor.dart';
|
import 'package:recording_tool/core/network/header_interceptor.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_interceptor.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_interceptor.dart';
|
||||||
import 'package:flutter_template/core/network/providers/network_providers.dart';
|
import 'package:recording_tool/core/network/providers/network_providers.dart';
|
||||||
import 'package:flutter_template/core/network/providers/offline_queue_providers.dart';
|
import 'package:recording_tool/core/network/providers/offline_queue_providers.dart';
|
||||||
|
|
||||||
final dioProvider = Provider<Dio>((ref) {
|
final dioProvider = Provider<Dio>((ref) {
|
||||||
final dio = Dio(
|
final dio = Dio(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_template/core/network/network_monitor.dart';
|
import 'package:recording_tool/core/network/network_monitor.dart';
|
||||||
import 'package:flutter_template/core/network/network_state.dart';
|
import 'package:recording_tool/core/network/network_state.dart';
|
||||||
|
|
||||||
final networkMonitorProvider = Provider<NetworkMonitor>((ref) {
|
final networkMonitorProvider = Provider<NetworkMonitor>((ref) {
|
||||||
final monitor = NetworkMonitor()..start();
|
final monitor = NetworkMonitor()..start();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_manager.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_manager.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_state.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_state.dart';
|
||||||
import 'package:flutter_template/core/network/offline_queue/offline_queue_storage.dart';
|
import 'package:recording_tool/core/network/offline_queue/offline_queue_storage.dart';
|
||||||
import 'package:flutter_template/core/network/providers/network_providers.dart';
|
import 'package:recording_tool/core/network/providers/network_providers.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
final offlineQueueStorageProvider = Provider<OfflineQueueStorage>((ref) {
|
final offlineQueueStorageProvider = Provider<OfflineQueueStorage>((ref) {
|
||||||
|
|||||||
@@ -17,6 +17,24 @@ class PermissionService {
|
|||||||
return permissions.toList().request();
|
return permissions.toList().request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 仅对尚未授予的权限发起系统授权弹窗,已授予则直接返回当前状态。
|
||||||
|
static Future<Map<Permission, PermissionStatus>> requestMissing(
|
||||||
|
Iterable<Permission> permissions,
|
||||||
|
) async {
|
||||||
|
final result = <Permission, PermissionStatus>{};
|
||||||
|
for (final permission in permissions) {
|
||||||
|
final current = await permission.status;
|
||||||
|
if (current.isGranted ||
|
||||||
|
current.isLimited ||
|
||||||
|
current.isPermanentlyDenied) {
|
||||||
|
result[permission] = current;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[permission] = await permission.request();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool> ensure(
|
static Future<bool> ensure(
|
||||||
Permission permission, {
|
Permission permission, {
|
||||||
bool openSettingsWhenPermanentlyDenied = true,
|
bool openSettingsWhenPermanentlyDenied = true,
|
||||||
|
|||||||
86
lib/core/platform/app_platform_info.dart
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
|
||||||
|
|
||||||
|
class AppPackageInfo {
|
||||||
|
const AppPackageInfo({
|
||||||
|
required this.appName,
|
||||||
|
required this.packageName,
|
||||||
|
required this.version,
|
||||||
|
required this.buildNumber,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AppPackageInfo.fromMap(Map<Object?, Object?> map) {
|
||||||
|
return AppPackageInfo(
|
||||||
|
appName: map['appName'] as String? ?? '',
|
||||||
|
packageName: map['packageName'] as String? ?? '',
|
||||||
|
version: map['version'] as String? ?? '',
|
||||||
|
buildNumber: map['buildNumber'] as String? ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String appName;
|
||||||
|
final String packageName;
|
||||||
|
final String version;
|
||||||
|
final String buildNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppDeviceInfo {
|
||||||
|
const AppDeviceInfo({
|
||||||
|
required this.platform,
|
||||||
|
required this.isPhysicalDevice,
|
||||||
|
required this.values,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AppDeviceInfo.fromMap(Map<Object?, Object?> map) {
|
||||||
|
final values = <String, String>{};
|
||||||
|
for (final entry in map.entries) {
|
||||||
|
final key = entry.key;
|
||||||
|
final value = entry.value;
|
||||||
|
if (key is String && value != null) {
|
||||||
|
values[key] = value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final isPhysicalDevice = map['isPhysicalDevice'];
|
||||||
|
return AppDeviceInfo(
|
||||||
|
platform: map['platform'] as String? ?? Platform.operatingSystem,
|
||||||
|
isPhysicalDevice: isPhysicalDevice is bool ? isPhysicalDevice : true,
|
||||||
|
values: values,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String platform;
|
||||||
|
final bool isPhysicalDevice;
|
||||||
|
final Map<String, String> values;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppPlatformInfo {
|
||||||
|
AppPlatformInfo._();
|
||||||
|
|
||||||
|
static const MethodChannel _channel = MethodChannel(
|
||||||
|
'com.dronex.rec/platform_info',
|
||||||
|
);
|
||||||
|
|
||||||
|
static Future<AppPackageInfo> packageInfo() async {
|
||||||
|
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||||
|
'packageInfo',
|
||||||
|
);
|
||||||
|
return AppPackageInfo.fromMap(result ?? const <Object?, Object?>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<AppDeviceInfo> deviceInfo() async {
|
||||||
|
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||||
|
'deviceInfo',
|
||||||
|
);
|
||||||
|
return AppDeviceInfo.fromMap(result ?? const <Object?, Object?>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<DeviceHealthSnapshot> deviceHealth() async {
|
||||||
|
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||||
|
'deviceHealth',
|
||||||
|
);
|
||||||
|
return DeviceHealthSnapshot.fromMap(result ?? const <Object?, Object?>{});
|
||||||
|
}
|
||||||
|
}
|
||||||
25
lib/core/platform/device_health_checker.dart
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
|
||||||
|
|
||||||
|
class DeviceHealthChecker {
|
||||||
|
DeviceHealthChecker._();
|
||||||
|
|
||||||
|
static const int thresholdPercent = 10;
|
||||||
|
|
||||||
|
static const String lowBatteryMessage = '电量低于10%,请充电';
|
||||||
|
static const String lowStorageMessage = '内存低于10%,请清理内存';
|
||||||
|
|
||||||
|
static List<String> warningLines(DeviceHealthSnapshot snapshot) {
|
||||||
|
final lines = <String>[];
|
||||||
|
|
||||||
|
final battery = snapshot.batteryLevelPercent;
|
||||||
|
if (battery != null && battery < thresholdPercent) {
|
||||||
|
lines.add(lowBatteryMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshot.storageAvailablePercent < thresholdPercent) {
|
||||||
|
lines.add(lowStorageMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
lib/core/platform/device_health_snapshot.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class DeviceHealthSnapshot {
|
||||||
|
const DeviceHealthSnapshot({
|
||||||
|
this.batteryLevelPercent,
|
||||||
|
required this.storageAvailablePercent,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory DeviceHealthSnapshot.fromMap(Map<Object?, Object?> map) {
|
||||||
|
final batteryRaw = map['batteryLevelPercent'];
|
||||||
|
int? batteryLevelPercent;
|
||||||
|
if (batteryRaw is int) {
|
||||||
|
batteryLevelPercent = batteryRaw;
|
||||||
|
} else if (batteryRaw is num) {
|
||||||
|
batteryLevelPercent = batteryRaw.round();
|
||||||
|
}
|
||||||
|
|
||||||
|
final storageRaw = map['storageAvailablePercent'];
|
||||||
|
final storageAvailablePercent = switch (storageRaw) {
|
||||||
|
final num value => value.toDouble(),
|
||||||
|
_ => 100.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
return DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: batteryLevelPercent,
|
||||||
|
storageAvailablePercent: storageAvailablePercent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int? batteryLevelPercent;
|
||||||
|
final double storageAvailablePercent;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||||
|
|
||||||
class DeviceUtils {
|
class DeviceUtils {
|
||||||
DeviceUtils._();
|
DeviceUtils._();
|
||||||
@@ -19,36 +19,13 @@ class DeviceUtils {
|
|||||||
MediaQuery.paddingOf(context).bottom;
|
MediaQuery.paddingOf(context).bottom;
|
||||||
|
|
||||||
static Future<bool> isPhysicalDevice() async {
|
static Future<bool> isPhysicalDevice() async {
|
||||||
final plugin = DeviceInfoPlugin();
|
return (await AppPlatformInfo.deviceInfo()).isPhysicalDevice;
|
||||||
if (Platform.isAndroid) {
|
|
||||||
return (await plugin.androidInfo).isPhysicalDevice;
|
|
||||||
}
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
return (await plugin.iosInfo).isPhysicalDevice;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Map<String, String>> deviceInfo() async {
|
static Future<Map<String, String>> deviceInfo() async {
|
||||||
final plugin = DeviceInfoPlugin();
|
if (!Platform.isAndroid && !Platform.isIOS) {
|
||||||
if (Platform.isAndroid) {
|
return {'platform': Platform.operatingSystem};
|
||||||
final info = await plugin.androidInfo;
|
|
||||||
return {
|
|
||||||
'platform': 'android',
|
|
||||||
'brand': info.brand,
|
|
||||||
'model': info.model,
|
|
||||||
'systemVersion': info.version.release,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (Platform.isIOS) {
|
return (await AppPlatformInfo.deviceInfo()).values;
|
||||||
final info = await plugin.iosInfo;
|
|
||||||
return {
|
|
||||||
'platform': 'ios',
|
|
||||||
'brand': info.systemName,
|
|
||||||
'model': info.utsname.machine,
|
|
||||||
'systemVersion': info.systemVersion,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {'platform': Platform.operatingSystem};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
|
|
||||||
class DemoState {
|
|
||||||
const DemoState({this.count = 0, this.query = ''});
|
|
||||||
|
|
||||||
final int count;
|
|
||||||
final String query;
|
|
||||||
|
|
||||||
DemoState copyWith({int? count, String? query}) {
|
|
||||||
return DemoState(count: count ?? this.count, query: query ?? this.query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DemoController extends Notifier<DemoState> {
|
|
||||||
@override
|
|
||||||
DemoState build() => const DemoState();
|
|
||||||
|
|
||||||
void increment() {
|
|
||||||
state = state.copyWith(count: state.count + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateQuery(String query) {
|
|
||||||
state = state.copyWith(query: query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final demoControllerProvider = NotifierProvider<DemoController, DemoState>(
|
|
||||||
DemoController.new,
|
|
||||||
);
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:flutter_template/app/theme/app_theme.dart';
|
|
||||||
import 'package:flutter_template/features/demo/demo_controller.dart';
|
|
||||||
import 'package:flutter_template/shared/widgets/widgets.dart';
|
|
||||||
|
|
||||||
class DemoPage extends ConsumerWidget {
|
|
||||||
const DemoPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(demoControllerProvider);
|
|
||||||
final controller = ref.read(demoControllerProvider.notifier);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: const Text('Flutter Template')),
|
|
||||||
body: SafeAreaWrapper(
|
|
||||||
child: ListView(
|
|
||||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
|
||||||
children: [
|
|
||||||
AppSearchBar(hint: '搜索模板组件', onChanged: controller.updateQuery),
|
|
||||||
const SizedBox(height: AppSpacing.lg),
|
|
||||||
AppCard(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const AppAvatar(initials: 'T', size: 48),
|
|
||||||
const SizedBox(width: AppSpacing.md),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'通用 Flutter 快速开发模板',
|
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
'已内置网络、缓存、路由、主题、权限、日志和常用 UI 组件。',
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium
|
|
||||||
?.copyWith(
|
|
||||||
color: Theme.of(
|
|
||||||
context,
|
|
||||||
).colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: AppSpacing.md),
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 8,
|
|
||||||
children: const [
|
|
||||||
AppTag(label: 'Riverpod', tone: AppTagTone.info),
|
|
||||||
AppTag(label: 'Dio', tone: AppTagTone.success),
|
|
||||||
AppTag(label: '缓存', tone: AppTagTone.warning),
|
|
||||||
AppTag(label: '无业务代码'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: AppSpacing.lg),
|
|
||||||
AppCard(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'状态管理示例',
|
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
|
||||||
),
|
|
||||||
const SizedBox(height: AppSpacing.sm),
|
|
||||||
Text('当前计数:${state.count}'),
|
|
||||||
if (state.query.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: AppSpacing.sm),
|
|
||||||
Text('搜索关键字:${state.query}'),
|
|
||||||
],
|
|
||||||
const SizedBox(height: AppSpacing.md),
|
|
||||||
AppButton(
|
|
||||||
label: '增加计数',
|
|
||||||
icon: const Icon(Icons.add, size: 18),
|
|
||||||
onPressed: controller.increment,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: AppSpacing.lg),
|
|
||||||
AppStatusView(
|
|
||||||
status: AppViewStatus.empty,
|
|
||||||
empty: AppEmptyView(
|
|
||||||
title: '空状态组件',
|
|
||||||
message: '业务项目可替换图标、文案和操作按钮。',
|
|
||||||
action: AppButton(
|
|
||||||
label: '显示确认弹窗',
|
|
||||||
variant: AppButtonVariant.outline,
|
|
||||||
icon: const Icon(Icons.open_in_new, size: 18),
|
|
||||||
onPressed: () async {
|
|
||||||
final confirmed = await AppDialog.confirm(
|
|
||||||
context,
|
|
||||||
title: '模板弹窗',
|
|
||||||
message: '这是可复用的确认弹窗示例。',
|
|
||||||
);
|
|
||||||
if (confirmed == true) {
|
|
||||||
AppToast.show('已确认');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const SizedBox.shrink(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
281
lib/features/dialog/dialog-record.dart
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
// ignore_for_file: file_names
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/gen/assets.gen.dart';
|
||||||
|
|
||||||
|
/// 录制页统一弹窗,支持单按钮和双按钮。
|
||||||
|
class RecordDialog extends StatelessWidget {
|
||||||
|
const RecordDialog({super.key, required this.title, required this.actions});
|
||||||
|
|
||||||
|
static const _transitionDuration = Duration(milliseconds: 280);
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final List<RecordDialogAction> actions;
|
||||||
|
|
||||||
|
static Future<void> showSingle(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
required String buttonText,
|
||||||
|
VoidCallback? onPressed,
|
||||||
|
bool barrierDismissible = true,
|
||||||
|
}) {
|
||||||
|
return _present(
|
||||||
|
context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return RecordDialog(
|
||||||
|
title: title,
|
||||||
|
actions: [
|
||||||
|
RecordDialogAction.primary(
|
||||||
|
text: buttonText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> showDouble(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
required String leftText,
|
||||||
|
required String rightText,
|
||||||
|
VoidCallback? onLeftPressed,
|
||||||
|
VoidCallback? onRightPressed,
|
||||||
|
bool barrierDismissible = false,
|
||||||
|
}) {
|
||||||
|
return _present(
|
||||||
|
context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return RecordDialog(
|
||||||
|
title: title,
|
||||||
|
actions: [
|
||||||
|
RecordDialogAction.secondary(
|
||||||
|
text: leftText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onLeftPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
RecordDialogAction.primary(
|
||||||
|
text: rightText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onRightPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _present(
|
||||||
|
BuildContext context, {
|
||||||
|
required Widget Function(BuildContext dialogContext) builder,
|
||||||
|
required bool barrierDismissible,
|
||||||
|
}) {
|
||||||
|
return showGeneralDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
||||||
|
barrierColor: Colors.black54,
|
||||||
|
transitionDuration: _transitionDuration,
|
||||||
|
pageBuilder: (dialogContext, animation, secondaryAnimation) {
|
||||||
|
return builder(dialogContext);
|
||||||
|
},
|
||||||
|
transitionBuilder: _buildTransition,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildTransition(
|
||||||
|
BuildContext context,
|
||||||
|
Animation<double> animation,
|
||||||
|
Animation<double> secondaryAnimation,
|
||||||
|
Widget child,
|
||||||
|
) {
|
||||||
|
final curved = CurvedAnimation(
|
||||||
|
parent: animation,
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
reverseCurve: Curves.easeInCubic,
|
||||||
|
);
|
||||||
|
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 0.08),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(curved),
|
||||||
|
child: ScaleTransition(
|
||||||
|
scale: Tween<double>(begin: 0.92, end: 1).animate(curved),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final actionWidgets = actions
|
||||||
|
.map((action) => Expanded(child: _RecordDialogButton(action: action)))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Dialog(
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
insetPadding: EdgeInsets.symmetric(horizontal: 37.w),
|
||||||
|
child: ClipRRect(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
|
||||||
|
borderRadius: BorderRadius.circular(18.r),
|
||||||
|
child: Container(
|
||||||
|
width: 315.w,
|
||||||
|
// height: 188.r,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
|
||||||
|
borderRadius: BorderRadius.circular(18.r),
|
||||||
|
),
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
top: -88.r,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Image.asset(
|
||||||
|
Assets.images.imageDialogBg.path,
|
||||||
|
width: double.maxFinite,
|
||||||
|
height: 155.h,
|
||||||
|
fit: BoxFit.fitWidth,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(24.w, 44.h, 24.w, 26.h),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: const Color(0xFF333333),
|
||||||
|
fontSize: 19.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
height: 1.35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 22.h),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
for (
|
||||||
|
var index = 0;
|
||||||
|
index < actionWidgets.length;
|
||||||
|
index++
|
||||||
|
) ...[
|
||||||
|
if (index > 0) SizedBox(width: 16.w),
|
||||||
|
actionWidgets[index],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordDialogAction {
|
||||||
|
const RecordDialogAction._({
|
||||||
|
required this.text,
|
||||||
|
required this.onPressed,
|
||||||
|
required this.isPrimary,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory RecordDialogAction.primary({
|
||||||
|
required String text,
|
||||||
|
required VoidCallback onPressed,
|
||||||
|
}) {
|
||||||
|
return RecordDialogAction._(
|
||||||
|
text: text,
|
||||||
|
onPressed: onPressed,
|
||||||
|
isPrimary: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RecordDialogAction.secondary({
|
||||||
|
required String text,
|
||||||
|
required VoidCallback onPressed,
|
||||||
|
}) {
|
||||||
|
return RecordDialogAction._(
|
||||||
|
text: text,
|
||||||
|
onPressed: onPressed,
|
||||||
|
isPrimary: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
final VoidCallback onPressed;
|
||||||
|
final bool isPrimary;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordDialogButton extends StatelessWidget {
|
||||||
|
const _RecordDialogButton({required this.action});
|
||||||
|
|
||||||
|
final RecordDialogAction action;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final child = Center(
|
||||||
|
child: Text(
|
||||||
|
action.text,
|
||||||
|
style: TextStyle(
|
||||||
|
color: action.isPrimary ? Colors.white : const Color(0xFF333333),
|
||||||
|
fontSize: 18.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
height: 48.h,
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: action.onPressed,
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(24.r),
|
||||||
|
),
|
||||||
|
backgroundColor: action.isPrimary ? null : const Color(0xFFF2F2F2),
|
||||||
|
),
|
||||||
|
child: action.isPrimary
|
||||||
|
? DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: const LinearGradient(
|
||||||
|
colors: [Color(0xFF2F85FF), Color(0xFF5DCCF4)],
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(24.r),
|
||||||
|
),
|
||||||
|
child: SizedBox.expand(child: child),
|
||||||
|
)
|
||||||
|
: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
lib/features/recording/model/model_clipboard.dart
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/// 小程序复制到剪切板的录制信息。
|
||||||
|
class ClipboardRecordingModel {
|
||||||
|
final String title;
|
||||||
|
int? startTimestamp;
|
||||||
|
int? endTimestamp;
|
||||||
|
final String address;
|
||||||
|
|
||||||
|
/// 录制文件名模板,如「选手名称_选手ID_赛事名称_赛项」。
|
||||||
|
final String? filename;
|
||||||
|
|
||||||
|
ClipboardRecordingModel({
|
||||||
|
required this.title,
|
||||||
|
this.startTimestamp,
|
||||||
|
this.endTimestamp,
|
||||||
|
required this.address,
|
||||||
|
this.filename,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory ClipboardRecordingModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return ClipboardRecordingModel(
|
||||||
|
title: _readString(json, 'title'),
|
||||||
|
startTimestamp: _readOptionalInt(json, 'startTimestamp'),
|
||||||
|
endTimestamp: _readOptionalInt(json, 'endTimestamp'),
|
||||||
|
address: _readString(json, 'address'),
|
||||||
|
filename: _readOptionalString(json, 'filename'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'title': title,
|
||||||
|
'startTimestamp': startTimestamp,
|
||||||
|
'endTimestamp': endTimestamp,
|
||||||
|
'address': address,
|
||||||
|
if (filename != null) 'filename': filename,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static String? _readOptionalString(Map<String, dynamic> json, String key) {
|
||||||
|
final value = json[key];
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value is String && value.isNotEmpty) return value;
|
||||||
|
if (value is! String) {
|
||||||
|
throw FormatException('Clipboard field "$key" must be a String.');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _readString(Map<String, dynamic> json, String key) {
|
||||||
|
final value = json[key];
|
||||||
|
if (value is String) return value;
|
||||||
|
throw FormatException('Clipboard field "$key" must be a String.');
|
||||||
|
}
|
||||||
|
|
||||||
|
static int? _readOptionalInt(Map<String, dynamic> json, String key) {
|
||||||
|
final value = json[key];
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value is int) return value;
|
||||||
|
throw FormatException('Clipboard field "$key" must be an int.');
|
||||||
|
}
|
||||||
|
}
|
||||||
52
lib/features/recording/model/model_recording.dart
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import 'package:recording_tool/features/recording/model/model_clipboard.dart';
|
||||||
|
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
||||||
|
|
||||||
|
class RecordingModel {
|
||||||
|
/// 剪切板内容
|
||||||
|
final ClipboardRecordingModel clipboardRecordingModel;
|
||||||
|
|
||||||
|
/// 剪切板是否包含有效的小程序录制信息
|
||||||
|
final bool hasValidClipboardInfo;
|
||||||
|
|
||||||
|
/// 录制会话状态
|
||||||
|
final RecordingSessionState session;
|
||||||
|
|
||||||
|
RecordingModel({
|
||||||
|
required this.clipboardRecordingModel,
|
||||||
|
this.hasValidClipboardInfo = false,
|
||||||
|
this.session = const RecordingSessionState(),
|
||||||
|
});
|
||||||
|
|
||||||
|
bool get isRecording => session.isRecording;
|
||||||
|
|
||||||
|
factory RecordingModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return RecordingModel(
|
||||||
|
clipboardRecordingModel: ClipboardRecordingModel.fromJson(
|
||||||
|
json['clipboardRecordingModel'],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {'clipboardRecordingModel': clipboardRecordingModel.toJson()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 剪切板是否包含可用于命名的 [ClipboardRecordingModel.filename]。
|
||||||
|
bool get hasClipboardFilename {
|
||||||
|
final name = clipboardRecordingModel.filename?.trim();
|
||||||
|
return hasValidClipboardInfo && name != null && name.isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordingModel copyWith({
|
||||||
|
ClipboardRecordingModel? clipboardRecordingModel,
|
||||||
|
bool? hasValidClipboardInfo,
|
||||||
|
RecordingSessionState? session,
|
||||||
|
}) {
|
||||||
|
return RecordingModel(
|
||||||
|
clipboardRecordingModel:
|
||||||
|
clipboardRecordingModel ?? this.clipboardRecordingModel,
|
||||||
|
hasValidClipboardInfo:
|
||||||
|
hasValidClipboardInfo ?? this.hasValidClipboardInfo,
|
||||||
|
session: session ?? this.session,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
95
lib/features/recording/model/model_recording_session.dart
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
|
||||||
|
/// 录制会话状态(相机预览、权限、录制进度等)。
|
||||||
|
class RecordingSessionState {
|
||||||
|
const RecordingSessionState({
|
||||||
|
this.status = const RecordingStatus(state: RecordingState.idle),
|
||||||
|
this.isTouchLocked = true,
|
||||||
|
this.isPreviewReady = false,
|
||||||
|
this.isStartingRecording = false,
|
||||||
|
this.hasDndAccess = false,
|
||||||
|
this.isBatteryOptimizedIgnored = true,
|
||||||
|
this.notificationsGranted = true,
|
||||||
|
this.isMicrophoneGranted = false,
|
||||||
|
this.zoomRatio = 1.0,
|
||||||
|
this.minZoomRatio = 1.0,
|
||||||
|
this.maxZoomRatio = 3.0,
|
||||||
|
this.lastOutputPath,
|
||||||
|
this.lastSavedDisplayName,
|
||||||
|
this.errorMessage,
|
||||||
|
this.permissionWarning,
|
||||||
|
this.fileSaveFailed = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final RecordingStatus status;
|
||||||
|
final bool isTouchLocked;
|
||||||
|
final bool isPreviewReady;
|
||||||
|
final bool isStartingRecording;
|
||||||
|
final bool hasDndAccess;
|
||||||
|
final bool isBatteryOptimizedIgnored;
|
||||||
|
final bool notificationsGranted;
|
||||||
|
final bool isMicrophoneGranted;
|
||||||
|
final double zoomRatio;
|
||||||
|
final double minZoomRatio;
|
||||||
|
final double maxZoomRatio;
|
||||||
|
final String? lastOutputPath;
|
||||||
|
final String? lastSavedDisplayName;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? permissionWarning;
|
||||||
|
final bool fileSaveFailed;
|
||||||
|
|
||||||
|
bool get isRecording => status.isRecording;
|
||||||
|
|
||||||
|
String get elapsedLabel {
|
||||||
|
final totalSeconds = status.elapsedMillis ~/ 1000;
|
||||||
|
final hours = (totalSeconds ~/ 3600).toString().padLeft(2, '0');
|
||||||
|
final minutes = ((totalSeconds % 3600) ~/ 60).toString().padLeft(2, '0');
|
||||||
|
final seconds = (totalSeconds % 60).toString().padLeft(2, '0');
|
||||||
|
return '$hours:$minutes:$seconds';
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordingSessionState copyWith({
|
||||||
|
RecordingStatus? status,
|
||||||
|
bool? isTouchLocked,
|
||||||
|
bool? isPreviewReady,
|
||||||
|
bool? isStartingRecording,
|
||||||
|
bool? hasDndAccess,
|
||||||
|
bool? isBatteryOptimizedIgnored,
|
||||||
|
bool? notificationsGranted,
|
||||||
|
bool? isMicrophoneGranted,
|
||||||
|
double? zoomRatio,
|
||||||
|
double? minZoomRatio,
|
||||||
|
double? maxZoomRatio,
|
||||||
|
String? lastOutputPath,
|
||||||
|
String? lastSavedDisplayName,
|
||||||
|
String? errorMessage,
|
||||||
|
String? permissionWarning,
|
||||||
|
bool? fileSaveFailed,
|
||||||
|
bool clearPermissionWarning = false,
|
||||||
|
bool clearLastSaved = false,
|
||||||
|
}) {
|
||||||
|
return RecordingSessionState(
|
||||||
|
status: status ?? this.status,
|
||||||
|
isTouchLocked: isTouchLocked ?? this.isTouchLocked,
|
||||||
|
isPreviewReady: isPreviewReady ?? this.isPreviewReady,
|
||||||
|
isStartingRecording: isStartingRecording ?? this.isStartingRecording,
|
||||||
|
hasDndAccess: hasDndAccess ?? this.hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored:
|
||||||
|
isBatteryOptimizedIgnored ?? this.isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: notificationsGranted ?? this.notificationsGranted,
|
||||||
|
isMicrophoneGranted: isMicrophoneGranted ?? this.isMicrophoneGranted,
|
||||||
|
zoomRatio: zoomRatio ?? this.zoomRatio,
|
||||||
|
minZoomRatio: minZoomRatio ?? this.minZoomRatio,
|
||||||
|
maxZoomRatio: maxZoomRatio ?? this.maxZoomRatio,
|
||||||
|
lastOutputPath: lastOutputPath ?? this.lastOutputPath,
|
||||||
|
lastSavedDisplayName: clearLastSaved
|
||||||
|
? null
|
||||||
|
: (lastSavedDisplayName ?? this.lastSavedDisplayName),
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
permissionWarning: clearPermissionWarning
|
||||||
|
? null
|
||||||
|
: (permissionWarning ?? this.permissionWarning),
|
||||||
|
fileSaveFailed: fileSaveFailed ?? this.fileSaveFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
491
lib/features/recording/pages/page_record.dart
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_checker.dart';
|
||||||
|
import 'package:recording_tool/features/dialog/dialog-record.dart';
|
||||||
|
import 'package:recording_tool/features/recording/model/model_recording.dart';
|
||||||
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
import 'package:recording_tool/features/recording/utils/recording_display_name.dart';
|
||||||
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_camera_preview.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_footer.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_header.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_timer.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_hud.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_loading_overlay.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_saved_dialog.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_touch_lock_overlay.dart';
|
||||||
|
import 'package:recording_tool/shared/widgets/widgets.dart';
|
||||||
|
|
||||||
|
/// 录制页入口
|
||||||
|
class RecordingPage extends ConsumerStatefulWidget {
|
||||||
|
const RecordingPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 创建页面状态
|
||||||
|
ConsumerState<RecordingPage> createState() => _RecordingPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingPageState extends ConsumerState<RecordingPage> {
|
||||||
|
var _immersiveApplied = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 首帧后初始化录制流程
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => _bootstrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 检查设备健康状态并弹窗提示
|
||||||
|
Future<void> _checkAndShowDeviceHealthAlerts() async {
|
||||||
|
final snapshot = await AppPlatformInfo.deviceHealth();
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
final lines = DeviceHealthChecker.warningLines(snapshot);
|
||||||
|
if (lines.isEmpty) return;
|
||||||
|
|
||||||
|
await RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: lines.join('\n'),
|
||||||
|
buttonText: '确定',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 页面启动:健康检查、读剪贴板、进入录制模式、准备相机会话
|
||||||
|
Future<void> _bootstrap() async {
|
||||||
|
await _checkAndShowDeviceHealthAlerts();
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
final clipboardResult = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.getClipboardContent();
|
||||||
|
if (!mounted) return;
|
||||||
|
if (clipboardResult == ClipboardReadResult.invalid) {
|
||||||
|
AppToast.show('无选手信息');
|
||||||
|
}
|
||||||
|
await _enterRecordingMode();
|
||||||
|
// Allow PlatformView to attach before binding CameraX preview.
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||||
|
if (!mounted) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).prepareSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Android 进入沉浸式全屏
|
||||||
|
Future<void> _enterRecordingMode() async {
|
||||||
|
if (!Platform.isAndroid) return;
|
||||||
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
|
await RecordingPlatform.setImmersiveMode(enabled: true);
|
||||||
|
_immersiveApplied = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析保存成功弹窗的标题文案
|
||||||
|
String _savedDialogSessionTitle(
|
||||||
|
RecordingModel recordingInfo,
|
||||||
|
String? savedName,
|
||||||
|
) {
|
||||||
|
final clipboard = recordingInfo.clipboardRecordingModel;
|
||||||
|
if (recordingInfo.hasValidClipboardInfo &&
|
||||||
|
clipboard.title.trim().isNotEmpty) {
|
||||||
|
return clipboard.title.trim();
|
||||||
|
}
|
||||||
|
if (savedName != null && savedName.isNotEmpty) {
|
||||||
|
return resolveRecordingDisplayName(savedName);
|
||||||
|
}
|
||||||
|
return '录制完成';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从剪贴板粘贴赛事信息(与 header「粘贴选手信息」一致)。
|
||||||
|
Future<void> _pasteEventInfo() async {
|
||||||
|
final result = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.getClipboardContent();
|
||||||
|
if (!mounted) return;
|
||||||
|
if (result != ClipboardReadResult.success) {
|
||||||
|
AppToast.show('无选手信息');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 无选手信息时弹窗提示
|
||||||
|
Future<void> _showNoPlayerInfoDialog() {
|
||||||
|
return RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: '无选手信息!',
|
||||||
|
buttonText: '粘贴',
|
||||||
|
onPressed: _pasteEventInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 根据缺失权限生成弹窗文案。
|
||||||
|
String _recordingPermissionDialogTitle(RecordingRequiredPermissions result) {
|
||||||
|
if (!result.cameraGranted && !result.microphoneGranted) {
|
||||||
|
return '录制需要开启相机和录音权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
if (!result.cameraGranted) {
|
||||||
|
return '录制需要开启相机权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
return '录制需要开启录音权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 开始录制前检测相机、录音权限,未授予则弹窗并跳转系统设置。
|
||||||
|
Future<bool> _ensureRecordingPermissions() async {
|
||||||
|
final result = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.ensureCameraAndMicrophonePermissions();
|
||||||
|
if (result.allGranted) {
|
||||||
|
final ready = ref.read(recordingViewModelProvider).session.isPreviewReady;
|
||||||
|
if (ready) return true;
|
||||||
|
if (!mounted) return false;
|
||||||
|
AppToast.show('相机预览启动失败,请重试');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!mounted) return false;
|
||||||
|
|
||||||
|
await RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: _recordingPermissionDialogTitle(result),
|
||||||
|
buttonText: '确定',
|
||||||
|
onPressed: openAppSettings,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 点击开始录制:校验剪贴板、权限与健康状态
|
||||||
|
Future<void> _onStartRecording() async {
|
||||||
|
final recordingInfo = ref.read(recordingViewModelProvider);
|
||||||
|
if (!recordingInfo.hasClipboardFilename) {
|
||||||
|
await _showNoPlayerInfoDialog();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!await _ensureRecordingPermissions()) return;
|
||||||
|
if (!mounted) return;
|
||||||
|
await _checkAndShowDeviceHealthAlerts();
|
||||||
|
if (!mounted) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).startRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止录制并按结果显示保存提示。
|
||||||
|
Future<void> _stopRecordingAndShowResult() async {
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).stopRecording();
|
||||||
|
if (!mounted) return;
|
||||||
|
final latest = ref.read(recordingViewModelProvider).session;
|
||||||
|
if (latest.fileSaveFailed) {
|
||||||
|
AppToast.show(latest.errorMessage ?? '保存到文件夹失败,请检查文件保存权限');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await _showRecordingSavedDialogIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 清空剪贴板信息,准备新一轮录制
|
||||||
|
void _clearClipboardForNewRound() {
|
||||||
|
final notifier = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
notifier.resetClipboardInfo();
|
||||||
|
notifier.clearSavedRecordingResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 保存成功后按需弹出完成对话框
|
||||||
|
Future<void> _showRecordingSavedDialogIfNeeded() async {
|
||||||
|
final recordingInfo = ref.read(recordingViewModelProvider);
|
||||||
|
final session = recordingInfo.session;
|
||||||
|
if (session.lastSavedDisplayName == null || session.fileSaveFailed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final sessionTitle = _savedDialogSessionTitle(
|
||||||
|
recordingInfo,
|
||||||
|
session.lastSavedDisplayName,
|
||||||
|
);
|
||||||
|
|
||||||
|
await showRecordingSavedDialog(
|
||||||
|
context,
|
||||||
|
sessionTitle: sessionTitle,
|
||||||
|
onContinueRound: () {
|
||||||
|
ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.clearSavedRecordingResult();
|
||||||
|
},
|
||||||
|
onRecordNewRound: _clearClipboardForNewRound,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 退出沉浸式并释放录制会话
|
||||||
|
Future<void> _exitRecordingMode() async {
|
||||||
|
if (!_immersiveApplied) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).teardown();
|
||||||
|
await SystemChrome.setEnabledSystemUIMode(
|
||||||
|
SystemUiMode.manual,
|
||||||
|
overlays: SystemUiOverlay.values,
|
||||||
|
);
|
||||||
|
await RecordingPlatform.setImmersiveMode(enabled: false);
|
||||||
|
_immersiveApplied = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 页面销毁时恢复系统 UI
|
||||||
|
void dispose() {
|
||||||
|
if (_immersiveApplied) {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(
|
||||||
|
SystemUiMode.manual,
|
||||||
|
overlays: SystemUiOverlay.values,
|
||||||
|
);
|
||||||
|
RecordingPlatform.setImmersiveMode(enabled: false);
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 构建录制页 UI
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return _RecordingPopScope(
|
||||||
|
onExitRecordingMode: _exitRecordingMode,
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
_RecordHeaderSection(
|
||||||
|
onPasteEventInfo: _pasteEventInfo,
|
||||||
|
onClearEventInfo: _clearClipboardForNewRound,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
const CameraPreviewWidget(),
|
||||||
|
const _PreviewLoadingLayer(),
|
||||||
|
const RecordTimerWidget(),
|
||||||
|
_RecordingHudLayer(
|
||||||
|
onStart: _onStartRecording,
|
||||||
|
onStop: _stopRecordingAndShowResult,
|
||||||
|
),
|
||||||
|
_TouchLockOverlayLayer(
|
||||||
|
onStopRecording: _stopRecordingAndShowResult,
|
||||||
|
),
|
||||||
|
const _StartingRecordingOverlay(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const RecordFooter(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingPopScope extends ConsumerWidget {
|
||||||
|
const _RecordingPopScope({
|
||||||
|
required this.onExitRecordingMode,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Future<void> Function() onExitRecordingMode;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final isRecording = ref.watch(
|
||||||
|
recordingViewModelProvider.select((m) => m.session.isRecording),
|
||||||
|
);
|
||||||
|
|
||||||
|
return PopScope(
|
||||||
|
canPop: !isRecording,
|
||||||
|
onPopInvokedWithResult: (didPop, result) async {
|
||||||
|
if (didPop) {
|
||||||
|
await onExitRecordingMode();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isRecording) {
|
||||||
|
AppToast.show('录制中无法返回,请先停止录制');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordHeaderSection extends ConsumerWidget {
|
||||||
|
const _RecordHeaderSection({
|
||||||
|
required this.onPasteEventInfo,
|
||||||
|
required this.onClearEventInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Future<void> Function() onPasteEventInfo;
|
||||||
|
final VoidCallback onClearEventInfo;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final headerState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (
|
||||||
|
m.hasValidClipboardInfo,
|
||||||
|
m.hasValidClipboardInfo ? m.clipboardRecordingModel.title : null,
|
||||||
|
m.session.isRecording,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (hasValidClipboardInfo, eventTitle, isRecording) = headerState;
|
||||||
|
|
||||||
|
return RecordHeaderWidget(
|
||||||
|
hasValidClipboardInfo: hasValidClipboardInfo,
|
||||||
|
eventTitle: eventTitle,
|
||||||
|
isRecording: isRecording,
|
||||||
|
onPasteEventInfo: onPasteEventInfo,
|
||||||
|
onClearEventInfo: onClearEventInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PreviewLoadingLayer extends ConsumerWidget {
|
||||||
|
const _PreviewLoadingLayer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final showLoading = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => !m.session.isPreviewReady && m.session.errorMessage == null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!showLoading) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return const RecordingLoadingOverlayWidget(message: '正在启动相机…');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingHudLayer extends ConsumerWidget {
|
||||||
|
const _RecordingHudLayer({required this.onStart, required this.onStop});
|
||||||
|
|
||||||
|
final Future<void> Function() onStart;
|
||||||
|
final Future<void> Function() onStop;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final hudState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (
|
||||||
|
m.session.errorMessage,
|
||||||
|
m.session.permissionWarning,
|
||||||
|
m.session.hasDndAccess,
|
||||||
|
m.session.isBatteryOptimizedIgnored,
|
||||||
|
m.session.notificationsGranted,
|
||||||
|
m.session.isRecording,
|
||||||
|
m.session.isStartingRecording,
|
||||||
|
m.session.isTouchLocked,
|
||||||
|
m.session.zoomRatio,
|
||||||
|
m.session.minZoomRatio,
|
||||||
|
m.session.maxZoomRatio,
|
||||||
|
m.hasValidClipboardInfo,
|
||||||
|
m.clipboardRecordingModel.address.trim(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (
|
||||||
|
errorMessage,
|
||||||
|
permissionWarning,
|
||||||
|
hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted,
|
||||||
|
isRecording,
|
||||||
|
isStartingRecording,
|
||||||
|
isTouchLocked,
|
||||||
|
zoomRatio,
|
||||||
|
minZoomRatio,
|
||||||
|
maxZoomRatio,
|
||||||
|
showClipboardHint,
|
||||||
|
clipboardAddress,
|
||||||
|
) = hudState;
|
||||||
|
final viewModel = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
|
||||||
|
return RecordingHudWidget(
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
permissionWarning: permissionWarning,
|
||||||
|
hasDndAccess: hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored: isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: notificationsGranted,
|
||||||
|
isRecording: isRecording,
|
||||||
|
isStartingRecording: isStartingRecording,
|
||||||
|
isTouchLocked: isTouchLocked,
|
||||||
|
zoomRatio: zoomRatio,
|
||||||
|
minZoomRatio: minZoomRatio,
|
||||||
|
maxZoomRatio: maxZoomRatio,
|
||||||
|
showClipboardHint: showClipboardHint,
|
||||||
|
clipboardAddress: clipboardAddress,
|
||||||
|
onStart: onStart,
|
||||||
|
onStop: onStop,
|
||||||
|
onOpenDnd: () async {
|
||||||
|
await viewModel.openDndSettings();
|
||||||
|
await viewModel.refreshDndAccess();
|
||||||
|
},
|
||||||
|
onOpenBattery: () async {
|
||||||
|
await viewModel.openBatterySettings();
|
||||||
|
await viewModel.refreshBatteryOptimization();
|
||||||
|
},
|
||||||
|
onToggleTouchLock: () {
|
||||||
|
final locked = ref
|
||||||
|
.read(recordingViewModelProvider)
|
||||||
|
.session
|
||||||
|
.isTouchLocked;
|
||||||
|
viewModel.setTouchLocked(!locked);
|
||||||
|
},
|
||||||
|
onZoomSelected: (ratio) async {
|
||||||
|
await viewModel.setZoomRatio(ratio);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TouchLockOverlayLayer extends ConsumerWidget {
|
||||||
|
const _TouchLockOverlayLayer({required this.onStopRecording});
|
||||||
|
|
||||||
|
final Future<void> Function() onStopRecording;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final overlayState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (m.session.isTouchLocked, m.session.isRecording),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (isTouchLocked, isRecording) = overlayState;
|
||||||
|
|
||||||
|
if (!isTouchLocked || !isRecording) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
final viewModel = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
|
||||||
|
return RecordingTouchLockOverlayWidget(
|
||||||
|
enabled: true,
|
||||||
|
onUnlocked: (intent) async {
|
||||||
|
viewModel.setTouchLocked(false);
|
||||||
|
if (intent == RecordingTouchLockUnlockIntent.stopRecording) {
|
||||||
|
await onStopRecording();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StartingRecordingOverlay extends ConsumerWidget {
|
||||||
|
const _StartingRecordingOverlay();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final isStartingRecording = ref.watch(
|
||||||
|
recordingViewModelProvider.select((m) => m.session.isStartingRecording),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isStartingRecording) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RecordingLoadingOverlayWidget(
|
||||||
|
message: '正在开始录制…',
|
||||||
|
backgroundColor: Colors.black.withValues(alpha: 0.24),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
abstract final class RecordingChannelNames {
|
||||||
|
static const packageName = 'com.dronex.rec';
|
||||||
|
static const method = '$packageName/recording';
|
||||||
|
static const events = '$packageName/recording_events';
|
||||||
|
}
|
||||||
227
lib/features/recording/platform/recording_platform.dart
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:recording_tool/features/recording/platform/recording_channel_names.dart';
|
||||||
|
|
||||||
|
enum RecordingState {
|
||||||
|
idle,
|
||||||
|
previewing,
|
||||||
|
recording,
|
||||||
|
stopping,
|
||||||
|
error;
|
||||||
|
|
||||||
|
static RecordingState fromRaw(String? raw) {
|
||||||
|
return RecordingState.values.firstWhere(
|
||||||
|
(value) => value.name == raw,
|
||||||
|
orElse: () => RecordingState.idle,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingStatus {
|
||||||
|
const RecordingStatus({
|
||||||
|
required this.state,
|
||||||
|
this.outputPath,
|
||||||
|
this.elapsedMillis = 0,
|
||||||
|
this.message,
|
||||||
|
});
|
||||||
|
|
||||||
|
final RecordingState state;
|
||||||
|
final String? outputPath;
|
||||||
|
final int elapsedMillis;
|
||||||
|
final String? message;
|
||||||
|
|
||||||
|
factory RecordingStatus.fromMap(Map<dynamic, dynamic> map) {
|
||||||
|
return RecordingStatus(
|
||||||
|
state: RecordingState.fromRaw(map['state'] as String?),
|
||||||
|
outputPath: map['outputPath'] as String?,
|
||||||
|
elapsedMillis: (map['elapsedMillis'] as num?)?.toInt() ?? 0,
|
||||||
|
message: map['message'] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isRecording => state == RecordingState.recording;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingPlatform {
|
||||||
|
RecordingPlatform._();
|
||||||
|
|
||||||
|
static const MethodChannel _channel = MethodChannel(
|
||||||
|
RecordingChannelNames.method,
|
||||||
|
);
|
||||||
|
static const EventChannel _events = EventChannel(
|
||||||
|
RecordingChannelNames.events,
|
||||||
|
);
|
||||||
|
|
||||||
|
static bool get isSupported =>
|
||||||
|
supportsHost(isAndroid: Platform.isAndroid, isIOS: Platform.isIOS);
|
||||||
|
|
||||||
|
static bool supportsHost({required bool isAndroid, required bool isIOS}) {
|
||||||
|
return isAndroid || isIOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Stream<RecordingStatus>? _statusStream;
|
||||||
|
|
||||||
|
static Stream<RecordingStatus> statusStream() {
|
||||||
|
if (!isSupported) {
|
||||||
|
return const Stream.empty();
|
||||||
|
}
|
||||||
|
_statusStream ??= _events.receiveBroadcastStream().map(
|
||||||
|
(event) =>
|
||||||
|
RecordingStatus.fromMap(Map<dynamic, dynamic>.from(event as Map)),
|
||||||
|
);
|
||||||
|
return _statusStream!;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingStatus> initializePreview() async {
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'initializePreview',
|
||||||
|
);
|
||||||
|
return RecordingStatus.fromMap(result ?? const {});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingZoomCapabilities> getZoomCapabilities() async {
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'getZoomCapabilities',
|
||||||
|
);
|
||||||
|
return RecordingZoomCapabilities.fromMap(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingZoomCapabilities> setZoomRatio(double ratio) async {
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'setZoomRatio',
|
||||||
|
<String, dynamic>{'zoomRatio': ratio},
|
||||||
|
);
|
||||||
|
return RecordingZoomCapabilities.fromMap(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingStartResult> startRecording({
|
||||||
|
bool withAudio = true,
|
||||||
|
bool enableDoNotDisturb = true,
|
||||||
|
String? displayName,
|
||||||
|
}) async {
|
||||||
|
final args = <String, dynamic>{
|
||||||
|
'withAudio': withAudio,
|
||||||
|
'enableDoNotDisturb': enableDoNotDisturb,
|
||||||
|
};
|
||||||
|
if (displayName != null) {
|
||||||
|
args['displayName'] = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'startRecording',
|
||||||
|
args,
|
||||||
|
);
|
||||||
|
return RecordingStartResult(
|
||||||
|
outputPath: result?['outputPath'] as String?,
|
||||||
|
status: RecordingStatus.fromMap(
|
||||||
|
Map<dynamic, dynamic>.from(result?['status'] as Map? ?? const {}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingStopResult> stopRecording() async {
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'stopRecording',
|
||||||
|
);
|
||||||
|
return RecordingStopResult.fromMap(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> disposePreview() =>
|
||||||
|
_channel.invokeMethod('disposePreview');
|
||||||
|
|
||||||
|
static Future<bool> hasNotificationPolicyAccess() async {
|
||||||
|
return await _channel.invokeMethod<bool>('hasNotificationPolicyAccess') ??
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> openNotificationPolicySettings() {
|
||||||
|
return _channel.invokeMethod('openNotificationPolicySettings');
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool> enableDoNotDisturb() async {
|
||||||
|
return await _channel.invokeMethod<bool>('enableDoNotDisturb') ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> disableDoNotDisturb() {
|
||||||
|
return _channel.invokeMethod('disableDoNotDisturb');
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool> isIgnoringBatteryOptimizations() async {
|
||||||
|
return await _channel.invokeMethod<bool>(
|
||||||
|
'isIgnoringBatteryOptimizations',
|
||||||
|
) ??
|
||||||
|
true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> openBatteryOptimizationSettings() {
|
||||||
|
return _channel.invokeMethod('openBatteryOptimizationSettings');
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> setImmersiveMode({required bool enabled}) {
|
||||||
|
return _channel.invokeMethod('setImmersiveMode', <String, dynamic>{
|
||||||
|
'enabled': enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecordingStatus> getStatus() async {
|
||||||
|
final result = await _channel.invokeMapMethod<String, dynamic>('getStatus');
|
||||||
|
return RecordingStatus.fromMap(result ?? const {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingZoomCapabilities {
|
||||||
|
const RecordingZoomCapabilities({
|
||||||
|
required this.zoomRatio,
|
||||||
|
required this.minZoomRatio,
|
||||||
|
required this.maxZoomRatio,
|
||||||
|
});
|
||||||
|
|
||||||
|
final double zoomRatio;
|
||||||
|
final double minZoomRatio;
|
||||||
|
final double maxZoomRatio;
|
||||||
|
|
||||||
|
factory RecordingZoomCapabilities.fromMap(Map<String, dynamic>? map) {
|
||||||
|
final minZoomRatio = (map?['minZoomRatio'] as num?)?.toDouble() ?? 1.0;
|
||||||
|
final maxZoomRatio = (map?['maxZoomRatio'] as num?)?.toDouble() ?? 3.0;
|
||||||
|
final zoomRatio = (map?['zoomRatio'] as num?)?.toDouble() ?? minZoomRatio;
|
||||||
|
return RecordingZoomCapabilities(
|
||||||
|
zoomRatio: zoomRatio.clamp(minZoomRatio, maxZoomRatio).toDouble(),
|
||||||
|
minZoomRatio: minZoomRatio,
|
||||||
|
maxZoomRatio: maxZoomRatio,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingStartResult {
|
||||||
|
const RecordingStartResult({this.outputPath, required this.status});
|
||||||
|
|
||||||
|
final String? outputPath;
|
||||||
|
final RecordingStatus status;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingStopResult {
|
||||||
|
const RecordingStopResult({
|
||||||
|
this.outputPath,
|
||||||
|
required this.status,
|
||||||
|
this.fileSaved = true,
|
||||||
|
this.fileErrorMessage,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String? outputPath;
|
||||||
|
final RecordingStatus status;
|
||||||
|
final bool fileSaved;
|
||||||
|
final String? fileErrorMessage;
|
||||||
|
|
||||||
|
factory RecordingStopResult.fromMap(Map<String, dynamic>? result) {
|
||||||
|
return RecordingStopResult(
|
||||||
|
outputPath: result?['outputPath'] as String?,
|
||||||
|
status: RecordingStatus.fromMap(
|
||||||
|
Map<dynamic, dynamic>.from(result?['status'] as Map? ?? const {}),
|
||||||
|
),
|
||||||
|
fileSaved: result?['fileSaved'] as bool? ?? true,
|
||||||
|
fileErrorMessage: result?['fileErrorMessage'] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
lib/features/recording/utils/recording_display_name.dart
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
/// 非法文件名字符(路径分隔符等)。
|
||||||
|
final _invalidNameChars = RegExp(r'[/\\:*?"<>|]');
|
||||||
|
|
||||||
|
const _maxBaseNameLength = 120;
|
||||||
|
|
||||||
|
/// 清洗小程序复制的文件名基底(不含扩展名)。
|
||||||
|
String? sanitizeRecordingBaseName(String raw) {
|
||||||
|
var name = raw.replaceAll(_invalidNameChars, '_').trim();
|
||||||
|
if (name.isEmpty) return null;
|
||||||
|
if (name.length > _maxBaseNameLength) {
|
||||||
|
name = name.substring(0, _maxBaseNameLength);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析录制展示名:优先剪切板 filename,否则 REC_时间戳。
|
||||||
|
String resolveRecordingDisplayName(String? clipboardFilename) {
|
||||||
|
final sanitized = clipboardFilename == null
|
||||||
|
? null
|
||||||
|
: sanitizeRecordingBaseName(clipboardFilename);
|
||||||
|
if (sanitized != null) return sanitized;
|
||||||
|
final now = DateTime.now();
|
||||||
|
final stamp =
|
||||||
|
'${now.year}'
|
||||||
|
'${now.month.toString().padLeft(2, '0')}'
|
||||||
|
'${now.day.toString().padLeft(2, '0')}_'
|
||||||
|
'${now.hour.toString().padLeft(2, '0')}'
|
||||||
|
'${now.minute.toString().padLeft(2, '0')}'
|
||||||
|
'${now.second.toString().padLeft(2, '0')}';
|
||||||
|
return 'REC_$stamp';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 为展示名补全视频扩展名(已有 .mp4/.mov 则保留)。
|
||||||
|
String withVideoExtension(String baseName, {bool? isIOS}) {
|
||||||
|
final ios = isIOS ?? Platform.isIOS;
|
||||||
|
final ext = ios ? '.mov' : '.mp4';
|
||||||
|
final lower = baseName.toLowerCase();
|
||||||
|
if (lower.endsWith('.mp4') || lower.endsWith('.mov')) {
|
||||||
|
return baseName;
|
||||||
|
}
|
||||||
|
return '$baseName$ext';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 传给原生的完整文件名(含扩展名)。
|
||||||
|
String recordingFileNameForPlatform(
|
||||||
|
String? clipboardFilename, {
|
||||||
|
bool? isIOS,
|
||||||
|
}) {
|
||||||
|
final base = resolveRecordingDisplayName(clipboardFilename);
|
||||||
|
return withVideoExtension(base, isIOS: isIOS);
|
||||||
|
}
|
||||||