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 1/3] 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 c4a96d5..820e9d4 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() From 3f146c76186d537f590f3f9026851ea9e8f0fce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 25 Aug 2023 09:45:22 +0200 Subject: [PATCH 2/3] Prevent widget long press while changing pages --- .../simplemobiletools/launcher/views/HomeScreenGrid.kt | 9 ++++++++- .../launcher/views/MyAppWidgetHostView.kt | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 820e9d4..6fcaad5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -75,7 +75,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel getWidth = { width }, getHandler = { handler }, getNextPageBound = { right - sideMargins.right - cellWidth / 2 }, - getPrevPageBound = { left + sideMargins.left + cellWidth / 2 } + getPrevPageBound = { left + sideMargins.left + cellWidth / 2 }, + pageChangeStarted = { widgetViews.forEach { it.resetTouches() } } ) // apply fake margins at the home screen. Real ones would cause the icons be cut at dragging at screen sides @@ -862,6 +863,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? { + if (pager.isAnimatingPageChange() || pager.isSwiped()) { + return null + } + for (gridItem in gridItems.filter { it.page == pager.getCurrentPage() || it.docked }) { if (gridItem.outOfBounds()) { continue @@ -995,6 +1000,7 @@ private class AnimatedGridPager( private val getHandler: () -> Handler, private val getNextPageBound: () -> Int, private val getPrevPageBound: () -> Int, + private val pageChangeStarted: () -> Unit, ) { companion object { @@ -1244,6 +1250,7 @@ private class AnimatedGridPager( val startingAt = 1 - abs(pageChangeSwipedPercentage) pageChangeSwipedPercentage = 0f getHandler().removeCallbacks(startFadingIndicators) + pageChangeStarted() if (redraw) { redrawGrid() } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt index 13e7ad6..112836d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt @@ -68,4 +68,8 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) { longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y) } } + + fun resetTouches() { + longPressHandler.removeCallbacksAndMessages(null) + } } From 1dc3ee0af4dc73525e749081713d9e600f2ab022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 31 Aug 2023 10:36:19 +0200 Subject: [PATCH 3/3] Fix pageChangeStarted callback --- .../com/simplemobiletools/launcher/views/HomeScreenGrid.kt | 5 ++--- 1 file changed, 2 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 43699f6..4ff480e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -85,9 +85,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel getNextPageBound = { right - sideMargins.right - cellWidth / 2 }, getPrevPageBound = { left + sideMargins.left + cellWidth / 2 }, pageChangeStarted = { - widgetViews.forEach { it.resetTouches() - closeFolder() - } + widgetViews.forEach { it.resetTouches() } + closeFolder() } )