Merge pull request #114 from esensar/simple-bounce-on-page-change
Add a simple bounce on page changes
This commit is contained in:
commit
8ee21b43a1
|
@ -21,6 +21,7 @@ import android.util.AttributeSet
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import android.util.SizeF
|
import android.util.SizeF
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.OvershootInterpolator
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
@ -83,7 +84,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
getHandler = { handler },
|
getHandler = { handler },
|
||||||
getNextPageBound = { right - sideMargins.right - cellWidth / 2 },
|
getNextPageBound = { right - sideMargins.right - cellWidth / 2 },
|
||||||
getPrevPageBound = { left + sideMargins.left + cellWidth / 2 },
|
getPrevPageBound = { left + sideMargins.left + cellWidth / 2 },
|
||||||
pageChangeStarted = { closeFolder() }
|
pageChangeStarted = {
|
||||||
|
widgetViews.forEach { it.resetTouches() }
|
||||||
|
closeFolder()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
private var currentlyOpenFolder: HomeScreenFolder? = null
|
private var currentlyOpenFolder: HomeScreenFolder? = null
|
||||||
|
@ -1205,6 +1209,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? {
|
fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? {
|
||||||
|
if (pager.isAnimatingPageChange() || pager.isSwiped()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
currentlyOpenFolder?.also { folder ->
|
currentlyOpenFolder?.also { folder ->
|
||||||
folder.getItems().forEach { gridItem ->
|
folder.getItems().forEach { gridItem ->
|
||||||
val rect = getClickableRect(gridItem)
|
val rect = getClickableRect(gridItem)
|
||||||
|
@ -1661,9 +1669,9 @@ private class AnimatedGridPager(
|
||||||
|
|
||||||
fun isSwiped() = abs(pageChangeSwipedPercentage) > 0f
|
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) {
|
fun getPageChangeIndicatorsAlpha() = if (pageChangeIndicatorsAlpha != 0f) {
|
||||||
(pageChangeIndicatorsAlpha * 255.0f).toInt()
|
(pageChangeIndicatorsAlpha * 255.0f).toInt()
|
||||||
|
@ -1707,7 +1715,7 @@ private class AnimatedGridPager(
|
||||||
currentPage
|
currentPage
|
||||||
}
|
}
|
||||||
val rangeEnd = rangeEndPage.toFloat()
|
val rangeEnd = rangeEndPage.toFloat()
|
||||||
val lerpAmount = if (pageChangeAnimLeftPercentage > 0f) {
|
val lerpAmount = if (pageChangeAnimLeftPercentage != 0f) {
|
||||||
1 - pageChangeAnimLeftPercentage
|
1 - pageChangeAnimLeftPercentage
|
||||||
} else {
|
} else {
|
||||||
abs(pageChangeSwipedPercentage)
|
abs(pageChangeSwipedPercentage)
|
||||||
|
@ -1874,11 +1882,13 @@ private class AnimatedGridPager(
|
||||||
val startingAt = 1 - abs(pageChangeSwipedPercentage)
|
val startingAt = 1 - abs(pageChangeSwipedPercentage)
|
||||||
pageChangeSwipedPercentage = 0f
|
pageChangeSwipedPercentage = 0f
|
||||||
getHandler().removeCallbacks(startFadingIndicators)
|
getHandler().removeCallbacks(startFadingIndicators)
|
||||||
|
pageChangeStarted()
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
redrawGrid()
|
redrawGrid()
|
||||||
}
|
}
|
||||||
ValueAnimator.ofFloat(startingAt, 0f)
|
ValueAnimator.ofFloat(startingAt, 0f)
|
||||||
.apply {
|
.apply {
|
||||||
|
interpolator = OvershootInterpolator(1f)
|
||||||
addUpdateListener {
|
addUpdateListener {
|
||||||
pageChangeAnimLeftPercentage = it.animatedValue as Float
|
pageChangeAnimLeftPercentage = it.animatedValue as Float
|
||||||
redrawGrid()
|
redrawGrid()
|
||||||
|
|
|
@ -68,4 +68,8 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
|
||||||
longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y)
|
longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetTouches() {
|
||||||
|
longPressHandler.removeCallbacksAndMessages(null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue