Clock is also displayed
This commit is contained in:
parent
35e51c0510
commit
b1c41b2985
@ -9,8 +9,11 @@ import android.graphics.Paint
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.icu.util.GregorianCalendar
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -25,6 +28,18 @@ class MainActivity : AppCompatActivity() {
|
||||
private lateinit var myButton: Button
|
||||
private lateinit var mainLayout: ConstraintLayout
|
||||
private lateinit var canvasview: View
|
||||
private lateinit var tv: TextView
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
private val updateFiboClock = object : Runnable {
|
||||
override fun run() {
|
||||
csacsi(mainLayout, canvasview, tv)
|
||||
handler.postDelayed(this, 30000) // Schedule the next update in 30 seconds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@ -37,17 +52,27 @@ class MainActivity : AppCompatActivity() {
|
||||
myButton = findViewById(R.id.button)
|
||||
mainLayout = findViewById(R.id.main)
|
||||
canvasview = findViewById(R.id.view)
|
||||
tv = findViewById(R.id.textView)
|
||||
|
||||
myButton.setOnClickListener {
|
||||
csacsi(mainLayout, canvasview)
|
||||
csacsi(mainLayout, canvasview, tv)
|
||||
}
|
||||
handler.post(updateFiboClock)
|
||||
}
|
||||
private fun csacsi (m: ConstraintLayout, cv: View) {
|
||||
private fun csacsi (m: ConstraintLayout, cv: View, tv: TextView) {
|
||||
val colors = List(3) { Random.nextInt(0,255)}
|
||||
val color = Color.rgb(colors[0],colors[1],colors[2])
|
||||
val text = "${GregorianCalendar().get(GregorianCalendar.HOUR)}:${GregorianCalendar().get(GregorianCalendar.MINUTE)}"
|
||||
tv.text = text
|
||||
m.background= CustomDrawable(color, cv)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
// Remove callbacks to avoid memory leaks
|
||||
handler.removeCallbacks(updateFiboClock)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user