added colors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.example.hairdryer
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.media.AudioAttributes
|
||||
import android.media.SoundPool
|
||||
import android.os.Bundle
|
||||
@@ -39,6 +40,12 @@ class MainActivity : Activity() {
|
||||
|
||||
soundId = soundPool.load(this, R.raw.sound, 1)
|
||||
|
||||
// Initial: Start-Zustand (grün)
|
||||
btn.setBackgroundColor(Color.GREEN)
|
||||
btn.setTextColor(Color.BLACK)
|
||||
status.setBackgroundColor(Color.LTGRAY)
|
||||
status.setTextColor(Color.BLACK)
|
||||
|
||||
btn.setOnClickListener {
|
||||
if (isPlaying) {
|
||||
stopSound(btn, status)
|
||||
@@ -51,18 +58,22 @@ class MainActivity : Activity() {
|
||||
|
||||
private fun startSound(minutes: Int, btn: Button, status: TextView) {
|
||||
stopSound(btn, status) // sicherstellen, dass nichts doppelt läuft
|
||||
streamId = soundPool.play(soundId, 1f, 1f, 1, -1, 1f) // -1 = loop unendlich
|
||||
streamId = soundPool.play(soundId, 1f, 1f, 1, -1, 1f)
|
||||
isPlaying = true
|
||||
btn.text = "Stop"
|
||||
btn.setBackgroundColor(Color.RED)
|
||||
btn.setTextColor(Color.BLACK)
|
||||
|
||||
status.setBackgroundColor(Color.GREEN)
|
||||
status.text = if (minutes > 0) "Läuft: ${minutes} min" else "Läuft: ∞"
|
||||
|
||||
if (minutes > 0) {
|
||||
remainingMinutes = minutes
|
||||
updateStatus(status)
|
||||
countdownRunnable = object : Runnable {
|
||||
override fun run() {
|
||||
remainingMinutes--
|
||||
if (remainingMinutes > 0) {
|
||||
updateStatus(status)
|
||||
status.text = "Läuft: ${remainingMinutes} min"
|
||||
handler.postDelayed(this, 60_000L)
|
||||
} else {
|
||||
stopSound(btn, status)
|
||||
@@ -70,8 +81,6 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
handler.postDelayed(countdownRunnable!!, 60_000L)
|
||||
} else {
|
||||
status.text = "Läuft: ∞"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,15 +88,16 @@ class MainActivity : Activity() {
|
||||
if (isPlaying) {
|
||||
soundPool.stop(streamId)
|
||||
isPlaying = false
|
||||
}
|
||||
remainingMinutes = 0
|
||||
handler.removeCallbacks(countdownRunnable ?: Runnable { })
|
||||
status.text = "Gestoppt"
|
||||
btn.text = "Start"
|
||||
}
|
||||
}
|
||||
status.setBackgroundColor(Color.RED)
|
||||
status.setTextColor(Color.BLACK)
|
||||
|
||||
private fun updateStatus(status: TextView) {
|
||||
status.text = "Läuft: ${remainingMinutes} min"
|
||||
btn.text = "Start"
|
||||
btn.setBackgroundColor(Color.GREEN)
|
||||
btn.setTextColor(Color.BLACK)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/parentDeviceTitle"
|
||||
android:gravity="center_horizontal"
|
||||
@@ -17,14 +18,24 @@
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp" />
|
||||
<View
|
||||
android:id="@+id/statusCircle"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/circle_gray" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statusText"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="Bereit"
|
||||
android:textSize="24sp"
|
||||
android:textColor="#000000"
|
||||
android:padding="12dp"
|
||||
android:background="#CCCCCC"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Info"
|
||||
@@ -50,7 +61,12 @@
|
||||
<Button
|
||||
android:id="@+id/mainBtn"
|
||||
android:text="Start"
|
||||
android:textColor="#000000"
|
||||
android:background="#00FF00"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"/>
|
||||
android:layout_marginTop="10dp"
|
||||
android:textSize="34sp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user