android-activity 0.5.0-beta.0
Pre-releaseThis is the first 0.5.0 beta that's aiming to be ready for the upcoming Winit 0.29 release
The main reason that a (breaking) semver bump was required was so we could update the 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.
A 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 aKeyCharacterMap
for a givendevice_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)
Changed
-
GameActivity updated to 2.0.2 (requires the corresponding 2.0.2
.aar
release from Google) (#88) -
AndroidApp::input_events()
is replaced byAndroidApp::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:?}"); } }
New Contributors
- @lexi-the-cute made their first contribution in #88
- @daxpedda made their first contribution in #85
Full Changelog: v0.4.3...v0.5.0-beta.0