From 75aeade4af0d6dc2e19b14a5f0255d48fd4eae03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 24 Aug 2023 16:20:51 +0200 Subject: [PATCH] Add a simple bounce on page changes --- .../simplemobiletools/launcher/views/HomeScreenGrid.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index c4a96d5e..820e9d4f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -20,6 +20,7 @@ import android.util.AttributeSet import android.util.Size import android.util.SizeF import android.view.View +import android.view.animation.OvershootInterpolator import android.widget.RelativeLayout import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toDrawable @@ -1032,9 +1033,9 @@ private class AnimatedGridPager( fun isSwiped() = abs(pageChangeSwipedPercentage) > 0f - fun isAnimatingPageChange() = pageChangeAnimLeftPercentage > 0f + fun isAnimatingPageChange() = pageChangeAnimLeftPercentage != 0f - fun shouldDisplayPageChangeIndicator() = isSwiped() || isAnimatingPageChange() || pageChangeIndicatorsAlpha > 0f + fun shouldDisplayPageChangeIndicator() = isSwiped() || isAnimatingPageChange() || pageChangeIndicatorsAlpha != 0f fun getPageChangeIndicatorsAlpha() = if (pageChangeIndicatorsAlpha != 0f) { (pageChangeIndicatorsAlpha * 255.0f).toInt() @@ -1078,7 +1079,7 @@ private class AnimatedGridPager( currentPage } val rangeEnd = rangeEndPage.toFloat() - val lerpAmount = if (pageChangeAnimLeftPercentage > 0f) { + val lerpAmount = if (pageChangeAnimLeftPercentage != 0f) { 1 - pageChangeAnimLeftPercentage } else { abs(pageChangeSwipedPercentage) @@ -1248,6 +1249,7 @@ private class AnimatedGridPager( } ValueAnimator.ofFloat(startingAt, 0f) .apply { + interpolator = OvershootInterpolator(1f) addUpdateListener { pageChangeAnimLeftPercentage = it.animatedValue as Float redrawGrid()