Skip to content

RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.

Aircraft: filter chip and list rows; radar labels show distance and altitude without overlapping

CIS-C07874e6529e2b
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index adf55d9..5fde52d 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -44,6 +44,7 @@ class MainActivity : AppCompatActivity() {
private const val CELL_ROW = "cell:"
private const val WAZE_ROW = "waze:"
private const val RADIO_ROW = "radio:"
+ private const val AIRCRAFT_ROW = "air:"
/** A radio row flashes while its transmitter was heard this recently. */
private const val RADIO_LIVE_MS = 15_000L
private const val BLUETOOTH_TAG_COLOR = 0xFF1565C0.toInt()
@@ -105,6 +106,12 @@ class MainActivity : AppCompatActivity() {
onClick = {
if (it.mac.startsWith(CELL_ROW)) startActivity(Intent(this, com.rfsentinel.app.ui.CellTowersActivity::class.java))
else if (it.mac.startsWith(RADIO_ROW)) startActivity(Intent(this, com.rfsentinel.app.ui.DetectionLogActivity::class.java))
+ else if (it.mac.startsWith(AIRCRAFT_ROW)) {
+ val hex = it.mac.removePrefix(AIRCRAFT_ROW)
+ currentAircraft(System.currentTimeMillis()).firstOrNull { a -> a.plane.hex == hex }?.let { a ->
+ com.rfsentinel.app.ui.MapActivity.onlineIntent(this, AIRCRAFT_ROW + hex, a.plane.lat, a.plane.lon)?.let { i -> startActivity(i) }
+ }
+ }
else if (it.mac.startsWith(WAZE_ROW)) {
com.rfsentinel.app.online.WazePolice.latest.firstOrNull { w -> WAZE_ROW + w.report.id == it.mac }?.let { w ->
startActivity(Intent(this, com.rfsentinel.app.ui.MapActivity::class.java)
@@ -114,7 +121,7 @@ class MainActivity : AppCompatActivity() {
}
else DeviceActions.openDetails(this, it.mac)
},
- onLongPress = { if (!it.mac.startsWith(CELL_ROW) && !it.mac.startsWith(WAZE_ROW) && !it.mac.startsWith(RADIO_ROW)) DeviceActions.showQuickActions(this, it.mac) }
+ onLongPress = { if (listOf(CELL_ROW, WAZE_ROW, RADIO_ROW, AIRCRAFT_ROW).none { p -> it.mac.startsWith(p) }) DeviceActions.showQuickActions(this, it.mac) }
)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter
@@ -571,6 +578,7 @@ class MainActivity : AppCompatActivity() {
val n = when (f) {
com.rfsentinel.app.ui.DeviceFilter.CELLS -> liveCellCount(now)
com.rfsentinel.app.ui.DeviceFilter.WAZE -> currentWaze(now).size
+ com.rfsentinel.app.ui.DeviceFilter.AIRCRAFT -> currentAircraft(now).size
com.rfsentinel.app.ui.DeviceFilter.RADIO -> if (ScanForegroundService.isRunning) com.rfsentinel.app.sdr.RadioLog.current(now).size else 0
else -> all.count { f.matches(it) }
}
@@ -604,12 +612,14 @@ class MainActivity : AppCompatActivity() {
val cells = cellRows(now)
val waze = wazeRows(now, threshold)
val radio = radioRows(now, threshold)
- // Waze reports and radios on the air that meet the alert threshold flash at the very top;
+ val air = aircraftRows(now, threshold)
+ // Waze reports, radios on the air and aircraft that meet the alert threshold flash at the very top;
// the rest follow the devices.
val (urgent, quiet) = waze.partition { it.flashing }
val (radioLive, radioOld) = radio.partition { it.flashing }
- submitRows(radioLive + urgent + visible.map { toRow(it, now, threshold) } + radioOld + cells + quiet)
- shownCells = cells.size + waze.size + radio.size
+ val (airUrgent, airQuiet) = air.partition { it.flashing }
+ submitRows(airUrgent + radioLive + urgent + visible.map { toRow(it, now, threshold) } + airQuiet + radioOld + cells + quiet)
+ shownCells = cells.size + waze.size + radio.size + air.size
}
binding.emptyText.visibility = if (visible.isEmpty() && (!panes.listShown || shownCells == 0)) View.VISIBLE else View.GONE
binding.emptyText.text = when {
@@ -619,6 +629,8 @@ class MainActivity : AppCompatActivity() {
"No Waze reports in range.\nTurn on Waze police reports in Settings and keep scanning."
filter == com.rfsentinel.app.ui.DeviceFilter.RADIO ->
"No radio transmissions heard in the last 5 minutes.\nNeeds an RTL-SDR on USB and the Police radio category on in Settings."
+ filter == com.rfsentinel.app.ui.DeviceFilter.AIRCRAFT ->
+ "No aircraft yet.\nThey come from an RTL-SDR on USB set to ADS-B, or from the online feeds when that's on in Settings."
filter == com.rfsentinel.app.ui.DeviceFilter.CELLS ->
"No cell towers yet - they're read every 15 s while scanning\n(needs the Fake cell tower category on in Settings)."
else -> "No devices match this filter."
@@ -727,6 +739,53 @@ class MainActivity : AppCompatActivity() {
}
}
+ /** The aircraft heard right now (RTL-SDR ADS-B and the online feeds); made-up ones in the demo. */
+ private fun currentAircraft(now: Long): List<com.rfsentinel.app.online.PoliceAircraft.Seen> = when {
+ demoMode -> com.rfsentinel.app.ui.DemoData.aircraft(com.rfsentinel.app.ui.DemoData.fakeLocation?.let { it.latitude to it.longitude } ?: (0.0 to 0.0))
+ !ScanForegroundService.isRunning -> emptyList()
+ else -> com.rfsentinel.app.online.PoliceAircraft.all(now)
+ }
+
+ /**
+ * Aircraft as rows: under All only the law-enforcement ones (so airliners don't fill the list), under
+ * Aircraft every one, police first, then nearest. A police one at or above the alert threshold is
+ * tinted, flashes and is pinned to the top. Tap: the aircraft on the map.
+ */
+ private fun aircraftRows(now: Long, threshold: Int): List<DeviceRow> {
+ if (filter != com.rfsentinel.app.ui.DeviceFilter.ALL && filter != com.rfsentinel.app.ui.DeviceFilter.AIRCRAFT) return emptyList()
+ val all = filter == com.rfsentinel.app.ui.DeviceFilter.AIRCRAFT
+ val me = (if (demoMode) com.rfsentinel.app.ui.DemoData.fakeLocation else ScanForegroundService.lastFix)?.let { it.latitude to it.longitude }
+ val color = com.rfsentinel.app.ui.ThemeManager.ink(this, Category.AIRCRAFT.colorArgb)
+ val air = com.rfsentinel.app.ui.AircraftActivity
+ return currentAircraft(now)
+ .filter { all || it.hit != null }
+ .filter { s -> query.isBlank() || listOfNotNull(air.name(s.plane), s.plane.type, s.plane.owner, s.plane.registration, s.hit?.label)
+ .any { it.contains(query.trim(), ignoreCase = true) } }
+ .map { s -> s to me?.let { com.rfsentinel.app.online.PoliceAircraft.distance(s.plane, it.first, it.second) } }
+ .sortedWith(compareByDescending<Pair<com.rfsentinel.app.online.PoliceAircraft.Seen, Double?>> { it.first.hit != null }
+ .thenBy { it.second ?: Double.MAX_VALUE })
+ .map { (s, d) ->
+ val p = s.plane
+ val hit = s.hit
+ val urgent = hit != null && hit.confidence >= threshold
+ val where = d?.let { m -> com.rfsentinel.app.util.Units.distance(m) +
+ me?.let { " " + air.compass(air.bearing(it.first, it.second, p.lat, p.lon)) }.orEmpty() }
+ DeviceRow(
+ mac = AIRCRAFT_ROW + p.hex,
+ title = "Aircraft " + air.name(p) + (hit?.let { " · ${it.label}" } ?: ""),
+ subtitle = listOfNotNull(where, air.altitude(p), p.speedKt?.let { String.format(java.util.Locale.US, "%.0f kt", it) })
+ .joinToString(" · "),
+ meta = listOfNotNull(p.type, p.owner, p.registration?.takeIf { it != air.name(p) }).joinToString(" · ").ifEmpty { p.hex.uppercase() },
+ tag = if (hit != null) "AIRCRAFT · ${hit.confidence}%" else "AIRCRAFT",
+ tagColor = color,
+ highlight = if (urgent) color else null,
+ flashing = urgent,
+ bold = hit != null,
+ confidence = hit?.confidence
+ )
+ }
+ }
+
private fun cellRows(now: Long): List<DeviceRow> {
if ((filter != com.rfsentinel.app.ui.DeviceFilter.ALL && filter != com.rfsentinel.app.ui.DeviceFilter.CELLS) ||
!ScanForegroundService.isRunning) return emptyList()
diff --git a/app/src/main/java/com/rfsentinel/app/car/DeviceListScreen.kt b/app/src/main/java/com/rfsentinel/app/car/DeviceListScreen.kt
index 84d8178..03916fc 100644
--- a/app/src/main/java/com/rfsentinel/app/car/DeviceListScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/DeviceListScreen.kt
@@ -63,7 +63,7 @@ class DeviceListScreen(carContext: CarContext, private val filter: DeviceFilter)
companion object {
/** The filters offered in the car (cell towers have their own screen). */
- val CAR_FILTERS = DeviceFilter.entries.filter { it != DeviceFilter.CELLS && it != DeviceFilter.WAZE && it != DeviceFilter.RADIO }
+ val CAR_FILTERS = DeviceFilter.entries.filter { it != DeviceFilter.CELLS && it != DeviceFilter.WAZE && it != DeviceFilter.RADIO && it != DeviceFilter.AIRCRAFT }
fun titleOf(f: DeviceFilter) = when (f) {
DeviceFilter.ALL -> "All nearby"
diff --git a/app/src/main/java/com/rfsentinel/app/ui/AircraftActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/AircraftActivity.kt
index 0dd174b..5f9a273 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/AircraftActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/AircraftActivity.kt
@@ -144,7 +144,8 @@ class AircraftActivity : AppCompatActivity() {
radar.set(list.mapNotNull { r ->
val d = r.distanceKm ?: return@mapNotNull null
val b = r.bearingDeg ?: return@mapNotNull null
- AircraftRadarView.Blip(b, d, r.seen.plane.trackDeg, name(r.seen.plane), altitude(r.seen.plane), r.seen.hit != null)
+ AircraftRadarView.Blip(b, d, r.seen.plane.trackDeg, name(r.seen.plane),
+ Units.distance(d * 1000) + (altitude(r.seen.plane)?.let { " · $it" } ?: ""), r.seen.hit != null)
}, range)
val now = System.currentTimeMillis()
val mine = if (now - PoliceAircraft.localAt <= 30_000L) PoliceAircraft.local.size else 0
@@ -172,7 +173,7 @@ class AircraftActivity : AppCompatActivity() {
val now = System.currentTimeMillis()
val me = if (demo) (DemoData.fakeLocation?.let { it.latitude to it.longitude } ?: (0.0 to 0.0))
else ScanForegroundService.lastFix?.let { it.latitude to it.longitude }
- val seen = if (demo) demoAircraft(me!!) else PoliceAircraft.all(now)
+ val seen = if (demo) DemoData.aircraft(me!!) else PoliceAircraft.all(now)
rows = seen.map { s ->
val p = s.plane
if (me == null) Row(s, null, null)
@@ -197,43 +198,25 @@ class AircraftActivity : AppCompatActivity() {
.putExtra(MapActivity.EXTRA_CENTER_LON, p.lon))
}
- private fun name(p: PoliceAircraft.Plane) = p.callsign?.trim()?.ifEmpty { null } ?: p.registration ?: p.hex.uppercase()
+ companion object {
+ private val POLICE = 0xFFD0503C.toInt()
- private fun altitude(p: PoliceAircraft.Plane): String? = p.altitudeFt?.let {
- if (Units.imperial) String.format(Locale.US, "%,d ft", it) else String.format(Locale.US, "%,d m", (it * 0.3048).toInt())
- }
+ /** Its callsign, else its registration, else its ICAO address. */
+ fun name(p: PoliceAircraft.Plane) = p.callsign?.trim()?.ifEmpty { null } ?: p.registration ?: p.hex.uppercase()
- private fun compass(deg: Double) = arrayOf("N", "NE", "E", "SE", "S", "SW", "W", "NW")[((deg + 22.5) / 45).toInt() % 8]
+ /** "alt 1,310 m", or "on the ground" (ADS-B reports the ground as 0 or below). */
+ fun altitude(p: PoliceAircraft.Plane): String? = p.altitudeFt?.let {
+ if (it <= 0) "on the ground"
+ else if (Units.imperial) String.format(Locale.US, "alt %,d ft", it) else String.format(Locale.US, "alt %,d m", (it * 0.3048).toInt())
+ }
- private fun bearing(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
- val p1 = Math.toRadians(lat1); val p2 = Math.toRadians(lat2); val dl = Math.toRadians(lon2 - lon1)
- val y = sin(dl) * cos(p2)
- val x = cos(p1) * sin(p2) - sin(p1) * cos(p2) * cos(dl)
- return (Math.toDegrees(atan2(y, x)) + 360) % 360
- }
+ fun compass(deg: Double) = arrayOf("N", "NE", "E", "SE", "S", "SW", "W", "NW")[((deg + 22.5) / 45).toInt() % 8]
- /** Debug builds' demo: a few made-up aircraft around [me], drifting along their headings. */
- private fun demoAircraft(me: Pair<Double, Double>): List<PoliceAircraft.Seen> {
- val t = (System.currentTimeMillis() / 1000 % 600) / 3600.0
- fun plane(hex: String, call: String, km: Double, brg: Double, trk: Double, ft: Int, kt: Double, police: Boolean): PoliceAircraft.Seen {
- val moved = km + kt * 1.852 * t * cos(Math.toRadians(trk - brg))
- val lat = me.first + moved / 111.0 * cos(Math.toRadians(brg))
- val lon = me.second + moved / (111.0 * cos(Math.toRadians(me.first)).coerceAtLeast(0.1)) * sin(Math.toRadians(brg))
- val p = PoliceAircraft.Plane(hex, call, null, if (police) "Helicopter" else "Airliner", if (police) "Demo police air unit" else null,
- lat, lon, ft, kt, trk, false)
- val hit = if (police) com.rfsentinel.app.detect.Hit(com.rfsentinel.app.detect.Category.AIRCRAFT, "Police helicopter", 85,
- "Demo data", "Demo") else null
- return PoliceAircraft.Seen(p, hit)
+ fun bearing(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
+ val p1 = Math.toRadians(lat1); val p2 = Math.toRadians(lat2); val dl = Math.toRadians(lon2 - lon1)
+ val y = sin(dl) * cos(p2)
+ val x = cos(p1) * sin(p2) - sin(p1) * cos(p2) * cos(dl)
+ return (Math.toDegrees(atan2(y, x)) + 360) % 360
}
- return listOf(
- plane("demo01", "POLICE1", 6.0, 40.0, 120.0, 1500, 90.0, true),
- plane("demo02", "DEMO123", 28.0, 200.0, 20.0, 31000, 450.0, false),
- plane("demo03", "DEMO456", 15.0, 300.0, 250.0, 12000, 280.0, false),
- plane("demo04", "DEMO789", 40.0, 110.0, 300.0, 36000, 470.0, false)
- )
- }
-
- companion object {
- private val POLICE = 0xFFD0503C.toInt()
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
index 6a3c50b..984329c 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
@@ -192,4 +192,25 @@ object DemoData {
// Oldest first: each new entry goes on top, so the newest ends up first.
entries.sortedByDescending { it.first }.forEach { it.second() }
}
+
+ /** Debug builds' demo: a few made-up aircraft around [me], drifting along their headings. */
+ fun aircraft(me: Pair<Double, Double>): List<com.rfsentinel.app.online.PoliceAircraft.Seen> {
+ val t = (System.currentTimeMillis() / 1000 % 600) / 3600.0
+ fun plane(hex: String, call: String, km: Double, brg: Double, trk: Double, ft: Int, kt: Double, police: Boolean): com.rfsentinel.app.online.PoliceAircraft.Seen {
+ val moved = km + kt * 1.852 * t * kotlin.math.cos(Math.toRadians(trk - brg))
+ val lat = me.first + moved / 111.0 * kotlin.math.cos(Math.toRadians(brg))
+ val lon = me.second + moved / (111.0 * kotlin.math.cos(Math.toRadians(me.first)).coerceAtLeast(0.1)) * kotlin.math.sin(Math.toRadians(brg))
+ val p = com.rfsentinel.app.online.PoliceAircraft.Plane(hex, call, null, if (police) "Helicopter" else "Airliner", if (police) "Demo police air unit" else null,
+ lat, lon, ft, kt, trk, false)
+ val hit = if (police) com.rfsentinel.app.detect.Hit(com.rfsentinel.app.detect.Category.AIRCRAFT, "Police helicopter", 85,
+ "Demo data", "Demo") else null
+ return com.rfsentinel.app.online.PoliceAircraft.Seen(p, hit)
+ }
+ return listOf(
+ plane("demo01", "POLICE1", 6.0, 40.0, 120.0, 1500, 90.0, true),
+ plane("demo02", "DEMO123", 28.0, 200.0, 20.0, 31000, 450.0, false),
+ plane("demo03", "DEMO456", 15.0, 300.0, 250.0, 12000, 280.0, false),
+ plane("demo04", "DEMO789", 40.0, 110.0, 300.0, 36000, 470.0, false)
+ )
+ }
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
index 6917d19..530185b 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
@@ -23,6 +23,8 @@ enum class DeviceFilter(val label: String) {
RADIO("Radio"),
/** Waze reports: not devices, drawn on the map from the Waze poll (map only). */
WAZE("Waze"),
+ /** Aircraft from the RTL-SDR's ADS-B receiver and the online feeds: not devices (list and map). */
+ AIRCRAFT("Aircraft"),
/** Heard by external hardware: an ESP32 board (USB or OUI-SPY over Bluetooth) or a USB WiFi adapter. */
EXTERNAL("External");
@@ -33,7 +35,7 @@ enum class DeviceFilter(val label: String) {
s.deviceType.contains("tracker", true) || s.deviceType.contains("Find My", true))
DRONES -> s.hits.any { it.category == Category.DRONE } || s.remoteId != null
NEW -> s.isNew
- CELLS, WAZE, RADIO -> false
+ CELLS, WAZE, RADIO, AIRCRAFT -> false
EXTERNAL -> com.rfsentinel.app.esp.HeardBy.esp.recent(s.mac) || com.rfsentinel.app.esp.HeardBy.usb.recent(s.mac)
FAVORITES -> Favorites.contains(s.mac)
BLE -> Advert.Source.BLE in s.sources
@@ -54,6 +56,6 @@ enum class DeviceFilter(val label: String) {
* The main screen's chip order: the counts worth a glance first (flagged, then what's heard on each
* radio), so they fit without scrolling; the narrower filters after them.
*/
- val MAIN_ORDER = listOf(ALL, FLAGGED, BLE, WIFI, CELLS, TRACKERS, DRONES, RADIO, WAZE, EXTERNAL, FAVORITES, NEW)
+ val MAIN_ORDER = listOf(ALL, FLAGGED, BLE, WIFI, CELLS, TRACKERS, DRONES, AIRCRAFT, RADIO, WAZE, EXTERNAL, FAVORITES, NEW)
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt b/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
index 817b201..f7b2b37 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
@@ -1242,6 +1242,7 @@ class MapFragment : Fragment() {
val n = when (f) {
DeviceFilter.CELLS -> rf?.towerCount ?: 0
DeviceFilter.WAZE -> com.rfsentinel.app.online.WazePolice.latest.size
+ DeviceFilter.AIRCRAFT -> com.rfsentinel.app.online.PoliceAircraft.all().size
else -> placed.count { f.matches(it) }
}
chip.text = if (f == DeviceFilter.ALL || n > 0) "${f.label} $n" else f.label
diff --git a/app/src/main/java/com/rfsentinel/app/ui/VisualViews.kt b/app/src/main/java/com/rfsentinel/app/ui/VisualViews.kt
index b00c915..b20b278 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/VisualViews.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/VisualViews.kt
@@ -392,7 +392,8 @@ class SatBarsView @JvmOverloads constructor(context: Context, attrs: AttributeSe
* law-enforcement ones in red.
*/
class AircraftRadarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) {
- class Blip(val bearingDeg: Double, val distanceKm: Double, val trackDeg: Double?, val label: String, val altitude: String?, val police: Boolean)
+ /** [detail]: the line under the name ("9.9 km · alt 1,310 m"). */
+ class Blip(val bearingDeg: Double, val distanceKm: Double, val trackDeg: Double?, val label: String, val detail: String?, val police: Boolean)
private var blips: List<Blip> = emptyList()
private var rangeKm = 50.0
@@ -440,6 +441,9 @@ class AircraftRadarView @JvmOverloads constructor(context: Context, attrs: Attri
plane.color = accent
canvas.drawCircle(cx, cy, 4 * dp, plane)
+ // Planes first (police drawn last, on top); then labels, police and nearest first, skipping any that would overlap.
+ val placed = ArrayList<RectF>()
+ val labels = ArrayList<Triple<Blip, Float, Float>>()
for (b in blips.sortedBy { it.police }) {
val f = (b.distanceKm / rangeKm).coerceAtMost(1.0)
val a = Math.toRadians(b.bearingDeg - 90)
@@ -456,13 +460,25 @@ class AircraftRadarView @JvmOverloads constructor(context: Context, attrs: Attri
canvas.drawPath(path, plane)
} else canvas.drawCircle(0f, 0f, s * 0.5f, plane)
canvas.restore()
- text.textAlign = Paint.Align.LEFT
+ labels += Triple(b, x, y)
+ }
+ text.textAlign = Paint.Align.LEFT
+ for ((b, x, y) in labels.sortedWith(compareByDescending<Triple<Blip, Float, Float>> { it.first.police }.thenBy { it.first.distanceKm })) {
+ val c = if (b.police) 0xFFD0503C.toInt() else ink
+ val s = (if (b.police) 9f else 7f) * dp
text.typeface = if (b.police) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
text.textSize = 10 * dp
+ val w1 = text.measureText(b.label)
+ text.textSize = 9 * dp
+ val w = maxOf(w1, b.detail?.let { text.measureText(it) } ?: 0f)
+ val lx = if (x > cx + r * 0.5f) x - w - s - 2 * dp else x + s + 2 * dp
+ val box = RectF(lx, y - 10 * dp, lx + w, y + (if (b.detail != null) 13 else 3) * dp)
+ if (placed.any { RectF.intersects(it, box) }) continue
+ placed += box
+ text.textSize = 10 * dp
text.color = c
- val lx = if (x > cx + r * 0.5f) x - text.measureText(b.label) - s - 2 * dp else x + s + 2 * dp
canvas.drawText(b.label, lx, y, text)
- b.altitude?.let {
+ b.detail?.let {
text.textSize = 9 * dp
text.color = alpha(c, 0xAA)
canvas.drawText(it, lx, y + 11 * dp, text)
diff --git a/app/src/test/java/com/rfsentinel/app/ui/AircraftTextTest.kt b/app/src/test/java/com/rfsentinel/app/ui/AircraftTextTest.kt
new file mode 100644
index 0000000..018a402
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/ui/AircraftTextTest.kt
@@ -0,0 +1,28 @@
+package com.rfsentinel.app.ui
+
+import com.rfsentinel.app.online.PoliceAircraft
+import com.rfsentinel.app.util.Units
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Test
+
+class AircraftTextTest {
+ private fun plane(ft: Int?) = PoliceAircraft.Plane("abc123", "TEST1", null, null, null, 0.0, 0.0, ft, null, null, false)
+
+ @Test
+ fun altitudeSaysAltAndTheGround() {
+ Units.imperial = false
+ assertEquals("alt 1,310 m", AircraftActivity.altitude(plane(4300)))
+ assertEquals("on the ground", AircraftActivity.altitude(plane(0)))
+ assertEquals("on the ground", AircraftActivity.altitude(plane(-175)))
+ Units.imperial = true
+ assertEquals("alt 4,300 ft", AircraftActivity.altitude(plane(4300)))
+ Units.imperial = false
+ }
+
+ @Test
+ fun aircraftAreNotDevices() {
+ assertFalse(DeviceFilter.AIRCRAFT in com.rfsentinel.app.car.DeviceListScreen.CAR_FILTERS)
+ assertEquals(DeviceFilter.AIRCRAFT, DeviceFilter.parse("AIRCRAFT"))
+ }
+}