|
1 | | -<!-- markdownlint-disable MD022 MD024 MD032 --> |
| 1 | +<!-- markdownlint-disable MD022 MD024 MD032 MD033 --> |
2 | 2 |
|
3 | 3 | # Changelog |
4 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
5 | 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
6 | 6 |
|
7 | 7 | ## [Unreleased] |
| 8 | + |
| 9 | +### Added |
| 10 | +- Added `KeyEvent::meta_state()` for being able to query the state of meta keys, needed for character mapping ([#102](https://github.com/rust-mobile/android-activity/pull/102)) |
| 11 | +- Added `KeyCharacterMap` JNI bindings to the corresponding Android SDK API ([#102](https://github.com/rust-mobile/android-activity/pull/102)) |
| 12 | +- Added `AndroidApp::device_key_character_map()` for being able to get a `KeyCharacterMap` for a given `device_id` for unicode character mapping ([#102](https://github.com/rust-mobile/android-activity/pull/102)) |
| 13 | + |
| 14 | + <details> |
| 15 | + <summary>Click here for an example of how to handle unicode character mapping:</summary> |
| 16 | + |
| 17 | + ```rust |
| 18 | + let mut combining_accent = None; |
| 19 | + // Snip |
| 20 | + |
| 21 | + |
| 22 | + let combined_key_char = if let Ok(map) = app.device_key_character_map(device_id) { |
| 23 | + match map.get(key_event.key_code(), key_event.meta_state()) { |
| 24 | + Ok(KeyMapChar::Unicode(unicode)) => { |
| 25 | + let combined_unicode = if let Some(accent) = combining_accent { |
| 26 | + match map.get_dead_char(accent, unicode) { |
| 27 | + Ok(Some(key)) => { |
| 28 | + info!("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'"); |
| 29 | + Some(key) |
| 30 | + } |
| 31 | + Ok(None) => None, |
| 32 | + Err(err) => { |
| 33 | + log::error!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}"); |
| 34 | + None |
| 35 | + } |
| 36 | + } |
| 37 | + } else { |
| 38 | + info!("KeyEvent: Pressed '{unicode}'"); |
| 39 | + Some(unicode) |
| 40 | + }; |
| 41 | + combining_accent = None; |
| 42 | + combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode)) |
| 43 | + } |
| 44 | + Ok(KeyMapChar::CombiningAccent(accent)) => { |
| 45 | + info!("KeyEvent: Pressed 'dead key' combining accent '{accent}'"); |
| 46 | + combining_accent = Some(accent); |
| 47 | + Some(KeyMapChar::CombiningAccent(accent)) |
| 48 | + } |
| 49 | + Ok(KeyMapChar::None) => { |
| 50 | + info!("KeyEvent: Pressed non-unicode key"); |
| 51 | + combining_accent = None; |
| 52 | + None |
| 53 | + } |
| 54 | + Err(err) => { |
| 55 | + log::error!("KeyEvent: Failed to get key map character: {err:?}"); |
| 56 | + combining_accent = None; |
| 57 | + None |
| 58 | + } |
| 59 | + } |
| 60 | + } else { |
| 61 | + None |
| 62 | + }; |
| 63 | + ``` |
| 64 | + |
| 65 | + </details> |
| 66 | + |
8 | 67 | ### Changed |
9 | 68 | - GameActivity updated to 2.0.2 (requires the corresponding 2.0.2 `.aar` release from Google) ([#88](https://github.com/rust-mobile/android-activity/pull/88)) |
| 69 | +- `AndroidApp::input_events()` is replaced by `AndroidApp::input_events_iter()` ([#102](https://github.com/rust-mobile/android-activity/pull/102)) |
| 70 | + |
| 71 | + <details> |
| 72 | + <summary>Click here for an example of how to use `input_events_iter()`:</summary> |
| 73 | + |
| 74 | + ```rust |
| 75 | + match app.input_events_iter() { |
| 76 | + Ok(mut iter) => { |
| 77 | + loop { |
| 78 | + let read_input = iter.next(|event| { |
| 79 | + let handled = match event { |
| 80 | + InputEvent::KeyEvent(key_event) => { |
| 81 | + // Snip |
| 82 | + } |
| 83 | + InputEvent::MotionEvent(motion_event) => { |
| 84 | + // Snip |
| 85 | + } |
| 86 | + event => { |
| 87 | + // Snip |
| 88 | + } |
| 89 | + }; |
| 90 | + |
| 91 | + handled |
| 92 | + }); |
| 93 | + |
| 94 | + if !read_input { |
| 95 | + break; |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + Err(err) => { |
| 100 | + log::error!("Failed to get input events iterator: {err:?}"); |
| 101 | + } |
| 102 | + } |
| 103 | + ``` |
| 104 | + |
| 105 | + </details> |
10 | 106 |
|
11 | 107 | ## [0.4.3] - 2022-07-30 |
12 | 108 | ### Fixed |
|
0 commit comments