initial works with ugly design

This commit is contained in:
pi
2025-10-29 01:36:17 +01:00
commit 4b4405a601
28 changed files with 766 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package com.example.hairdryer
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.hairdryer", appContext.packageName)
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hairdryer">
<application
android:label="Hairdryer/Dunstabzugshaube"
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@android:style/Theme.Light.NoTitleBar">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,57 @@
package com.example.hairdryer
import android.app.Activity
import android.media.AudioAttributes
import android.media.SoundPool
import android.os.Bundle
import android.os.Handler
import android.widget.Button
import android.widget.EditText
class MainActivity : Activity() {
private lateinit var soundPool: SoundPool
private var soundId = 0
private var streamId = 0
private val handler = Handler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val input = findViewById<EditText>(R.id.timerInput)
val btn = findViewById<Button>(R.id.startBtn)
val attrs = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build()
soundPool = SoundPool.Builder()
.setMaxStreams(1)
.setAudioAttributes(attrs)
.build()
soundId = soundPool.load(this, R.raw.sound, 1)
btn.setOnClickListener {
val min = input.text.toString().toIntOrNull() ?: 0
startLoopingSound(min)
}
}
private fun startLoopingSound(minutes: Int) {
// Starte Sound in Schleife
streamId = soundPool.play(soundId, 1f, 1f, 1, -1, 1f) // -1 = loop unendlich
if (minutes > 0) {
handler.postDelayed({
soundPool.stop(streamId)
}, minutes * 60_000L)
}
}
override fun onDestroy() {
super.onDestroy()
soundPool.release()
}
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/timerInput"
android:hint="Sleep Timer (Minuten)"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/startBtn"
android:text="Start"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Binary file not shown.

View File

@@ -0,0 +1,3 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.AppCompat.Light.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>

View File

@@ -0,0 +1,17 @@
package com.example.hairdryer
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}