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
This commit is contained in:
Robert Bragg
2022-09-19 21:36:46 +01:00
parent 6245866228
commit 7cdb77eca4
18 changed files with 97 additions and 39 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent};
use log::info;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
@@ -131,6 +131,7 @@ fn android_main(app: AndroidApp) {
// Handle input
app.input_events(|event| {
info!("Input Event: {event:?}");
InputStatus::Unhandled
});
info!("Render...");
+2
View File
@@ -75,6 +75,8 @@ dependencies = [
[[package]]
name = "android-activity"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe057899cd59c5254279b74382bf8132d683f8619ea50592c096710d65d03902"
dependencies = [
"android-properties",
"bitflags",
+11 -4
View File
@@ -38,10 +38,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity" }
# entrypoint for a native Rust application there can only be a single
# implementation of the crate linked with the application.
#
# Since Winit also depends on android-activity (version = "0.2") but we'd like
# to build against the local version of android-activity in this repo then we
# use a [patch] to ensure we only end up with a single implementation.
android-activity = { path = "../../android-activity" }
# By default the Winit-based examples use released versions of android-activity
# to help keep the version in sync with the Winit backend.
#
# If you'd like to build this example against the local checkout of
# android-activity you should specify a patch here to make sure you also affect
# the version that Winit uses.
#
# Note: also check that the local android-activity/Cargo.toml version matches
# the android-activity version that Winit depends on (in case you need to check
# out a release branch locally to be compatible)
#android-activity = { path = "../../android-activity" }
# Egui 0.19 is missing some fixes for Android so we need to build against
# git master for now
+2
View File
@@ -76,6 +76,8 @@ dependencies = [
[[package]]
name = "android-activity"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe057899cd59c5254279b74382bf8132d683f8619ea50592c096710d65d03902"
dependencies = [
"android-properties",
"bitflags",
+11 -4
View File
@@ -39,10 +39,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity" }
# entrypoint for a native Rust application there can only be a single
# implementation of the crate linked with the application.
#
# Since Winit also depends on android-activity (version = "0.2") but we'd like
# to build against the local version of android-activity in this repo then we
# use a [patch] to ensure we only end up with a single implementation.
android-activity = { path = "../../android-activity" }
# By default the Winit-based examples use released versions of android-activity
# to help keep the version in sync with the Winit backend.
#
# If you'd like to build this example against the local checkout of
# android-activity you should specify a patch here to make sure you also affect
# the version that Winit uses.
#
# Note: also check that the local android-activity/Cargo.toml version matches
# the android-activity version that Winit depends on (in case you need to check
# out a release branch locally to be compatible)
#android-activity = { path = "../../android-activity" }
[features]
default = []
+2 -1
View File
@@ -1,4 +1,4 @@
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent};
use log::info;
#[no_mangle]
@@ -71,6 +71,7 @@ fn android_main(app: AndroidApp) {
// Handle input
app.input_events(|event| {
info!("Input Event: {event:?}");
InputStatus::Unhandled
});
info!("Render...");
+5 -2
View File
@@ -43,6 +43,7 @@ impl SineGen {
}
/// Pause audio stream
#[allow(dead_code)]
pub fn try_pause(&mut self) {
if let Some(stream) = &mut self.stream {
log::debug!("pause stream: {:?}", stream);
@@ -92,6 +93,7 @@ impl SineParam {
);
}
#[allow(dead_code)]
fn set_frequency(&self, frequency: f32) {
let sample_rate = self.sample_rate.load(Ordering::Relaxed);
let delta = frequency * 2.0 * PI / sample_rate;
@@ -100,6 +102,7 @@ impl SineParam {
self.frequency.store(frequency, Ordering::Relaxed);
}
#[allow(dead_code)]
fn set_gain(&self, gain: f32) {
self.gain.store(gain, Ordering::Relaxed);
}
@@ -151,7 +154,7 @@ impl AudioOutputCallback for SineWave<f32, Mono> {
fn on_audio_ready(
&mut self,
stream: &mut dyn AudioOutputStreamSafe,
_stream: &mut dyn AudioOutputStreamSafe,
frames: &mut [f32],
) -> DataCallbackResult {
for frame in frames {
@@ -166,7 +169,7 @@ impl AudioOutputCallback for SineWave<f32, Stereo> {
fn on_audio_ready(
&mut self,
stream: &mut dyn AudioOutputStreamSafe,
_stream: &mut dyn AudioOutputStreamSafe,
frames: &mut [(f32, f32)],
) -> DataCallbackResult {
for frame in frames {
+2 -1
View File
@@ -1,4 +1,4 @@
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_activity::{AndroidApp, MainEvent, PollEvent, InputStatus};
use log::info;
mod audio;
@@ -75,6 +75,7 @@ fn android_main(app: AndroidApp) {
// Handle input
app.input_events(|event| {
info!("Input Event: {event:?}");
InputStatus::Unhandled
});
info!("Render...");
+2
View File
@@ -60,6 +60,8 @@ dependencies = [
[[package]]
name = "android-activity"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe057899cd59c5254279b74382bf8132d683f8619ea50592c096710d65d03902"
dependencies = [
"android-properties",
"bitflags",
+11 -4
View File
@@ -34,10 +34,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity-0.27"
# entrypoint for a native Rust application there can only be a single
# implementation of the crate linked with the application.
#
# Since Winit also depends on android-activity (version = "0.2") but we'd like
# to build against the local version of android-activity in this repo then we
# use a [patch] to ensure we only end up with a single implementation.
android-activity = { path="../../android-activity" }
# By default the Winit-based examples use released versions of android-activity
# to help keep the version in sync with the Winit backend.
#
# If you'd like to build this example against the local checkout of
# android-activity you should specify a patch here to make sure you also affect
# the version that Winit uses.
#
# Note: also check that the local android-activity/Cargo.toml version matches
# the android-activity version that Winit depends on (in case you need to check
# out a release branch locally to be compatible)
#android-activity = { path = "../../android-activity" }
[features]
default = []
+2 -1
View File
@@ -1,4 +1,4 @@
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_activity::{AndroidApp, MainEvent, PollEvent, InputStatus};
use log::info;
#[no_mangle]
@@ -71,6 +71,7 @@ fn android_main(app: AndroidApp) {
// Handle input
app.input_events(|event| {
info!("Input Event: {event:?}");
InputStatus::Unhandled
});
info!("Render...");
+2 -1
View File
@@ -1,4 +1,4 @@
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_activity::{AndroidApp, MainEvent, PollEvent, InputStatus};
use log::Level;
use log::{info, trace};
use serde::{Deserialize, Serialize};
@@ -77,6 +77,7 @@ fn android_main(app: AndroidApp) {
// Handle input
app.input_events(|event| {
info!("Input Event: {event:?}");
InputStatus::Unhandled
});
// Render...
+2
View File
@@ -47,6 +47,8 @@ dependencies = [
[[package]]
name = "android-activity"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe057899cd59c5254279b74382bf8132d683f8619ea50592c096710d65d03902"
dependencies = [
"android-properties",
"bitflags",
+11 -4
View File
@@ -34,10 +34,17 @@ winit = { git = "https://github.com/rib/winit", branch = "android-activity-0.27"
# entrypoint for a native Rust application there can only be a single
# implementation of the crate linked with the application.
#
# Since Winit also depends on android-activity (version = "0.2") but we'd like
# to build against the local version of android-activity in this repo then we
# use a [patch] to ensure we only end up with a single implementation.
android-activity = { path="../../android-activity" }
# By default the Winit-based examples use released versions of android-activity
# to help keep the version in sync with the Winit backend.
#
# If you'd like to build this example against the local checkout of
# android-activity you should specify a patch here to make sure you also affect
# the version that Winit uses.
#
# Note: also check that the local android-activity/Cargo.toml version matches
# the android-activity version that Winit depends on (in case you need to check
# out a release branch locally to be compatible)
#android-activity = { path = "../../android-activity" }
[features]
default = []