also looking at this
feat(android): haptic and vibrate — ratchet 91 -> 89
#150
7 files
+410
-3
| @@ -70,6 +70,8 @@ object CraftNative { | ||
| 70 | 70 | private external fun nativeSecureGet(prefs: SharedPreferences, key: String): String? |
| 71 | 71 | private external fun nativeSecureRemove(prefs: SharedPreferences, key: String): Boolean |
| 72 | 72 | 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 | |
| 73 | 75 | |
| 74 | 76 | /** |
| 75 | 77 | * `getDeviceInfo`, or null to use the Kotlin implementation. |
| @@ -249,4 +251,31 @@ object CraftNative { | ||
| 249 | 251 | false |
| 250 | 252 | } |
| 251 | 253 | } |
| 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 | } | |
| 252 | 281 | } |