also looking at this
feat(android): haptic and vibrate — ratchet 91 -> 89
#150
7 files
+410
-3
| @@ -696,6 +696,30 @@ pub const Jni = struct { | ||
| 696 | 696 | return value; |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | // --- Arrays ----------------------------------------------------------- | |
| 700 | // | |
| 701 | // Only `long[]` so far, because only `VibrationEffect.createWaveform` | |
| 702 | // needs one. `SetLongArrayRegion` copies from a Zig slice in one call | |
| 703 | // rather than element by element, which is both faster and the only form | |
| 704 | // that cannot leave a partially-filled array behind on an error. | |
| 705 | ||
| 706 | pub fn newLongArray(self: Self, values: []const jlong) JniError!jobject { | |
| 707 | const new: *const fn (JNIEnv, jsize) callconv(.c) jobject = | |
| 708 | @ptrCast(self.table().NewLongArray orelse return JniError.NotFound); | |
| 709 | const array = new(self.env, @intCast(values.len)) orelse { | |
| 710 | try self.check(); | |
| 711 | return JniError.OutOfMemory; | |
| 712 | }; | |
| 713 | ||
| 714 | if (values.len == 0) return array; | |
| 715 | ||
| 716 | const set: *const fn (JNIEnv, jobject, jsize, jsize, [*]const jlong) callconv(.c) void = | |
| 717 | @ptrCast(self.table().SetLongArrayRegion orelse return JniError.NotFound); | |
| 718 | set(self.env, array, 0, @intCast(values.len), values.ptr); | |
| 719 | try self.check(); | |
| 720 | return array; | |
| 721 | } | |
| 722 | ||
| 699 | 723 | /// Make a Java `String` from UTF-8. |
| 700 | 724 | /// |
| 701 | 725 | /// The JVM wants *modified* UTF-8 here, the same encoding `stringToUtf8` |