ReviewOS

also looking at this

craft-native/craft

feat(android): haptic and vibrate — ratchet 91 -> 89

#150
Merged chris wants to merge feat/android-haptics into main
7 files +410 -3
packages/android/templates/CraftNative.kt.templatemodified+29-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -70,6 +70,8 @@ object CraftNative {
7070 private external fun nativeSecureGet(prefs: SharedPreferences, key: String): String?
7171 private external fun nativeSecureRemove(prefs: SharedPreferences, key: String): Boolean
7272 private external fun nativeSecureClear(prefs: SharedPreferences): Boolean
73 private external fun nativeHaptic(activity: Activity, style: String): Boolean
74 private external fun nativeVibrate(activity: Activity, patternJson: String): Boolean
7375
7476 /**
7577 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -249,4 +251,31 @@ object CraftNative {
249251 false
250252 }
251253 }
254
255 /** Returns whether Zig played the haptic; false falls through. */
256 fun haptic(activity: Activity, style: String): Boolean {
257 if (!isAvailable) return false
258 return try {
259 nativeHaptic(activity, style)
260 } catch (e: UnsatisfiedLinkError) {
261 false
262 }
263 }
264
265 /**
266 * Returns whether Zig played the pattern.
267 *
268 * False also covers a pattern Zig could not parse — deliberately, so the
269 * Kotlin runs, throws the JSONException it would have thrown anyway, and
270 * writes its "Vibration error" line. Handling it here would reach the same
271 * silence and lose the log.
272 */
273 fun vibrate(activity: Activity, patternJson: String): Boolean {
274 if (!isAvailable) return false
275 return try {
276 nativeVibrate(activity, patternJson)
277 } catch (e: UnsatisfiedLinkError) {
278 false
279 }
280 }
252281}