feat(android): add fpv-android-ffi JNI bridge and Galaxy Tab S8 Ultra Compose/MediaCodec app

This commit is contained in:
bleack committed 2026-11-27 00:08:57 +01:00
1 parent 16d05785fb
commit 6ccdb82f89
50 files changed
+2962 -1

No files matched your search

@@ -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<ComponentActivity>()
@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")
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.SteamFrameFPV">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -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)
}
}
@@ -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<ByteArray>()
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
}
}
@@ -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()
}
}
@@ -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
}
@@ -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<Main> {
MainScreen(onItemClick = { navKey -> backStack.add(navKey) })
}
},
)
}
@@ -0,0 +1,6 @@
package com.steamframe.fpv
import androidx.navigation3.runtime.NavKey
import kotlinx.serialization.Serializable
@Serializable data object Main : NavKey
@@ -0,0 +1,12 @@
package com.steamframe.fpv.data
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
interface DataRepository {
val data: Flow<List<String>>
}
class DefaultDataRepository : DataRepository {
override val data: Flow<List<String>> = flow { emit(listOf("Android")) }
}
@@ -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<String>, 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")) }
}
@@ -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<MainScreenUiState> =
dataRepository.data
.map<List<String>, 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<String>) : MainScreenUiState
}
@@ -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)
*/
@@ -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
)
}
@@ -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
)
*/
)
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">SteamFrame FPV</string>
</resources>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.SteamFrameFPV" parent="android:Theme.Material.Light.NoActionBar" />
</resources>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older than API 31
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
</full-backup-content>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!-- TODO: Use <include> and <exclude> to control what is backed up.
<include .../>
<exclude .../>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>
@@ -0,0 +1,27 @@
package com.steamframe.fpv.ui.main
import com.steamframe.fpv.data.DataRepository
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.test.runTest
import org.junit.Test
class MainScreenViewModelTest {
@Test
fun uiState_initiallyLoading() = runTest {
val viewModel = MainScreenViewModel(FakeMyModelRepository())
assertEquals(viewModel.uiState.first(), MainScreenUiState.Loading)
}
@Test
fun uiState_onItemSaved_isDisplayed() = runTest {
val viewModel = MainScreenViewModel(FakeMyModelRepository())
assertEquals(viewModel.uiState.first(), MainScreenUiState.Loading)
}
}
private class FakeMyModelRepository : DataRepository {
override val data: Flow<List<String>> = flow { emit(listOf("Sample")) }
}