Separate `InputEventJava` into `Key`/`Motion` `Java` structs to `Deref` into (and provide methods on) their native variants
Currently InputEventJava doesn't have any available methods, can we modify it to an enumeration?
pub enum InputEventJava {
MotionEvent(MotionEventJava),
KeyEvent(KeyEventJava)
}
pub struct MotionEventJava(MotionEvent);
impl Deref for MotionEventJava {
type Target = MotionEvent;
fn deref(&self) -> &Self::Target {
todo!()
}
}
impl Drop for MotionEventJava {
fn drop(&mut self) {
todo!()
}
}
pub struct KeyEventJava(KeyEvent);
impl Deref for KeyEventJava {
type Target = KeyEvent;
fn deref(&self) -> &Self::Target {
todo!()
}
}
impl Drop for KeyEventJava {
fn drop(&mut self) {
todo!()
}
}
Good point, I didn't initially understand your request to use an enum here since that won't be changing/solving anything, but instead you need MotionEvent::from_java() and KeyEvent::from_java() to return two independent structures that Deref into the respective native wrapper to be able to call those methods on them.
I can do that.
Good point, I didn't initially understand your request to use an
enumhere since that won't be changing/solving anything, but instead you needMotionEvent::from_java()andKeyEvent::from_java()to return two independent structures thatDerefinto the respective native wrapper to be able to call those methods on them.I can do that.
Can we add an unchecked version, in most of my project usage motion_event/key_event is always from java, and is unlikely to be null, giving the user the freedom to choose if they want to check for null pointers or not, and taking into account the fact that the from_java method has already been flagged as unsafe
pub unsafe fn from_java_unchecked(env: *mut JNIEnv, key_event: jobject) -> MotionEventJava {
let ptr = unsafe { ffi::AMotionEvent_fromJava(env, key_event) };
MotionEventJava(Self::from_ptr(NonNull::new_unchecked(
ptr.cast_mut(),
)?))
}