Skip to content

Commit

Permalink
55924-elys
Browse files Browse the repository at this point in the history
  • Loading branch information
ELY M committed Dec 11, 2024
1 parent 79159aa commit 7800bd5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 38 deletions.
90 changes: 60 additions & 30 deletions app/src/main/java/joshuatee/wx/radarcolorpalettes/ColorPalette.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ class ColorPalette(val context: Context, private val colormapCode: Int) {
}
}

// comma separated r,g,b (4bit)
fun putLine(line: String) {
val colors = line.split(",")
putBytes(colors[0].toInt(), colors[1].toInt(), colors[2].toInt())
}

fun putLine(colorPaletteLine: ColorPaletteLine) {
putBytes(colorPaletteLine.red, colorPaletteLine.green, colorPaletteLine.blue)
}
Expand Down Expand Up @@ -129,7 +123,8 @@ class ColorPalette(val context: Context, private val colormapCode: Int) {
}
UtilityIO.readTextFileFromRaw(context.resources, fileId).split("\n").forEach { line ->
if (line.contains(",")) {
colorMap[product]!!.putLine(line)
val objectColorPaletteLines = ColorPaletteLine.fourBit(line.split(","))
colorMap[product]!!.putLine(objectColorPaletteLines)
}
}
}
Expand All @@ -139,7 +134,8 @@ class ColorPalette(val context: Context, private val colormapCode: Int) {
val objectColorPalette = colorMap[radarColorPaletteCode]!!
objectColorPalette.position(0)
val colorPaletteLines = mutableListOf<ColorPaletteLine>()
val text = UtilityColorPalette.getColorMapStringFromDisk(context, radarColorPaletteCode, code)
val text =
UtilityColorPalette.getColorMapStringFromDisk(context, radarColorPaletteCode, code)
val lines = text.split("\n").dropLastWhile { it.isEmpty() }
lines.forEach { line ->
if (line.contains("olor") && !line.contains("#")) {
Expand Down Expand Up @@ -230,30 +226,52 @@ class ColorPalette(val context: Context, private val colormapCode: Int) {
var g = "0"
var b = "0"
var priorLineHas6 = false
UtilityColorPalette.getColorMapStringFromDisk(context, colorMapProductCode, code).split("\n").forEach { line ->
if (line.contains("olor") && !line.contains("#")) {
val items = if (line.contains(",")) {
line.split(",")
} else {
line.split(" ")
}
if (items.size > 4) {
if (priorLineHas6) {
colorPaletteLines.add(ColorPaletteLine((To.double(items[1]) * prodScale + prodOffset - 1).toInt(), r, g, b))
colorPaletteLines.add(ColorPaletteLine((To.double(items[1]) * prodScale + prodOffset).toInt(), items[2], items[3], items[4]))
priorLineHas6 = false
UtilityColorPalette.getColorMapStringFromDisk(context, colorMapProductCode, code)
.split("\n").forEach { line ->
if (line.contains("olor") && !line.contains("#")) {
val items = if (line.contains(",")) {
line.split(",")
} else {
colorPaletteLines.add(ColorPaletteLine((To.double(items[1]) * prodScale + prodOffset).toInt(), items[2], items[3], items[4]))
line.split(" ")
}
if (items.size > 7) {
priorLineHas6 = true
r = items[5]
g = items[6]
b = items[7]
if (items.size > 4) {
if (priorLineHas6) {
colorPaletteLines.add(
ColorPaletteLine(
(To.double(items[1]) * prodScale + prodOffset - 1).toInt(),
r,
g,
b
)
)
colorPaletteLines.add(
ColorPaletteLine(
(To.double(items[1]) * prodScale + prodOffset).toInt(),
items[2],
items[3],
items[4]
)
)
priorLineHas6 = false
} else {
colorPaletteLines.add(
ColorPaletteLine(
(To.double(items[1]) * prodScale + prodOffset).toInt(),
items[2],
items[3],
items[4]
)
)
}
if (items.size > 7) {
priorLineHas6 = true
r = items[5]
g = items[6]
b = items[7]
}
}
}
}
}
if (colorMapProductCode == 161) {
// pad first 16, think this is needed
repeat(10) {
Expand Down Expand Up @@ -291,11 +309,23 @@ class ColorPalette(val context: Context, private val colormapCode: Int) {
(1 until diff).forEach { j ->
@Suppress("KotlinConstantConditions")
if (scale == 1) {
val colorInt = UtilityNexradColors.interpolateColor(lowColor, highColor, j.toFloat() / (diff * scale).toFloat())
val colorInt = UtilityNexradColors.interpolateColor(
lowColor,
highColor,
j.toFloat() / (diff * scale).toFloat()
)
objectColorPalette.putInt(colorInt)
} else if (scale == 2) {
val colorInt = UtilityNexradColors.interpolateColor(lowColor, highColor, (j * scale - 1).toFloat() / (diff * scale).toFloat())
val colorInt2 = UtilityNexradColors.interpolateColor(lowColor, highColor, (j * scale).toFloat() / (diff * scale).toFloat())
val colorInt = UtilityNexradColors.interpolateColor(
lowColor,
highColor,
(j * scale - 1).toFloat() / (diff * scale).toFloat()
)
val colorInt2 = UtilityNexradColors.interpolateColor(
lowColor,
highColor,
(j * scale).toFloat() / (diff * scale).toFloat()
)
objectColorPalette.putInt(colorInt)
objectColorPalette.putInt(colorInt2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ class ColorPaletteLine {
}

val asInt get() = Color.rgb(red, green, blue)

companion object {
fun fourBit(items: List<String>): ColorPaletteLine {
return ColorPaletteLine(0, items[0], items[1], items[2])
}
}
}
8 changes: 2 additions & 6 deletions app/src/main/java/joshuatee/wx/settings/UIPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ object UIPreferences {
var normalTextSize = 16
var navDrawerMainScreen = false
var navDrawerMainScreenOnRight = true
var useNwsApi =
false // dec 2024 hardcode to use old API until next month, comment out below in pref set

// var useNwsApi = true
var useNwsApi = true
var useNwsApiForHourly = true
var tabHeaders = arrayOf("", "", "")
var widgetPreventTap = false
Expand Down Expand Up @@ -136,8 +133,7 @@ object UIPreferences {
const val HOMESCREEN_FAVORITE_DEFAULT = "TXT-CC2:TXT-HAZ:OGL-RADAR:TXT-7DAY2"

fun initPreferences(context: Context) {
// dec 2024 hardcode to use old API until next month
// useNwsApi = Utility.readPref(context, "USE_NWS_API_SEVEN_DAY", "true").startsWith("t")
useNwsApi = Utility.readPref(context, "USE_NWS_API_SEVEN_DAY", "true").startsWith("t")
useNwsApiForHourly = Utility.readPref(context, "USE_NWS_API_HOURLY", "true").startsWith("t")
navDrawerMainScreen =
Utility.readPref(context, "NAV_DRAWER_MAIN_SCREEN", "false").startsWith("t")
Expand Down
6 changes: 4 additions & 2 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

# Developer ChangeLog

## 55924 2024_12_03
## 55924 2024_12_09

* [ADD]
* [ADD] per **PNS24-66 Updated** NWS will implement a fix in advance of Dec 22 for the NWS API, thus
7 day forecast is now configurable again and defaults to using the new NWS API
* [REF] refactor parts of color palette generators to match other ports

## 55923 2024_12_03

Expand Down

0 comments on commit 7800bd5

Please sign in to comment.