android_activity/
input.rs

1use bitflags::bitflags;
2
3pub use crate::activity_impl::input::*;
4use crate::InputStatus;
5
6mod sdk;
7pub use sdk::*;
8
9/// An enum representing the source of an [`MotionEvent`] or [`KeyEvent`]
10///
11/// See [the InputDevice docs](https://developer.android.com/reference/android/view/InputDevice#SOURCE_ANY)
12///
13/// # Android Extensible Enum
14///
15/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
16/// should be handled similar to a `#[non_exhaustive]` enum to maintain
17/// forwards compatibility.
18///
19/// This implements `Into<u32>` and `From<u32>` for converting to/from Android
20/// SDK integer values.
21///
22#[derive(Debug, Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
23#[non_exhaustive]
24#[repr(u32)]
25pub enum Source {
26    BluetoothStylus = 0x0000c002,
27    Dpad = 0x00000201,
28    /// Either a gamepad or a joystick
29    Gamepad = 0x00000401,
30    Hdmi = 0x02000001,
31    /// Either a gamepad or a joystick
32    Joystick = 0x01000010,
33    /// Pretty much any device with buttons. Query the keyboard type to determine
34    /// if it has alphabetic keys and can be used for text entry.
35    Keyboard = 0x00000101,
36    /// A pointing device, such as a mouse or trackpad
37    Mouse = 0x00002002,
38    /// A pointing device, such as a mouse or trackpad whose relative motions should be treated as navigation events
39    MouseRelative = 0x00020004,
40    /// An input device akin to a scroll wheel
41    RotaryEncoder = 0x00400000,
42    Sensor = 0x04000000,
43    Stylus = 0x00004002,
44    Touchpad = 0x00100008,
45    Touchscreen = 0x00001002,
46    TouchNavigation = 0x00200000,
47    Trackball = 0x00010004,
48
49    // We need to consider that the enum variants may be extended across
50    // different versions of Android (i.e. effectively at runtime) but at the
51    // same time we don't want it to be an API break to extend this enum in
52    // future releases of `android-activity` with new variants from the latest
53    // NDK/SDK.
54    //
55    // We can't just use `#[non_exhaustive]` because that only really helps
56    // when adding new variants in sync with android-activity releases.
57    //
58    // On the other hand we also can't rely on a catch-all `Unknown(u32)` that
59    // only really helps with unknown variants seen at runtime.
60    //
61    // What we aim for instead is to have a hidden catch-all variant that
62    // is considered (practically) unmatchable so code is forced to have
63    // a `unknown => {}` catch-all pattern match that will cover unknown variants
64    // either in the form of Rust variants added in future versions or
65    // in the form of an `__Unknown(u32)` integer that represents an unknown
66    // variant seen at runtime.
67    //
68    // Any `unknown => {}` pattern match can rely on `IntoPrimitive` to convert
69    // the `unknown` variant to the integer that comes from the Android SDK
70    // in case that values needs to be passed on, even without knowing its
71    // semantic meaning at compile time.
72    #[doc(hidden)]
73    #[num_enum(catch_all)]
74    __Unknown(u32),
75}
76
77// ndk_sys doesn't currently have the `TRACKBALL` flag so we define our
78// own internal class constants for now
79bitflags! {
80    #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
81    struct SourceFlags: u32 {
82        const CLASS_MASK = 0x000000ff;
83
84        const BUTTON = 0x00000001;
85        const POINTER = 0x00000002;
86        const TRACKBALL = 0x00000004;
87        const POSITION = 0x00000008;
88        const JOYSTICK = 0x00000010;
89        const NONE = 0;
90    }
91}
92
93impl Source {
94    #[inline]
95    pub fn is_button_class(self) -> bool {
96        let class = SourceFlags::from_bits_truncate(self.into());
97        class.contains(SourceFlags::BUTTON)
98    }
99    #[inline]
100    pub fn is_pointer_class(self) -> bool {
101        let class = SourceFlags::from_bits_truncate(self.into());
102        class.contains(SourceFlags::POINTER)
103    }
104    #[inline]
105    pub fn is_trackball_class(self) -> bool {
106        let class = SourceFlags::from_bits_truncate(self.into());
107        class.contains(SourceFlags::TRACKBALL)
108    }
109    #[inline]
110    pub fn is_position_class(self) -> bool {
111        let class = SourceFlags::from_bits_truncate(self.into());
112        class.contains(SourceFlags::POSITION)
113    }
114    #[inline]
115    pub fn is_joystick_class(self) -> bool {
116        let class = SourceFlags::from_bits_truncate(self.into());
117        class.contains(SourceFlags::JOYSTICK)
118    }
119}
120
121/// A bitfield representing the state of modifier keys during an event.
122///
123/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-25)
124#[derive(Copy, Clone, Debug, PartialEq, Eq)]
125pub struct MetaState(pub u32);
126
127impl MetaState {
128    #[inline]
129    pub fn alt_on(self) -> bool {
130        self.0 & ndk_sys::AMETA_ALT_ON != 0
131    }
132    #[inline]
133    pub fn alt_left_on(self) -> bool {
134        self.0 & ndk_sys::AMETA_ALT_LEFT_ON != 0
135    }
136    #[inline]
137    pub fn alt_right_on(self) -> bool {
138        self.0 & ndk_sys::AMETA_ALT_RIGHT_ON != 0
139    }
140    #[inline]
141    pub fn shift_on(self) -> bool {
142        self.0 & ndk_sys::AMETA_SHIFT_ON != 0
143    }
144    #[inline]
145    pub fn shift_left_on(self) -> bool {
146        self.0 & ndk_sys::AMETA_SHIFT_LEFT_ON != 0
147    }
148    #[inline]
149    pub fn shift_right_on(self) -> bool {
150        self.0 & ndk_sys::AMETA_SHIFT_RIGHT_ON != 0
151    }
152    #[inline]
153    pub fn sym_on(self) -> bool {
154        self.0 & ndk_sys::AMETA_SYM_ON != 0
155    }
156    #[inline]
157    pub fn function_on(self) -> bool {
158        self.0 & ndk_sys::AMETA_FUNCTION_ON != 0
159    }
160    #[inline]
161    pub fn ctrl_on(self) -> bool {
162        self.0 & ndk_sys::AMETA_CTRL_ON != 0
163    }
164    #[inline]
165    pub fn ctrl_left_on(self) -> bool {
166        self.0 & ndk_sys::AMETA_CTRL_LEFT_ON != 0
167    }
168    #[inline]
169    pub fn ctrl_right_on(self) -> bool {
170        self.0 & ndk_sys::AMETA_CTRL_RIGHT_ON != 0
171    }
172    #[inline]
173    pub fn meta_on(self) -> bool {
174        self.0 & ndk_sys::AMETA_META_ON != 0
175    }
176    #[inline]
177    pub fn meta_left_on(self) -> bool {
178        self.0 & ndk_sys::AMETA_META_LEFT_ON != 0
179    }
180    #[inline]
181    pub fn meta_right_on(self) -> bool {
182        self.0 & ndk_sys::AMETA_META_RIGHT_ON != 0
183    }
184    #[inline]
185    pub fn caps_lock_on(self) -> bool {
186        self.0 & ndk_sys::AMETA_CAPS_LOCK_ON != 0
187    }
188    #[inline]
189    pub fn num_lock_on(self) -> bool {
190        self.0 & ndk_sys::AMETA_NUM_LOCK_ON != 0
191    }
192    #[inline]
193    pub fn scroll_lock_on(self) -> bool {
194        self.0 & ndk_sys::AMETA_SCROLL_LOCK_ON != 0
195    }
196}
197
198impl From<ndk::event::MetaState> for MetaState {
199    fn from(value: ndk::event::MetaState) -> Self {
200        Self(value.0)
201    }
202}
203
204/// A motion action.
205///
206/// See [the NDK
207/// docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-29)
208///
209/// # Android Extensible Enum
210///
211/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
212/// should be handled similar to a `#[non_exhaustive]` enum to maintain
213/// forwards compatibility.
214///
215/// This implements `Into<u32>` and `From<u32>` for converting to/from Android
216/// SDK integer values.
217///
218#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
219#[non_exhaustive]
220#[repr(u32)]
221pub enum MotionAction {
222    Down = ndk_sys::AMOTION_EVENT_ACTION_DOWN,
223    Up = ndk_sys::AMOTION_EVENT_ACTION_UP,
224    Move = ndk_sys::AMOTION_EVENT_ACTION_MOVE,
225    Cancel = ndk_sys::AMOTION_EVENT_ACTION_CANCEL,
226    Outside = ndk_sys::AMOTION_EVENT_ACTION_OUTSIDE,
227    PointerDown = ndk_sys::AMOTION_EVENT_ACTION_POINTER_DOWN,
228    PointerUp = ndk_sys::AMOTION_EVENT_ACTION_POINTER_UP,
229    HoverMove = ndk_sys::AMOTION_EVENT_ACTION_HOVER_MOVE,
230    Scroll = ndk_sys::AMOTION_EVENT_ACTION_SCROLL,
231    HoverEnter = ndk_sys::AMOTION_EVENT_ACTION_HOVER_ENTER,
232    HoverExit = ndk_sys::AMOTION_EVENT_ACTION_HOVER_EXIT,
233    ButtonPress = ndk_sys::AMOTION_EVENT_ACTION_BUTTON_PRESS,
234    ButtonRelease = ndk_sys::AMOTION_EVENT_ACTION_BUTTON_RELEASE,
235
236    #[doc(hidden)]
237    #[num_enum(catch_all)]
238    __Unknown(u32),
239}
240
241/// Identifies buttons that are associated with motion events.
242///
243/// See [the NDK
244/// docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-47)
245///
246/// # Android Extensible Enum
247///
248/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
249/// should be handled similar to a `#[non_exhaustive]` enum to maintain
250/// forwards compatibility.
251///
252/// This implements `Into<u32>` and `From<u32>` for converting to/from Android
253/// SDK integer values.
254///
255#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
256#[non_exhaustive]
257#[repr(u32)]
258pub enum Button {
259    Back = ndk_sys::AMOTION_EVENT_BUTTON_BACK,
260    Forward = ndk_sys::AMOTION_EVENT_BUTTON_FORWARD,
261    Primary = ndk_sys::AMOTION_EVENT_BUTTON_PRIMARY,
262    Secondary = ndk_sys::AMOTION_EVENT_BUTTON_SECONDARY,
263    StylusPrimary = ndk_sys::AMOTION_EVENT_BUTTON_STYLUS_PRIMARY,
264    StylusSecondary = ndk_sys::AMOTION_EVENT_BUTTON_STYLUS_SECONDARY,
265    Tertiary = ndk_sys::AMOTION_EVENT_BUTTON_TERTIARY,
266
267    #[doc(hidden)]
268    #[num_enum(catch_all)]
269    __Unknown(u32),
270}
271
272/// An axis of a motion event.
273///
274/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-32)
275///
276/// # Android Extensible Enum
277///
278/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
279/// should be handled similar to a `#[non_exhaustive]` enum to maintain
280/// forwards compatibility.
281///
282/// This implements `Into<u32>` and `From<u32>` for converting to/from Android
283/// SDK integer values.
284///
285#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
286#[non_exhaustive]
287#[repr(u32)]
288pub enum Axis {
289    X = ndk_sys::AMOTION_EVENT_AXIS_X,
290    Y = ndk_sys::AMOTION_EVENT_AXIS_Y,
291    Pressure = ndk_sys::AMOTION_EVENT_AXIS_PRESSURE,
292    Size = ndk_sys::AMOTION_EVENT_AXIS_SIZE,
293    TouchMajor = ndk_sys::AMOTION_EVENT_AXIS_TOUCH_MAJOR,
294    TouchMinor = ndk_sys::AMOTION_EVENT_AXIS_TOUCH_MINOR,
295    ToolMajor = ndk_sys::AMOTION_EVENT_AXIS_TOOL_MAJOR,
296    ToolMinor = ndk_sys::AMOTION_EVENT_AXIS_TOOL_MINOR,
297    Orientation = ndk_sys::AMOTION_EVENT_AXIS_ORIENTATION,
298    Vscroll = ndk_sys::AMOTION_EVENT_AXIS_VSCROLL,
299    Hscroll = ndk_sys::AMOTION_EVENT_AXIS_HSCROLL,
300    Z = ndk_sys::AMOTION_EVENT_AXIS_Z,
301    Rx = ndk_sys::AMOTION_EVENT_AXIS_RX,
302    Ry = ndk_sys::AMOTION_EVENT_AXIS_RY,
303    Rz = ndk_sys::AMOTION_EVENT_AXIS_RZ,
304    HatX = ndk_sys::AMOTION_EVENT_AXIS_HAT_X,
305    HatY = ndk_sys::AMOTION_EVENT_AXIS_HAT_Y,
306    Ltrigger = ndk_sys::AMOTION_EVENT_AXIS_LTRIGGER,
307    Rtrigger = ndk_sys::AMOTION_EVENT_AXIS_RTRIGGER,
308    Throttle = ndk_sys::AMOTION_EVENT_AXIS_THROTTLE,
309    Rudder = ndk_sys::AMOTION_EVENT_AXIS_RUDDER,
310    Wheel = ndk_sys::AMOTION_EVENT_AXIS_WHEEL,
311    Gas = ndk_sys::AMOTION_EVENT_AXIS_GAS,
312    Brake = ndk_sys::AMOTION_EVENT_AXIS_BRAKE,
313    Distance = ndk_sys::AMOTION_EVENT_AXIS_DISTANCE,
314    Tilt = ndk_sys::AMOTION_EVENT_AXIS_TILT,
315    Scroll = ndk_sys::AMOTION_EVENT_AXIS_SCROLL,
316    RelativeX = ndk_sys::AMOTION_EVENT_AXIS_RELATIVE_X,
317    RelativeY = ndk_sys::AMOTION_EVENT_AXIS_RELATIVE_Y,
318    Generic1 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_1,
319    Generic2 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_2,
320    Generic3 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_3,
321    Generic4 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_4,
322    Generic5 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_5,
323    Generic6 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_6,
324    Generic7 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_7,
325    Generic8 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_8,
326    Generic9 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_9,
327    Generic10 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_10,
328    Generic11 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_11,
329    Generic12 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_12,
330    Generic13 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_13,
331    Generic14 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_14,
332    Generic15 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_15,
333    Generic16 = ndk_sys::AMOTION_EVENT_AXIS_GENERIC_16,
334
335    #[doc(hidden)]
336    #[num_enum(catch_all)]
337    __Unknown(u32),
338}
339
340/// The tool type of a pointer.
341///
342/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-48)
343///
344/// # Android Extensible Enum
345///
346/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
347/// should be handled similar to a `#[non_exhaustive]` enum to maintain
348/// forwards compatibility.
349///
350/// Implements `Into<u32>` and `From<u32>` for converting to/from Android SDK
351/// integer values.
352///
353#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
354#[non_exhaustive]
355#[repr(u32)]
356pub enum ToolType {
357    /// Unknown tool type.
358    ///
359    /// This constant is used when the tool type is not known or is not relevant, such as for a trackball or other non-pointing device.
360    Unknown = ndk_sys::AMOTION_EVENT_TOOL_TYPE_UNKNOWN,
361
362    /// The tool is a finger.
363    Finger = ndk_sys::AMOTION_EVENT_TOOL_TYPE_FINGER,
364
365    /// The tool is a stylus.
366    Stylus = ndk_sys::AMOTION_EVENT_TOOL_TYPE_STYLUS,
367
368    ///  The tool is a mouse.
369    Mouse = ndk_sys::AMOTION_EVENT_TOOL_TYPE_MOUSE,
370
371    /// The tool is an eraser or a stylus being used in an inverted posture.
372    Eraser = ndk_sys::AMOTION_EVENT_TOOL_TYPE_ERASER,
373
374    /// The tool is a palm and should be rejected
375    Palm = ndk_sys::AMOTION_EVENT_TOOL_TYPE_PALM,
376
377    #[doc(hidden)]
378    #[num_enum(catch_all)]
379    __Unknown(u32),
380}
381
382/// A bitfield representing the state of buttons during a motion event.
383///
384/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-33)
385#[derive(Copy, Clone, Debug, PartialEq, Eq)]
386pub struct ButtonState(pub u32);
387
388impl ButtonState {
389    #[inline]
390    pub fn primary(self) -> bool {
391        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_PRIMARY != 0
392    }
393    #[inline]
394    pub fn secondary(self) -> bool {
395        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_SECONDARY != 0
396    }
397    #[inline]
398    pub fn teriary(self) -> bool {
399        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_TERTIARY != 0
400    }
401    #[inline]
402    pub fn back(self) -> bool {
403        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_BACK != 0
404    }
405    #[inline]
406    pub fn forward(self) -> bool {
407        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_FORWARD != 0
408    }
409    #[inline]
410    pub fn stylus_primary(self) -> bool {
411        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_STYLUS_PRIMARY != 0
412    }
413    #[inline]
414    pub fn stylus_secondary(self) -> bool {
415        self.0 & ndk_sys::AMOTION_EVENT_BUTTON_STYLUS_SECONDARY != 0
416    }
417}
418
419impl From<ndk::event::ButtonState> for ButtonState {
420    fn from(value: ndk::event::ButtonState) -> Self {
421        Self(value.0)
422    }
423}
424
425/// A bitfield representing which edges were touched by a motion event.
426///
427/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-31)
428#[derive(Copy, Clone, Debug, PartialEq, Eq)]
429pub struct EdgeFlags(pub u32);
430
431impl EdgeFlags {
432    #[inline]
433    pub fn top(self) -> bool {
434        self.0 & ndk_sys::AMOTION_EVENT_EDGE_FLAG_TOP != 0
435    }
436    #[inline]
437    pub fn bottom(self) -> bool {
438        self.0 & ndk_sys::AMOTION_EVENT_EDGE_FLAG_BOTTOM != 0
439    }
440    #[inline]
441    pub fn left(self) -> bool {
442        self.0 & ndk_sys::AMOTION_EVENT_EDGE_FLAG_LEFT != 0
443    }
444    #[inline]
445    pub fn right(self) -> bool {
446        self.0 & ndk_sys::AMOTION_EVENT_EDGE_FLAG_RIGHT != 0
447    }
448}
449
450impl From<ndk::event::EdgeFlags> for EdgeFlags {
451    fn from(value: ndk::event::EdgeFlags) -> Self {
452        Self(value.0)
453    }
454}
455
456/// Flags associated with this [`MotionEvent`].
457///
458/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-30)
459#[derive(Copy, Clone, Debug, PartialEq, Eq)]
460pub struct MotionEventFlags(pub u32);
461
462impl MotionEventFlags {
463    #[inline]
464    pub fn window_is_obscured(self) -> bool {
465        self.0 & ndk_sys::AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED != 0
466    }
467}
468
469impl From<ndk::event::MotionEventFlags> for MotionEventFlags {
470    fn from(value: ndk::event::MotionEventFlags) -> Self {
471        Self(value.0)
472    }
473}
474
475/// Key actions.
476///
477/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-27)
478///
479/// # Android Extensible Enum
480///
481/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
482/// should be handled similar to a `#[non_exhaustive]` enum to maintain
483/// forwards compatibility.
484///
485/// Implements `Into<u32>` and `From<u32>` for converting to/from Android SDK
486/// integer values.
487///
488#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
489#[non_exhaustive]
490#[repr(u32)]
491pub enum KeyAction {
492    Down = ndk_sys::AKEY_EVENT_ACTION_DOWN,
493    Up = ndk_sys::AKEY_EVENT_ACTION_UP,
494    Multiple = ndk_sys::AKEY_EVENT_ACTION_MULTIPLE,
495
496    #[doc(hidden)]
497    #[num_enum(catch_all)]
498    __Unknown(u32),
499}
500
501/// Key codes.
502///
503/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-39)
504///
505/// # Android Extensible Enum
506///
507/// This is a runtime [extensible enum](`crate#android-extensible-enums`) and
508/// should be handled similar to a `#[non_exhaustive]` enum to maintain
509/// forwards compatibility.
510///
511/// Implements `Into<u32>` and `From<u32>` for converting to/from Android SDK
512/// integer values.
513///
514#[derive(Copy, Clone, Debug, PartialEq, Eq, num_enum::FromPrimitive, num_enum::IntoPrimitive)]
515#[non_exhaustive]
516#[repr(u32)]
517pub enum Keycode {
518    Unknown = ndk_sys::AKEYCODE_UNKNOWN,
519    SoftLeft = ndk_sys::AKEYCODE_SOFT_LEFT,
520    SoftRight = ndk_sys::AKEYCODE_SOFT_RIGHT,
521    Home = ndk_sys::AKEYCODE_HOME,
522    Back = ndk_sys::AKEYCODE_BACK,
523    Call = ndk_sys::AKEYCODE_CALL,
524    Endcall = ndk_sys::AKEYCODE_ENDCALL,
525    Keycode0 = ndk_sys::AKEYCODE_0,
526    Keycode1 = ndk_sys::AKEYCODE_1,
527    Keycode2 = ndk_sys::AKEYCODE_2,
528    Keycode3 = ndk_sys::AKEYCODE_3,
529    Keycode4 = ndk_sys::AKEYCODE_4,
530    Keycode5 = ndk_sys::AKEYCODE_5,
531    Keycode6 = ndk_sys::AKEYCODE_6,
532    Keycode7 = ndk_sys::AKEYCODE_7,
533    Keycode8 = ndk_sys::AKEYCODE_8,
534    Keycode9 = ndk_sys::AKEYCODE_9,
535    Star = ndk_sys::AKEYCODE_STAR,
536    Pound = ndk_sys::AKEYCODE_POUND,
537    DpadUp = ndk_sys::AKEYCODE_DPAD_UP,
538    DpadDown = ndk_sys::AKEYCODE_DPAD_DOWN,
539    DpadLeft = ndk_sys::AKEYCODE_DPAD_LEFT,
540    DpadRight = ndk_sys::AKEYCODE_DPAD_RIGHT,
541    DpadCenter = ndk_sys::AKEYCODE_DPAD_CENTER,
542    VolumeUp = ndk_sys::AKEYCODE_VOLUME_UP,
543    VolumeDown = ndk_sys::AKEYCODE_VOLUME_DOWN,
544    Power = ndk_sys::AKEYCODE_POWER,
545    Camera = ndk_sys::AKEYCODE_CAMERA,
546    Clear = ndk_sys::AKEYCODE_CLEAR,
547    A = ndk_sys::AKEYCODE_A,
548    B = ndk_sys::AKEYCODE_B,
549    C = ndk_sys::AKEYCODE_C,
550    D = ndk_sys::AKEYCODE_D,
551    E = ndk_sys::AKEYCODE_E,
552    F = ndk_sys::AKEYCODE_F,
553    G = ndk_sys::AKEYCODE_G,
554    H = ndk_sys::AKEYCODE_H,
555    I = ndk_sys::AKEYCODE_I,
556    J = ndk_sys::AKEYCODE_J,
557    K = ndk_sys::AKEYCODE_K,
558    L = ndk_sys::AKEYCODE_L,
559    M = ndk_sys::AKEYCODE_M,
560    N = ndk_sys::AKEYCODE_N,
561    O = ndk_sys::AKEYCODE_O,
562    P = ndk_sys::AKEYCODE_P,
563    Q = ndk_sys::AKEYCODE_Q,
564    R = ndk_sys::AKEYCODE_R,
565    S = ndk_sys::AKEYCODE_S,
566    T = ndk_sys::AKEYCODE_T,
567    U = ndk_sys::AKEYCODE_U,
568    V = ndk_sys::AKEYCODE_V,
569    W = ndk_sys::AKEYCODE_W,
570    X = ndk_sys::AKEYCODE_X,
571    Y = ndk_sys::AKEYCODE_Y,
572    Z = ndk_sys::AKEYCODE_Z,
573    Comma = ndk_sys::AKEYCODE_COMMA,
574    Period = ndk_sys::AKEYCODE_PERIOD,
575    AltLeft = ndk_sys::AKEYCODE_ALT_LEFT,
576    AltRight = ndk_sys::AKEYCODE_ALT_RIGHT,
577    ShiftLeft = ndk_sys::AKEYCODE_SHIFT_LEFT,
578    ShiftRight = ndk_sys::AKEYCODE_SHIFT_RIGHT,
579    Tab = ndk_sys::AKEYCODE_TAB,
580    Space = ndk_sys::AKEYCODE_SPACE,
581    Sym = ndk_sys::AKEYCODE_SYM,
582    Explorer = ndk_sys::AKEYCODE_EXPLORER,
583    Envelope = ndk_sys::AKEYCODE_ENVELOPE,
584    Enter = ndk_sys::AKEYCODE_ENTER,
585    Del = ndk_sys::AKEYCODE_DEL,
586    Grave = ndk_sys::AKEYCODE_GRAVE,
587    Minus = ndk_sys::AKEYCODE_MINUS,
588    Equals = ndk_sys::AKEYCODE_EQUALS,
589    LeftBracket = ndk_sys::AKEYCODE_LEFT_BRACKET,
590    RightBracket = ndk_sys::AKEYCODE_RIGHT_BRACKET,
591    Backslash = ndk_sys::AKEYCODE_BACKSLASH,
592    Semicolon = ndk_sys::AKEYCODE_SEMICOLON,
593    Apostrophe = ndk_sys::AKEYCODE_APOSTROPHE,
594    Slash = ndk_sys::AKEYCODE_SLASH,
595    At = ndk_sys::AKEYCODE_AT,
596    Num = ndk_sys::AKEYCODE_NUM,
597    Headsethook = ndk_sys::AKEYCODE_HEADSETHOOK,
598    Focus = ndk_sys::AKEYCODE_FOCUS,
599    Plus = ndk_sys::AKEYCODE_PLUS,
600    Menu = ndk_sys::AKEYCODE_MENU,
601    Notification = ndk_sys::AKEYCODE_NOTIFICATION,
602    Search = ndk_sys::AKEYCODE_SEARCH,
603    MediaPlayPause = ndk_sys::AKEYCODE_MEDIA_PLAY_PAUSE,
604    MediaStop = ndk_sys::AKEYCODE_MEDIA_STOP,
605    MediaNext = ndk_sys::AKEYCODE_MEDIA_NEXT,
606    MediaPrevious = ndk_sys::AKEYCODE_MEDIA_PREVIOUS,
607    MediaRewind = ndk_sys::AKEYCODE_MEDIA_REWIND,
608    MediaFastForward = ndk_sys::AKEYCODE_MEDIA_FAST_FORWARD,
609    Mute = ndk_sys::AKEYCODE_MUTE,
610    PageUp = ndk_sys::AKEYCODE_PAGE_UP,
611    PageDown = ndk_sys::AKEYCODE_PAGE_DOWN,
612    Pictsymbols = ndk_sys::AKEYCODE_PICTSYMBOLS,
613    SwitchCharset = ndk_sys::AKEYCODE_SWITCH_CHARSET,
614    ButtonA = ndk_sys::AKEYCODE_BUTTON_A,
615    ButtonB = ndk_sys::AKEYCODE_BUTTON_B,
616    ButtonC = ndk_sys::AKEYCODE_BUTTON_C,
617    ButtonX = ndk_sys::AKEYCODE_BUTTON_X,
618    ButtonY = ndk_sys::AKEYCODE_BUTTON_Y,
619    ButtonZ = ndk_sys::AKEYCODE_BUTTON_Z,
620    ButtonL1 = ndk_sys::AKEYCODE_BUTTON_L1,
621    ButtonR1 = ndk_sys::AKEYCODE_BUTTON_R1,
622    ButtonL2 = ndk_sys::AKEYCODE_BUTTON_L2,
623    ButtonR2 = ndk_sys::AKEYCODE_BUTTON_R2,
624    ButtonThumbl = ndk_sys::AKEYCODE_BUTTON_THUMBL,
625    ButtonThumbr = ndk_sys::AKEYCODE_BUTTON_THUMBR,
626    ButtonStart = ndk_sys::AKEYCODE_BUTTON_START,
627    ButtonSelect = ndk_sys::AKEYCODE_BUTTON_SELECT,
628    ButtonMode = ndk_sys::AKEYCODE_BUTTON_MODE,
629    Escape = ndk_sys::AKEYCODE_ESCAPE,
630    ForwardDel = ndk_sys::AKEYCODE_FORWARD_DEL,
631    CtrlLeft = ndk_sys::AKEYCODE_CTRL_LEFT,
632    CtrlRight = ndk_sys::AKEYCODE_CTRL_RIGHT,
633    CapsLock = ndk_sys::AKEYCODE_CAPS_LOCK,
634    ScrollLock = ndk_sys::AKEYCODE_SCROLL_LOCK,
635    MetaLeft = ndk_sys::AKEYCODE_META_LEFT,
636    MetaRight = ndk_sys::AKEYCODE_META_RIGHT,
637    Function = ndk_sys::AKEYCODE_FUNCTION,
638    Sysrq = ndk_sys::AKEYCODE_SYSRQ,
639    Break = ndk_sys::AKEYCODE_BREAK,
640    MoveHome = ndk_sys::AKEYCODE_MOVE_HOME,
641    MoveEnd = ndk_sys::AKEYCODE_MOVE_END,
642    Insert = ndk_sys::AKEYCODE_INSERT,
643    Forward = ndk_sys::AKEYCODE_FORWARD,
644    MediaPlay = ndk_sys::AKEYCODE_MEDIA_PLAY,
645    MediaPause = ndk_sys::AKEYCODE_MEDIA_PAUSE,
646    MediaClose = ndk_sys::AKEYCODE_MEDIA_CLOSE,
647    MediaEject = ndk_sys::AKEYCODE_MEDIA_EJECT,
648    MediaRecord = ndk_sys::AKEYCODE_MEDIA_RECORD,
649    F1 = ndk_sys::AKEYCODE_F1,
650    F2 = ndk_sys::AKEYCODE_F2,
651    F3 = ndk_sys::AKEYCODE_F3,
652    F4 = ndk_sys::AKEYCODE_F4,
653    F5 = ndk_sys::AKEYCODE_F5,
654    F6 = ndk_sys::AKEYCODE_F6,
655    F7 = ndk_sys::AKEYCODE_F7,
656    F8 = ndk_sys::AKEYCODE_F8,
657    F9 = ndk_sys::AKEYCODE_F9,
658    F10 = ndk_sys::AKEYCODE_F10,
659    F11 = ndk_sys::AKEYCODE_F11,
660    F12 = ndk_sys::AKEYCODE_F12,
661    NumLock = ndk_sys::AKEYCODE_NUM_LOCK,
662    Numpad0 = ndk_sys::AKEYCODE_NUMPAD_0,
663    Numpad1 = ndk_sys::AKEYCODE_NUMPAD_1,
664    Numpad2 = ndk_sys::AKEYCODE_NUMPAD_2,
665    Numpad3 = ndk_sys::AKEYCODE_NUMPAD_3,
666    Numpad4 = ndk_sys::AKEYCODE_NUMPAD_4,
667    Numpad5 = ndk_sys::AKEYCODE_NUMPAD_5,
668    Numpad6 = ndk_sys::AKEYCODE_NUMPAD_6,
669    Numpad7 = ndk_sys::AKEYCODE_NUMPAD_7,
670    Numpad8 = ndk_sys::AKEYCODE_NUMPAD_8,
671    Numpad9 = ndk_sys::AKEYCODE_NUMPAD_9,
672    NumpadDivide = ndk_sys::AKEYCODE_NUMPAD_DIVIDE,
673    NumpadMultiply = ndk_sys::AKEYCODE_NUMPAD_MULTIPLY,
674    NumpadSubtract = ndk_sys::AKEYCODE_NUMPAD_SUBTRACT,
675    NumpadAdd = ndk_sys::AKEYCODE_NUMPAD_ADD,
676    NumpadDot = ndk_sys::AKEYCODE_NUMPAD_DOT,
677    NumpadComma = ndk_sys::AKEYCODE_NUMPAD_COMMA,
678    NumpadEnter = ndk_sys::AKEYCODE_NUMPAD_ENTER,
679    NumpadEquals = ndk_sys::AKEYCODE_NUMPAD_EQUALS,
680    NumpadLeftParen = ndk_sys::AKEYCODE_NUMPAD_LEFT_PAREN,
681    NumpadRightParen = ndk_sys::AKEYCODE_NUMPAD_RIGHT_PAREN,
682    VolumeMute = ndk_sys::AKEYCODE_VOLUME_MUTE,
683    Info = ndk_sys::AKEYCODE_INFO,
684    ChannelUp = ndk_sys::AKEYCODE_CHANNEL_UP,
685    ChannelDown = ndk_sys::AKEYCODE_CHANNEL_DOWN,
686    ZoomIn = ndk_sys::AKEYCODE_ZOOM_IN,
687    ZoomOut = ndk_sys::AKEYCODE_ZOOM_OUT,
688    Tv = ndk_sys::AKEYCODE_TV,
689    Window = ndk_sys::AKEYCODE_WINDOW,
690    Guide = ndk_sys::AKEYCODE_GUIDE,
691    Dvr = ndk_sys::AKEYCODE_DVR,
692    Bookmark = ndk_sys::AKEYCODE_BOOKMARK,
693    Captions = ndk_sys::AKEYCODE_CAPTIONS,
694    Settings = ndk_sys::AKEYCODE_SETTINGS,
695    TvPower = ndk_sys::AKEYCODE_TV_POWER,
696    TvInput = ndk_sys::AKEYCODE_TV_INPUT,
697    StbPower = ndk_sys::AKEYCODE_STB_POWER,
698    StbInput = ndk_sys::AKEYCODE_STB_INPUT,
699    AvrPower = ndk_sys::AKEYCODE_AVR_POWER,
700    AvrInput = ndk_sys::AKEYCODE_AVR_INPUT,
701    ProgRed = ndk_sys::AKEYCODE_PROG_RED,
702    ProgGreen = ndk_sys::AKEYCODE_PROG_GREEN,
703    ProgYellow = ndk_sys::AKEYCODE_PROG_YELLOW,
704    ProgBlue = ndk_sys::AKEYCODE_PROG_BLUE,
705    AppSwitch = ndk_sys::AKEYCODE_APP_SWITCH,
706    Button1 = ndk_sys::AKEYCODE_BUTTON_1,
707    Button2 = ndk_sys::AKEYCODE_BUTTON_2,
708    Button3 = ndk_sys::AKEYCODE_BUTTON_3,
709    Button4 = ndk_sys::AKEYCODE_BUTTON_4,
710    Button5 = ndk_sys::AKEYCODE_BUTTON_5,
711    Button6 = ndk_sys::AKEYCODE_BUTTON_6,
712    Button7 = ndk_sys::AKEYCODE_BUTTON_7,
713    Button8 = ndk_sys::AKEYCODE_BUTTON_8,
714    Button9 = ndk_sys::AKEYCODE_BUTTON_9,
715    Button10 = ndk_sys::AKEYCODE_BUTTON_10,
716    Button11 = ndk_sys::AKEYCODE_BUTTON_11,
717    Button12 = ndk_sys::AKEYCODE_BUTTON_12,
718    Button13 = ndk_sys::AKEYCODE_BUTTON_13,
719    Button14 = ndk_sys::AKEYCODE_BUTTON_14,
720    Button15 = ndk_sys::AKEYCODE_BUTTON_15,
721    Button16 = ndk_sys::AKEYCODE_BUTTON_16,
722    LanguageSwitch = ndk_sys::AKEYCODE_LANGUAGE_SWITCH,
723    MannerMode = ndk_sys::AKEYCODE_MANNER_MODE,
724    Keycode3dMode = ndk_sys::AKEYCODE_3D_MODE,
725    Contacts = ndk_sys::AKEYCODE_CONTACTS,
726    Calendar = ndk_sys::AKEYCODE_CALENDAR,
727    Music = ndk_sys::AKEYCODE_MUSIC,
728    Calculator = ndk_sys::AKEYCODE_CALCULATOR,
729    ZenkakuHankaku = ndk_sys::AKEYCODE_ZENKAKU_HANKAKU,
730    Eisu = ndk_sys::AKEYCODE_EISU,
731    Muhenkan = ndk_sys::AKEYCODE_MUHENKAN,
732    Henkan = ndk_sys::AKEYCODE_HENKAN,
733    KatakanaHiragana = ndk_sys::AKEYCODE_KATAKANA_HIRAGANA,
734    Yen = ndk_sys::AKEYCODE_YEN,
735    Ro = ndk_sys::AKEYCODE_RO,
736    Kana = ndk_sys::AKEYCODE_KANA,
737    Assist = ndk_sys::AKEYCODE_ASSIST,
738    BrightnessDown = ndk_sys::AKEYCODE_BRIGHTNESS_DOWN,
739    BrightnessUp = ndk_sys::AKEYCODE_BRIGHTNESS_UP,
740    MediaAudioTrack = ndk_sys::AKEYCODE_MEDIA_AUDIO_TRACK,
741    Sleep = ndk_sys::AKEYCODE_SLEEP,
742    Wakeup = ndk_sys::AKEYCODE_WAKEUP,
743    Pairing = ndk_sys::AKEYCODE_PAIRING,
744    MediaTopMenu = ndk_sys::AKEYCODE_MEDIA_TOP_MENU,
745    Keycode11 = ndk_sys::AKEYCODE_11,
746    Keycode12 = ndk_sys::AKEYCODE_12,
747    LastChannel = ndk_sys::AKEYCODE_LAST_CHANNEL,
748    TvDataService = ndk_sys::AKEYCODE_TV_DATA_SERVICE,
749    VoiceAssist = ndk_sys::AKEYCODE_VOICE_ASSIST,
750    TvRadioService = ndk_sys::AKEYCODE_TV_RADIO_SERVICE,
751    TvTeletext = ndk_sys::AKEYCODE_TV_TELETEXT,
752    TvNumberEntry = ndk_sys::AKEYCODE_TV_NUMBER_ENTRY,
753    TvTerrestrialAnalog = ndk_sys::AKEYCODE_TV_TERRESTRIAL_ANALOG,
754    TvTerrestrialDigital = ndk_sys::AKEYCODE_TV_TERRESTRIAL_DIGITAL,
755    TvSatellite = ndk_sys::AKEYCODE_TV_SATELLITE,
756    TvSatelliteBs = ndk_sys::AKEYCODE_TV_SATELLITE_BS,
757    TvSatelliteCs = ndk_sys::AKEYCODE_TV_SATELLITE_CS,
758    TvSatelliteService = ndk_sys::AKEYCODE_TV_SATELLITE_SERVICE,
759    TvNetwork = ndk_sys::AKEYCODE_TV_NETWORK,
760    TvAntennaCable = ndk_sys::AKEYCODE_TV_ANTENNA_CABLE,
761    TvInputHdmi1 = ndk_sys::AKEYCODE_TV_INPUT_HDMI_1,
762    TvInputHdmi2 = ndk_sys::AKEYCODE_TV_INPUT_HDMI_2,
763    TvInputHdmi3 = ndk_sys::AKEYCODE_TV_INPUT_HDMI_3,
764    TvInputHdmi4 = ndk_sys::AKEYCODE_TV_INPUT_HDMI_4,
765    TvInputComposite1 = ndk_sys::AKEYCODE_TV_INPUT_COMPOSITE_1,
766    TvInputComposite2 = ndk_sys::AKEYCODE_TV_INPUT_COMPOSITE_2,
767    TvInputComponent1 = ndk_sys::AKEYCODE_TV_INPUT_COMPONENT_1,
768    TvInputComponent2 = ndk_sys::AKEYCODE_TV_INPUT_COMPONENT_2,
769    TvInputVga1 = ndk_sys::AKEYCODE_TV_INPUT_VGA_1,
770    TvAudioDescription = ndk_sys::AKEYCODE_TV_AUDIO_DESCRIPTION,
771    TvAudioDescriptionMixUp = ndk_sys::AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP,
772    TvAudioDescriptionMixDown = ndk_sys::AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN,
773    TvZoomMode = ndk_sys::AKEYCODE_TV_ZOOM_MODE,
774    TvContentsMenu = ndk_sys::AKEYCODE_TV_CONTENTS_MENU,
775    TvMediaContextMenu = ndk_sys::AKEYCODE_TV_MEDIA_CONTEXT_MENU,
776    TvTimerProgramming = ndk_sys::AKEYCODE_TV_TIMER_PROGRAMMING,
777    Help = ndk_sys::AKEYCODE_HELP,
778    NavigatePrevious = ndk_sys::AKEYCODE_NAVIGATE_PREVIOUS,
779    NavigateNext = ndk_sys::AKEYCODE_NAVIGATE_NEXT,
780    NavigateIn = ndk_sys::AKEYCODE_NAVIGATE_IN,
781    NavigateOut = ndk_sys::AKEYCODE_NAVIGATE_OUT,
782    StemPrimary = ndk_sys::AKEYCODE_STEM_PRIMARY,
783    Stem1 = ndk_sys::AKEYCODE_STEM_1,
784    Stem2 = ndk_sys::AKEYCODE_STEM_2,
785    Stem3 = ndk_sys::AKEYCODE_STEM_3,
786    DpadUpLeft = ndk_sys::AKEYCODE_DPAD_UP_LEFT,
787    DpadDownLeft = ndk_sys::AKEYCODE_DPAD_DOWN_LEFT,
788    DpadUpRight = ndk_sys::AKEYCODE_DPAD_UP_RIGHT,
789    DpadDownRight = ndk_sys::AKEYCODE_DPAD_DOWN_RIGHT,
790    MediaSkipForward = ndk_sys::AKEYCODE_MEDIA_SKIP_FORWARD,
791    MediaSkipBackward = ndk_sys::AKEYCODE_MEDIA_SKIP_BACKWARD,
792    MediaStepForward = ndk_sys::AKEYCODE_MEDIA_STEP_FORWARD,
793    MediaStepBackward = ndk_sys::AKEYCODE_MEDIA_STEP_BACKWARD,
794    SoftSleep = ndk_sys::AKEYCODE_SOFT_SLEEP,
795    Cut = ndk_sys::AKEYCODE_CUT,
796    Copy = ndk_sys::AKEYCODE_COPY,
797    Paste = ndk_sys::AKEYCODE_PASTE,
798    SystemNavigationUp = ndk_sys::AKEYCODE_SYSTEM_NAVIGATION_UP,
799    SystemNavigationDown = ndk_sys::AKEYCODE_SYSTEM_NAVIGATION_DOWN,
800    SystemNavigationLeft = ndk_sys::AKEYCODE_SYSTEM_NAVIGATION_LEFT,
801    SystemNavigationRight = ndk_sys::AKEYCODE_SYSTEM_NAVIGATION_RIGHT,
802    AllApps = ndk_sys::AKEYCODE_ALL_APPS,
803    Refresh = ndk_sys::AKEYCODE_REFRESH,
804    ThumbsUp = ndk_sys::AKEYCODE_THUMBS_UP,
805    ThumbsDown = ndk_sys::AKEYCODE_THUMBS_DOWN,
806    ProfileSwitch = ndk_sys::AKEYCODE_PROFILE_SWITCH,
807
808    #[doc(hidden)]
809    #[num_enum(catch_all)]
810    __Unknown(u32),
811}
812
813/// Flags associated with [`KeyEvent`].
814///
815/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-28)
816#[derive(Copy, Clone, Debug, PartialEq, Eq)]
817pub struct KeyEventFlags(pub u32);
818
819impl KeyEventFlags {
820    #[inline]
821    pub fn cancelled(&self) -> bool {
822        self.0 & ndk_sys::AKEY_EVENT_FLAG_CANCELED != 0
823    }
824    #[inline]
825    pub fn cancelled_long_press(&self) -> bool {
826        self.0 & ndk_sys::AKEY_EVENT_FLAG_CANCELED_LONG_PRESS != 0
827    }
828    #[inline]
829    pub fn editor_action(&self) -> bool {
830        self.0 & ndk_sys::AKEY_EVENT_FLAG_EDITOR_ACTION != 0
831    }
832    #[inline]
833    pub fn fallback(&self) -> bool {
834        self.0 & ndk_sys::AKEY_EVENT_FLAG_FALLBACK != 0
835    }
836    #[inline]
837    pub fn from_system(&self) -> bool {
838        self.0 & ndk_sys::AKEY_EVENT_FLAG_FROM_SYSTEM != 0
839    }
840    #[inline]
841    pub fn keep_touch_mode(&self) -> bool {
842        self.0 & ndk_sys::AKEY_EVENT_FLAG_KEEP_TOUCH_MODE != 0
843    }
844    #[inline]
845    pub fn long_press(&self) -> bool {
846        self.0 & ndk_sys::AKEY_EVENT_FLAG_LONG_PRESS != 0
847    }
848    #[inline]
849    pub fn soft_keyboard(&self) -> bool {
850        self.0 & ndk_sys::AKEY_EVENT_FLAG_SOFT_KEYBOARD != 0
851    }
852    #[inline]
853    pub fn tracking(&self) -> bool {
854        self.0 & ndk_sys::AKEY_EVENT_FLAG_TRACKING != 0
855    }
856    #[inline]
857    pub fn virtual_hard_key(&self) -> bool {
858        self.0 & ndk_sys::AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY != 0
859    }
860    #[inline]
861    pub fn woke_here(&self) -> bool {
862        self.0 & ndk_sys::AKEY_EVENT_FLAG_WOKE_HERE != 0
863    }
864}
865
866impl From<ndk::event::KeyEventFlags> for KeyEventFlags {
867    fn from(value: ndk::event::KeyEventFlags) -> Self {
868        Self(value.0)
869    }
870}
871
872/// This struct holds a span within a region of text from `start` to `end`.
873///
874/// The `start` index may be greater than the `end` index (swapping `start` and `end` will represent the same span)
875///
876/// The lower index is inclusive and the higher index is exclusive.
877///
878/// An empty span or cursor position is specified with `start == end`.
879///
880#[derive(Debug, Clone, Copy)]
881pub struct TextSpan {
882    /// The start of the span (inclusive)
883    pub start: usize,
884
885    /// The end of the span (exclusive)
886    pub end: usize,
887}
888
889#[derive(Debug, Clone)]
890pub struct TextInputState {
891    pub text: String,
892
893    /// A selection defined on the text.
894    ///
895    /// To set the cursor position, start and end should have the same value.
896    ///
897    /// Changing the selection has no effect on the compose_region.
898    pub selection: TextSpan,
899
900    /// A composing region defined on the text.
901    ///
902    /// When being set, then if there was a composing region, the region is replaced.
903    ///
904    /// The given indices will be clamped to the `text` bounds
905    ///
906    /// If the resulting region is zero-sized, no region is marked (equivalent to passing `None`)
907    pub compose_region: Option<TextSpan>,
908}
909
910/// An exclusive, lending iterator for input events
911pub struct InputIterator<'a> {
912    pub(crate) inner: crate::activity_impl::InputIteratorInner<'a>,
913}
914
915impl<'a> InputIterator<'a> {
916    /// Reads and handles the next input event by passing it to the given `callback`
917    ///
918    /// `callback` should return [`InputStatus::Unhandled`] for any input events that aren't directly
919    /// handled by the application, or else [`InputStatus::Handled`]. Unhandled events may lead to a
920    /// fallback interpretation of the event.
921    pub fn next<F>(&mut self, callback: F) -> bool
922    where
923        F: FnOnce(&crate::activity_impl::input::InputEvent) -> InputStatus,
924    {
925        self.inner.next(callback)
926    }
927}
928
929/// A view into the data of a specific pointer in a motion event.
930#[derive(Debug)]
931pub struct Pointer<'a> {
932    pub(crate) inner: PointerImpl<'a>,
933}
934
935impl<'a> Pointer<'a> {
936    #[inline]
937    pub fn pointer_index(&self) -> usize {
938        self.inner.pointer_index()
939    }
940
941    #[inline]
942    pub fn pointer_id(&self) -> i32 {
943        self.inner.pointer_id()
944    }
945
946    #[inline]
947    pub fn axis_value(&self, axis: Axis) -> f32 {
948        self.inner.axis_value(axis)
949    }
950
951    #[inline]
952    pub fn orientation(&self) -> f32 {
953        self.axis_value(Axis::Orientation)
954    }
955
956    #[inline]
957    pub fn pressure(&self) -> f32 {
958        self.axis_value(Axis::Pressure)
959    }
960
961    #[inline]
962    pub fn raw_x(&self) -> f32 {
963        self.inner.raw_x()
964    }
965
966    #[inline]
967    pub fn raw_y(&self) -> f32 {
968        self.inner.raw_y()
969    }
970
971    #[inline]
972    pub fn x(&self) -> f32 {
973        self.axis_value(Axis::X)
974    }
975
976    #[inline]
977    pub fn y(&self) -> f32 {
978        self.axis_value(Axis::Y)
979    }
980
981    #[inline]
982    pub fn size(&self) -> f32 {
983        self.axis_value(Axis::Size)
984    }
985
986    #[inline]
987    pub fn tool_major(&self) -> f32 {
988        self.axis_value(Axis::ToolMajor)
989    }
990
991    #[inline]
992    pub fn tool_minor(&self) -> f32 {
993        self.axis_value(Axis::ToolMinor)
994    }
995
996    #[inline]
997    pub fn touch_major(&self) -> f32 {
998        self.axis_value(Axis::TouchMajor)
999    }
1000
1001    #[inline]
1002    pub fn touch_minor(&self) -> f32 {
1003        self.axis_value(Axis::TouchMinor)
1004    }
1005
1006    #[inline]
1007    pub fn tool_type(&self) -> ToolType {
1008        self.inner.tool_type()
1009    }
1010}
1011
1012/// An iterator over the pointers in a [`MotionEvent`].
1013#[derive(Debug)]
1014pub struct PointersIter<'a> {
1015    pub(crate) inner: PointersIterImpl<'a>,
1016}
1017
1018impl<'a> Iterator for PointersIter<'a> {
1019    type Item = Pointer<'a>;
1020    fn next(&mut self) -> Option<Pointer<'a>> {
1021        self.inner.next()
1022    }
1023
1024    fn size_hint(&self) -> (usize, Option<usize>) {
1025        self.inner.size_hint()
1026    }
1027}
1028
1029impl<'a> ExactSizeIterator for PointersIter<'a> {
1030    fn len(&self) -> usize {
1031        self.inner.len()
1032    }
1033}