bug fixes to AI suggested enhancements

This commit is contained in:
2026-05-26 02:39:53 -07:00
parent e00de3d340
commit cb5c9dc547
3 changed files with 40 additions and 47 deletions
@@ -1,6 +1,5 @@
package com.example.countdowntimer package com.example.countdowntimer
import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import android.graphics.Canvas import android.graphics.Canvas
@@ -8,7 +7,6 @@ import android.graphics.Paint
import android.graphics.RectF import android.graphics.RectF
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
class CountdownCanvasView @JvmOverloads constructor( class CountdownCanvasView @JvmOverloads constructor(
context: Context, context: Context,
@@ -25,24 +23,16 @@ class CountdownCanvasView @JvmOverloads constructor(
isFakeBoldText = false isFakeBoldText = false
} }
private val ringPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { private val ringPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.parseColor("#D0BCFF") color = Color.parseColor("#6750A4")
style = Paint.Style.STROKE style = Paint.Style.STROKE
strokeWidth = 16f strokeWidth = 16f
} }
private val ringBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { private val ringBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.parseColor("#E8DEF8") color = Color.parseColor("#D0BCFF")
style = Paint.Style.STROKE style = Paint.Style.STROKE
strokeWidth = 16f strokeWidth = 16f
} }
private val rectF = RectF() private val rectF = RectF()
private val progressAnimator = ValueAnimator.ofFloat(1.0f, 0.0f).apply {
duration = 10000
interpolator = AccelerateDecelerateInterpolator()
addUpdateListener { animation ->
progressFraction = animation.animatedValue as Float
invalidate()
}
}
fun setText(text: String) { fun setText(text: String) {
if (textToDraw != text) { if (textToDraw != text) {
@@ -52,19 +42,10 @@ class CountdownCanvasView @JvmOverloads constructor(
} }
fun setProgress(fraction: Float) { fun setProgress(fraction: Float) {
progressFraction = fraction progressFraction = fraction.coerceIn(0f, 1f)
invalidate() invalidate()
} }
fun startProgressAnimation(duration: Long) {
progressAnimator.duration = duration
progressAnimator.start()
}
fun cancelProgressAnimation() {
progressAnimator.cancel()
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh) super.onSizeChanged(w, h, oldw, oldh)
val inset = ringPaint.strokeWidth / 2f + 12f val inset = ringPaint.strokeWidth / 2f + 12f
@@ -79,9 +60,10 @@ class CountdownCanvasView @JvmOverloads constructor(
val cx = rectF.centerX() val cx = rectF.centerX()
val cy = rectF.centerY() val cy = rectF.centerY()
// Draw background ring // Draw full background ring (always visible track)
canvas.drawArc(rectF, -90f, 360f, false, ringBgPaint) val bgRect = RectF(rectF.left, rectF.top, rectF.right, rectF.bottom)
// Draw progress ring (remaining time, starts at 12 o'clock) canvas.drawArc(bgRect, -90f, 360f, false, ringBgPaint)
// Draw progress arc on top (remaining time, starts at 12 o'clock)
canvas.drawArc(rectF, -90f, 360f * progressFraction, false, ringPaint) canvas.drawArc(rectF, -90f, 360f * progressFraction, false, ringPaint)
// Draw text // Draw text
@@ -11,7 +11,6 @@ import android.os.Vibrator
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.Button import android.widget.Button
import com.google.android.material.chip.ChipGroup
class CountdownDialog( class CountdownDialog(
private val context: Context, private val context: Context,
@@ -59,15 +58,17 @@ class CountdownDialog(
cvCountdown.setProgress(1f) cvCountdown.setProgress(1f)
timer = object : CountDownTimer(durationMillis, 1000) { timer = object : CountDownTimer(durationMillis, 1000) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
val secondsLeft = (millisUntilFinished / 1000).toInt() + 1
val progress = millisUntilFinished.toFloat() / durationMillis val progress = millisUntilFinished.toFloat() / durationMillis
if (secondsLeft < 10) {
cvCountdown.setText(secondsLeft.toString())
} else {
cvCountdown.setText(context.getString(R.string.countdown_text))
}
cvCountdown.setProgress(progress) cvCountdown.setProgress(progress)
if (secondsLeft in 1..3) {
if (millisUntilFinished >= durationMillis) {
cvCountdown.setText(context.getString(R.string.countdown_text))
} else {
val secondsLeft = (millisUntilFinished / 1000).toInt() + 1
cvCountdown.setText(secondsLeft.toString())
}
if (millisUntilFinished <= 3000 && millisUntilFinished > 1000) {
playTone(ToneGenerator.TONE_PROP_BEEP) playTone(ToneGenerator.TONE_PROP_BEEP)
if (prefs.getBoolean("vibration", true)) { if (prefs.getBoolean("vibration", true)) {
vibrator?.vibrate(50) vibrator?.vibrate(50)
@@ -23,6 +23,25 @@ class MainActivity : AppCompatActivity() {
private lateinit var chipGroup: ChipGroup private lateinit var chipGroup: ChipGroup
private var selectedDuration: Long = DEFAULT_DURATION private var selectedDuration: Long = DEFAULT_DURATION
private fun durationToChipId(duration: Long): Int = when (duration) {
5000L -> R.id.chip5s
15000L -> R.id.chip15s
30000L -> R.id.chip30s
else -> R.id.chip10s
}
private fun chipIdToDuration(chipId: Int): Long = when (chipId) {
R.id.chip5s -> 5000L
R.id.chip10s -> 10000L
R.id.chip15s -> 15000L
R.id.chip30s -> 30000L
else -> DEFAULT_DURATION
}
private fun updateDurationLabel() {
btnDurationLabel.text = "${selectedDuration / 1000}s"
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
@@ -34,13 +53,10 @@ class MainActivity : AppCompatActivity() {
hsvDurationOptions = findViewById(R.id.hsvDurationOptions) hsvDurationOptions = findViewById(R.id.hsvDurationOptions)
chipGroup = findViewById(R.id.chipGroup) chipGroup = findViewById(R.id.chipGroup)
updateDurationLabel()
// Restore selected chip // Restore selected chip
val chipId = when (selectedDuration) { val chipId = durationToChipId(selectedDuration)
5000L -> R.id.chip5s
15000L -> R.id.chip15s
30000L -> R.id.chip30s
else -> R.id.chip10s
}
chipGroup.check(chipId) chipGroup.check(chipId)
btnDurationLabel.setOnClickListener { btnDurationLabel.setOnClickListener {
@@ -58,16 +74,10 @@ class MainActivity : AppCompatActivity() {
chipGroup.setOnCheckedChangeListener { _, checkedId -> chipGroup.setOnCheckedChangeListener { _, checkedId ->
if (checkedId != -1) { if (checkedId != -1) {
selectedDuration = when (checkedId) { selectedDuration = chipIdToDuration(checkedId)
R.id.chip5s -> 5000L
R.id.chip10s -> 10000L
R.id.chip15s -> 15000L
R.id.chip30s -> 30000L
else -> DEFAULT_DURATION
}
prefs.edit().putLong(KEY_SELECTED_DURATION, selectedDuration).apply() prefs.edit().putLong(KEY_SELECTED_DURATION, selectedDuration).apply()
updateDurationLabel()
hsvDurationOptions.visibility = View.GONE hsvDurationOptions.visibility = View.GONE
chipGroup.clearCheck()
} }
} }