mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
feat: Strip HUD size, a one-line bar across the top or bottom edge (#1935)
This commit is contained in:
1 parent
730b3affae
commit
65b414df93
38 files changed
+222
-6
No files matched your search
@@ -45,6 +45,7 @@ class DroidDeckHudPanelTest {
|
||||
}
|
||||
val snapshot = SNAPSHOT
|
||||
for (size in DroidDeckHudSize.values()) {
|
||||
if (size == DroidDeckHudSize.STRIP) continue
|
||||
val view = DroidDeckHudView(RuntimeEnvironment.getApplication())
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to size.token)))
|
||||
view.setFrameStats(stats)
|
||||
@@ -70,6 +71,73 @@ class DroidDeckHudPanelTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun stripIsOneLineAcrossTheParentWithTheClockOnTheRight() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(2400, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 2400, 1080)
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token) +
|
||||
("showBattery" to "1")))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(unspecified, unspecified)
|
||||
|
||||
assertTrue(view.isStrip)
|
||||
assertEquals(2400, view.measuredWidth)
|
||||
val lines = view.linesForTest()
|
||||
assertEquals(lines.toString(), 1, lines.size)
|
||||
val line = lines.single()
|
||||
listOf("DXVK", "fps", "GPU", "CPU", "RAM", "BAT 79%").forEach { assertTrue(line, it in line) }
|
||||
assertTrue(line, line.indexOf("DXVK") < line.indexOf("GPU") && line.indexOf("GPU") < line.indexOf("BAT"))
|
||||
|
||||
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
|
||||
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
|
||||
view.draw(Canvas(bitmap))
|
||||
val png = ByteArrayOutputStream().also { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
println("DROIDDECKHUD-STRIP-PNG ${Base64.getEncoder().encodeToString(png.toByteArray())}")
|
||||
}
|
||||
|
||||
@Test fun stripLeavesOffWhatNoLongerFitsBeforeTheClock() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(700, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 700, 400)
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token)))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val line = view.linesForTest().single()
|
||||
assertTrue(line, "fps" in line)
|
||||
assertFalse(line, "BAT" in line)
|
||||
}
|
||||
|
||||
@Test fun stripFollowsTheHudScaleInHeightAndKeepsTheFullWidth() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(2400, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 2400, 1080)
|
||||
fun at(scale: Int): Pair<Float, Float> {
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token) +
|
||||
("hudScale" to scale.toString())))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(unspecified, unspecified)
|
||||
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
|
||||
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
|
||||
view.draw(Canvas(bitmap))
|
||||
val png = ByteArrayOutputStream().also { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
println("DROIDDECKHUD-STRIP$scale-PNG ${Base64.getEncoder().encodeToString(png.toByteArray())}")
|
||||
return Pair(view.contentWidth, view.contentHeight)
|
||||
}
|
||||
val small = at(70); val big = at(150)
|
||||
assertEquals(2400f, small.first); assertEquals(2400f, big.first)
|
||||
assertEquals(big.second / small.second, 150f / 70f, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun pillShowsEachBatteryPartOnItsOwnSwitch() {
|
||||
fun pill(vararg settings: Pair<String, String>): List<String> {
|
||||
val view = DroidDeckHudView(RuntimeEnvironment.getApplication())
|
||||
|
||||
Reference in new issue
Block a user