19
19
//! ```
20
20
//!
21
21
//! and implement a `#[no_mangle]` `android_main` entry point like this:
22
- //! ```
22
+ //! ```no_run
23
23
//! #[no_mangle]
24
24
//! fn android_main(app: android_activity::AndroidApp) {
25
25
//!
@@ -132,7 +132,7 @@ use ndk::native_window::NativeWindow;
132
132
pub use ndk;
133
133
pub use ndk_sys;
134
134
135
- #[ cfg( all ( not( target_os = "android" ) , not ( feature = "test" ) ) ) ]
135
+ #[ cfg( not( target_os = "android" ) ) ]
136
136
compile_error ! ( "android-activity only supports compiling for Android" ) ;
137
137
138
138
#[ cfg( all( feature = "game-activity" , feature = "native-activity" ) ) ]
@@ -560,7 +560,7 @@ impl AndroidApp {
560
560
/// ```no_run
561
561
/// # use jni::JavaVM;
562
562
/// # let app: android_activity::AndroidApp = todo!();
563
- /// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().ast ()) };
563
+ /// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().cast ()) };
564
564
/// ```
565
565
///
566
566
/// [`jni`]: https://crates.io/crates/jni
@@ -732,20 +732,23 @@ impl AndroidApp {
732
732
/// # Example
733
733
/// Code to iterate all pending input events would look something like this:
734
734
///
735
- /// ```
735
+ /// ```no_run
736
+ /// # use android_activity::{AndroidApp, InputStatus, input::InputEvent};
737
+ /// # let app: AndroidApp = todo!();
736
738
/// match app.input_events_iter() {
737
739
/// Ok(mut iter) => {
738
740
/// loop {
739
741
/// let read_input = iter.next(|event| {
740
742
/// let handled = match event {
741
743
/// InputEvent::KeyEvent(key_event) => {
742
744
/// // Snip
745
+ /// InputStatus::Handled
743
746
/// }
744
747
/// InputEvent::MotionEvent(motion_event) => {
745
- /// // Snip
748
+ /// InputStatus::Unhandled
746
749
/// }
747
750
/// event => {
748
- /// // Snip
751
+ /// InputStatus::Unhandled
749
752
/// }
750
753
/// };
751
754
///
@@ -767,7 +770,7 @@ impl AndroidApp {
767
770
///
768
771
/// This must only be called from your `android_main()` thread and it may panic if called
769
772
/// from another thread.
770
- pub fn input_events_iter ( & self ) -> Result < input:: InputIterator > {
773
+ pub fn input_events_iter ( & self ) -> Result < input:: InputIterator < ' _ > > {
771
774
let receiver = {
772
775
let guard = self . inner . read ( ) . unwrap ( ) ;
773
776
guard. input_events_receiver ( ) ?
@@ -787,44 +790,47 @@ impl AndroidApp {
787
790
///
788
791
/// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
789
792
///
790
- /// ```
793
+ /// ```no_run
794
+ /// # use android_activity::{AndroidApp, input::{InputEvent, KeyEvent, KeyMapChar}};
795
+ /// # let app: AndroidApp = todo!();
796
+ /// # let key_event: KeyEvent = todo!();
791
797
/// let mut combining_accent = None;
792
798
/// // Snip
793
799
///
794
- /// 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() ) {
795
801
/// match map.get(key_event.key_code(), key_event.meta_state()) {
796
802
/// Ok(KeyMapChar::Unicode(unicode)) => {
797
803
/// let combined_unicode = if let Some(accent) = combining_accent {
798
804
/// match map.get_dead_char(accent, unicode) {
799
805
/// Ok(Some(key)) => {
800
- /// info !("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
806
+ /// println !("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
801
807
/// Some(key)
802
808
/// }
803
809
/// Ok(None) => None,
804
810
/// Err(err) => {
805
- /// 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:?}");
806
812
/// None
807
813
/// }
808
814
/// }
809
815
/// } else {
810
- /// info !("KeyEvent: Pressed '{unicode}'");
816
+ /// println !("KeyEvent: Pressed '{unicode}'");
811
817
/// Some(unicode)
812
818
/// };
813
819
/// combining_accent = None;
814
820
/// combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
815
821
/// }
816
822
/// Ok(KeyMapChar::CombiningAccent(accent)) => {
817
- /// info !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
823
+ /// println !("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
818
824
/// combining_accent = Some(accent);
819
825
/// Some(KeyMapChar::CombiningAccent(accent))
820
826
/// }
821
827
/// Ok(KeyMapChar::None) => {
822
- /// info !("KeyEvent: Pressed non-unicode key");
828
+ /// println !("KeyEvent: Pressed non-unicode key");
823
829
/// combining_accent = None;
824
830
/// None
825
831
/// }
826
832
/// Err(err) => {
827
- /// log::error !("KeyEvent: Failed to get key map character: {err:?}");
833
+ /// eprintln !("KeyEvent: Failed to get key map character: {err:?}");
828
834
/// combining_accent = None;
829
835
/// None
830
836
/// }
0 commit comments