playback: deslop stepper

Actually meaningful improvement to functionality this time.
This commit is contained in:
Alexander Capehart
2026-05-14 20:47:59 -06:00
parent 00ddba54bb
commit b78fb5a6d8
7 changed files with 289 additions and 415 deletions
@@ -807,18 +807,30 @@ constructor(
pathMeasure.getSegment(startDistance, endDistance, displayedWavePath, true)
startPoint.reset()
val startPosArr = floatArrayOf(startPoint.posVec.x, startPoint.posVec.y)
val startTanArr = floatArrayOf(startPoint.tanVec.x, startPoint.tanVec.y)
pathMeasure.getPosTan(
startDistance,
floatArrayOf(startPoint.posVec.x, startPoint.posVec.y),
floatArrayOf(startPoint.tanVec.x, startPoint.tanVec.y),
)
endPoint.reset()
pathMeasure.getPosTan(
startDistance,
floatArrayOf(endPoint.posVec.x, endPoint.posVec.y),
floatArrayOf(endPoint.tanVec.x, endPoint.tanVec.y),
startPosArr,
startTanArr
)
startPoint.posVec.x = startPosArr[0]
startPoint.posVec.y = startPosArr[1]
startPoint.tanVec.x = startTanArr[0]
startPoint.tanVec.y = startTanArr[1]
endPoint.reset()
val endPosArr = floatArrayOf(endPoint.posVec.x, endPoint.posVec.y)
val endTanArr = floatArrayOf(endPoint.tanVec.x, endPoint.tanVec.y)
pathMeasure.getPosTan(
endDistance,
endPosArr,
endTanArr
)
endPoint.posVec.x = endPosArr[0]
endPoint.posVec.y = endPosArr[1]
endPoint.tanVec.x = endTanArr[0]
endPoint.tanVec.y = endTanArr[1]
transform.reset()
transform.setTranslate(resultTranslationX, baseTranslationY)
startPoint.translate(resultTranslationX, baseTranslationY)
@@ -41,7 +41,7 @@ import org.oxycblt.auxio.music.resolve
import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.playback.ui.StyledSeekBar
import org.oxycblt.auxio.playback.ui.stepper.DisplayPortion
import org.oxycblt.auxio.playback.ui.stepper.Direction
import org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collectImmediately
@@ -104,10 +104,7 @@ class PlaybackPanelFragment :
binding.playbackCover.onSwipeListener = null
// Set up fast seek overlay
binding.playbackFastSeekOverlay?.apply {
performListener(this@PlaybackPanelFragment)
seekSecondsSupplier { 10 } // 10 seconds per double-tap
}
binding.playbackFastSeekOverlay?.performListener = this
binding.playbackSong.apply {
isSelected = true
setOnClickListener { navigateToCurrentSong() }
@@ -279,25 +276,10 @@ class PlaybackPanelFragment :
playbackModel.song.value?.let { detailModel.showAlbum(it.album) }
}
override fun getFastSeekDirection(
portion: DisplayPortion
): PlayerFastSeekOverlay.PerformListener.FastSeekDirection {
return when (portion) {
DisplayPortion.LEFT,
DisplayPortion.LEFT_HALF ->
PlayerFastSeekOverlay.PerformListener.FastSeekDirection.BACKWARD
DisplayPortion.RIGHT,
DisplayPortion.RIGHT_HALF ->
PlayerFastSeekOverlay.PerformListener.FastSeekDirection.FORWARD
else -> PlayerFastSeekOverlay.PerformListener.FastSeekDirection.NONE
}
}
override fun seek(forward: Boolean) {
if (forward) {
playbackModel.stepForward()
} else {
playbackModel.stepBack()
override fun seek(direction: Direction) {
when (direction) {
Direction.FORWARDS -> playbackModel.stepForward()
Direction.BACKWARDS -> playbackModel.stepBackwards()
}
}
}
@@ -428,7 +428,7 @@ constructor(
}
/** Step back by 10 seconds in the current song. */
fun stepBack() {
fun stepBackwards() {
L.d("Stepping back 10 seconds")
val currentPositionMs = playbackManager.progression.calculateElapsedPositionMs()
val newPositionMs = (currentPositionMs - 10000).coerceAtLeast(0)
@@ -441,7 +441,7 @@ constructor(
val currentPositionMs = playbackManager.progression.calculateElapsedPositionMs()
val currentSong = playbackManager.currentSong
if (currentSong != null) {
val newPositionMs = (currentPositionMs + 10000).coerceAtMost(currentSong.durationMs)
val newPositionMs = (currentPositionMs + STEP_INCREMENT).coerceAtMost(currentSong.durationMs)
playbackManager.seekTo(newPositionMs)
}
}
@@ -626,6 +626,10 @@ constructor(
}
_openPanel.put(panel)
}
private companion object {
private const val STEP_INCREMENT = 10000 // ms
}
}
/**
@@ -19,102 +19,95 @@
package org.oxycblt.auxio.playback.ui.stepper
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.view.GestureDetector
import android.view.LayoutInflater
import android.view.MotionEvent
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.withStyledAttributes
import androidx.dynamicanimation.animation.SpringAnimation
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.Effect
import org.oxycblt.auxio.ui.UISettings
import timber.log.Timber as L
import javax.inject.Inject
enum class DisplayPortion {
LEFT,
MIDDLE,
RIGHT,
LEFT_HALF,
RIGHT_HALF,
}
interface DoubleTapListener {
fun onDoubleTapStarted(portion: DisplayPortion)
fun onDoubleTapProgressDown(portion: DisplayPortion)
fun onDoubleTapFinished()
enum class Direction {
FORWARDS,
BACKWARDS
}
@AndroidEntryPoint
class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
ConstraintLayout(context, attrs), DoubleTapListener, GestureDetector.OnDoubleTapListener {
ConstraintLayout(context, attrs), GestureDetector.OnDoubleTapListener {
private sealed interface OverlayState {
data object Invisible : OverlayState
data class Entering(val tap: SpringAnimation, val seconds: SpringAnimation) : OverlayState
data class Wait(val runnable: Runnable) : OverlayState
data class Exiting(val tap: SpringAnimation, val seconds: SpringAnimation) : OverlayState
}
@Inject lateinit var uiSettings: UISettings
private var leftSecondsView: SecondsView
private var rightSecondsView: SecondsView
private var leftCircleClipTapView: CircleClipTapView
private var rightCircleClipTapView: CircleClipTapView
private var rootConstraintLayout: ConstraintLayout
private var leftTapView: TapView
private var rightTapView: TapView
private val gestureDetector: GestureDetector
private val shapeAppearance: ShapeAppearanceModel
var performListener: PerformListener? = null
private val alphaSpring = Effect.FAST
private var leftOverlayState: OverlayState = OverlayState.Invisible
private var rightOverlayState: OverlayState = OverlayState.Invisible
interface PerformListener {
fun seek(direction: Direction)
}
init {
LayoutInflater.from(context).inflate(R.layout.player_fast_seek_overlay, this, true)
// Set up shape appearance based on UISettings similar to CoverView
val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.PlayerFastSeekOverlay)
val shapeAppearanceRes =
styledAttrs.getResourceId(R.styleable.PlayerFastSeekOverlay_shapeAppearance, 0)
context.withStyledAttributes(attrs, R.styleable.PlayerFastSeekOverlay) {
val shapeAppearanceRes =
getResourceId(
R.styleable.PlayerFastSeekOverlay_shapeAppearance,
com.google.android.material.R.style
.ShapeAppearance_Material3_Corner_Medium
)
shapeAppearance =
if (uiSettings.roundMode) {
if (shapeAppearanceRes != 0) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder(
context,
com.google.android.material.R.style
.ShapeAppearance_Material3_Corner_Medium,
-1,
)
.build()
}
background =
MaterialShapeDrawable().apply {
shapeAppearanceModel = if (uiSettings.roundMode) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder().build()
}
styledAttrs.recycle()
}
// Set transparent background as we only want the clipping
fillColor = ColorStateList.valueOf(Color.TRANSPARENT)
}
}
leftSecondsView = findViewById(R.id.left_seconds_view)
rightSecondsView = findViewById(R.id.right_seconds_view)
leftCircleClipTapView = findViewById(R.id.left_circle_clip_tap_view)
rightCircleClipTapView = findViewById(R.id.right_circle_clip_tap_view)
rootConstraintLayout = findViewById(R.id.root_constraint_layout)
leftTapView = findViewById(R.id.left_circle_clip_tap_view)
rightTapView = findViewById(R.id.right_circle_clip_tap_view)
// Apply shape clipping to the overlay
clipToOutline = true
background =
MaterialShapeDrawable().apply {
shapeAppearanceModel = shapeAppearance
// Set transparent background as we only want the clipping
fillColor =
android.content.res.ColorStateList.valueOf(android.graphics.Color.TRANSPARENT)
}
// Hide overlay elements by default
leftSecondsView.alpha = 0f
rightSecondsView.alpha = 0f
leftCircleClipTapView.alpha = 0f
rightCircleClipTapView.alpha = 0f
leftSecondsView.visibility = INVISIBLE
rightSecondsView.visibility = INVISIBLE
leftCircleClipTapView.visibility = INVISIBLE
rightCircleClipTapView.visibility = INVISIBLE
leftTapView.alpha = 0f
rightTapView.alpha = 0f
// Set up gesture detection
gestureDetector =
@@ -127,243 +120,170 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
gestureDetector.setOnDoubleTapListener(this)
addOnLayoutChangeListener { view, _, _, _, _, _, _, _, _ ->
leftCircleClipTapView.updateArcSize(view)
rightCircleClipTapView.updateArcSize(view)
leftTapView.updateArcSize(view)
rightTapView.updateArcSize(view)
}
// Initialize directions for each side
leftSecondsView.setForwarding(false)
rightSecondsView.setForwarding(true)
leftCircleClipTapView.updatePosition(true) // isLeft = true for left side
rightCircleClipTapView.updatePosition(false) // isLeft = false for right side
leftSecondsView.setDirection(Direction.BACKWARDS)
rightSecondsView.setDirection(Direction.FORWARDS)
leftTapView.setDirection(Direction.BACKWARDS) // isLeft = true for left side
rightTapView.setDirection(Direction.FORWARDS) // isLeft = false for right side
}
private var performListener: PerformListener? = null
fun performListener(listener: PerformListener?) = apply { performListener = listener }
private var seekSecondsSupplier: () -> Int = { 0 }
fun seekSecondsSupplier(supplier: (() -> Int)?) = apply {
seekSecondsSupplier = supplier ?: { 0 }
}
// Track state for left overlay
private var leftInitTap: Boolean = false
private var leftIsAnimatingIn: Boolean = false
private var leftFadeOutRunnable: Runnable? = null
// Track state for right overlay
private var rightInitTap: Boolean = false
private var rightIsAnimatingIn: Boolean = false
private var rightFadeOutRunnable: Runnable? = null
override fun onDoubleTapStarted(portion: DisplayPortion) {
L.d("onDoubleTapStarted called with portion = [$portion]")
val shouldForward: Boolean =
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
if (shouldForward) {
rightInitTap = false
rightSecondsView.stopAnimation()
} else {
leftInitTap = false
leftSecondsView.stopAnimation()
}
}
override fun onDoubleTapProgressDown(portion: DisplayPortion) {
val shouldForward: Boolean =
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
L.d("onDoubleTapProgressDown called with shouldForward = [$shouldForward]")
if (shouldForward) {
handleRightOverlayTap()
} else {
handleLeftOverlayTap()
}
performListener?.seek(forward = shouldForward)
}
private fun handleLeftOverlayTap() {
// Cancel any pending fade out for left overlay
leftFadeOutRunnable?.let {
removeCallbacks(it)
leftFadeOutRunnable = null
}
if (!leftInitTap) {
// Reset seconds for new tap series
leftSecondsView.seconds = 0
leftInitTap = true
// Only fade in if we're not already visible and animating
if (!leftIsAnimatingIn && leftSecondsView.alpha < 1f) {
leftIsAnimatingIn = true
leftSecondsView.visibility = VISIBLE
leftCircleClipTapView.visibility = VISIBLE
leftSecondsView.startAnimation()
leftSecondsView
.animate()
.alpha(1f)
.setDuration(200)
.withEndAction { leftIsAnimatingIn = false }
.start()
leftCircleClipTapView.animate().alpha(1f).setDuration(200).start()
}
} else {
// For rapid taps, ensure we're fully visible without re-animating
if (leftSecondsView.alpha < 1f && !leftIsAnimatingIn) {
leftSecondsView.alpha = 1f
leftCircleClipTapView.alpha = 1f
leftSecondsView.visibility = VISIBLE
leftCircleClipTapView.visibility = VISIBLE
}
}
leftSecondsView.seconds += seekSecondsSupplier.invoke()
}
private fun handleRightOverlayTap() {
// Cancel any pending fade out for right overlay
rightFadeOutRunnable?.let {
removeCallbacks(it)
rightFadeOutRunnable = null
}
if (!rightInitTap) {
// Reset seconds for new tap series
rightSecondsView.seconds = 0
rightInitTap = true
// Only fade in if we're not already visible and animating
if (!rightIsAnimatingIn && rightSecondsView.alpha < 1f) {
rightIsAnimatingIn = true
rightSecondsView.visibility = VISIBLE
rightCircleClipTapView.visibility = VISIBLE
rightSecondsView.startAnimation()
rightSecondsView
.animate()
.alpha(1f)
.setDuration(200)
.withEndAction { rightIsAnimatingIn = false }
.start()
rightCircleClipTapView.animate().alpha(1f).setDuration(200).start()
}
} else {
// For rapid taps, ensure we're fully visible without re-animating
if (rightSecondsView.alpha < 1f && !rightIsAnimatingIn) {
rightSecondsView.alpha = 1f
rightCircleClipTapView.alpha = 1f
rightSecondsView.visibility = VISIBLE
rightCircleClipTapView.visibility = VISIBLE
}
}
rightSecondsView.seconds += seekSecondsSupplier.invoke()
}
override fun onDoubleTapFinished() {
L.d("onDoubleTapFinished called")
// Handle left overlay fade out
if (leftInitTap) {
leftInitTap = false
leftSecondsView.stopAnimation()
// Cancel any existing fade out
leftFadeOutRunnable?.let { removeCallbacks(it) }
// Schedule fade out for left overlay after a delay
leftFadeOutRunnable = Runnable {
leftIsAnimatingIn = false
leftSecondsView
.animate()
.alpha(0f)
.setDuration(200)
.withEndAction { leftSecondsView.visibility = INVISIBLE }
.start()
leftCircleClipTapView
.animate()
.alpha(0f)
.setDuration(200)
.withEndAction { leftCircleClipTapView.visibility = INVISIBLE }
.start()
leftFadeOutRunnable = null
}
postDelayed(leftFadeOutRunnable, 400)
}
// Handle right overlay fade out
if (rightInitTap) {
rightInitTap = false
rightSecondsView.stopAnimation()
// Cancel any existing fade out
rightFadeOutRunnable?.let { removeCallbacks(it) }
// Schedule fade out for right overlay after a delay
rightFadeOutRunnable = Runnable {
rightIsAnimatingIn = false
rightSecondsView
.animate()
.alpha(0f)
.setDuration(200)
.withEndAction { rightSecondsView.visibility = INVISIBLE }
.start()
rightCircleClipTapView
.animate()
.alpha(0f)
.setDuration(200)
.withEndAction { rightCircleClipTapView.visibility = INVISIBLE }
.start()
rightFadeOutRunnable = null
}
postDelayed(rightFadeOutRunnable, 400)
}
}
interface PerformListener {
/** Determines if the playback should forward/rewind or do nothing. */
fun getFastSeekDirection(portion: DisplayPortion): FastSeekDirection
fun seek(forward: Boolean)
enum class FastSeekDirection(val directionAsBoolean: Boolean?) {
NONE(null),
FORWARD(true),
BACKWARD(false),
}
}
override fun onTouchEvent(event: MotionEvent): Boolean =
gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
override fun onSingleTapConfirmed(e: MotionEvent) = false
private fun enter(secondsView: SecondsView, tapView: TapView, overlayState: (OverlayState) -> Unit) {
// start animating the seconds icon
secondsView.startAnimation()
val secondsIn = alphaSpring.alpha(secondsView, 1.0f)
val tapIn = alphaSpring.alpha(tapView, 1.0f)
// will execute after a delay
val out = Runnable {
exit(secondsView, tapView, overlayState)
}
tapIn.addEndListener { _, cancelled, _, _ ->
if (!cancelled) {
postDelayed(out, EXIT_DELAY_MS)
overlayState(OverlayState.Wait(out))
}
}
overlayState(OverlayState.Entering(secondsIn, tapIn))
}
private fun exit(secondsView: SecondsView, tapView: TapView, overlayState: (OverlayState) -> Unit) {
val secondsOut = alphaSpring.alpha(secondsView, 0.0f)
val tapOut = alphaSpring.alpha(tapView, 0.0f)
tapOut.addEndListener { _, cancelled, _, _ ->
if (!cancelled) {
secondsView.stopAnimation()
secondsView.seconds = 0
overlayState(OverlayState.Invisible)
}
}
overlayState(OverlayState.Exiting(secondsOut, tapOut))
}
private fun tap(
tappedSecondsView: SecondsView,
tappedTapView: TapView,
tappedOverlayState: OverlayState,
setTappedOverlayState: (OverlayState) -> Unit,
idleSecondsView: SecondsView,
idleTapView: TapView,
idleOverlayState: OverlayState,
setIdleOverlayState: (OverlayState) -> Unit,
) {
// (re)activate the side that was tapped on
when (tappedOverlayState) {
is OverlayState.Invisible -> {
enter(tappedSecondsView, tappedTapView, setTappedOverlayState)
}
is OverlayState.Entering -> {
// do nothing
}
is OverlayState.Wait -> {
// refresh the exit timeout
removeCallbacks(tappedOverlayState.runnable)
postDelayed(tappedOverlayState.runnable, EXIT_DELAY_MS)
}
is OverlayState.Exiting -> {
// cancel exit and re-enter
tappedOverlayState.seconds.cancel()
tappedOverlayState.tap.cancel()
enter(tappedSecondsView, tappedTapView, setTappedOverlayState)
}
}
// clear out the idle side if it's active
when (idleOverlayState) {
is OverlayState.Invisible -> {
// nothing to clear
}
is OverlayState.Entering -> {
// cancel enter and exit immediately
idleOverlayState.seconds.cancel()
idleOverlayState.tap.cancel()
exit(idleSecondsView, idleTapView, setIdleOverlayState)
}
is OverlayState.Wait -> {
// dont wait for an exit, exit immediately
removeCallbacks(idleOverlayState.runnable)
exit(idleSecondsView, idleTapView, setIdleOverlayState)
}
is OverlayState.Exiting -> {
// nothing to clear
}
}
// update seconds from tap - reset when exit anim clears
// largely implicit shared understanding that seeking occurs by 10s
// todo: probably share this constant
tappedSecondsView.seconds += 10
}
override fun onDoubleTap(e: MotionEvent): Boolean {
val width = width
val tapX = e.x
val portion =
val direction =
when {
tapX < width * 0.33f -> DisplayPortion.LEFT_HALF
tapX > width * 0.67f -> DisplayPortion.RIGHT_HALF
else -> DisplayPortion.MIDDLE
tapX < width * 0.5 -> Direction.BACKWARDS
tapX > width * 0.5 -> Direction.FORWARDS
// dont care
else -> return false
}
if (portion != DisplayPortion.MIDDLE) {
onDoubleTapStarted(portion)
onDoubleTapProgressDown(portion)
onDoubleTapFinished()
return true
// a bit duplicated but already the generic `enter`/`exit` logic
// requires a good amount of params and trying to share the helpe
when (direction) {
Direction.BACKWARDS -> {
tap(
leftSecondsView,
leftTapView,
leftOverlayState,
{ leftOverlayState = it },
rightSecondsView,
rightTapView,
rightOverlayState,
{ rightOverlayState = it }
)
}
Direction.FORWARDS -> {
// forwards, we tap on the right
tap(
rightSecondsView,
rightTapView,
rightOverlayState,
{ rightOverlayState = it },
leftSecondsView,
leftTapView,
leftOverlayState,
{ leftOverlayState = it },
)
}
}
performListener?.seek(direction)
return false
}
override fun onDoubleTapEvent(e: MotionEvent) = false
private companion object {
private const val EXIT_DELAY_MS = 500L
}
}
@@ -25,25 +25,14 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.animation.addListener
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.dynamicanimation.animation.SpringAnimation
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.PlayerFastSeekSecondsViewBinding
import org.oxycblt.auxio.ui.Effect
class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {
companion object {
const val ICON_ANIMATION_DURATION = 750L
}
var cycleDuration: Long = ICON_ANIMATION_DURATION
set(value) {
firstAnimator.duration = value / 5
secondAnimator.duration = value / 5
thirdAnimator.duration = value / 5
fourthAnimator.duration = value / 5
fifthAnimator.duration = value / 5
field = value
}
var seconds: Int = 0
set(value) {
binding.tvSeconds.text =
@@ -59,22 +48,34 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
1F,
) != 0F
private val alphaSpring = Effect.FAST
private var animations: List<SpringAnimation> = listOf()
val binding = PlayerFastSeekSecondsViewBinding.inflate(LayoutInflater.from(context), this)
init {
orientation = VERTICAL
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
reset()
}
fun setForwarding(isForward: Boolean) {
binding.triangleContainer.rotation = if (isForward) 0f else 180f
fun setDirection(direction: Direction) {
// easy flip if in the other direction, dont have to change icons or anim order
binding.triangleContainer.rotation = if (direction == Direction.FORWARDS) 0f else 180f
}
fun startAnimation() {
stopAnimation()
if (animations.any { it.isRunning }) {
// animations ongoing
// we never try to stop ongoing animations when this is
// called again, as that will likely result in the indicator always
// resetting
// TODO: might want to change this
return
}
reset()
if (animationsEnabled) {
firstAnimator.start()
cycle()
} else {
// If no animations are enable show the arrow(s) without animation
showWithoutAnimation()
@@ -82,12 +83,7 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
}
fun stopAnimation() {
firstAnimator.cancel()
secondAnimator.cancel()
thirdAnimator.cancel()
fourthAnimator.cancel()
fifthAnimator.cancel()
animations.forEach { it.cancel() }
reset()
}
@@ -103,76 +99,38 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
binding.icon3.alpha = 1f
}
private val firstAnimator: ValueAnimator =
CustomValueAnimator(
{
binding.icon1.alpha = 0f
binding.icon2.alpha = 0f
binding.icon3.alpha = 0f
},
{ binding.icon1.alpha = it },
{ secondAnimator.start() },
)
// cycle animation for the 3 icons
private val cyclicAlpha = floatArrayOf(
1.00f, 0.25f, 0.25f,
1.00f, 1.00f, 0.25f,
0.25f, 1.00f, 1.00f,
0.25f, 0.25f, 1.00f,
0.25f, 0.25f, 0.25f,
)
private val secondAnimator: ValueAnimator =
CustomValueAnimator(
{
binding.icon1.alpha = 1f
binding.icon2.alpha = 0f
binding.icon3.alpha = 0f
},
{ binding.icon2.alpha = it },
{ thirdAnimator.start() },
)
private val thirdAnimator: ValueAnimator =
CustomValueAnimator(
{
binding.icon1.alpha = 1f
binding.icon2.alpha = 1f
binding.icon3.alpha = 0f
},
{
binding.icon1.alpha = 1f - binding.icon3.alpha
binding.icon3.alpha = it
},
{ fourthAnimator.start() },
)
private val fourthAnimator: ValueAnimator =
CustomValueAnimator(
{
binding.icon1.alpha = 0f
binding.icon2.alpha = 1f
binding.icon3.alpha = 1f
},
{ binding.icon2.alpha = 1f - it },
{ fifthAnimator.start() },
)
private val fifthAnimator: ValueAnimator =
CustomValueAnimator(
{
binding.icon1.alpha = 0f
binding.icon2.alpha = 0f
binding.icon3.alpha = 1f
},
{ binding.icon3.alpha = 1f - it },
{ firstAnimator.start() },
)
private inner class CustomValueAnimator(
start: () -> Unit,
update: (value: Float) -> Unit,
end: () -> Unit,
) : ValueAnimator() {
init {
duration = cycleDuration / 5
setFloatValues(0f, 1f)
addUpdateListener { update(it.animatedValue as Float) }
addListener(onStart = { start() }, onEnd = { end() })
private fun cycle(at: Int = 0) {
animations.forEach { it.cancel() }
val row = at * 3
val one = alphaSpring.alpha(binding.icon1, cyclicAlpha[row])
val two = alphaSpring.alpha(binding.icon2, cyclicAlpha[row + 1])
val three = alphaSpring.alpha(binding.icon3, cyclicAlpha[row + 2])
val endListener = DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) {
cycle((at + 1) % 5)
}
}
when {
cyclicAlpha[row] != binding.icon1.alpha -> {
one.addEndListener(endListener)
}
cyclicAlpha[row + 1] != binding.icon2.alpha -> {
two.addEndListener(endListener)
}
cyclicAlpha[row + 2] != binding.icon3.alpha -> {
three.addEndListener(endListener)
}
}
animations = listOf(one, two, three)
}
}
@@ -25,7 +25,10 @@ import android.graphics.Path
import android.util.AttributeSet
import android.view.View
class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context, attrs) {
/**
* Cricle
*/
class TapView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var backgroundPaint = Paint()
@@ -33,14 +36,11 @@ class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context,
private var heightPx = 0
// Background
private var shapePath = Path()
private var arcSize: Float = 80f
private var isLeft = true
private var direction = Direction.FORWARDS
init {
requireNotNull(context) { "Context is null." }
backgroundPaint.apply {
style = Paint.Style.FILL
isAntiAlias = true
@@ -62,11 +62,9 @@ class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context,
}
}
fun updatePosition(newIsLeft: Boolean) {
if (isLeft != newIsLeft) {
isLeft = newIsLeft
updatePathShape()
}
fun setDirection(newDirection: Direction) {
direction = newDirection
updatePathShape()
}
private fun updatePathShape() {
@@ -74,8 +72,8 @@ class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context,
shapePath.reset()
val w = if (isLeft) 0f else widthPx.toFloat()
val f = if (isLeft) 1 else -1
val w = if (direction == Direction.BACKWARDS) 0f else widthPx.toFloat()
val f = if (direction == Direction.BACKWARDS) 1 else -1
shapePath.moveTo(w, 0f)
shapePath.lineTo(f * (halfWidth - arcSize) + w, 0f)
@@ -6,7 +6,7 @@
android:layout_height="match_parent">
<!-- Left overlay views -->
<org.oxycblt.auxio.playback.ui.stepper.CircleClipTapView
<org.oxycblt.auxio.playback.ui.stepper.TapView
android:id="@+id/left_circle_clip_tap_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -26,7 +26,7 @@
app:layout_constraintWidth_percent="0.5" />
<!-- Right overlay views -->
<org.oxycblt.auxio.playback.ui.stepper.CircleClipTapView
<org.oxycblt.auxio.playback.ui.stepper.TapView
android:id="@+id/right_circle_clip_tap_view"
android:layout_width="match_parent"
android:layout_height="match_parent"