mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(agent): the pet's windows move without the system's move animation (#2582)
This commit is contained in:
1 parent
8a37e71e10
commit
1e6aebd216
1 file changed
+19
-1
@@ -110,7 +110,11 @@ internal class PetMotion(private val context: Context) {
|
||||
private val margin = 6 * density
|
||||
private val inset = 24 * density
|
||||
private var settle: ValueAnimator? = null
|
||||
private val spring = FlingSpring { sx, sy -> x = sx; y = sy }
|
||||
// A fling's overshoot may carry the pet past the edge it settles on, but never so far that it leaves the screen.
|
||||
private val spring = FlingSpring { sx, sy ->
|
||||
x = sx.coerceIn(-size / 2, (width - size / 2).coerceAtLeast(-size / 2))
|
||||
y = sy.coerceIn(0f, (height - size).coerceAtLeast(0f))
|
||||
}
|
||||
|
||||
val dockX get() = width - size - margin
|
||||
|
||||
@@ -333,11 +337,24 @@ internal class PetWindows(private val context: Context) {
|
||||
gravity = Gravity.TOP or Gravity.START
|
||||
if (full) softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
noMoveAnimation(this)
|
||||
}
|
||||
if (onSize != null) compose.addOnLayoutChangeListener { v, _, _, _, _, _, _, _, _ -> onSize(v.width, v.height) }
|
||||
return Window(frame, params, touchable)
|
||||
}
|
||||
|
||||
/**
|
||||
* The system otherwise eases a moved overlay from where it last placed it, so the pet trails behind
|
||||
* the finger, lags the chat as it opens, or flashes at an old spot. setCanPlayMoveAnimation sets the
|
||||
* same flag but makes some ROMs refuse the window, so the flag is set directly.
|
||||
*/
|
||||
private fun noMoveAnimation(params: WindowManager.LayoutParams) {
|
||||
runCatching {
|
||||
val field = WindowManager.LayoutParams::class.java.getField("privateFlags")
|
||||
field.setInt(params, field.getInt(params) or PRIVATE_FLAG_NO_MOVE_ANIMATION)
|
||||
}
|
||||
}
|
||||
|
||||
/** A hidden overlay window still owns its frame, which the system can stretch over the screen, so it also stops taking touches. */
|
||||
private fun setVisible(window: Window, shown: Boolean) {
|
||||
window.view.visibility = if (shown) View.VISIBLE else View.GONE
|
||||
@@ -467,6 +484,7 @@ internal class PetWindows(private val context: Context) {
|
||||
|
||||
companion object {
|
||||
private const val OFFSCREEN = 10_000
|
||||
private const val PRIVATE_FLAG_NO_MOVE_ANIMATION = 0x40
|
||||
fun allowed(context: Context) = Settings.canDrawOverlays(context)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user