mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-04 05:47:26 +00:00
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:
@@ -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...");
|
||||
|
||||
Generated
+2
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Generated
+2
@@ -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",
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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...");
|
||||
|
||||
Generated
+2
@@ -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",
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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...
|
||||
|
||||
Generated
+2
@@ -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",
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user