Skip to content

Commit 6c85ba1

Browse files
committed
Let applications report if they handled input events
The callback given to `AndroidApp::input_events()` is now expected to return `InputStatus::Handled` or `InputStatus::Unhandled`. When running with NativeActivity then if we know an input event hasn't been handled we can notify the InputQueue which may result in fallback handling. Although the status is currently ignored with the GameActivity backend. Since this is a breaking change that also affects the current Winit backend this updates the winit based examples to stick with the 0.3 release of android-activity for now. Fixes: #31
1 parent 4c286e5 commit 6c85ba1

File tree

14 files changed

+67
-23
lines changed

14 files changed

+67
-23
lines changed

agdk-cpal/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use android_activity::{AndroidApp, MainEvent, PollEvent};
1+
use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent};
22
use log::info;
33

44
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
@@ -131,6 +131,7 @@ fn android_main(app: AndroidApp) {
131131
// Handle input
132132
app.input_events(|event| {
133133
info!("Input Event: {event:?}");
134+
InputStatus::Unhandled
134135
});
135136

136137
info!("Render...");

agdk-eframe/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agdk-eframe/Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity" }
3838
# entrypoint for a native Rust application there can only be a single
3939
# implementation of the crate linked with the application.
4040
#
41-
# Since Winit also depends on android-activity (version = "0.2") but we'd like
42-
# to build against the local version of android-activity in this repo then we
43-
# use a [patch] to ensure we only end up with a single implementation.
44-
android-activity = { path = "../../android-activity" }
41+
# By default the Winit-based examples use released versions of android-activity
42+
# to help keep the version in sync with the Winit backend.
43+
#
44+
# If you'd like to build this example against the local checkout of
45+
# android-activity you should specify a patch here to make sure you also affect
46+
# the version that Winit uses.
47+
#
48+
# Note: also check that the local android-activity/Cargo.toml version matches
49+
# the android-activity version that Winit depends on (in case you need to check
50+
# out a release branch locally to be compatible)
51+
#android-activity = { path = "../../android-activity" }
4552

4653
# Egui 0.19 is missing some fixes for Android so we need to build against
4754
# git master for now

agdk-egui/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agdk-egui/Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity" }
3939
# entrypoint for a native Rust application there can only be a single
4040
# implementation of the crate linked with the application.
4141
#
42-
# Since Winit also depends on android-activity (version = "0.2") but we'd like
43-
# to build against the local version of android-activity in this repo then we
44-
# use a [patch] to ensure we only end up with a single implementation.
45-
android-activity = { path = "../../android-activity" }
42+
# By default the Winit-based examples use released versions of android-activity
43+
# to help keep the version in sync with the Winit backend.
44+
#
45+
# If you'd like to build this example against the local checkout of
46+
# android-activity you should specify a patch here to make sure you also affect
47+
# the version that Winit uses.
48+
#
49+
# Note: also check that the local android-activity/Cargo.toml version matches
50+
# the android-activity version that Winit depends on (in case you need to check
51+
# out a release branch locally to be compatible)
52+
#android-activity = { path = "../../android-activity" }
4653

4754
[features]
4855
default = []

agdk-mainloop/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use android_activity::{AndroidApp, MainEvent, PollEvent};
1+
use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent};
22
use log::info;
33

44
#[no_mangle]
@@ -71,6 +71,7 @@ fn android_main(app: AndroidApp) {
7171
// Handle input
7272
app.input_events(|event| {
7373
info!("Input Event: {event:?}");
74+
InputStatus::Unhandled
7475
});
7576

7677
info!("Render...");

agdk-oboe/src/audio.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl SineGen {
4343
}
4444

4545
/// Pause audio stream
46+
#[allow(dead_code)]
4647
pub fn try_pause(&mut self) {
4748
if let Some(stream) = &mut self.stream {
4849
log::debug!("pause stream: {:?}", stream);
@@ -92,6 +93,7 @@ impl SineParam {
9293
);
9394
}
9495

96+
#[allow(dead_code)]
9597
fn set_frequency(&self, frequency: f32) {
9698
let sample_rate = self.sample_rate.load(Ordering::Relaxed);
9799
let delta = frequency * 2.0 * PI / sample_rate;
@@ -100,6 +102,7 @@ impl SineParam {
100102
self.frequency.store(frequency, Ordering::Relaxed);
101103
}
102104

105+
#[allow(dead_code)]
103106
fn set_gain(&self, gain: f32) {
104107
self.gain.store(gain, Ordering::Relaxed);
105108
}
@@ -151,7 +154,7 @@ impl AudioOutputCallback for SineWave<f32, Mono> {
151154

152155
fn on_audio_ready(
153156
&mut self,
154-
stream: &mut dyn AudioOutputStreamSafe,
157+
_stream: &mut dyn AudioOutputStreamSafe,
155158
frames: &mut [f32],
156159
) -> DataCallbackResult {
157160
for frame in frames {
@@ -166,7 +169,7 @@ impl AudioOutputCallback for SineWave<f32, Stereo> {
166169

167170
fn on_audio_ready(
168171
&mut self,
169-
stream: &mut dyn AudioOutputStreamSafe,
172+
_stream: &mut dyn AudioOutputStreamSafe,
170173
frames: &mut [(f32, f32)],
171174
) -> DataCallbackResult {
172175
for frame in frames {

agdk-oboe/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use android_activity::{AndroidApp, MainEvent, PollEvent};
1+
use android_activity::{AndroidApp, MainEvent, PollEvent, InputStatus};
22
use log::info;
33

44
mod audio;
@@ -75,6 +75,7 @@ fn android_main(app: AndroidApp) {
7575
// Handle input
7676
app.input_events(|event| {
7777
info!("Input Event: {event:?}");
78+
InputStatus::Unhandled
7879
});
7980

8081
info!("Render...");

agdk-winit-wgpu/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agdk-winit-wgpu/Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity-0.27"
3434
# entrypoint for a native Rust application there can only be a single
3535
# implementation of the crate linked with the application.
3636
#
37-
# Since Winit also depends on android-activity (version = "0.2") but we'd like
38-
# to build against the local version of android-activity in this repo then we
39-
# use a [patch] to ensure we only end up with a single implementation.
40-
android-activity = { path="../../android-activity" }
37+
# By default the Winit-based examples use released versions of android-activity
38+
# to help keep the version in sync with the Winit backend.
39+
#
40+
# If you'd like to build this example against the local checkout of
41+
# android-activity you should specify a patch here to make sure you also affect
42+
# the version that Winit uses.
43+
#
44+
# Note: also check that the local android-activity/Cargo.toml version matches
45+
# the android-activity version that Winit depends on (in case you need to check
46+
# out a release branch locally to be compatible)
47+
#android-activity = { path = "../../android-activity" }
4148

4249
[features]
4350
default = []

0 commit comments

Comments
 (0)