Qwen suggestions #1

Merged
kfj001 merged 3 commits from qwen_suggestions into main 2026-05-26 02:32:50 -07:00
3 changed files with 40 additions and 47 deletions
Showing only changes of commit 43bb282e74 - Show all commits
@@ -1,6 +1,5 @@
package com.example.countdowntimer
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
@@ -8,7 +7,6 @@ import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
class CountdownCanvasView @JvmOverloads constructor(
context: Context,
@@ -25,24 +23,16 @@ class CountdownCanvasView @JvmOverloads constructor(
isFakeBoldText = false
}
private val ringPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.parseColor("#D0BCFF")
color = Color.parseColor("#6750A4")
style = Paint.Style.STROKE
strokeWidth = 16f
}
private val ringBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.parseColor("#E8DEF8")
color = Color.parseColor("#D0BCFF")
style = Paint.Style.STROKE
strokeWidth = 16f
}
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) {
if (textToDraw != text) {
@@ -52,19 +42,10 @@ class CountdownCanvasView @JvmOverloads constructor(
}
fun setProgress(fraction: Float) {
progressFraction = fraction
progressFraction = fraction.coerceIn(0f, 1f)
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) {
super.onSizeChanged(w, h, oldw, oldh)
val inset = ringPaint.strokeWidth / 2f + 12f
@@ -79,9 +60,10 @@ class CountdownCanvasView @JvmOverloads constructor(
val cx = rectF.centerX()
val cy = rectF.centerY()
// Draw background ring
canvas.drawArc(rectF, -90f, 360f, false, ringBgPaint)
// Draw progress ring (remaining time, starts at 12 o'clock)
// Draw full background ring (always visible track)
val bgRect = RectF(rectF.left, rectF.top, rectF.right, rectF.bottom)
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)
// Draw text
@@ -11,7 +11,6 @@ import android.os.Vibrator
import android.view.View
import android.view.WindowManager
import android.widget.Button
import com.google.android.material.chip.ChipGroup
class CountdownDialog(
private val context: Context,
@@ -59,15 +58,17 @@ class CountdownDialog(
cvCountdown.setProgress(1f)
timer = object : CountDownTimer(durationMillis, 1000) {
override fun onTick(millisUntilFinished: Long) {
val secondsLeft = (millisUntilFinished / 1000).toInt() + 1
val progress = millisUntilFinished.toFloat() / durationMillis
if (secondsLeft < 10) {
cvCountdown.setText(secondsLeft.toString())
} else {
cvCountdown.setText(context.getString(R.string.countdown_text))
}
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)
if (prefs.getBoolean("vibration", true)) {
vibrator?.vibrate(50)
@@ -23,6 +23,25 @@ class MainActivity : AppCompatActivity() {
private lateinit var chipGroup: ChipGroup
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?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@@ -34,13 +53,10 @@ class MainActivity : AppCompatActivity() {
hsvDurationOptions = findViewById(R.id.hsvDurationOptions)
chipGroup = findViewById(R.id.chipGroup)
updateDurationLabel()
// Restore selected chip
val chipId = when (selectedDuration) {
5000L -> R.id.chip5s
15000L -> R.id.chip15s
30000L -> R.id.chip30s
else -> R.id.chip10s
}
val chipId = durationToChipId(selectedDuration)
chipGroup.check(chipId)
btnDurationLabel.setOnClickListener {
@@ -58,16 +74,10 @@ class MainActivity : AppCompatActivity() {
chipGroup.setOnCheckedChangeListener { _, checkedId ->
if (checkedId != -1) {
selectedDuration = when (checkedId) {
R.id.chip5s -> 5000L
R.id.chip10s -> 10000L
R.id.chip15s -> 15000L
R.id.chip30s -> 30000L
else -> DEFAULT_DURATION
}
selectedDuration = chipIdToDuration(checkedId)
prefs.edit().putLong(KEY_SELECTED_DURATION, selectedDuration).apply()
updateDurationLabel()
hsvDurationOptions.visibility = View.GONE
chipGroup.clearCheck()
}
}