-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from rust-mobile/rib/pr/input-api-rework-with…
…-key-character-maps Rework `input_events` API and expose `KeyCharacterMap` bindings
- Loading branch information
Showing
15 changed files
with
1,555 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
The third-party glue code, under the native-activity-csrc/ and game-activity-csrc/ directories | ||
is covered by the Apache 2.0 license only: | ||
# License | ||
|
||
Apache License, Version 2.0 (docs/LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) | ||
## GameActivity | ||
|
||
The third-party glue code, under the game-activity-csrc/ directory is covered by | ||
the Apache 2.0 license only: | ||
|
||
Apache License, Version 2.0 (docs/LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>) | ||
|
||
## SDK Documentation | ||
|
||
Documentation for APIs that are direct bindings of Android platform APIs are covered | ||
by the Apache 2.0 license only: | ||
|
||
Apache License, Version 2.0 (docs/LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>) | ||
|
||
## android-activity | ||
|
||
All other code is dual-licensed under either | ||
|
||
* MIT License (docs/LICENSE-MIT or http://opensource.org/licenses/MIT) | ||
* Apache License, Version 2.0 (docs/LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) | ||
- MIT License (docs/LICENSE-MIT or <http://opensource.org/licenses/MIT>) | ||
- Apache License, Version 2.0 (docs/LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>) | ||
|
||
at your option. | ||
at your option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum AppError { | ||
#[error("Operation only supported from the android_main() thread: {0}")] | ||
NonMainThread(String), | ||
|
||
#[error("Java VM or JNI error, including Java exceptions")] | ||
JavaError(String), | ||
|
||
#[error("Input unavailable")] | ||
InputUnavailable, | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, AppError>; | ||
|
||
// XXX: we don't want to expose jni-rs in the public API | ||
// so we have an internal error type that we can generally | ||
// use in the backends and then we can strip the error | ||
// in the frontend of the API. | ||
// | ||
// This way we avoid exposing a public trait implementation for | ||
// `From<jni::errors::Error>` | ||
#[derive(Error, Debug)] | ||
pub(crate) enum InternalAppError { | ||
#[error("A JNI error")] | ||
JniError(jni::errors::JniError), | ||
#[error("A Java Exception was thrown via a JNI method call")] | ||
JniException(String), | ||
#[error("A Java VM error")] | ||
JvmError(jni::errors::Error), | ||
#[error("Input unavailable")] | ||
InputUnavailable, | ||
} | ||
|
||
pub(crate) type InternalResult<T> = std::result::Result<T, InternalAppError>; | ||
|
||
impl From<jni::errors::Error> for InternalAppError { | ||
fn from(value: jni::errors::Error) -> Self { | ||
InternalAppError::JvmError(value) | ||
} | ||
} | ||
impl From<jni::errors::JniError> for InternalAppError { | ||
fn from(value: jni::errors::JniError) -> Self { | ||
InternalAppError::JniError(value) | ||
} | ||
} | ||
|
||
impl From<InternalAppError> for AppError { | ||
fn from(value: InternalAppError) -> Self { | ||
match value { | ||
InternalAppError::JniError(err) => AppError::JavaError(err.to_string()), | ||
InternalAppError::JniException(msg) => AppError::JavaError(msg), | ||
InternalAppError::JvmError(err) => AppError::JavaError(err.to_string()), | ||
InternalAppError::InputUnavailable => AppError::InputUnavailable, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.