initial works with ugly design
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
21
app/src/main/AndroidManifest.xml
Normal file
21
app/src/main/AndroidManifest.xml
Normal 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>
|
||||
57
app/src/main/java/com/example/hairdryer/MainActivity.kt
Normal file
57
app/src/main/java/com/example/hairdryer/MainActivity.kt
Normal 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()
|
||||
}
|
||||
}
|
||||
22
app/src/main/res/layout/activity_main.xml
Normal file
22
app/src/main/res/layout/activity_main.xml
Normal 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>
|
||||
BIN
app/src/main/res/raw/sound.mp3
Normal file
BIN
app/src/main/res/raw/sound.mp3
Normal file
Binary file not shown.
3
app/src/main/res/values/styles.xml
Normal file
3
app/src/main/res/values/styles.xml
Normal 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>
|
||||
17
app/src/test/java/com/example/hairdryer/ExampleUnitTest.kt
Normal file
17
app/src/test/java/com/example/hairdryer/ExampleUnitTest.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user