mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: FusionHUD Pill battery row, and a locked HUD lets on-screen controls work (#1763)
Pill: battery level, temperature and watts share one "BAT" row, as on the other sizes, and each part follows its own switch. Turning Memory off no longer hides the battery temperature (reported by Keegan), and watts show without the battery level. Touch (part of #1752, reported by ZZCSK): a locked HUD lets a touch through where an on-screen control under it takes it: controller buttons and sticks, Steam touch controls, screen keys and the controls panel below the game. Each layer answers takesTouchAt with its own touch checks. Everywhere else the HUD keeps the touch, so a long press still locks or unlocks it. A new HUD starts locked. The "Lock in place" hint says so in every language. Tests: Pill battery row per switch combination; takesTouchAt agrees with a real touch over a grid for the controller buttons, screen keys and both controls panel layouts (Deck and gamepad, landscape and portrait); a locked HUD passes touches to a control under it, keeps the rest, and unlocks on a long press.
This commit is contained in:
1 parent
283e3b4549
commit
5de690ef39
46 files changed
+279
-61
No files matched your search
@@ -3,16 +3,24 @@ package com.droiddeck.launcher.hud
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.widget.FrameLayout
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.time.Duration
|
||||
import java.util.Base64
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sqrt
|
||||
@@ -25,6 +33,10 @@ class FusionHudPanelTest {
|
||||
assertEquals(FusionSize.MINIMAL, FusionSize.from(FusionHudConfig.DEFAULTS["hudSize"]))
|
||||
}
|
||||
|
||||
@Test fun theHudStartsLocked() {
|
||||
assertEquals("1", FusionHudConfig.DEFAULTS["hudLocked"])
|
||||
}
|
||||
|
||||
@Test fun everySizeDrawsTheDPanelWithEverythingInsideIt() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
@@ -33,11 +45,7 @@ class FusionHudPanelTest {
|
||||
now += frametime
|
||||
stats.add(frametime, now)
|
||||
}
|
||||
val snapshot = HudMetrics.Snapshot(64, 52, 3302, 1050, 89, 79, 10_800_000_000L, 16_000_000_000L, 67f,
|
||||
1_800_000_000L, HudMetrics.Battery(16f, false, 79, 34, null),
|
||||
intArrayOf(91, 91, 48, 50, 48, 19, 17, 73), intArrayOf(2265, 2265, 3148, 3148, 3148, 2956, 2956, 3302),
|
||||
2_700_000_000L, 6_400_000_000L, 31_000L, 9_000L)
|
||||
|
||||
val snapshot = SNAPSHOT
|
||||
for (size in FusionSize.values()) {
|
||||
val view = FusionHudView(RuntimeEnvironment.getApplication())
|
||||
view.applyConfig(FusionHudConfig.encode(FusionHudConfig.DEFAULTS + ("hudSize" to size.token)))
|
||||
@@ -65,4 +73,76 @@ class FusionHudPanelTest {
|
||||
assertTrue("$size orb on the left side", Color.blue(orb) > 200 && Color.alpha(orb) > 200)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pillShowsEachBatteryPartOnItsOwnSwitch() {
|
||||
fun pill(vararg settings: Pair<String, String>): List<String> {
|
||||
val view = FusionHudView(RuntimeEnvironment.getApplication())
|
||||
view.applyConfig(FusionHudConfig.encode(FusionHudConfig.DEFAULTS + ("hudSize" to FusionSize.PILL.token) + settings))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
return view.linesForTest()
|
||||
}
|
||||
val all = pill("showBattery" to "1")
|
||||
assertTrue(all.toString(), all.any { "BAT 79% · 34°C · 16.0W" in it })
|
||||
assertEquals(all.toString(), 1, all.count { "BAT" in it })
|
||||
assertFalse(all.toString(), all.single { "RAM" in it }.contains("BAT"))
|
||||
|
||||
val noMemory = pill("showBattery" to "1", "showRAM" to "0")
|
||||
assertTrue(noMemory.toString(), noMemory.none { "RAM" in it })
|
||||
assertTrue(noMemory.toString(), noMemory.any { "BAT 79% · 34°C · 16.0W" in it })
|
||||
|
||||
val defaults = pill()
|
||||
assertTrue(defaults.toString(), defaults.any { "BAT 34°C · 16.0W" in it })
|
||||
val wattsOnly = pill("showBatteryTemp" to "0")
|
||||
assertTrue(wattsOnly.toString(), wattsOnly.any { "BAT 16.0W" in it })
|
||||
val nothing = pill("showBatteryTemp" to "0", "showPower" to "0")
|
||||
assertTrue(nothing.toString(), nothing.none { "BAT" in it })
|
||||
}
|
||||
|
||||
@Test fun aLockedHudLetsTouchesThroughOnlyWhereAControlTakesThem() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
var reached = 0
|
||||
val under = View(app).apply {
|
||||
setOnTouchListener { _, e -> if (e.actionMasked == MotionEvent.ACTION_DOWN) reached++; true }
|
||||
}
|
||||
val hud = FusionHudView(app)
|
||||
val parent = FrameLayout(app)
|
||||
parent.addView(under, FrameLayout.LayoutParams(2000, 2000))
|
||||
parent.addView(hud, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
var control = false
|
||||
hud.passesTouchAt = { _, _ -> control }
|
||||
val locks = ArrayList<Boolean>()
|
||||
hud.setOnLockChangedListener { locks += it }
|
||||
hud.applyConfig(FusionHudConfig.encode(FusionHudConfig.DEFAULTS + ("hudLocked" to "0")))
|
||||
hud.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val exactly = View.MeasureSpec.makeMeasureSpec(2000, View.MeasureSpec.EXACTLY)
|
||||
parent.measure(exactly, exactly)
|
||||
parent.layout(0, 0, 2000, 2000)
|
||||
assertTrue(hud.width > 0 && hud.height > 0)
|
||||
fun touch(holdMs: Long = 50L) {
|
||||
val x = hud.width / 2f; val y = hud.height / 2f
|
||||
val down = SystemClock.uptimeMillis()
|
||||
MotionEvent.obtain(down, down, MotionEvent.ACTION_DOWN, x, y, 0).also { parent.dispatchTouchEvent(it); it.recycle() }
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(holdMs))
|
||||
MotionEvent.obtain(down, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y, 0).also { parent.dispatchTouchEvent(it); it.recycle() }
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
}
|
||||
control = true
|
||||
touch()
|
||||
assertEquals("an unlocked HUD keeps the touch (tap, drag, long press)", 0, reached)
|
||||
hud.applyConfig(FusionHudConfig.encode(FusionHudConfig.DEFAULTS + ("hudLocked" to "1")))
|
||||
touch()
|
||||
assertEquals("a locked HUD passes it to the control under it", 1, reached)
|
||||
control = false
|
||||
touch()
|
||||
assertEquals("a locked HUD keeps a touch no control takes", 1, reached)
|
||||
touch(holdMs = ViewConfiguration.getLongPressTimeout() + 300L)
|
||||
assertEquals("a long press there unlocks it", listOf(false), locks)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val SNAPSHOT = HudMetrics.Snapshot(64, 52, 3302, 1050, 89, 79, 10_800_000_000L, 16_000_000_000L, 67f,
|
||||
1_800_000_000L, HudMetrics.Battery(16f, false, 79, 34, null),
|
||||
intArrayOf(91, 91, 48, 50, 48, 19, 17, 73), intArrayOf(2265, 2265, 3148, 3148, 3148, 2956, 2956, 3302),
|
||||
2_700_000_000L, 6_400_000_000L, 31_000L, 9_000L)
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,17 @@ class OnScreenControlsTest {
|
||||
assertEquals(-1, field(control("rs"), "pressedBy"))
|
||||
}
|
||||
|
||||
@Test fun takesTouchAtMatchesWhatATouchDoes() {
|
||||
var checked = 0
|
||||
for (x in 0 until 1200 step 40) for (y in 0 until 800 step 40) {
|
||||
val expected = view.takesTouchAt(x.toFloat(), y.toFloat())
|
||||
assertEquals("($x, $y)", expected, touch(MotionEvent.ACTION_DOWN, 0 to (x.toFloat() to y.toFloat())))
|
||||
touch(MotionEvent.ACTION_UP, 0 to (x.toFloat() to y.toFloat()))
|
||||
if (expected) checked++
|
||||
}
|
||||
assertTrue("some points land on controls", checked > 0)
|
||||
}
|
||||
|
||||
@Test fun fixedSticksAndEditorRemainVisibleAtSavedPositions() {
|
||||
ControllerPrefs.setAdaptiveSticks(context, false)
|
||||
view.reload()
|
||||
|
||||
@@ -68,6 +68,22 @@ class ScreenKeysTest {
|
||||
assertTrue(accepts(GestureTouchStreamGate.Source.SURFACE, MotionEvent.ACTION_DOWN))
|
||||
}
|
||||
|
||||
@Test fun takesTouchAtMatchesWhatATouchDoes() {
|
||||
val keys = ScreenKeys(context) { _, _ -> }
|
||||
keys.layout(0, 0, 1000, 600)
|
||||
keys.add(listOf(KeyEvent.KEYCODE_W))
|
||||
var checked = 0
|
||||
for (x in 0 until 1000 step 25) for (y in 0 until 600 step 25) {
|
||||
val expected = keys.takesTouchAt(x.toFloat(), y.toFloat())
|
||||
val down = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat(), 0)
|
||||
assertEquals("($x, $y)", expected, keys.onTouchEvent(down))
|
||||
down.recycle()
|
||||
MotionEvent.obtain(0L, 1L, MotionEvent.ACTION_UP, x.toFloat(), y.toFloat(), 0).also { keys.onTouchEvent(it); it.recycle() }
|
||||
if (expected) checked++
|
||||
}
|
||||
assertTrue("some points land on the key", checked > 0)
|
||||
}
|
||||
|
||||
@Test fun loadingLayoutReleasesLatchedKeysBeforeReplacingEntries() {
|
||||
val sent = mutableListOf<Pair<Int, Boolean>>()
|
||||
val keys = ScreenKeys(context) { code, down -> sent += code to down }
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import com.droiddeck.launcher.input.JoyConPadTest
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.nio.file.Files
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, instrumentedPackages = ["com.droiddeck.launcher.input.FakeInputWriter"],
|
||||
shadows = [JoyConPadTest.RecordingWriter::class])
|
||||
class DeckControlsPanelTest {
|
||||
@Test fun takesTouchAtMatchesWhatATouchDoes() {
|
||||
val directory = Files.createTempDirectory("deck-panel").toFile()
|
||||
try {
|
||||
SessionState.deckPad = false
|
||||
// No pad: the Deck layouts (trackpads, grips). A pad without Deck controls: the gamepad layout
|
||||
// (sticks, d-pad, face buttons).
|
||||
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) {
|
||||
val name = "pad=${pad != null} portraitDock=$portraitDock"
|
||||
val panel = DeckControlsPanel(RuntimeEnvironment.getApplication(), onClose = {}, onSteamMenu = {}, onQam = {},
|
||||
pad = pad, portraitDock = portraitDock)
|
||||
assertEquals(name, pad == null, panel.deckControls)
|
||||
// The portrait dock sits under a portrait game; its gamepad layout needs a tall panel.
|
||||
val (w, h) = if (portraitDock) 720 to 1000 else 1200 to 480
|
||||
panel.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY))
|
||||
panel.layout(0, 0, w, h)
|
||||
var taken = 0
|
||||
var missed = 0
|
||||
for (x in 0 until w step w / 40) for (y in 0 until h step h / 24) {
|
||||
val expected = panel.takesTouchAt(x.toFloat(), y.toFloat())
|
||||
val down = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat(), 0)
|
||||
assertEquals("$name ($x, $y)", expected, panel.dispatchTouchEvent(down))
|
||||
down.recycle()
|
||||
// Cancel rather than lift, so no button fires its action.
|
||||
MotionEvent.obtain(0L, 1L, MotionEvent.ACTION_CANCEL, x.toFloat(), y.toFloat(), 0).also { panel.dispatchTouchEvent(it); it.recycle() }
|
||||
if (expected) taken++ else missed++
|
||||
}
|
||||
assertTrue("$name: some points land on controls", taken > 0)
|
||||
assertTrue("$name: some points land between them", missed > 0)
|
||||
}
|
||||
} finally {
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user