📳 Haptics
Unified haptic feedback manager for all Android versions
Overview
The Haptics module provides a simple, unified API for haptic feedback (vibrations) across all Android versions. It handles the complexity of different APIs and provides predefined patterns for common use cases.
Basic Usage
// Simple vibration
ADict.Haptics.vibrate(100) // 100ms
// With intensity
ADict.Haptics.vibrate(200, Haptics.Intensity.STRONG)
// Predefined feedback
ADict.Haptics.click()
ADict.Haptics.success()
ADict.Haptics.error()
ADict.Haptics.warning()
Predefined Patterns
| Method | Description | Use Case |
|---|---|---|
click() |
Light click feedback | Button taps |
doubleClick() |
Double tap feedback | Double tap actions |
tick() |
Very light tick | Scrolling, selections |
success() |
Success pattern | Completed actions |
error() |
Error pattern | Failed actions |
warning() |
Warning pattern | Alerts, warnings |
notification() |
Notification pattern | New notifications |
heartbeat() |
Heartbeat pattern | Timers, countdowns |
longPress() |
Long press feedback | Long press actions |
View Extensions
import rip.nerd.adictlibrary.modules.setOnClickWithHaptic
import rip.nerd.adictlibrary.modules.hapticClick
// Extension function for click with haptic
button.setOnClickWithHaptic {
doSomething()
}
// Manual haptic on view
button.setOnClickListener { view ->
view.hapticClick()
doSomething()
}
// Long press with haptic
button.setOnLongClickWithHaptic {
doLongPressAction()
true
}
Custom Patterns
// Custom vibration pattern
// timings: [delay, vibrate, pause, vibrate, ...]
ADict.Haptics.pattern(
timings = longArrayOf(0, 100, 50, 100, 50, 200),
amplitudes = intArrayOf(0, 150, 0, 200, 0, 255) // API 26+
)
// Play predefined pattern enum
ADict.Haptics.play(Haptics.Pattern.HEARTBEAT)
System Effects (API 29+)
// Use system predefined effects for best quality
ADict.Haptics.systemClick()
ADict.Haptics.systemDoubleClick()
ADict.Haptics.systemHeavyClick()
ADict.Haptics.systemTick()
Configuration
// Configure global settings
ADict.Haptics.configure(
enabled = true,
defaultIntensity = Haptics.Intensity.MEDIUM
)
// Enable/disable haptics
ADict.Haptics.setEnabled(false)
// Check if available
if (ADict.Haptics.isAvailable()) {
ADict.Haptics.click()
}
Intensity Levels
| Level | Amplitude | Description |
|---|---|---|
LIGHT |
50 | Subtle feedback |
MEDIUM |
128 | Standard feedback (default) |
STRONG |
255 | Strong feedback |
Integration with Other Modules
// With Achievements
ADict.Achievements.unlock("first_win") { achievement ->
ADict.Haptics.success()
showAchievementPopup(achievement)
}
// With Timer
ADict.Timer.countdown("game", 10_000) {
onTick = { remaining ->
if (remaining <= 3000) {
ADict.Haptics.tick()
}
}
onFinish = {
ADict.Haptics.notification()
}
}
// With ReviewTrap
ADict.ReviewTrap.prompt(activity) { event ->
when (event) {
is ReviewTrap.Event.LikedYes -> ADict.Haptics.success()
is ReviewTrap.Event.DislikedNo -> ADict.Haptics.error()
}
}