diff --git a/.gitignore b/.gitignore index 7de017b..5e0d1c2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,9 @@ graphify-out/ .DS_Store __pycache__/ *.pyc +android/.gradle/ +android/build/ +android/app/build/ +android/app/src/main/jniLibs/ +android/local.properties +android/.kotlin/ diff --git a/Cargo.lock b/Cargo.lock index 7c49cbd..74c32e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,23 @@ dependencies = [ "equator", ] +[[package]] +name = "android_log-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" + +[[package]] +name = "android_logger" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b07e8e73d720a1f2e4b6014766e6039fd2e96a4fa44e2a78d0e1fa2ff49826" +dependencies = [ + "android_log-sys", + "env_filter", + "log", +] + [[package]] name = "android_system_properties" version = "0.1.6" @@ -841,6 +858,12 @@ dependencies = [ "shlex 2.0.1", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cexpr" version = "0.6.0" @@ -1050,6 +1073,16 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "combine" +version = "4.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "command-fds" version = "0.3.3" @@ -1616,6 +1649,16 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "env_filter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equator" version = "0.4.2" @@ -1923,6 +1966,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fpv-android-ffi" +version = "0.4.0" +dependencies = [ + "android_logger", + "fpv-core", + "jni", + "log", + "parking_lot", +] + [[package]] name = "fpv-core" version = "0.4.0" @@ -3192,6 +3246,50 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + [[package]] name = "jobserver" version = "0.1.35" @@ -6908,6 +7006,15 @@ dependencies = [ "windows-link 0.2.1", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -6944,6 +7051,21 @@ dependencies = [ "windows-link 0.2.1", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -7001,6 +7123,12 @@ dependencies = [ "windows-link 0.1.3", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -7019,6 +7147,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -7037,6 +7171,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -7067,6 +7207,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -7085,6 +7231,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -7103,6 +7255,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -7121,6 +7279,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index e57e7bd..439f691 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [".", "crates/fpv-core"] +members = [".", "crates/fpv-core", "crates/fpv-android-ffi"] resolver = "2" [package] diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/android/app/.gitignore b/android/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 0000000..3a86262 --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,87 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.kotlin.serialization) +} + +android { + namespace = "com.steamframe.fpv" + compileSdk = 36 + defaultConfig { + applicationId = "com.steamframe.fpv" + minSdk = 31 + targetSdk = 36 + versionCode = 1 + versionName = "0.4.0" + ndk { + abiFilters += "arm64-v8a" + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + buildFeatures { + compose = true + aidl = false + buildConfig = false + shaders = false + } + + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +kotlin { + jvmToolchain(17) +} + +dependencies { + val composeBom = platform(libs.androidx.compose.bom) + implementation(composeBom) + androidTestImplementation(composeBom) + + // Core Android dependencies + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + + // Arch Components + implementation(libs.androidx.lifecycle.runtime.compose) + implementation(libs.androidx.lifecycle.viewmodel.compose) + + // Compose + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + // Tooling + debugImplementation(libs.androidx.compose.ui.tooling) + // Instrumented tests + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.test.manifest) + + // Local tests: jUnit, coroutines, Android runner + testImplementation(libs.junit) + testImplementation(libs.kotlinx.coroutines.test) + + // Instrumented tests: jUnit rules and runners + androidTestImplementation(libs.androidx.test.core) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.androidx.test.espresso.core) + + // Navigation + implementation(libs.androidx.navigation3.ui) + implementation(libs.androidx.navigation3.runtime) + implementation(libs.androidx.lifecycle.viewmodel.navigation3) +} diff --git a/android/app/src/androidTest/kotlin/com/steamframe/fpv/ui/main/MainScreenTest.kt b/android/app/src/androidTest/kotlin/com/steamframe/fpv/ui/main/MainScreenTest.kt new file mode 100644 index 0000000..e63c535 --- /dev/null +++ b/android/app/src/androidTest/kotlin/com/steamframe/fpv/ui/main/MainScreenTest.kt @@ -0,0 +1,26 @@ +package com.steamframe.fpv.ui.main + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithText +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +/** UI tests for [com.steamframe.fpv.ui.main.MainScreen]. */ +class MainScreenTest { + + @get:Rule val composeTestRule = createAndroidComposeRule() + + @Before + fun setup() { + composeTestRule.setContent { MainScreen(FAKE_DATA) } + } + + @Test + fun firstItem_exists() { + FAKE_DATA.forEach { composeTestRule.onNodeWithText("Hello $it!").assertExists() } + } +} + +private val FAKE_DATA = listOf("Sample1", "Sample2", "Sample3") diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..67c86f0 --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/CockpitScreen.kt b/android/app/src/main/kotlin/com/steamframe/fpv/CockpitScreen.kt new file mode 100644 index 0000000..613fbad --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/CockpitScreen.kt @@ -0,0 +1,345 @@ +package com.steamframe.fpv + +import android.view.Surface +import android.view.SurfaceHolder +import android.view.SurfaceView +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Surface as ComposeSurface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.viewinterop.AndroidView +import java.util.Locale + +private val HudBg = Color(0x990B1018) +private val HudGreen = Color(0xFF4ADE80) +private val HudAmber = Color(0xFFFBBF24) +private val HudRed = Color(0xFFF87171) +private val HudCyan = Color(0xFF38BDF8) + +@Composable +fun CockpitScreen( + snapshot: FpvSnapshot, + osdEnabled: Boolean, + dvrRecording: Boolean, + codec: String, + transport: String, + pingStatus: String, + onSurfaceReady: (Surface?) -> Unit, + onToggleDvr: () -> Unit, + onToggleOsd: () -> Unit, + onCycleCodec: () -> Unit, + onCycleTransport: () -> Unit, + onPingRadxa: () -> Unit, +) { + var controlsVisible by remember { mutableStateOf(true) } + + Box( + modifier = Modifier + .fillMaxSize() + .background(Color.Black) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null, + ) { controlsVisible = !controlsVisible }, + ) { + // 1. Surface vidéo plein écran zéro-copie (MediaCodec -> SurfaceView) + AndroidView( + modifier = Modifier.fillMaxSize(), + factory = { ctx -> + SurfaceView(ctx).apply { + holder.addCallback(object : SurfaceHolder.Callback { + override fun surfaceCreated(holder: SurfaceHolder) { + onSurfaceReady(holder.surface) + } + + override fun surfaceChanged( + holder: SurfaceHolder, + format: Int, + width: Int, + height: Int, + ) { + } + + override fun surfaceDestroyed(holder: SurfaceHolder) { + onSurfaceReady(null) + } + }) + } + }, + ) + + // 2. Bannière d'attente signal si aucun paquet vidéo reçu + if (!snapshot.video.signalLive) { + Box( + modifier = Modifier + .align(Alignment.Center) + .background(HudBg, RoundedCornerShape(12.dp)) + .padding(horizontal = 24.dp, vertical = 14.dp), + ) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = "EN ATTENTE DU FLUX RADXA (UDP :5600 • ${codec.uppercase()} / ${transport.uppercase()})", + color = HudAmber, + fontSize = 16.sp, + fontWeight = FontWeight.Bold, + fontFamily = FontFamily.Monospace, + ) + Spacer(Modifier.height(4.dp)) + Text( + text = "Branchez la Radxa Zero 3W en USB-C (usb0 : 192.168.1.1) — Tap écran pour afficher/masquer les contrôles", + color = Color(0xFFCBD5E1), + fontSize = 13.sp, + ) + } + } + } + + // 3. Overlay OSD FPV vectoriel net (14,6" Tab S8 Ultra) + if (osdEnabled) { + OsdOverlay( + snapshot = snapshot, + dvrRecording = dvrRecording, + modifier = Modifier + .fillMaxSize() + .padding(18.dp), + ) + } + + // 4. Barre de contrôles tactiles escamotable en bas + AnimatedVisibility( + visible = controlsVisible, + enter = fadeIn(), + exit = fadeOut(), + modifier = Modifier + .align(Alignment.BottomCenter) + .padding(bottom = 18.dp), + ) { + ComposeSurface( + color = Color(0xCC0F172A), + shape = RoundedCornerShape(14.dp), + ) { + Row( + modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp), + horizontalArrangement = Arrangement.spacedBy(10.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + HudActionButton( + label = if (dvrRecording) "⏹ STOP DVR" else "⏺ DVR", + containerColor = if (dvrRecording) HudRed else Color(0xFF1E293B), + onClick = onToggleDvr, + ) + HudActionButton( + label = if (osdEnabled) "OSD: ON" else "OSD: OFF", + containerColor = if (osdEnabled) Color(0xFF0F766E) else Color(0xFF1E293B), + onClick = onToggleOsd, + ) + HudActionButton( + label = "CODEC: ${codec.uppercase()}", + containerColor = Color(0xFF1E293B), + onClick = onCycleCodec, + ) + HudActionButton( + label = "FLUX: ${transport.uppercase()}", + containerColor = Color(0xFF1E293B), + onClick = onCycleTransport, + ) + HudActionButton( + label = "PING RADXA", + containerColor = Color(0xFF1D4ED8), + onClick = onPingRadxa, + ) + if (pingStatus.isNotBlank()) { + Text( + text = pingStatus, + color = HudCyan, + fontSize = 13.sp, + fontFamily = FontFamily.Monospace, + modifier = Modifier.padding(horizontal = 6.dp), + ) + } + } + } + } + } +} + +@Composable +private fun OsdOverlay( + snapshot: FpvSnapshot, + dvrRecording: Boolean, + modifier: Modifier = Modifier, +) { + val v = snapshot.video + val t = snapshot.telemetry + val g = snapshot.g29 + + Box(modifier = modifier) { + // Haut-gauche : Batterie LiPo Auto-détectée + HudPill(modifier = Modifier.align(Alignment.TopStart)) { + val battColor = when { + !t.live -> Color(0xFF94A3B8) + t.cellV in 0.1f..3.50f -> HudRed + t.cellV in 3.50f..3.65f -> HudAmber + else -> HudGreen + } + val battText = if (t.live && t.batteryV > 0.5f) { + if (t.cells > 0) { + String.format(Locale.US, "BAT %.2fV (%dS • %.2fV/c)", t.batteryV, t.cells, t.cellV) + } else { + String.format(Locale.US, "BAT %.2fV", t.batteryV) + } + } else { + "BAT --.-V" + } + Text(battText, color = battColor, fontWeight = FontWeight.Bold, fontFamily = FontFamily.Monospace, fontSize = 15.sp) + if (t.flightMode.isNotBlank()) { + Text("MODE ${t.flightMode}", color = HudCyan, fontFamily = FontFamily.Monospace, fontSize = 13.sp) + } + } + + // Haut-centre : Statut Armement / DVR / Toast G29 + Column( + modifier = Modifier.align(Alignment.TopCenter), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + if (dvrRecording) { + HudPill { + Text("● REC", color = HudRed, fontWeight = FontWeight.ExtraBold, fontFamily = FontFamily.Monospace, fontSize = 15.sp) + } + } + if (g.live) { + HudPill { + val (armLbl, armCol) = when { + g.failsafe -> "FAILSAFE" to HudRed + g.armed -> "ARMED" to HudGreen + else -> "DISARMED" to HudAmber + } + Text(armLbl, color = armCol, fontWeight = FontWeight.Bold, fontFamily = FontFamily.Monospace, fontSize = 15.sp) + } + } + } + if (g.toast.isNotBlank()) { + Spacer(Modifier.height(6.dp)) + HudPill { + Text(g.toast, color = HudCyan, fontWeight = FontWeight.Bold, fontFamily = FontFamily.Monospace, fontSize = 16.sp) + } + } + } + + // Haut-droite : Métriques Vidéo & Lien Radio ELRS + HudPill(modifier = Modifier.align(Alignment.TopEnd)) { + val fpsCol = if (v.signalLive && v.fps >= 45f) HudGreen else HudAmber + Text( + text = String.format(Locale.US, "%.0f FPS • %.1fms • %d kbps", v.fps, v.jitterMs, v.bitrateKbps), + color = fpsCol, + fontWeight = FontWeight.Bold, + fontFamily = FontFamily.Monospace, + fontSize = 15.sp, + ) + val lqCol = if (t.linkQuality >= 70) HudGreen else if (t.linkQuality >= 50) HudAmber else HudRed + Text( + text = if (t.live) "LQ ${t.linkQuality}% • ${t.rssiDbm} dBm • DROP ${v.droppedPackets}" else "LQ --% • DROP ${v.droppedPackets}", + color = if (t.live) lqCol else Color(0xFF94A3B8), + fontFamily = FontFamily.Monospace, + fontSize = 13.sp, + ) + } + + // Bas-gauche : GPS, Vitesse & Distance Home + HudPill(modifier = Modifier.align(Alignment.BottomStart).padding(bottom = 58.dp)) { + val gpsText = if (t.gpsFix) { + String.format(Locale.US, "GPS %d sats • %.1f km/h • ALT %.0fm", t.sats, t.speedKmh, t.altitudeM) + } else { + "GPS ${t.sats} sats (NO FIX)" + } + Text(gpsText, color = if (t.gpsFix) Color.White else Color(0xFF94A3B8), fontFamily = FontFamily.Monospace, fontSize = 14.sp) + if (t.homeDistM >= 0f) { + Text( + text = String.format(Locale.US, "HOME %.0fm • CAP %.0f°", t.homeDistM, t.homeBearingDeg), + color = HudCyan, + fontWeight = FontWeight.Bold, + fontFamily = FontFamily.Monospace, + fontSize = 14.sp, + ) + } + } + + // Bas-droite : Boîte de vitesses G29 + Pédales + if (g.live) { + HudPill(modifier = Modifier.align(Alignment.BottomEnd).padding(bottom = 58.dp)) { + Text( + text = "RAPPORT [${g.gearLabel}] • ${g.source}", + color = Color.White, + fontWeight = FontWeight.Bold, + fontFamily = FontFamily.Monospace, + fontSize = 15.sp, + ) + Text( + text = "GAZ ${g.throttlePct}% • FREIN ${g.brakePct}% • DIR ${g.steeringPct}%", + color = HudAmber, + fontFamily = FontFamily.Monospace, + fontSize = 13.sp, + ) + } + } + } +} + +@Composable +private fun HudPill( + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + Column( + modifier = modifier + .background(HudBg, RoundedCornerShape(10.dp)) + .padding(horizontal = 12.dp, vertical = 7.dp), + ) { + content() + } +} + +@Composable +private fun HudActionButton( + label: String, + containerColor: Color, + onClick: () -> Unit, +) { + Button( + onClick = onClick, + colors = ButtonDefaults.buttonColors(containerColor = containerColor, contentColor = Color.White), + shape = RoundedCornerShape(8.dp), + ) { + Text(text = label, fontWeight = FontWeight.SemiBold, fontSize = 13.sp) + } +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/LowLatencyVideoDecoder.kt b/android/app/src/main/kotlin/com/steamframe/fpv/LowLatencyVideoDecoder.kt new file mode 100644 index 0000000..2e2609b --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/LowLatencyVideoDecoder.kt @@ -0,0 +1,336 @@ +package com.steamframe.fpv + +import android.content.ContentValues +import android.content.Context +import android.media.MediaCodec +import android.media.MediaFormat +import android.media.MediaMuxer +import android.os.Environment +import android.provider.MediaStore +import android.util.Log +import android.view.Surface +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.nio.ByteBuffer +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale +import java.util.concurrent.atomic.AtomicBoolean + +/** + * Décodeur vidéo matériel ultra-basse latence (Snapdragon 8 Gen 1 / Tab S8 Ultra) + * rendu directement en zéro-copie sur un [Surface] + enregistreur DVR MP4 (`MediaMuxer`) & `.srt`. + */ +class LowLatencyVideoDecoder(private val context: Context) { + companion object { + private const val TAG = "SteamFrameFPV.Video" + } + + private val lock = Any() + private var surface: Surface? = null + private var codec: MediaCodec? = null + private var mimeType: String = MediaFormat.MIMETYPE_VIDEO_AVC + private var codecConfigured = false + private var awaitingKeyframe = true + + // Cache SPS / PPS / VPS pour (re)configurer instantanément MediaCodec & MediaMuxer + private var cachedConfigNals = mutableListOf() + private var drainThread: Thread? = null + private val running = AtomicBoolean(false) + + // DVR MP4 natif (zéro ré-encodage) + sous-titres .srt + private var muxer: MediaMuxer? = null + private var muxerTrackIndex = -1 + private var muxerStarted = false + private var dvrStartPtsUs = -1L + private var dvrFile: File? = null + private var srtWriter: BufferedWriter? = null + private var srtSeq = 0 + private var lastSrtMs = -1000L + private val dvrRecording = AtomicBoolean(false) + + fun isRecording(): Boolean = dvrRecording.get() + + fun setSurface(newSurface: Surface?, codecName: String) { + synchronized(lock) { + releaseCodecLocked() + surface = newSurface + mimeType = if (codecName.equals("h265", ignoreCase = true) || codecName.equals("hevc", ignoreCase = true)) { + MediaFormat.MIMETYPE_VIDEO_HEVC + } else { + MediaFormat.MIMETYPE_VIDEO_AVC + } + if (newSurface != null && newSurface.isValid) { + initCodecLocked(newSurface) + } + } + } + + private fun initCodecLocked(targetSurface: Surface) { + try { + val mc = MediaCodec.createDecoderByType(mimeType) + val format = MediaFormat.createVideoFormat(mimeType, 1920, 1080).apply { + setInteger(MediaFormat.KEY_LOW_LATENCY, 1) + setInteger(MediaFormat.KEY_PRIORITY, 0) // Temps réel + setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE.toInt()) + // Clé matérielle Qualcomm (Snapdragon 8 Gen 1 / Tab S8 Ultra) pour zéro frame buffering + setInteger("vendor.qti-ext-dec-low-latency.enable", 1) + } + mc.configure(format, targetSurface, null, 0) + mc.start() + codec = mc + codecConfigured = true + awaitingKeyframe = true + running.set(true) + + // Réinjecter immédiatement SPS/PPS/VPS en cache si disponibles + for (cfg in cachedConfigNals) { + queueBufferLocked(mc, cfg, 0L, MediaCodec.BUFFER_FLAG_CODEC_CONFIG) + } + + drainThread = Thread({ drainLoop(mc) }, "fpv-mediacodec-drain").apply { + priority = Thread.MAX_PRIORITY + start() + } + Log.i(TAG, "MediaCodec démarré ($mimeType, Low-Latency Snapdragon actif)") + } catch (e: Exception) { + Log.e(TAG, "Échec initialisation MediaCodec ($mimeType): ${e.message}") + releaseCodecLocked() + } + } + + fun submitNal(data: ByteArray, ptsUs: Long, isKeyframe: Boolean, isCodecConfig: Boolean) { + synchronized(lock) { + if (isCodecConfig) { + if (cachedConfigNals.size >= 4) cachedConfigNals.clear() + cachedConfigNals.add(data.copyOf()) + } + + // Enregistrement DVR MP4 zéro-CPU + if (dvrRecording.get()) { + writeDvrSampleLocked(data, ptsUs, isKeyframe, isCodecConfig) + } + + val mc = codec ?: return + if (!codecConfigured) return + + if (awaitingKeyframe && !isCodecConfig && !isKeyframe) { + return + } + if (isKeyframe) { + awaitingKeyframe = false + } + + var flags = 0 + if (isCodecConfig) flags = flags or MediaCodec.BUFFER_FLAG_CODEC_CONFIG + if (isKeyframe) flags = flags or MediaCodec.BUFFER_FLAG_KEY_FRAME + + queueBufferLocked(mc, data, ptsUs, flags) + } + } + + private fun queueBufferLocked(mc: MediaCodec, data: ByteArray, ptsUs: Long, flags: Int) { + try { + val idx = mc.dequeueInputBuffer(5_000) + if (idx >= 0) { + val inputBuf = mc.getInputBuffer(idx) ?: return + inputBuf.clear() + if (data.size <= inputBuf.capacity()) { + inputBuf.put(data) + mc.queueInputBuffer(idx, 0, data.size, ptsUs, flags) + } else { + mc.queueInputBuffer(idx, 0, 0, 0L, 0) + } + } + } catch (e: Exception) { + Log.w(TAG, "Erreur queueInputBuffer, réarmement décodeur: ${e.message}") + val surf = surface + releaseCodecLocked() + if (surf != null && surf.isValid) { + initCodecLocked(surf) + } + } + } + + private fun drainLoop(mc: MediaCodec) { + val info = MediaCodec.BufferInfo() + while (running.get()) { + try { + val outIdx = mc.dequeueOutputBuffer(info, 10_000) + if (outIdx >= 0) { + // render = true -> affichage immédiat sur SurfaceView sans attente de PTS (latence minimale) + mc.releaseOutputBuffer(outIdx, true) + } + } catch (_: IllegalStateException) { + break + } catch (e: Exception) { + Log.w(TAG, "Erreur drainLoop MediaCodec: ${e.message}") + break + } + } + } + + fun startDvr(): Boolean { + synchronized(lock) { + if (dvrRecording.get()) return true + return try { + val ts = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date()) + val dir = File(context.getExternalFilesDir(Environment.DIRECTORY_MOVIES), "SteamFrameFPV") + dir.mkdirs() + val outFile = File(dir, "fpv_$ts.mp4") + val srtFile = File(dir, "fpv_$ts.srt") + dvrFile = outFile + muxer = MediaMuxer(outFile.absolutePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4) + muxerTrackIndex = -1 + muxerStarted = false + dvrStartPtsUs = -1L + srtWriter = BufferedWriter(FileWriter(srtFile)) + srtSeq = 0 + lastSrtMs = -1000L + dvrRecording.set(true) + Log.i(TAG, "DVR démarré : ${outFile.absolutePath}") + true + } catch (e: Exception) { + Log.e(TAG, "Échec démarrage DVR : ${e.message}") + false + } + } + } + + fun pushSrtCaption(caption: String) { + if (!dvrRecording.get() || caption.isBlank()) return + synchronized(lock) { + val w = srtWriter ?: return + if (dvrStartPtsUs < 0L) return + val elapsedMs = ((System.nanoTime() / 1000L) - dvrStartPtsUs).coerceAtLeast(0L) / 1000L + if (elapsedMs - lastSrtMs < 950L) return + lastSrtMs = elapsedMs + srtSeq += 1 + try { + w.write("$srtSeq\n${formatSrtTs(elapsedMs)} --> ${formatSrtTs(elapsedMs + 1000L)}\n$caption\n\n") + } catch (_: Exception) { + } + } + } + + fun stopDvr(): String? { + synchronized(lock) { + if (!dvrRecording.getAndSet(false)) return null + val savedPath = dvrFile?.absolutePath + try { + if (muxerStarted) { + muxer?.stop() + } + muxer?.release() + } catch (e: Exception) { + Log.w(TAG, "Arrêt MediaMuxer : ${e.message}") + } + muxer = null + muxerStarted = false + muxerTrackIndex = -1 + try { + srtWriter?.flush() + srtWriter?.close() + } catch (_: Exception) { + } + srtWriter = null + + // Publier dans la Galerie Samsung (MediaStore) si le fichier est non vide + dvrFile?.let { f -> + if (f.exists() && f.length() > 4096) { + exportToGallery(f) + } + } + return savedPath + } + } + + private fun writeDvrSampleLocked(data: ByteArray, ptsUs: Long, isKeyframe: Boolean, isCodecConfig: Boolean) { + val mx = muxer ?: return + if (!muxerStarted) { + if (!isKeyframe || cachedConfigNals.isEmpty()) return + try { + val fmt = MediaFormat.createVideoFormat(mimeType, 1920, 1080) + val csd = ByteArray(cachedConfigNals.sumOf { it.size }) + var pos = 0 + for (c in cachedConfigNals) { + System.arraycopy(c, 0, csd, pos, c.size) + pos += c.size + } + fmt.setByteBuffer("csd-0", ByteBuffer.wrap(csd)) + muxerTrackIndex = mx.addTrack(fmt) + mx.start() + muxerStarted = true + dvrStartPtsUs = ptsUs + } catch (e: Exception) { + Log.w(TAG, "Init MediaMuxer track échouée : ${e.message}") + return + } + } + if (isCodecConfig || muxerTrackIndex < 0) return + try { + val info = MediaCodec.BufferInfo().apply { + offset = 0 + size = data.size + presentationTimeUs = (ptsUs - dvrStartPtsUs).coerceAtLeast(0L) + flags = if (isKeyframe) MediaCodec.BUFFER_FLAG_KEY_FRAME else 0 + } + mx.writeSampleData(muxerTrackIndex, ByteBuffer.wrap(data), info) + } catch (e: Exception) { + Log.w(TAG, "writeSampleData DVR : ${e.message}") + } + } + + private fun exportToGallery(file: File) { + try { + val values = ContentValues().apply { + put(MediaStore.Video.Media.DISPLAY_NAME, file.name) + put(MediaStore.Video.Media.MIME_TYPE, "video/mp4") + put(MediaStore.Video.Media.RELATIVE_PATH, "${Environment.DIRECTORY_MOVIES}/SteamFrameFPV") + } + val resolver = context.contentResolver + val uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values) ?: return + resolver.openOutputStream(uri)?.use { out -> + file.inputStream().use { inp -> inp.copyTo(out) } + } + } catch (e: Exception) { + Log.w(TAG, "Export Galerie ignoré : ${e.message}") + } + } + + private fun formatSrtTs(ms: Long): String { + val h = ms / 3_600_000 + val m = (ms % 3_600_000) / 60_000 + val s = (ms % 60_000) / 1_000 + val rem = ms % 1_000 + return String.format(Locale.US, "%02d:%02d:%02d,%03d", h, m, s, rem) + } + + fun release() { + stopDvr() + synchronized(lock) { + releaseCodecLocked() + surface = null + } + } + + private fun releaseCodecLocked() { + running.set(false) + codecConfigured = false + try { + codec?.stop() + } catch (_: Exception) { + } + try { + codec?.release() + } catch (_: Exception) { + } + codec = null + try { + drainThread?.join(200) + } catch (_: Exception) { + } + drainThread = null + } +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/MainActivity.kt b/android/app/src/main/kotlin/com/steamframe/fpv/MainActivity.kt new file mode 100644 index 0000000..6cacc84 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/MainActivity.kt @@ -0,0 +1,183 @@ +package com.steamframe.fpv + +import android.os.Bundle +import android.view.Surface +import android.view.WindowManager +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.withContext +import java.util.Locale + +class MainActivity : ComponentActivity() { + private lateinit var decoder: LowLatencyVideoDecoder + private var nativeHandle: Long = 0L + private var currentSurface: Surface? = null + + private var snapshot by mutableStateOf(FpvSnapshot()) + private var osdEnabled by mutableStateOf(true) + private var dvrRecording by mutableStateOf(false) + private var codecName by mutableStateOf("h264") + private var transportName by mutableStateOf("rtp") + private var pingStatus by mutableStateOf("") + + private val radxaIp = "192.168.1.1" + private val videoPort = 5600 + private val g29Port = 14552 + private val telemetryPort = 14551 + + private val nativeCallback = object : NativeFpvCallback { + override fun onVideoNal( + data: ByteArray, + ptsUs: Long, + isKeyframe: Boolean, + isCodecConfig: Boolean, + ) { + decoder.submitNal(data, ptsUs, isKeyframe, isCodecConfig) + } + + override fun onG29Action(actionCode: Int) { + runOnUiThread { + when (actionCode) { + NativeFpvEngine.ACTION_TOGGLE_DVR -> toggleDvr() + NativeFpvEngine.ACTION_TOGGLE_OSD -> { + osdEnabled = !osdEnabled + syncNativeFlags() + } + } + } + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + hideSystemBars() + + decoder = LowLatencyVideoDecoder(applicationContext) + restartNativeEngine() + + setContent { + LaunchedEffect(Unit) { + while (true) { + val h = nativeHandle + if (h != 0L) { + val json = withContext(Dispatchers.IO) { + NativeFpvEngine.nativePollSnapshotJson(h) + } + val snap = FpvSnapshot.fromJson(json) + snapshot = snap + if (dvrRecording && snap.telemetry.srtLine.isNotBlank()) { + decoder.pushSrtCaption(snap.telemetry.srtLine) + } + } + delay(50L) // Rafraîchissement OSD 20 Hz + } + } + + CockpitScreen( + snapshot = snapshot, + osdEnabled = osdEnabled, + dvrRecording = dvrRecording, + codec = codecName, + transport = transportName, + pingStatus = pingStatus, + onSurfaceReady = { surf -> + currentSurface = surf + decoder.setSurface(surf, codecName) + }, + onToggleDvr = { toggleDvr() }, + onToggleOsd = { + osdEnabled = !osdEnabled + syncNativeFlags() + }, + onCycleCodec = { + codecName = if (codecName == "h264") "h265" else "h264" + decoder.setSurface(currentSurface, codecName) + restartNativeEngine() + }, + onCycleTransport = { + transportName = if (transportName == "rtp") "raw" else "rtp" + restartNativeEngine() + }, + onPingRadxa = { runPingRadxa() }, + ) + } + } + + private fun hideSystemBars() { + WindowCompat.setDecorFitsSystemWindows(window, false) + val controller = WindowInsetsControllerCompat(window, window.decorView) + controller.hide(WindowInsetsCompat.Type.systemBars()) + controller.systemBarsBehavior = + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + + private fun restartNativeEngine() { + stopNativeEngine() + nativeHandle = NativeFpvEngine.nativeStart( + callback = nativeCallback, + videoPort = videoPort, + codec = codecName, + transport = transportName, + g29Port = g29Port, + telemetryPort = telemetryPort, + ) + syncNativeFlags() + } + + private fun stopNativeEngine() { + val h = nativeHandle + nativeHandle = 0L + if (h != 0L) { + NativeFpvEngine.nativeStop(h) + } + } + + private fun syncNativeFlags() { + val h = nativeHandle + if (h != 0L) { + NativeFpvEngine.nativeSyncUiFlags(h, dvrRecording, osdEnabled) + } + } + + private fun toggleDvr() { + if (dvrRecording) { + decoder.stopDvr() + dvrRecording = false + } else { + dvrRecording = decoder.startDvr() + } + syncNativeFlags() + } + + private fun runPingRadxa() { + pingStatus = "Ping..." + Thread { + val rtt = NativeFpvEngine.nativePingRadxa(radxaIp, g29Port) + runOnUiThread { + pingStatus = if (rtt >= 0f) { + String.format(Locale.US, "Radxa %.1f ms", rtt) + } else { + "Radxa hors ligne" + } + } + }.start() + } + + override fun onDestroy() { + stopNativeEngine() + decoder.release() + super.onDestroy() + } +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/NativeFpvEngine.kt b/android/app/src/main/kotlin/com/steamframe/fpv/NativeFpvEngine.kt new file mode 100644 index 0000000..cc7367d --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/NativeFpvEngine.kt @@ -0,0 +1,138 @@ +package com.steamframe.fpv + +import org.json.JSONObject + +data class VideoMetricsSnapshot( + val fps: Float = 0f, + val jitterMs: Float = 0f, + val bitrateKbps: Int = 0, + val droppedPackets: Long = 0L, + val receivedPackets: Long = 0L, + val signalLive: Boolean = false, +) + +data class TelemetrySnapshot( + val live: Boolean = false, + val batteryV: Float = 0f, + val cells: Int = 0, + val cellV: Float = 0f, + val batteryPct: Int = -1, + val rssiDbm: Int = -127, + val linkQuality: Int = 0, + val sats: Int = 0, + val gpsFix: Boolean = false, + val altitudeM: Float = 0f, + val speedKmh: Float = 0f, + val homeDistM: Float = -1f, + val homeBearingDeg: Float = 0f, + val flightMode: String = "", + val srtLine: String = "", +) + +data class G29Snapshot( + val live: Boolean = false, + val armed: Boolean = false, + val failsafe: Boolean = false, + val gear: Int = 0, + val gearLabel: String = "N", + val steeringPct: Int = 0, + val throttlePct: Int = 0, + val brakePct: Int = 0, + val toast: String = "", + val source: String = "Volant G29", +) + +data class FpvSnapshot( + val video: VideoMetricsSnapshot = VideoMetricsSnapshot(), + val telemetry: TelemetrySnapshot = TelemetrySnapshot(), + val g29: G29Snapshot = G29Snapshot(), +) { + companion object { + fun fromJson(raw: String): FpvSnapshot { + return try { + val root = JSONObject(raw) + val v = root.optJSONObject("video") + val t = root.optJSONObject("telemetry") + val g = root.optJSONObject("g29") + FpvSnapshot( + video = if (v != null) VideoMetricsSnapshot( + fps = v.optDouble("fps", 0.0).toFloat(), + jitterMs = v.optDouble("jitterMs", 0.0).toFloat(), + bitrateKbps = v.optInt("bitrateKbps", 0), + droppedPackets = v.optLong("droppedPackets", 0L), + receivedPackets = v.optLong("receivedPackets", 0L), + signalLive = v.optBoolean("signalLive", false), + ) else VideoMetricsSnapshot(), + telemetry = if (t != null) TelemetrySnapshot( + live = t.optBoolean("live", false), + batteryV = t.optDouble("batteryV", 0.0).toFloat(), + cells = t.optInt("cells", 0), + cellV = t.optDouble("cellV", 0.0).toFloat(), + batteryPct = t.optInt("batteryPct", -1), + rssiDbm = t.optInt("rssiDbm", -127), + linkQuality = t.optInt("linkQuality", 0), + sats = t.optInt("sats", 0), + gpsFix = t.optBoolean("gpsFix", false), + altitudeM = t.optDouble("altitudeM", 0.0).toFloat(), + speedKmh = t.optDouble("speedKmh", 0.0).toFloat(), + homeDistM = t.optDouble("homeDistM", -1.0).toFloat(), + homeBearingDeg = t.optDouble("homeBearingDeg", 0.0).toFloat(), + flightMode = t.optString("flightMode", ""), + srtLine = t.optString("srtLine", ""), + ) else TelemetrySnapshot(), + g29 = if (g != null) G29Snapshot( + live = g.optBoolean("live", false), + armed = g.optBoolean("armed", false), + failsafe = g.optBoolean("failsafe", false), + gear = g.optInt("gear", 0), + gearLabel = g.optString("gearLabel", "N"), + steeringPct = g.optInt("steeringPct", 0), + throttlePct = g.optInt("throttlePct", 0), + brakePct = g.optInt("brakePct", 0), + toast = g.optString("toast", ""), + source = g.optString("source", "Volant G29"), + ) else G29Snapshot(), + ) + } catch (_: Exception) { + FpvSnapshot() + } + } + } +} + +interface NativeFpvCallback { + fun onVideoNal(data: ByteArray, ptsUs: Long, isKeyframe: Boolean, isCodecConfig: Boolean) + fun onG29Action(actionCode: Int) +} + +object NativeFpvEngine { + const val ACTION_TOGGLE_DVR = 1 + const val ACTION_TOGGLE_OSD = 2 + const val ACTION_RECENTER_HT = 3 + + init { + System.loadLibrary("fpv_android_ffi") + } + + @JvmStatic + external fun nativeStart( + callback: NativeFpvCallback, + videoPort: Int, + codec: String, + transport: String, + g29Port: Int, + telemetryPort: Int, + ): Long + + @JvmStatic + external fun nativeStop(handle: Long) + + @JvmStatic + external fun nativeSyncUiFlags(handle: Long, dvrActive: Boolean, osdActive: Boolean) + + @JvmStatic + external fun nativePollSnapshotJson(handle: Long): String + + @JvmStatic + external fun nativePingRadxa(radxaIp: String, port: Int): Float +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/Navigation.kt b/android/app/src/main/kotlin/com/steamframe/fpv/Navigation.kt new file mode 100644 index 0000000..1f861b2 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/Navigation.kt @@ -0,0 +1,27 @@ +package com.steamframe.fpv + +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawingPadding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation3.runtime.entryProvider +import androidx.navigation3.runtime.rememberNavBackStack +import androidx.navigation3.ui.NavDisplay +import com.steamframe.fpv.ui.main.MainScreen + +@Composable +fun MainNavigation() { + val backStack = rememberNavBackStack(Main) + + NavDisplay( + backStack = backStack, + onBack = { backStack.removeLastOrNull() }, + entryProvider = + entryProvider { + entry
{ + MainScreen(onItemClick = { navKey -> backStack.add(navKey) }) + } + }, + ) +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/NavigationKeys.kt b/android/app/src/main/kotlin/com/steamframe/fpv/NavigationKeys.kt new file mode 100644 index 0000000..082d730 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/NavigationKeys.kt @@ -0,0 +1,6 @@ +package com.steamframe.fpv + +import androidx.navigation3.runtime.NavKey +import kotlinx.serialization.Serializable + +@Serializable data object Main : NavKey diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/data/DataRepository.kt b/android/app/src/main/kotlin/com/steamframe/fpv/data/DataRepository.kt new file mode 100644 index 0000000..695d95b --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/data/DataRepository.kt @@ -0,0 +1,12 @@ +package com.steamframe.fpv.data + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow + +interface DataRepository { + val data: Flow> +} + +class DefaultDataRepository : DataRepository { + override val data: Flow> = flow { emit(listOf("Android")) } +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreen.kt b/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreen.kt new file mode 100644 index 0000000..d24f4a6 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreen.kt @@ -0,0 +1,105 @@ +package com.steamframe.fpv.ui.main + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.CenterAlignedTopAppBar +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.navigation3.runtime.NavKey +import com.steamframe.fpv.R +import com.steamframe.fpv.data.DefaultDataRepository +import com.steamframe.fpv.ui.theme.SteamFrameFPVTheme + +@Composable +fun MainScreen( + onItemClick: (NavKey) -> Unit, + modifier: Modifier = Modifier, + viewModel: MainScreenViewModel = viewModel { MainScreenViewModel(DefaultDataRepository()) }, +) { + val uiState by viewModel.uiState.collectAsStateWithLifecycle() + when (val state = uiState) { + MainScreenUiState.Loading -> { + Box( + modifier = modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator() + } + } + is MainScreenUiState.Success -> { + MainScreen(data = state.data, modifier = modifier) + } + is MainScreenUiState.Error -> { + Text("Error loading data: ${state.throwable.message}") + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun MainScreen(data: List, modifier: Modifier = Modifier) { + Scaffold( + modifier = modifier, + topBar = { + CenterAlignedTopAppBar( + title = { Text(stringResource(R.string.app_name)) }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + titleContentColor = MaterialTheme.colorScheme.primary + ) + ) + } + ) { innerPadding -> + + // App Content + + Column( + modifier = Modifier.padding(innerPadding), + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + data.forEach { Greeting(it) } + Button( + modifier = Modifier.padding(24.dp, 24.dp), + onClick = { /* Button clicked */ } + ) { + Text("OK") + } + + // TODO: Extend app UI with more Jetpack Compose UI elements here + + } + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name !", + modifier = modifier.padding(16.dp, 16.dp), + style = MaterialTheme.typography.bodyLarge + ) +} + +@Preview(showBackground = true, showSystemUi = true) +@Composable +fun MainScreenPreview() { + SteamFrameFPVTheme { MainScreen(listOf("Android")) } +} + diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreenViewModel.kt b/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreenViewModel.kt new file mode 100644 index 0000000..7d6b616 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/ui/main/MainScreenViewModel.kt @@ -0,0 +1,27 @@ +package com.steamframe.fpv.ui.main + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.steamframe.fpv.data.DataRepository +import com.steamframe.fpv.ui.main.MainScreenUiState.Success +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn + +class MainScreenViewModel(dataRepository: DataRepository) : ViewModel() { + val uiState: StateFlow = + dataRepository.data + .map, MainScreenUiState>(::Success) + .catch { emit(MainScreenUiState.Error(it)) } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), MainScreenUiState.Loading) +} + +sealed interface MainScreenUiState { + object Loading : MainScreenUiState + + data class Error(val throwable: Throwable) : MainScreenUiState + + data class Success(val data: List) : MainScreenUiState +} diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Color.kt b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Color.kt new file mode 100644 index 0000000..54e119a --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Color.kt @@ -0,0 +1,275 @@ +/* + * Copyright 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.steamframe.fpv.ui.theme + +import androidx.compose.ui.graphics.Color + +//Start - Partial Color List + +//Light Colors +val primaryLight = Color(0xFF00506E) +val primaryContainerLight = Color(0xFF23759B) +val secondaryLight = Color(0xFF486271) +val tertiaryLight = Color(0xFF613A73) + + +//Dark Colors +val primaryDark = Color(0xFF87CFF9) +val primaryContainerDark = Color(0xFF005C7D) +val secondaryDark = Color(0xFFB0CADC) +val tertiaryDark = Color(0xFFE6B5F8) + +//End - Partial Color List + +/* + +//Full Color List generated by the Google Material Theme Builder +// https://material-foundation.github.io/material-theme-builder/ +// Source / Primary Color: 2300668B +// Color Match: true + +//Light Colors + +val primaryLight = Color(0xFF00506E) +val onPrimaryLight = Color(0xFFFFFFFF) +val primaryContainerLight = Color(0xFF23759B) +val onPrimaryContainerLight = Color(0xFFFFFFFF) +val secondaryLight = Color(0xFF486271) +val onSecondaryLight = Color(0xFFFFFFFF) +val secondaryContainerLight = Color(0xFFCFEAFD) +val onSecondaryContainerLight = Color(0xFF344D5C) +val tertiaryLight = Color(0xFF613A73) +val onTertiaryLight = Color(0xFFFFFFFF) +val tertiaryContainerLight = Color(0xFF885E9A) +val onTertiaryContainerLight = Color(0xFFFFFFFF) +val errorLight = Color(0xFFBA1A1A) +val onErrorLight = Color(0xFFFFFFFF) +val errorContainerLight = Color(0xFFFFDAD6) +val onErrorContainerLight = Color(0xFF410002) +val backgroundLight = Color(0xFFF7F9FD) +val onBackgroundLight = Color(0xFF191C1F) +val surfaceLight = Color(0xFFF7F9FD) +val onSurfaceLight = Color(0xFF191C1F) +val surfaceVariantLight = Color(0xFFDBE4EB) +val onSurfaceVariantLight = Color(0xFF40484E) +val outlineLight = Color(0xFF70787E) +val outlineVariantLight = Color(0xFFBFC8CF) +val scrimLight = Color(0xFF000000) +val inverseSurfaceLight = Color(0xFF2D3133) +val inverseOnSurfaceLight = Color(0xFFEFF1F4) +val inversePrimaryLight = Color(0xFF87CFF9) +val surfaceDimLight = Color(0xFFD8DADD) +val surfaceBrightLight = Color(0xFFF7F9FD) +val surfaceContainerLowestLight = Color(0xFFFFFFFF) +val surfaceContainerLowLight = Color(0xFFF2F4F7) +val surfaceContainerLight = Color(0xFFECEEF1) +val surfaceContainerHighLight = Color(0xFFE6E8EC) +val surfaceContainerHighestLight = Color(0xFFE0E3E6) + +//Light Colors - Medium Contrast + +val primaryLightMediumContrast = Color(0xFF004864) +val onPrimaryLightMediumContrast = Color(0xFFFFFFFF) +val primaryContainerLightMediumContrast = Color(0xFF23759B) +val onPrimaryContainerLightMediumContrast = Color(0xFFFFFFFF) +val secondaryLightMediumContrast = Color(0xFF2D4655) +val onSecondaryLightMediumContrast = Color(0xFFFFFFFF) +val secondaryContainerLightMediumContrast = Color(0xFF5E7888) +val onSecondaryContainerLightMediumContrast = Color(0xFFFFFFFF) +val tertiaryLightMediumContrast = Color(0xFF5A336C) +val onTertiaryLightMediumContrast = Color(0xFFFFFFFF) +val tertiaryContainerLightMediumContrast = Color(0xFF885E9A) +val onTertiaryContainerLightMediumContrast = Color(0xFFFFFFFF) +val errorLightMediumContrast = Color(0xFF8C0009) +val onErrorLightMediumContrast = Color(0xFFFFFFFF) +val errorContainerLightMediumContrast = Color(0xFFDA342E) +val onErrorContainerLightMediumContrast = Color(0xFFFFFFFF) +val backgroundLightMediumContrast = Color(0xFFF7F9FD) +val onBackgroundLightMediumContrast = Color(0xFF191C1F) +val surfaceLightMediumContrast = Color(0xFFF7F9FD) +val onSurfaceLightMediumContrast = Color(0xFF191C1F) +val surfaceVariantLightMediumContrast = Color(0xFFDBE4EB) +val onSurfaceVariantLightMediumContrast = Color(0xFF3C444A) +val outlineLightMediumContrast = Color(0xFF586066) +val outlineVariantLightMediumContrast = Color(0xFF737C82) +val scrimLightMediumContrast = Color(0xFF000000) +val inverseSurfaceLightMediumContrast = Color(0xFF2D3133) +val inverseOnSurfaceLightMediumContrast = Color(0xFFEFF1F4) +val inversePrimaryLightMediumContrast = Color(0xFF87CFF9) +val surfaceDimLightMediumContrast = Color(0xFFD8DADD) +val surfaceBrightLightMediumContrast = Color(0xFFF7F9FD) +val surfaceContainerLowestLightMediumContrast = Color(0xFFFFFFFF) +val surfaceContainerLowLightMediumContrast = Color(0xFFF2F4F7) +val surfaceContainerLightMediumContrast = Color(0xFFECEEF1) +val surfaceContainerHighLightMediumContrast = Color(0xFFE6E8EC) +val surfaceContainerHighestLightMediumContrast = Color(0xFFE0E3E6) + +//Light Colors - High Contrast + +val primaryLightHighContrast = Color(0xFF002536) +val onPrimaryLightHighContrast = Color(0xFFFFFFFF) +val primaryContainerLightHighContrast = Color(0xFF004864) +val onPrimaryContainerLightHighContrast = Color(0xFFFFFFFF) +val secondaryLightHighContrast = Color(0xFF082533) +val onSecondaryLightHighContrast = Color(0xFFFFFFFF) +val secondaryContainerLightHighContrast = Color(0xFF2D4655) +val onSecondaryContainerLightHighContrast = Color(0xFFFFFFFF) +val tertiaryLightHighContrast = Color(0xFF361048) +val onTertiaryLightHighContrast = Color(0xFFFFFFFF) +val tertiaryContainerLightHighContrast = Color(0xFF5A336C) +val onTertiaryContainerLightHighContrast = Color(0xFFFFFFFF) +val errorLightHighContrast = Color(0xFF4E0002) +val onErrorLightHighContrast = Color(0xFFFFFFFF) +val errorContainerLightHighContrast = Color(0xFF8C0009) +val onErrorContainerLightHighContrast = Color(0xFFFFFFFF) +val backgroundLightHighContrast = Color(0xFFF7F9FD) +val onBackgroundLightHighContrast = Color(0xFF191C1F) +val surfaceLightHighContrast = Color(0xFFF7F9FD) +val onSurfaceLightHighContrast = Color(0xFF000000) +val surfaceVariantLightHighContrast = Color(0xFFDBE4EB) +val onSurfaceVariantLightHighContrast = Color(0xFF1D252A) +val outlineLightHighContrast = Color(0xFF3C444A) +val outlineVariantLightHighContrast = Color(0xFF3C444A) +val scrimLightHighContrast = Color(0xFF000000) +val inverseSurfaceLightHighContrast = Color(0xFF2D3133) +val inverseOnSurfaceLightHighContrast = Color(0xFFFFFFFF) +val inversePrimaryLightHighContrast = Color(0xFFD9EFFF) +val surfaceDimLightHighContrast = Color(0xFFD8DADD) +val surfaceBrightLightHighContrast = Color(0xFFF7F9FD) +val surfaceContainerLowestLightHighContrast = Color(0xFFFFFFFF) +val surfaceContainerLowLightHighContrast = Color(0xFFF2F4F7) +val surfaceContainerLightHighContrast = Color(0xFFECEEF1) +val surfaceContainerHighLightHighContrast = Color(0xFFE6E8EC) +val surfaceContainerHighestLightHighContrast = Color(0xFFE0E3E6) + +//Dark Colors + +val primaryDark = Color(0xFF87CFF9) +val onPrimaryDark = Color(0xFF00344A) +val primaryContainerDark = Color(0xFF005C7D) +val onPrimaryContainerDark = Color(0xFFF4F9FF) +val secondaryDark = Color(0xFFB0CADC) +val onSecondaryDark = Color(0xFF193342) +val secondaryContainerDark = Color(0xFF294351) +val onSecondaryContainerDark = Color(0xFFBDD8EA) +val tertiaryDark = Color(0xFFE6B5F8) +val onTertiaryDark = Color(0xFF462058) +val tertiaryContainerDark = Color(0xFF6E4680) +val onTertiaryContainerDark = Color(0xFFFFF9FB) +val errorDark = Color(0xFFFFB4AB) +val onErrorDark = Color(0xFF690005) +val errorContainerDark = Color(0xFF93000A) +val onErrorContainerDark = Color(0xFFFFDAD6) +val backgroundDark = Color(0xFF101416) +val onBackgroundDark = Color(0xFFE0E3E6) +val surfaceDark = Color(0xFF101416) +val onSurfaceDark = Color(0xFFE0E3E6) +val surfaceVariantDark = Color(0xFF40484E) +val onSurfaceVariantDark = Color(0xFFBFC8CF) +val outlineDark = Color(0xFF899298) +val outlineVariantDark = Color(0xFF40484E) +val scrimDark = Color(0xFF000000) +val inverseSurfaceDark = Color(0xFFE0E3E6) +val inverseOnSurfaceDark = Color(0xFF2D3133) +val inversePrimaryDark = Color(0xFF00668A) +val surfaceDimDark = Color(0xFF101416) +val surfaceBrightDark = Color(0xFF363A3C) +val surfaceContainerLowestDark = Color(0xFF0B0F11) +val surfaceContainerLowDark = Color(0xFF191C1F) +val surfaceContainerDark = Color(0xFF1D2023) +val surfaceContainerHighDark = Color(0xFF272A2D) +val surfaceContainerHighestDark = Color(0xFF323538) + +//Dark Colors - Medium Contrast + +val primaryDarkMediumContrast = Color(0xFF8BD3FD) +val onPrimaryDarkMediumContrast = Color(0xFF001925) +val primaryContainerDarkMediumContrast = Color(0xFF4E99C0) +val onPrimaryContainerDarkMediumContrast = Color(0xFF000000) +val secondaryDarkMediumContrast = Color(0xFFB4CEE1) +val onSecondaryDarkMediumContrast = Color(0xFF001925) +val secondaryContainerDarkMediumContrast = Color(0xFF7A94A5) +val onSecondaryContainerDarkMediumContrast = Color(0xFF000000) +val tertiaryDarkMediumContrast = Color(0xFFEAB9FD) +val onTertiaryDarkMediumContrast = Color(0xFF29013B) +val tertiaryContainerDarkMediumContrast = Color(0xFFAD80BF) +val onTertiaryContainerDarkMediumContrast = Color(0xFF000000) +val errorDarkMediumContrast = Color(0xFFFFBAB1) +val onErrorDarkMediumContrast = Color(0xFF370001) +val errorContainerDarkMediumContrast = Color(0xFFFF5449) +val onErrorContainerDarkMediumContrast = Color(0xFF000000) +val backgroundDarkMediumContrast = Color(0xFF101416) +val onBackgroundDarkMediumContrast = Color(0xFFE0E3E6) +val surfaceDarkMediumContrast = Color(0xFF101416) +val onSurfaceDarkMediumContrast = Color(0xFFF9FBFE) +val surfaceVariantDarkMediumContrast = Color(0xFF40484E) +val onSurfaceVariantDarkMediumContrast = Color(0xFFC3CCD3) +val outlineDarkMediumContrast = Color(0xFF9CA4AB) +val outlineVariantDarkMediumContrast = Color(0xFF7C848B) +val scrimDarkMediumContrast = Color(0xFF000000) +val inverseSurfaceDarkMediumContrast = Color(0xFFE0E3E6) +val inverseOnSurfaceDarkMediumContrast = Color(0xFF272A2D) +val inversePrimaryDarkMediumContrast = Color(0xFF004E6B) +val surfaceDimDarkMediumContrast = Color(0xFF101416) +val surfaceBrightDarkMediumContrast = Color(0xFF363A3C) +val surfaceContainerLowestDarkMediumContrast = Color(0xFF0B0F11) +val surfaceContainerLowDarkMediumContrast = Color(0xFF191C1F) +val surfaceContainerDarkMediumContrast = Color(0xFF1D2023) +val surfaceContainerHighDarkMediumContrast = Color(0xFF272A2D) +val surfaceContainerHighestDarkMediumContrast = Color(0xFF323538) + +//Dark Colors - High Contrast + +val primaryDarkHighContrast = Color(0xFFF8FBFF) +val onPrimaryDarkHighContrast = Color(0xFF000000) +val primaryContainerDarkHighContrast = Color(0xFF8BD3FD) +val onPrimaryContainerDarkHighContrast = Color(0xFF000000) +val secondaryDarkHighContrast = Color(0xFFF8FBFF) +val onSecondaryDarkHighContrast = Color(0xFF000000) +val secondaryContainerDarkHighContrast = Color(0xFFB4CEE1) +val onSecondaryContainerDarkHighContrast = Color(0xFF000000) +val tertiaryDarkHighContrast = Color(0xFFFFF9FB) +val onTertiaryDarkHighContrast = Color(0xFF000000) +val tertiaryContainerDarkHighContrast = Color(0xFFEAB9FD) +val onTertiaryContainerDarkHighContrast = Color(0xFF000000) +val errorDarkHighContrast = Color(0xFFFFF9F9) +val onErrorDarkHighContrast = Color(0xFF000000) +val errorContainerDarkHighContrast = Color(0xFFFFBAB1) +val onErrorContainerDarkHighContrast = Color(0xFF000000) +val backgroundDarkHighContrast = Color(0xFF101416) +val onBackgroundDarkHighContrast = Color(0xFFE0E3E6) +val surfaceDarkHighContrast = Color(0xFF101416) +val onSurfaceDarkHighContrast = Color(0xFFFFFFFF) +val surfaceVariantDarkHighContrast = Color(0xFF40484E) +val onSurfaceVariantDarkHighContrast = Color(0xFFF8FBFF) +val outlineDarkHighContrast = Color(0xFF3C444A) +val outlineVariantDarkHighContrast = Color(0xFF3C444A) +val scrimDarkHighContrast = Color(0xFF000000) +val inverseSurfaceDarkHighContrast = Color(0xFFE0E3E6) +val inverseOnSurfaceDarkHighContrast = Color(0xFF000000) +val inversePrimaryDarkHighContrast = Color(0xFF002E41) +val surfaceDimDarkHighContrast = Color(0xFF101416) +val surfaceBrightDarkHighContrast = Color(0xFF363A3C) +val surfaceContainerLowestDarkHighContrast = Color(0xFF0B0F11) +val surfaceContainerLowDarkHighContrast = Color(0xFF191C1F) +val surfaceContainerDarkHighContrast = Color(0xFF1D2023) +val surfaceContainerHighDarkHighContrast = Color(0xFF272A2D) +val surfaceContainerHighestDarkHighContrast = Color(0xFF323538) + +*/ + + diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Theme.kt b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Theme.kt new file mode 100644 index 0000000..b6188a8 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Theme.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.steamframe.fpv.ui.theme + +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = primaryDark, + primaryContainer = primaryContainerDark, + secondary = secondaryDark, + tertiary = tertiaryDark +) + +private val LightColorScheme = lightColorScheme( + primary = primaryLight, + primaryContainer = primaryContainerLight, + secondary = secondaryLight, + tertiary = tertiaryLight +) + +@Composable +fun SteamFrameFPVTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = false, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} + diff --git a/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Type.kt b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Type.kt new file mode 100644 index 0000000..63db8b4 --- /dev/null +++ b/android/app/src/main/kotlin/com/steamframe/fpv/ui/theme/Type.kt @@ -0,0 +1,36 @@ +package com.steamframe.fpv.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = + Typography( + bodyLarge = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ + ) diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..ff66216 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + SteamFrame FPV + \ No newline at end of file diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..c8b5cdc --- /dev/null +++ b/android/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +