2026-01-28 15:26:41 +01:00
|
|
|
package no.naiv.tiltshift.util
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.os.VibrationEffect
|
|
|
|
|
import android.os.VibratorManager
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides haptic feedback for user interactions.
|
|
|
|
|
*/
|
|
|
|
|
class HapticFeedback(private val context: Context) {
|
|
|
|
|
|
2026-02-27 15:25:16 +01:00
|
|
|
private val vibrator by lazy {
|
|
|
|
|
val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
|
|
|
|
vibratorManager.defaultVibrator
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Light tick for UI feedback (button press, slider change).
|
|
|
|
|
*/
|
|
|
|
|
fun tick() {
|
2026-02-27 15:25:16 +01:00
|
|
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Click feedback for confirmations.
|
|
|
|
|
*/
|
|
|
|
|
fun click() {
|
2026-02-27 15:25:16 +01:00
|
|
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK))
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Heavy click for important actions (photo capture).
|
|
|
|
|
*/
|
|
|
|
|
fun heavyClick() {
|
2026-02-27 15:25:16 +01:00
|
|
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK))
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Success feedback pattern.
|
|
|
|
|
*/
|
|
|
|
|
fun success() {
|
2026-02-27 15:25:16 +01:00
|
|
|
val timings = longArrayOf(0, 30, 50, 30)
|
|
|
|
|
val amplitudes = intArrayOf(0, 100, 0, 200)
|
|
|
|
|
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Error feedback pattern.
|
|
|
|
|
*/
|
|
|
|
|
fun error() {
|
2026-02-27 15:25:16 +01:00
|
|
|
val timings = longArrayOf(0, 50, 30, 50, 30, 50)
|
|
|
|
|
val amplitudes = intArrayOf(0, 150, 0, 150, 0, 150)
|
|
|
|
|
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|