-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AOD burn in protection for lockscreen items on Android 15
Currently it is set to trigger every 45 minutes Signed-off-by: DrDisagree <29881338+Mahmud0808@users.noreply.github.com>
- Loading branch information
1 parent
a02178f
commit 3071f0d
Showing
4 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/drdisagree/iconify/xposed/modules/extras/views/BurnInProtection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.drdisagree.iconify.xposed.modules.extras.views | ||
|
||
import android.view.View | ||
import android.view.animation.TranslateAnimation | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
class AodBurnInProtection(private val view: View) { | ||
|
||
private var isMovementEnabled: Boolean = false | ||
private var originalX: Float = 0f | ||
private var originalY: Float = 0f | ||
private var movementJob: Job? = null | ||
|
||
init { | ||
originalX = view.x | ||
originalY = view.y | ||
} | ||
|
||
fun setMovementEnabled(enabled: Boolean) { | ||
if (enabled != isMovementEnabled) { | ||
isMovementEnabled = enabled | ||
|
||
if (isMovementEnabled) { | ||
startMovement() | ||
} else { | ||
stopMovement() | ||
} | ||
} | ||
} | ||
|
||
private fun startMovement() { | ||
if (movementJob?.isActive == true) return | ||
|
||
originalX = view.x | ||
originalY = view.y | ||
|
||
movementJob = CoroutineScope(Dispatchers.Main).launch { | ||
while (isMovementEnabled) { | ||
moveViewSlightly() | ||
delay(45 * 60 * 1000L) // Delay for 45 minutes | ||
} | ||
} | ||
} | ||
|
||
private fun stopMovement() { | ||
movementJob?.cancel() | ||
resetViewPosition() | ||
} | ||
|
||
private fun moveViewSlightly() { | ||
val offsetX = (6..10).random().toFloat() * if (Math.random() > 0.5) 1 else -1 | ||
val offsetY = (6..10).random().toFloat() * if (Math.random() > 0.5) 1 else -1 | ||
|
||
val animation = TranslateAnimation(view.x, offsetX, view.y, offsetY) | ||
animation.duration = 1000 // 1 second duration for the movement | ||
animation.fillAfter = true // Keep the final position after the animation finishes | ||
|
||
view.startAnimation(animation) | ||
} | ||
|
||
private fun resetViewPosition() { | ||
view.animate().x(originalX).y(originalY).setDuration(300).start() | ||
} | ||
|
||
companion object { | ||
private val activeMovements = mutableMapOf<View, AodBurnInProtection>() | ||
|
||
fun registerForView(view: View): AodBurnInProtection { | ||
return activeMovements.getOrPut(view) { | ||
AodBurnInProtection(view).also { | ||
it.startMovement() | ||
} | ||
} | ||
} | ||
|
||
fun unregisterForView(view: View) { | ||
activeMovements[view]?.apply { | ||
stopMovement() | ||
} | ||
activeMovements.remove(view) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters