playback: basic stepping indicator
Compeletely made by Claude 4 as a prototype, still gotta add more stuff on and then refine.
This commit is contained in:
@@ -18,14 +18,20 @@
|
|||||||
|
|
||||||
package org.oxycblt.auxio.playback.ui
|
package org.oxycblt.auxio.playback.ui
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Path
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.util.Log
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.GestureDetector.OnDoubleTapListener
|
import android.view.GestureDetector.OnDoubleTapListener
|
||||||
import android.view.GestureDetector.OnGestureListener
|
import android.view.GestureDetector.OnGestureListener
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import org.oxycblt.auxio.image.CoverView
|
import org.oxycblt.auxio.image.CoverView
|
||||||
@@ -42,6 +48,23 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
|
|
||||||
var onSwipeListener: OnSwipeListener? = null
|
var onSwipeListener: OnSwipeListener? = null
|
||||||
|
|
||||||
|
// Circle clip animation properties
|
||||||
|
private val backgroundPaint =
|
||||||
|
Paint().apply {
|
||||||
|
style = Paint.Style.FILL
|
||||||
|
isAntiAlias = true
|
||||||
|
color = 0x80000000.toInt() // Increased opacity for visibility
|
||||||
|
}
|
||||||
|
|
||||||
|
private val shapePath = Path()
|
||||||
|
private var arcSize: Float = 80f
|
||||||
|
private var isLeftSide = true
|
||||||
|
private var animationProgress = 0f
|
||||||
|
private var fadeAnimator: ValueAnimator? = null
|
||||||
|
private var fadeOutAnimator: ValueAnimator? = null
|
||||||
|
private var lastTapTime = 0L
|
||||||
|
private var isAnimating = false
|
||||||
|
|
||||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||||
return gestureDetector.onTouchEvent(event)
|
return gestureDetector.onTouchEvent(event)
|
||||||
}
|
}
|
||||||
@@ -100,6 +123,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
tapX < width * 0.33f -> {
|
tapX < width * 0.33f -> {
|
||||||
|
showCircleAnimation(isLeft = true)
|
||||||
if (isRtl) {
|
if (isRtl) {
|
||||||
onSwipeListener?.onStepForward()
|
onSwipeListener?.onStepForward()
|
||||||
} else {
|
} else {
|
||||||
@@ -108,6 +132,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
tapX > width * 0.67f -> {
|
tapX > width * 0.67f -> {
|
||||||
|
showCircleAnimation(isLeft = false)
|
||||||
if (isRtl) {
|
if (isRtl) {
|
||||||
onSwipeListener?.onStepBack()
|
onSwipeListener?.onStepBack()
|
||||||
} else {
|
} else {
|
||||||
@@ -129,6 +154,148 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
onSwipeListener?.run { if (isRtl) onSwipePrevious() else onSwipeNext() }
|
onSwipeListener?.run { if (isRtl) onSwipePrevious() else onSwipeNext() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showCircleAnimation(isLeft: Boolean) {
|
||||||
|
Log.d(
|
||||||
|
"ControlledCoverView",
|
||||||
|
"showCircleAnimation: isLeft = $isLeft, isAnimating = $isAnimating")
|
||||||
|
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
val timeSinceLastTap = currentTime - lastTapTime
|
||||||
|
lastTapTime = currentTime
|
||||||
|
|
||||||
|
val isSwitchingSides = isLeftSide != isLeft
|
||||||
|
|
||||||
|
// Update the path if switching sides or initializing
|
||||||
|
if (isSwitchingSides || !isAnimating) {
|
||||||
|
isLeftSide = isLeft
|
||||||
|
arcSize = height / 11.4f
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
|
||||||
|
// If animation is already running and it's a rapid tap (within 600ms)
|
||||||
|
if (isAnimating && timeSinceLastTap < 600 && !isSwitchingSides) {
|
||||||
|
// Cancel any fade out that might be scheduled
|
||||||
|
fadeOutAnimator?.cancel()
|
||||||
|
removeCallbacks(fadeOutRunnable)
|
||||||
|
|
||||||
|
// Keep the animation at full opacity or fade it back in if it was fading out
|
||||||
|
if (animationProgress < 1f) {
|
||||||
|
fadeAnimator?.cancel()
|
||||||
|
fadeAnimator =
|
||||||
|
ValueAnimator.ofFloat(animationProgress, 1f).apply {
|
||||||
|
duration = ((1f - animationProgress) * 200).toLong()
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
addUpdateListener { animation ->
|
||||||
|
animationProgress = animation.animatedValue as Float
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule fade out after a delay
|
||||||
|
postDelayed(fadeOutRunnable, 600)
|
||||||
|
} else {
|
||||||
|
// Start fresh animation (either first tap, timeout, or side switch)
|
||||||
|
isAnimating = true
|
||||||
|
|
||||||
|
// Cancel any existing animations
|
||||||
|
fadeAnimator?.cancel()
|
||||||
|
fadeOutAnimator?.cancel()
|
||||||
|
removeCallbacks(fadeOutRunnable)
|
||||||
|
|
||||||
|
// If switching sides during rapid taps, do a quick crossfade
|
||||||
|
if (isSwitchingSides && timeSinceLastTap < 600 && animationProgress > 0) {
|
||||||
|
// Quick fade to new side
|
||||||
|
fadeAnimator =
|
||||||
|
ValueAnimator.ofFloat(0f, 1f).apply {
|
||||||
|
duration = 150
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
addUpdateListener { animation ->
|
||||||
|
animationProgress = animation.animatedValue as Float
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Normal fade in
|
||||||
|
fadeAnimator =
|
||||||
|
ValueAnimator.ofFloat(0f, 1f).apply {
|
||||||
|
duration = 250
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
addUpdateListener { animation ->
|
||||||
|
animationProgress = animation.animatedValue as Float
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule fade out
|
||||||
|
postDelayed(fadeOutRunnable, 600)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val fadeOutRunnable = Runnable {
|
||||||
|
fadeOutAnimator?.cancel()
|
||||||
|
fadeOutAnimator =
|
||||||
|
ValueAnimator.ofFloat(animationProgress, 0f).apply {
|
||||||
|
duration = 200
|
||||||
|
addUpdateListener { animation ->
|
||||||
|
animationProgress = animation.animatedValue as Float
|
||||||
|
invalidate()
|
||||||
|
|
||||||
|
if (animationProgress == 0f) {
|
||||||
|
isAnimating = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePathShape() {
|
||||||
|
val halfWidth = width * 0.5f
|
||||||
|
|
||||||
|
shapePath.reset()
|
||||||
|
|
||||||
|
val w = if (isLeftSide) 0f else width.toFloat()
|
||||||
|
val f = if (isLeftSide) 1 else -1
|
||||||
|
|
||||||
|
shapePath.moveTo(w, 0f)
|
||||||
|
shapePath.lineTo(f * (halfWidth - arcSize) + w, 0f)
|
||||||
|
shapePath.quadTo(
|
||||||
|
f * (halfWidth + arcSize) + w,
|
||||||
|
height.toFloat() / 2,
|
||||||
|
f * (halfWidth - arcSize) + w,
|
||||||
|
height.toFloat())
|
||||||
|
shapePath.lineTo(w, height.toFloat())
|
||||||
|
|
||||||
|
shapePath.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
arcSize = h / 11.4f
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispatchDraw(canvas: Canvas) {
|
||||||
|
super.dispatchDraw(canvas)
|
||||||
|
|
||||||
|
// Draw the animation overlay on top of everything
|
||||||
|
if (animationProgress > 0f) {
|
||||||
|
Log.d(
|
||||||
|
"ControlledCoverView",
|
||||||
|
"Drawing animation: progress = $animationProgress, arcSize = $arcSize")
|
||||||
|
|
||||||
|
// Set alpha based on animation progress
|
||||||
|
backgroundPaint.alpha = (0x80 * animationProgress).toInt()
|
||||||
|
|
||||||
|
// Draw the curved shape without clipping
|
||||||
|
canvas.drawPath(shapePath, backgroundPaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface OnSwipeListener {
|
interface OnSwipeListener {
|
||||||
|
|
||||||
fun onSwipePrevious()
|
fun onSwipePrevious()
|
||||||
|
|||||||
Reference in New Issue
Block a user