60 lines
1.9 KiB
Kotlin
60 lines
1.9 KiB
Kotlin
/**
|
|
* @file StepCounterUiController.kt
|
|
* @brief Rendering for the live step-counter card.
|
|
*/
|
|
package com.example.jnicpp.bowling
|
|
|
|
import android.view.View
|
|
import android.widget.TextView
|
|
|
|
/**
|
|
* @brief Owns rendering for [BowlingCameraActivity]'s step-counter card.
|
|
*
|
|
* @param cardStepCounter The step-counter card container view.
|
|
* @param textStepCountBig The large step-count number TextView.
|
|
*/
|
|
class StepCounterUiController(
|
|
private val cardStepCounter: View,
|
|
private val textStepCountBig: TextView,
|
|
) {
|
|
// Last step count rendered, so pulse() in renderStepCount only plays
|
|
// when a new step actually pushed the count up.
|
|
private var lastRenderedStepCount = 0
|
|
|
|
/**
|
|
* @brief Shows or hides the step counter card.
|
|
* @param visible true to reveal (recording in progress), false to hide.
|
|
*/
|
|
fun setVisible(visible: Boolean) {
|
|
cardStepCounter.visibility = if (visible) View.VISIBLE else View.GONE
|
|
}
|
|
|
|
/** @brief Clears pulse-tracking state; call whenever a new recording starts. */
|
|
fun resetTracking() {
|
|
lastRenderedStepCount = 0
|
|
}
|
|
|
|
/**
|
|
* @brief Renders the current step count, pulsing the card if a new step was just confirmed.
|
|
* @param stepCount Total steps counted so far in the current attempt.
|
|
*/
|
|
fun renderStepCount(stepCount: Int) {
|
|
textStepCountBig.text = stepCount.toString()
|
|
if (stepCount > lastRenderedStepCount) {
|
|
pulse()
|
|
}
|
|
lastRenderedStepCount = stepCount
|
|
}
|
|
|
|
/** @brief Briefly scales the step counter up and back down, drawing the eye to a newly confirmed step. */
|
|
private fun pulse() {
|
|
cardStepCounter.animate()
|
|
.scaleX(1.15f).scaleY(1.15f)
|
|
.setDuration(80)
|
|
.withEndAction {
|
|
cardStepCounter.animate().scaleX(1f).scaleY(1f).setDuration(120).start()
|
|
}
|
|
.start()
|
|
}
|
|
}
|