Skip to content

android-activity 0.5.0

Compare
Choose a tag to compare
@rib rib released this 16 Oct 23:33
· 25 commits to main since this release
a7114c8

Probably the most notable (breaking) change in this release is the updated API for reading input events to better support being able to use other AndroidApp APIs while iterating input events, to support unicode character mapping for Keycodes.

The other big change with this release is the update of the game-activity backend, updating to GameActivity 2.0.2. Applications using the game-activity backend will need to ensure they pull in the corresponding 2.0.2 .aar from Google (For example, see https://github.com/rust-mobile/android-activity/blob/main/examples/agdk-mainloop/app/build.gradle)

Added

  • Added KeyEvent::meta_state() for being able to query the state of meta keys, needed for character mapping (#102)

  • Added KeyCharacterMap JNI bindings to the corresponding Android SDK API (#102)

  • Added AndroidApp::device_key_character_map() for being able to get a KeyCharacterMap for a given device_id for unicode character mapping (#102)

    Click here for an example of how to handle unicode character mapping:
    let mut combining_accent = None;
    // Snip
    
    
    let combined_key_char = if let Ok(map) = app.device_key_character_map(device_id) {
        match map.get(key_event.key_code(), key_event.meta_state()) {
            Ok(KeyMapChar::Unicode(unicode)) => {
                let combined_unicode = if let Some(accent) = combining_accent {
                    match map.get_dead_char(accent, unicode) {
                        Ok(Some(key)) => {
                            info!("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
                            Some(key)
                        }
                        Ok(None) => None,
                        Err(err) => {
                            log::error!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
                            None
                        }
                    }
                } else {
                    info!("KeyEvent: Pressed '{unicode}'");
                    Some(unicode)
                };
                combining_accent = None;
                combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
            }
            Ok(KeyMapChar::CombiningAccent(accent)) => {
                info!("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
                combining_accent = Some(accent);
                Some(KeyMapChar::CombiningAccent(accent))
            }
            Ok(KeyMapChar::None) => {
                info!("KeyEvent: Pressed non-unicode key");
                combining_accent = None;
                None
            }
            Err(err) => {
                log::error!("KeyEvent: Failed to get key map character: {err:?}");
                combining_accent = None;
                None
            }
        }
    } else {
        None
    };
  • Added TextEvent Input Method event for supporting text editing via virtual keyboards (#24)

  • Added MotionEvent::action_button() exposing the button associated with button press/release actions (#138)

Changed

  • rust-version bumped to 0.68 (#123)

  • Breaking: update to ndk 0.8 and ndk-sys 0.5 (#128)

  • GameActivity updated to 2.0.2 (requires the corresponding 2.0.2 .aar release from Google) (#88)

  • AndroidApp::input_events() is replaced by AndroidApp::input_events_iter() (#102)

    Click here for an example of how to use `input_events_iter()`:
    match app.input_events_iter() {
        Ok(mut iter) => {
            loop {
                let read_input = iter.next(|event| {
                    let handled = match event {
                        InputEvent::KeyEvent(key_event) => {
                            // Snip
                        }
                        InputEvent::MotionEvent(motion_event) => {
                            // Snip
                        }
                        event => {
                            // Snip
                        }
                    };
    
                    handled
                });
    
                if !read_input {
                    break;
                }
            }
        }
        Err(err) => {
            log::error!("Failed to get input events iterator: {err:?}");
        }
    }
  • The Pointer and PointerIter types from the ndk crate are no longer directly exposed in the public API (#122)

  • All input API enums based on Android SDK enums have been made runtime extensible via hidden __Unknown(u32) variants (#131)

New Contributors

Full Changelog: v0.4.3...v0.5.0