13
13
//! a wider range of devices.
14
14
//!
15
15
//! Standalone applications based on this crate need to be built as `cdylib` libraries, like:
16
- //! ```
16
+ //! ```toml
17
17
//! [lib]
18
18
//! crate_type=["cdylib"]
19
19
//! ```
20
20
//!
21
21
//! and implement a `#[no_mangle]` `android_main` entry point like this:
22
- //! ```rust
22
+ //! ```no_run
23
23
//! #[no_mangle]
24
- //! fn android_main(app: AndroidApp) {
24
+ //! fn android_main(app: android_activity:: AndroidApp) {
25
25
//!
26
26
//! }
27
27
//! ```
64
64
//! These are undone after `android_main()` returns
65
65
//!
66
66
//! # Android Extensible Enums
67
+ // TODO: Move this to the NDK crate, which now implements this for most of the code?
67
68
//!
68
69
//! There are numerous enums in the `android-activity` API which are effectively
69
70
//! bindings to enums declared in the Android SDK which need to be considered
95
96
//! For example, here is how you could ensure forwards compatibility with both
96
97
//! compile-time and runtime extensions of a `SomeEnum` enum:
97
98
//!
98
- //! ```rust
99
+ //! ```ignore
99
100
//! match some_enum {
100
101
//! SomeEnum::Foo => {},
101
102
//! SomeEnum::Bar => {},
@@ -556,10 +557,10 @@ impl AndroidApp {
556
557
/// between native Rust code and Java/Kotlin code running within the JVM.
557
558
///
558
559
/// If you use the [`jni`] crate you can wrap this as a [`JavaVM`] via:
559
- /// ```ignore
560
+ /// ```no_run
560
561
/// # use jni::JavaVM;
561
- /// # let app: AndroidApp = todo!();
562
- /// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr()) };
562
+ /// # let app: android_activity:: AndroidApp = todo!();
563
+ /// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().cast() ) };
563
564
/// ```
564
565
///
565
566
/// [`jni`]: https://crates.io/crates/jni
@@ -571,10 +572,10 @@ impl AndroidApp {
571
572
/// Returns a JNI object reference for this application's JVM `Activity` as a pointer
572
573
///
573
574
/// If you use the [`jni`] crate you can wrap this as an object reference via:
574
- /// ```ignore
575
+ /// ```no_run
575
576
/// # use jni::objects::JObject;
576
- /// # let app: AndroidApp = todo!();
577
- /// let activity = unsafe { JObject::from_raw(app.activity_as_ptr()) };
577
+ /// # let app: android_activity:: AndroidApp = todo!();
578
+ /// let activity = unsafe { JObject::from_raw(app.activity_as_ptr().cast() ) };
578
579
/// ```
579
580
///
580
581
/// # JNI Safety
@@ -731,20 +732,23 @@ impl AndroidApp {
731
732
/// # Example
732
733
/// Code to iterate all pending input events would look something like this:
733
734
///
734
- /// ```rust
735
+ /// ```no_run
736
+ /// # use android_activity::{AndroidApp, InputStatus, input::InputEvent};
737
+ /// # let app: AndroidApp = todo!();
735
738
/// match app.input_events_iter() {
736
739
/// Ok(mut iter) => {
737
740
/// loop {
738
741
/// let read_input = iter.next(|event| {
739
742
/// let handled = match event {
740
743
/// InputEvent::KeyEvent(key_event) => {
741
744
/// // Snip
745
+ /// InputStatus::Handled
742
746
/// }
743
747
/// InputEvent::MotionEvent(motion_event) => {
744
- /// // Snip
748
+ /// InputStatus::Unhandled
745
749
/// }
746
750
/// event => {
747
- /// // Snip
751
+ /// InputStatus::Unhandled
748
752
/// }
749
753
/// };
750
754
///
@@ -766,7 +770,7 @@ impl AndroidApp {
766
770
///
767
771
/// This must only be called from your `android_main()` thread and it may panic if called
768
772
/// from another thread.
769
- pub fn input_events_iter ( & self ) -> Result < input:: InputIterator > {
773
+ pub fn input_events_iter ( & self ) -> Result < input:: InputIterator < ' _ > > {
770
774
let receiver = {
771
775
let guard = self . inner . read ( ) . unwrap ( ) ;
772
776
guard. input_events_receiver ( ) ?
@@ -786,44 +790,47 @@ impl AndroidApp {
786
790
///
787
791
/// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
788
792
///
789
- /// ```rust
793
+ /// ```no_run
794
+ /// # use android_activity::{AndroidApp, input::{InputEvent, KeyEvent, KeyMapChar}};
795
+ /// # let app: AndroidApp = todo!();
796
+ /// # let key_event: KeyEvent = todo!();
790
797
/// let mut combining_accent = None;
791
798
/// // Snip
792
799
///
793
- /// let combined_key_char = if let Ok(map) = app.device_key_character_map(device_id) {
800
+ /// let combined_key_char = if let Ok(map) = app.device_key_character_map(key_event. device_id() ) {
794
801
/// match map.get(key_event.key_code(), key_event.meta_state()) {
795
802
/// Ok(KeyMapChar::Unicode(unicode)) => {
796
803
/// let combined_unicode = if let Some(accent) = combining_accent {
797
804
/// match map.get_dead_char(accent, unicode) {
798
805
/// Ok(Some(key)) => {
799
- /// info !("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
806
+ /// println !("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
800
807
/// Some(key)
801
808
/// }
802
809
/// Ok(None) => None,
803
810
/// Err(err) => {
804
- /// log::error !("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
811
+ /// eprintln !("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
805
812
/// None
806
813
/// }
807
814
/// }
808
815
/// } else {
809
- /// info !("KeyEvent: Pressed '{unicode}'");
816
+ /// println !("KeyEvent: Pressed '{unicode}'");
810
817
/// Some(unicode)
811
818
/// };
812
819
/// combining_accent = None;
813
820
/// combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
814
821
/// }
815
822
/// Ok(KeyMapChar::CombiningAccent(accent)) => {
816
- /// info !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
823
+ /// println !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
817
824
/// combining_accent = Some(accent);
818
825
/// Some(KeyMapChar::CombiningAccent(accent))
819
826
/// }
820
827
/// Ok(KeyMapChar::None) => {
821
- /// info !("KeyEvent: Pressed non-unicode key");
828
+ /// println !("KeyEvent: Pressed non-unicode key");
822
829
/// combining_accent = None;
823
830
/// None
824
831
/// }
825
832
/// Err(err) => {
826
- /// log::error !("KeyEvent: Failed to get key map character: {err:?}");
833
+ /// eprintln !("KeyEvent: Failed to get key map character: {err:?}");
827
834
/// combining_accent = None;
828
835
/// None
829
836
/// }
0 commit comments