feat: add node colors (#618)

This commit is contained in:
Andre K 2023-04-13 17:54:52 -03:00 committed by GitHub
parent dc596e25a2
commit a8be41d158
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package com.geeksville.mesh
import android.graphics.Color
import android.os.Parcelable
import com.geeksville.mesh.util.bearing
import com.geeksville.mesh.util.latLongToMeter
@ -153,6 +154,15 @@ data class NodeInfo(
var environmentMetrics: EnvironmentMetrics? = null,
) : Parcelable {
val colors: Pair<Int, Int>
get() { // returns foreground and background @ColorInt for each 'num'
val r = (num and 0xFF0000) shr 16
val g = (num and 0x00FF00) shr 8
val b = num and 0x0000FF
val brightness = ((r * 0.299) + (g * 0.587) + (b * 0.114)) / 255
return Pair(if (brightness > 0.5) Color.BLACK else Color.WHITE, Color.rgb(r, g, b))
}
val batteryLevel get() = deviceMetrics?.batteryLevel
val voltage get() = deviceMetrics?.voltage
val batteryStr get() = if (batteryLevel in 1..100) String.format("%d%%", batteryLevel) else ""