Struct MotionEvent

Source
pub struct MotionEvent { /* private fields */ }
Expand description

A motion event

Wraps an AInputEvent * of the ffi::AINPUT_EVENT_TYPE_MOTION type.

For general discussion of motion events in Android, see the relevant javadoc.

Implementations§

Source§

impl MotionEvent

Source

pub unsafe fn from_ptr(ptr: NonNull<AInputEvent>) -> Self

Constructs a MotionEvent from a pointer to a native ffi::AInputEvent

§Safety

By calling this method, you assert that the pointer is a valid, non-null pointer to a native ffi::AInputEvent and that ffi::AInputEvent is an AMotionEvent.

Source

pub unsafe fn from_java( env: *mut JNIEnv, key_event: jobject, ) -> Option<InputEventJava>

Available on crate feature api-level-31 only.

Creates a native InputEvent object that is a copy of the specified Java android.view.MotionEvent. The result may be used with generic and MotionEvent-specific functions.

§Safety

This function should be called with a healthy JVM pointer and with a non-null android.view.MotionEvent.

Source

pub fn ptr(&self) -> NonNull<AInputEvent>

Returns a pointer to the native ffi::AInputEvent.

Source

pub fn source(&self) -> Source

Get the source of the event.

See the NDK docs

Source

pub fn device_id(&self) -> i32

Get the device id associated with the event.

See the NDK docs

Source

pub fn action(&self) -> MotionAction

Returns the motion action associated with the event.

See the NDK docs

Source

pub fn pointer_index(&self) -> usize

Returns the pointer index of an Up or Down event.

Pointer indices can change per motion event. For an identifier that stays the same, see Pointer::pointer_id().

This only has a meaning when the action is one of Up, Down, PointerUp, or PointerDown.

Source

pub fn pointer_count(&self) -> usize

Returns the number of pointers in this event

See the NDK docs

Source

pub fn pointers(&self) -> PointersIter<'_>

An iterator over the pointers in this motion event

Source

pub fn pointer_at_index(&self, index: usize) -> Pointer<'_>

The pointer at a given pointer index. Panics if the pointer index is out of bounds.

If you need to loop over all the pointers, prefer the pointers() method.

Source

pub fn history_size(&self) -> usize

Returns the size of the history contained in this event.

See the NDK docs

Source

pub fn history(&self) -> HistoricalMotionEventsIter<'_>

An iterator over the historical events contained in this event.

Source

pub fn meta_state(&self) -> MetaState

Returns the state of any modifier keys that were pressed during the event.

See the NDK docs

Source

pub fn button_state(&self) -> ButtonState

Returns the button state during this event, as a bitfield.

See the NDK docs

Source

pub fn down_time(&self) -> i64

Returns the time of the start of this gesture, in the java.lang.System.nanoTime() time base

See the NDK docs

Source

pub fn edge_flags(&self) -> EdgeFlags

Returns a bitfield indicating which edges were touched by this event.

See the NDK docs

Source

pub fn event_time(&self) -> i64

Returns the time of this event, in the java.lang.System.nanoTime() time base

See the NDK docs

Source

pub fn flags(&self) -> MotionEventFlags

The flags associated with a motion event.

See the NDK docs

Source

pub fn x_offset(&self) -> f32

Returns the offset in the x direction between the coordinates and the raw coordinates

See the NDK docs

Source

pub fn y_offset(&self) -> f32

Returns the offset in the y direction between the coordinates and the raw coordinates

See the NDK docs

Source

pub fn x_precision(&self) -> f32

Returns the precision of the x value of the coordinates

See the NDK docs

Source

pub fn y_precision(&self) -> f32

Returns the precision of the y value of the coordinates

See the NDK docs

Trait Implementations§

Source§

impl Clone for MotionEvent

Source§

fn clone(&self) -> MotionEvent

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MotionEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.