mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat(hud): long press collapses or expands the HUD, locking becomes an option (#2723)
* feat(hud): long press collapses or expands the HUD, locking becomes an option * fix(hud): keep the collapsing tab at the press point while layout runs The layout listener could run keepOnScreen during the dock animation and replace the press-centered target with the anchored edge position, which was then saved as the tab position. The dock animation now holds the same guard the other HUD animations use until the dock is committed.
This commit is contained in:
1 parent
8e514ada62
commit
fde3089900
41 files changed
+369
-51
No files matched your search
@@ -5,7 +5,7 @@ import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
internal object DroidDeckHudConfig {
|
||||
val DEFAULTS: Map<String, String> = linkedMapOf(
|
||||
"hudSize" to "minimal", "hudLocked" to "1", "hudSnap" to "1", "hudScale" to "100", "hudDock" to "none", "hudOpacity" to "80", "hudColor" to "mid",
|
||||
"hudSize" to "minimal", "hudLocked" to "1", "hudHold" to "collapse", "hudSnap" to "1", "hudScale" to "100", "hudDock" to "none", "hudOpacity" to "80", "hudColor" to "mid",
|
||||
"hudOutline" to "40", "hudOutlineAccent" to "1",
|
||||
"showGpuModel" to "1", "showGPULoad" to "1", "showCPUUsage" to "1", "showCPULoad" to "1",
|
||||
"showPerCore" to "1", "showTemp" to "1", "showBatteryTemp" to "1", "showGpuTemp" to "0",
|
||||
@@ -18,6 +18,8 @@ internal object DroidDeckHudConfig {
|
||||
"tempUnit" to "c", "tempBands" to "1", "tempAuto" to "1", "tempRedCpu" to "90", "tempRedGpu" to "90", "tempRedBat" to "48",
|
||||
)
|
||||
|
||||
const val HOLD_LOCKS = "lock"
|
||||
|
||||
private val NOT_READINGS = setOf("showCPULoad", "showRenderer", "fpsDecimal")
|
||||
|
||||
/** Orders saved before the GPU switch was named after the alias the HUD actually reads. */
|
||||
|
||||
@@ -119,6 +119,7 @@ class DroidDeckHudHost(context: Context) {
|
||||
}
|
||||
hud.setOnSizeCycledListener { size -> DroidDeckHudConfig.set(context, "hudSize", size); onConfigChanged?.invoke() }
|
||||
hud.setOnDockChangedListener { token -> setDock(hud, DroidDeckHudDock.from(token)) }
|
||||
hud.setOnHoldListener { rawX, rawY -> collapseAt(hud, rawX, rawY) }
|
||||
hud.setOnScaledListener { percent ->
|
||||
DroidDeckHudConfig.set(context, "hudScale", percent.toString())
|
||||
onConfigChanged?.invoke()
|
||||
@@ -291,7 +292,7 @@ class DroidDeckHudHost(context: Context) {
|
||||
DroidDeckHudDock.RIGHT -> (maxX - hud.x) / hud.width
|
||||
DroidDeckHudDock.TOP -> hud.y / hud.height
|
||||
DroidDeckHudDock.BOTTOM -> (maxY - hud.y) / hud.height
|
||||
DroidDeckHudDock.NONE -> 0f
|
||||
DroidDeckHudDock.NONE, DroidDeckHudDock.FLOAT -> 0f
|
||||
}
|
||||
if (pulled >= 1f) { setDock(hud, DroidDeckHudDock.NONE); return }
|
||||
wantX = hud.x; wantY = hud.y
|
||||
@@ -375,12 +376,30 @@ class DroidDeckHudHost(context: Context) {
|
||||
hud.scaleX = s; hud.scaleY = s
|
||||
}
|
||||
|
||||
private fun setDock(hud: DroidDeckHudView, edge: DroidDeckHudDock) {
|
||||
private fun setDock(hud: DroidDeckHudView, edge: DroidDeckHudDock, center: Pair<Float, Float>? = null) {
|
||||
if (edge == hud.dock) return
|
||||
animateDock(hud, edge) { commitDock(hud, edge) }
|
||||
animateDock(hud, edge, center) { commitDock(hud, edge) }
|
||||
}
|
||||
|
||||
private fun collapseAt(hud: DroidDeckHudView, rawX: Float, rawY: Float) {
|
||||
if (hud.dock != DroidDeckHudDock.NONE) return
|
||||
val p = hud.parent as? View ?: return
|
||||
val at = IntArray(2).also { p.getLocationOnScreen(it) }
|
||||
val x = rawX - at[0]
|
||||
val y = rawY - at[1]
|
||||
val edge = if (snaps) nearestEdge(x, y, p.width.toFloat(), p.height.toFloat()) else DroidDeckHudDock.FLOAT
|
||||
setDock(hud, edge, Pair(x, y))
|
||||
}
|
||||
|
||||
private fun nearestEdge(x: Float, y: Float, width: Float, height: Float): DroidDeckHudDock = mapOf(
|
||||
DroidDeckHudDock.LEFT to x,
|
||||
DroidDeckHudDock.RIGHT to width - x,
|
||||
DroidDeckHudDock.TOP to y,
|
||||
DroidDeckHudDock.BOTTOM to height - y,
|
||||
).minByOrNull { it.value }!!.key
|
||||
|
||||
private fun commitDock(hud: DroidDeckHudView, edge: DroidDeckHudDock) {
|
||||
snapping = false
|
||||
val tabX = hud.x; val tabY = hud.y
|
||||
if (edge != DroidDeckHudDock.NONE) {
|
||||
val p = hud.parent as? View
|
||||
@@ -407,12 +426,17 @@ class DroidDeckHudHost(context: Context) {
|
||||
SessionPrefs.setDroidDeckHudPosition(context, wantX, wantY)
|
||||
}
|
||||
|
||||
private fun animateDock(hud: DroidDeckHudView, edge: DroidDeckHudDock, commit: () -> Unit) {
|
||||
private fun animateDock(hud: DroidDeckHudView, edge: DroidDeckHudDock, center: Pair<Float, Float>?, commit: () -> Unit) {
|
||||
stopMotion(hud)
|
||||
previewFade?.cancel(); previewFade = null
|
||||
snapping = false
|
||||
hud.alpha = 1f
|
||||
val p = hud.parent as? View
|
||||
if (edge != DroidDeckHudDock.NONE && center != null) {
|
||||
val (tabW, tabH) = hud.dockTabSize()
|
||||
wantX = center.first - tabW / 2f
|
||||
wantY = center.second - tabH / 2f
|
||||
}
|
||||
if (Motion.scale == 0f || p == null || !hud.isLaidOut || hud.width <= 0) {
|
||||
hud.scaleX = 1f; hud.scaleY = 1f
|
||||
hud.setDockPreview(DroidDeckHudDock.NONE, 0f)
|
||||
@@ -424,11 +448,14 @@ class DroidDeckHudHost(context: Context) {
|
||||
hud.pivotX = 0f; hud.pivotY = 0f
|
||||
hud.x = left; hud.y = top
|
||||
val (tabW, tabH) = hud.dockTabSize()
|
||||
wantX = left + (shownW - tabW) / 2f
|
||||
wantY = top + (shownH - tabH) / 2f
|
||||
if (center == null) {
|
||||
wantX = left + (shownW - tabW) / 2f
|
||||
wantY = top + (shownH - tabH) / 2f
|
||||
}
|
||||
val (tabX, tabY) = settled(p, edge, tabW, tabH)
|
||||
val sx = tabW / hud.width; val sy = tabH / hud.height
|
||||
val from = hud.dockPreviewBlend
|
||||
snapping = true
|
||||
hud.animate().x(tabX).y(tabY).scaleX(sx).scaleY(sy).setDuration(Motion.ms(220).toLong()).setInterpolator(EASE)
|
||||
.setUpdateListener { hud.setDockPreview(edge, from + (1f - from) * it.animatedFraction) }
|
||||
.withEndAction {
|
||||
@@ -473,7 +500,7 @@ class DroidDeckHudHost(context: Context) {
|
||||
DroidDeckHudDock.RIGHT -> x = maxX
|
||||
DroidDeckHudDock.TOP -> y = 0f
|
||||
DroidDeckHudDock.BOTTOM -> y = maxY
|
||||
DroidDeckHudDock.NONE -> {}
|
||||
DroidDeckHudDock.NONE, DroidDeckHudDock.FLOAT -> {}
|
||||
}
|
||||
return Pair(x, y)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
|
||||
}
|
||||
|
||||
enum class DroidDeckHudDock(val token: String) {
|
||||
NONE("none"), LEFT("left"), RIGHT("right"), TOP("top"), BOTTOM("bottom");
|
||||
NONE("none"), LEFT("left"), RIGHT("right"), TOP("top"), BOTTOM("bottom"), FLOAT("float");
|
||||
|
||||
companion object {
|
||||
fun from(token: String?): DroidDeckHudDock = values().firstOrNull { it.token == token } ?: NONE
|
||||
|
||||
@@ -191,6 +191,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
private var onMovedListener: BiConsumer<Float, Float>? = null
|
||||
private var onSizeCycledListener: Consumer<String>? = null
|
||||
private var onLockChangedListener: Consumer<Boolean>? = null
|
||||
private var onHoldListener: BiConsumer<Float, Float>? = null
|
||||
fun setOnHoldListener(l: BiConsumer<Float, Float>?) { onHoldListener = l }
|
||||
fun setOnMovedListener(l: BiConsumer<Float, Float>?) { onMovedListener = l }
|
||||
fun setOnSizeCycledListener(l: Consumer<String>?) { onSizeCycledListener = l }
|
||||
fun setOnLockChangedListener(l: Consumer<Boolean>?) { onLockChangedListener = l }
|
||||
@@ -209,6 +211,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
override fun onDragged(rawX: Float, rawY: Float) { onDraggedListener?.accept(rawX, rawY) }
|
||||
override fun onFlung(velocityX: Float, velocityY: Float) { onFlungListener?.accept(velocityX, velocityY) }
|
||||
override fun onLockChanged(locked: Boolean) { onLockChangedListener?.accept(locked) }
|
||||
override fun onHold(rawX: Float, rawY: Float) { onHoldListener?.accept(rawX, rawY) }
|
||||
override fun onPinch(factor: Float) {
|
||||
val next = (scale * factor).coerceIn(MIN_SCALE, MAX_SCALE)
|
||||
if (next == scale) return
|
||||
@@ -224,6 +227,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
private var tabStartX = 0f
|
||||
private var tabStartY = 0f
|
||||
private var tabDragging = false
|
||||
private var tabPressed = false
|
||||
private var onTabDraggedListener: BiConsumer<Float, Float>? = null
|
||||
private var onTabDroppedListener: Runnable? = null
|
||||
private var onTabDragCancelledListener: Runnable? = null
|
||||
@@ -237,19 +241,24 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
tabDownRawX = event.rawX; tabDownRawY = event.rawY
|
||||
tabStartX = x; tabStartY = y
|
||||
tabDragging = false
|
||||
tabPressed = true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
MotionEvent.ACTION_MOVE -> if (tabPressed) {
|
||||
val dx = event.rawX - tabDownRawX; val dy = event.rawY - tabDownRawY
|
||||
if (!tabDragging && dx * dx + dy * dy > touchSlop * touchSlop) tabDragging = true
|
||||
if (tabDragging) onTabDraggedListener?.accept(tabStartX + dx, tabStartY + dy)
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
MotionEvent.ACTION_UP -> if (tabPressed) {
|
||||
tabPressed = false
|
||||
if (tabDragging) { tabDragging = false; onTabDroppedListener?.run() }
|
||||
else onDockChangedListener?.accept(DroidDeckHudDock.NONE.token)
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> if (tabDragging) {
|
||||
tabDragging = false
|
||||
onTabDragCancelledListener?.run()
|
||||
MotionEvent.ACTION_CANCEL -> {
|
||||
tabPressed = false
|
||||
if (tabDragging) {
|
||||
tabDragging = false
|
||||
onTabDragCancelledListener?.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
@@ -341,6 +350,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
showSession = switchOn("showSession")
|
||||
tempDisplay = HudMetrics.TempDisplay.from(cfg)
|
||||
lockController.setLocked(cfg.get("hudLocked", "1") == "1")
|
||||
lockController.setHoldLocks(cfg.get("hudHold", "collapse") == DroidDeckHudConfig.HOLD_LOCKS)
|
||||
dock = DroidDeckHudDock.from(cfg.get("hudDock", "none"))
|
||||
|
||||
colorIntensity = when (cfg.get("hudColor", "vivid")) {
|
||||
@@ -591,7 +601,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
DroidDeckHudDock.RIGHT -> intArrayOf(1, 2)
|
||||
DroidDeckHudDock.TOP -> intArrayOf(0, 1)
|
||||
DroidDeckHudDock.BOTTOM -> intArrayOf(2, 3)
|
||||
DroidDeckHudDock.NONE -> intArrayOf()
|
||||
DroidDeckHudDock.NONE, DroidDeckHudDock.FLOAT -> intArrayOf()
|
||||
}
|
||||
for (corner in edge) { round[corner * 2] = 0f; round[corner * 2 + 1] = 0f }
|
||||
tabPath.rewind()
|
||||
|
||||
@@ -36,6 +36,7 @@ public class HudLockController {
|
||||
default void onDragged(float rawX, float rawY) {}
|
||||
default void onFlung(float velocityX, float velocityY) {}
|
||||
void onLockChanged(boolean locked);
|
||||
default void onHold(float rawX, float rawY) {}
|
||||
default void onPinch(float factor) {}
|
||||
default void onPinchEnd() {}
|
||||
}
|
||||
@@ -53,6 +54,7 @@ public class HudLockController {
|
||||
private final android.view.VelocityTracker velocity = android.view.VelocityTracker.obtain();
|
||||
|
||||
private boolean locked = false;
|
||||
private boolean holdLocks = false;
|
||||
|
||||
private float downRawX, downRawY, startX, startY;
|
||||
private boolean dragging = false;
|
||||
@@ -80,6 +82,8 @@ public class HudLockController {
|
||||
|
||||
public void setLocked(boolean locked) { this.locked = locked; }
|
||||
|
||||
public void setHoldLocks(boolean holdLocks) { this.holdLocks = holdLocks; }
|
||||
|
||||
public boolean isLocked() { return locked; }
|
||||
|
||||
public boolean isDragging() { return dragging; }
|
||||
@@ -119,6 +123,10 @@ public class HudLockController {
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
if (!holdLocks) {
|
||||
cb.onHold(e.getRawX(), e.getRawY());
|
||||
return;
|
||||
}
|
||||
locked = !locked;
|
||||
cb.onLockChanged(locked);
|
||||
flash(locked, HOLD_TOGGLE_MS);
|
||||
|
||||
@@ -37,6 +37,11 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
DroidDeckHudSize.STRIP to stringResource(R.string.hud_size_strip),
|
||||
),
|
||||
size, chipModifier = track("hud-size")) { a.onHudSetting("hudSize", it.token) }
|
||||
ChoiceRow(host, "hud-hold", stringResource(R.string.hud_hold), null,
|
||||
listOf("collapse" to stringResource(R.string.hud_hold_collapse),
|
||||
DroidDeckHudConfig.HOLD_LOCKS to stringResource(R.string.hud_hold_lock)),
|
||||
if (cfg["hudHold"] == DroidDeckHudConfig.HOLD_LOCKS) DroidDeckHudConfig.HOLD_LOCKS else "collapse",
|
||||
chipModifier = track("hud-hold")) { a.onHudSetting("hudHold", it) }
|
||||
ToggleRow(host, "hud-locked", stringResource(R.string.hud_locked), stringResource(R.string.hud_locked_hint), on("hudLocked"),
|
||||
chipModifier = track("hud-locked")) { a.onHudSetting("hudLocked", flag(it)) }
|
||||
ToggleRow(host, "hud-snap", stringResource(R.string.hud_snap), stringResource(R.string.hud_snap_hint), on("hudSnap"),
|
||||
|
||||
Reference in new issue
Block a user