62 lines
2.0 KiB
Kotlin
62 lines
2.0 KiB
Kotlin
package com.example.timert
|
||
|
||
import android.app.AlertDialog
|
||
import android.content.Intent
|
||
import android.media.Image
|
||
import android.os.Bundle
|
||
import android.widget.Button
|
||
import android.widget.ImageButton
|
||
import androidx.activity.enableEdgeToEdge
|
||
import androidx.appcompat.app.AppCompatActivity
|
||
import androidx.core.view.ViewCompat
|
||
import androidx.core.view.WindowInsetsCompat
|
||
|
||
class timer : AppCompatActivity() {
|
||
private var isPlay = false
|
||
override fun onCreate(savedInstanceState: Bundle?) {
|
||
super.onCreate(savedInstanceState)
|
||
enableEdgeToEdge()
|
||
setContentView(R.layout.activity_timer)
|
||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||
insets
|
||
}
|
||
val button: ImageButton = findViewById(R.id.stop)
|
||
button.setOnClickListener {
|
||
AlertDialog.Builder(this)
|
||
.setTitle("Сброс таймера")
|
||
.setMessage("Закрыть таймер и перейти на главную страницу?")
|
||
.setPositiveButton("Да") { _, _ ->
|
||
|
||
val intent = Intent(this, MainActivity::class.java)
|
||
startActivity(intent)
|
||
}
|
||
.setNegativeButton("Нет") { dialog, _ ->
|
||
dialog.dismiss()
|
||
}
|
||
.show()
|
||
}
|
||
|
||
|
||
|
||
val pauseButton: ImageButton = findViewById(R.id.play)
|
||
|
||
pauseButton.setOnClickListener {
|
||
if (isPlay) {
|
||
|
||
pauseButton.setImageResource(R.drawable.icon_play)
|
||
// здесь ещё можно возобновить таймер
|
||
} else {
|
||
|
||
pauseButton.setImageResource(R.drawable.icon_pause)
|
||
// здесь можно остановить таймер
|
||
}
|
||
isPlay = !isPlay
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
} |