Compare commits
2 Commits
f70a7444a6
...
1ac060d19a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ac060d19a | |||
| 8273fe2bbc |
@ -5,11 +5,11 @@ import android.os.VibrationEffect
|
|||||||
import android.os.Vibrator
|
import android.os.Vibrator
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.material.Button
|
import androidx.compose.material.Button
|
||||||
import androidx.compose.material.ButtonDefaults
|
import androidx.compose.material.ButtonDefaults
|
||||||
@ -24,10 +24,11 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.luminance
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import de.luh.hci.mi.vibrationpattern.ui.theme.VibrationPatternTheme
|
import de.luh.hci.mi.vibrationpattern.ui.theme.VibrationPatternTheme
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private lateinit var vibrator: Vibrator
|
private lateinit var vibrator: Vibrator
|
||||||
@ -43,7 +44,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun View() {
|
fun View() {
|
||||||
var isVibrating by remember { mutableStateOf(false)}
|
var isVibrating by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
VibrationPatternTheme {
|
VibrationPatternTheme {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@ -55,36 +57,73 @@ class MainActivity : ComponentActivity() {
|
|||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
Text(text = "Select vibration pattern")
|
Text(text = "Select vibration pattern")
|
||||||
if (vibrator.hasVibrator()){
|
val vibrationSupport =
|
||||||
Text(text = "✅ Supports vibration")
|
if (vibrator.hasVibrator()) "✅ Supports vibration" else "❌ Vibration not supported"
|
||||||
} else {
|
val amplitudeSupport =
|
||||||
Text(text = "❌ Vibration not supported")
|
if (vibrator.hasAmplitudeControl()) "✅ Supports amplitude control" else "❌ Amplitude control not supported"
|
||||||
}
|
Text(text = vibrationSupport, fontSize = 12.sp)
|
||||||
if (vibrator.hasAmplitudeControl()){
|
Text(text = amplitudeSupport, fontSize = 12.sp)
|
||||||
Text(text = "✅ Supports amplitude control")
|
Spacer(modifier = Modifier.height(50.dp))
|
||||||
} else {
|
|
||||||
Text(text = "❌ Amplitude control not supported")
|
|
||||||
}
|
Column(
|
||||||
Button(
|
modifier = Modifier.fillMaxWidth(0.5f)
|
||||||
onClick = { vibrator.vibrate(HEART); isVibrating = true },
|
|
||||||
) {
|
) {
|
||||||
Text("Heartbeat")
|
Button(
|
||||||
}
|
onClick = { vibrator.vibrate(HEART); isVibrating = true },
|
||||||
Button(
|
modifier = Modifier.fillMaxWidth()
|
||||||
onClick = { vibrator.vibrate(SOS); isVibrating = true },
|
) {
|
||||||
) {
|
Text("Heartbeat")
|
||||||
Text("SOS")
|
}
|
||||||
}
|
Button(
|
||||||
Button(
|
onClick = { vibrator.vibrate(SOS); isVibrating = true },
|
||||||
onClick = { vibrator.vibrate(WALTZ); isVibrating = true },
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text("Waltz")
|
Text("SOS")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = { vibrator.vibrate(WALTZ); isVibrating = true },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text("Waltz")
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
vibrator.vibrate(
|
||||||
|
VibrationEffect.createWaveform(
|
||||||
|
LongArray(Random.Default.nextInt(2,10)){
|
||||||
|
Random.Default.nextLong(100, 2000)},
|
||||||
|
1))
|
||||||
|
isVibrating = true
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text("Random")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = { vibrator.vibrate(ANGRY); isVibrating = true },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text("Angry")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = { vibrator.vibrate(CHILL); isVibrating = true },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text("Chill")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(50.dp))
|
Spacer(modifier = Modifier.height(50.dp))
|
||||||
Button(
|
Button(
|
||||||
enabled = isVibrating,
|
enabled = isVibrating,
|
||||||
onClick = { vibrator.cancel(); isVibrating = false },
|
onClick = { vibrator.cancel(); isVibrating = false },
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red, contentColor = Color.White)
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
backgroundColor = Color.Red,
|
||||||
|
contentColor = Color.White
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
Text("Stop")
|
Text("Stop")
|
||||||
}
|
}
|
||||||
@ -97,7 +136,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
companion object {
|
companion object {
|
||||||
private val HEART = VibrationEffect.createWaveform(
|
private val HEART = VibrationEffect.createWaveform(
|
||||||
longArrayOf(
|
longArrayOf(
|
||||||
0, 65, 297, 44, 552 // wait 0ms, vibrate 65 ms, pause 297 ms, vibrate 44 ms, pause 552 ms
|
0,
|
||||||
|
65,
|
||||||
|
297,
|
||||||
|
44,
|
||||||
|
552 // wait 0ms, vibrate 65 ms, pause 297 ms, vibrate 44 ms, pause 552 ms
|
||||||
), 1
|
), 1
|
||||||
)
|
)
|
||||||
private val SOS = VibrationEffect.createWaveform(
|
private val SOS = VibrationEffect.createWaveform(
|
||||||
@ -113,6 +156,16 @@ class MainActivity : ComponentActivity() {
|
|||||||
0, 100, 200, 70, 230, 70, 230
|
0, 100, 200, 70, 230, 70, 230
|
||||||
), 1
|
), 1
|
||||||
)
|
)
|
||||||
|
private val ANGRY = VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(
|
||||||
|
0, 500, 100
|
||||||
|
), 1
|
||||||
|
)
|
||||||
|
private val CHILL = VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(
|
||||||
|
0, 100, 50, 150, 1600
|
||||||
|
), 1
|
||||||
|
)
|
||||||
private val vibes = arrayOf(HEART, SOS, WALTZ)
|
private val vibes = arrayOf(HEART, SOS, WALTZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user