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