Skip to content

Commit

Permalink
Restore floating button position periodically #562
Browse files Browse the repository at this point in the history
  • Loading branch information
cvzi committed Aug 19, 2024
1 parent 8efa8d8 commit 070f777
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,35 @@ class ScreenshotAccessibilityService : AccessibilityService() {
if (animate) {
(buttonScreenshot.drawable as? Animatable)?.start()
}

// Only Android 13+:
// Periodically check if the button is still at correct position and reposition it if necessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Handler(Looper.getMainLooper()).apply {
removeCallbacks(checkPositionRunnable)
postDelayed(checkPositionRunnable, 10000)
}
}
}

private val checkPositionRunnable = Runnable {
checkAndCorrectPosition()
}

private fun checkAndCorrectPosition() {
// Check if the floating button is still at the correct position and reposition it if necessary
if (!floatingButtonShown) {
return
}
val root = binding?.root ?: return
val p = prefManager.getFloatingButtonPosition(screenOrientation)
val x = p.x
val y = p.y
val layoutParams = root.layoutParams as WindowManager.LayoutParams
if (layoutParams.x != x || layoutParams.y != y) {
updateWindowViewPosition(root, x, y)
}
Handler(Looper.getMainLooper()).postDelayed(checkPositionRunnable, 10000)
}

private fun showCountDown(
Expand Down

0 comments on commit 070f777

Please sign in to comment.