1313//! a wider range of devices.
1414//!
1515//! Standalone applications based on this crate need to be built as `cdylib` libraries, like:
16- //! ```
16+ //! ```toml
1717//! [lib]
1818//! crate_type=["cdylib"]
1919//! ```
2020//!
2121//! and implement a `#[no_mangle]` `android_main` entry point like this:
22- //! ```rust
22+ //! ```no_run
2323//! #[no_mangle]
24- //! fn android_main(app: AndroidApp) {
24+ //! fn android_main(app: android_activity:: AndroidApp) {
2525//!
2626//! }
2727//! ```
6464//! These are undone after `android_main()` returns
6565//!
6666//! # Android Extensible Enums
67+ // TODO: Move this to the NDK crate, which now implements this for most of the code?
6768//!
6869//! There are numerous enums in the `android-activity` API which are effectively
6970//! bindings to enums declared in the Android SDK which need to be considered
9596//! For example, here is how you could ensure forwards compatibility with both
9697//! compile-time and runtime extensions of a `SomeEnum` enum:
9798//!
98- //! ```rust
99+ //! ```ignore
99100//! match some_enum {
100101//! SomeEnum::Foo => {},
101102//! SomeEnum::Bar => {},
@@ -556,10 +557,10 @@ impl AndroidApp {
556557 /// between native Rust code and Java/Kotlin code running within the JVM.
557558 ///
558559 /// If you use the [`jni`] crate you can wrap this as a [`JavaVM`] via:
559- /// ```ignore
560+ /// ```no_run
560561 /// # 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() ) };
563564 /// ```
564565 ///
565566 /// [`jni`]: https://crates.io/crates/jni
@@ -571,10 +572,10 @@ impl AndroidApp {
571572 /// Returns a JNI object reference for this application's JVM `Activity` as a pointer
572573 ///
573574 /// If you use the [`jni`] crate you can wrap this as an object reference via:
574- /// ```ignore
575+ /// ```no_run
575576 /// # 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() ) };
578579 /// ```
579580 ///
580581 /// # JNI Safety
@@ -731,20 +732,23 @@ impl AndroidApp {
731732 /// # Example
732733 /// Code to iterate all pending input events would look something like this:
733734 ///
734- /// ```rust
735+ /// ```no_run
736+ /// # use android_activity::{AndroidApp, InputStatus, input::InputEvent};
737+ /// # let app: AndroidApp = todo!();
735738 /// match app.input_events_iter() {
736739 /// Ok(mut iter) => {
737740 /// loop {
738741 /// let read_input = iter.next(|event| {
739742 /// let handled = match event {
740743 /// InputEvent::KeyEvent(key_event) => {
741744 /// // Snip
745+ /// InputStatus::Handled
742746 /// }
743747 /// InputEvent::MotionEvent(motion_event) => {
744- /// // Snip
748+ /// InputStatus::Unhandled
745749 /// }
746750 /// event => {
747- /// // Snip
751+ /// InputStatus::Unhandled
748752 /// }
749753 /// };
750754 ///
@@ -766,7 +770,7 @@ impl AndroidApp {
766770 ///
767771 /// This must only be called from your `android_main()` thread and it may panic if called
768772 /// from another thread.
769- pub fn input_events_iter ( & self ) -> Result < input:: InputIterator > {
773+ pub fn input_events_iter ( & self ) -> Result < input:: InputIterator < ' _ > > {
770774 let receiver = {
771775 let guard = self . inner . read ( ) . unwrap ( ) ;
772776 guard. input_events_receiver ( ) ?
@@ -786,44 +790,47 @@ impl AndroidApp {
786790 ///
787791 /// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
788792 ///
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!();
790797 /// let mut combining_accent = None;
791798 /// // Snip
792799 ///
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() ) {
794801 /// match map.get(key_event.key_code(), key_event.meta_state()) {
795802 /// Ok(KeyMapChar::Unicode(unicode)) => {
796803 /// let combined_unicode = if let Some(accent) = combining_accent {
797804 /// match map.get_dead_char(accent, unicode) {
798805 /// 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}'");
800807 /// Some(key)
801808 /// }
802809 /// Ok(None) => None,
803810 /// 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:?}");
805812 /// None
806813 /// }
807814 /// }
808815 /// } else {
809- /// info !("KeyEvent: Pressed '{unicode}'");
816+ /// println !("KeyEvent: Pressed '{unicode}'");
810817 /// Some(unicode)
811818 /// };
812819 /// combining_accent = None;
813820 /// combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
814821 /// }
815822 /// Ok(KeyMapChar::CombiningAccent(accent)) => {
816- /// info !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
823+ /// println !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
817824 /// combining_accent = Some(accent);
818825 /// Some(KeyMapChar::CombiningAccent(accent))
819826 /// }
820827 /// Ok(KeyMapChar::None) => {
821- /// info !("KeyEvent: Pressed non-unicode key");
828+ /// println !("KeyEvent: Pressed non-unicode key");
822829 /// combining_accent = None;
823830 /// None
824831 /// }
825832 /// Err(err) => {
826- /// log::error !("KeyEvent: Failed to get key map character: {err:?}");
833+ /// eprintln !("KeyEvent: Failed to get key map character: {err:?}");
827834 /// combining_accent = None;
828835 /// None
829836 /// }
0 commit comments