Skip to main content

ferroui_android/
i_activity_result_handler.rs

1//! The results an activity receives: of an activity it started, and of a
2//! request for permissions.
3
4use std::rc::Rc;
5
6/// An `android.content.Intent`. On another system than Android, where the
7/// crate is its logic only, there is none.
8#[cfg(target_os = "android")]
9pub type Intent = crate::interop::java::JavaObject;
10#[cfg(not(target_os = "android"))]
11pub type Intent = std::convert::Infallible;
12
13/// `Activity.RESULT_OK`, `RESULT_CANCELED` and `RESULT_FIRST_USER` (the
14/// `Result` of the reference).
15pub const RESULT_OK: i32 = -1;
16pub const RESULT_CANCELED: i32 = 0;
17pub const RESULT_FIRST_USER: i32 = 1;
18
19/// `PackageManager.PERMISSION_GRANTED` and `PERMISSION_DENIED` (the
20/// `Permission` of the reference).
21pub const PERMISSION_GRANTED: i32 = 0;
22pub const PERMISSION_DENIED: i32 = -1;
23
24/// The request code, the result code and the intent of the result (an
25/// `android.content.Intent`), if any.
26pub type ActivityResultHandler = Rc<dyn Fn(i32, i32, Option<&Intent>)>;
27
28/// The request code, the permissions and what was granted of each.
29pub type RequestPermissionsResultHandler = Rc<dyn Fn(i32, &[String], &[i32])>;
30
31pub trait IActivityResultHandler {
32    fn activity_result(&self) -> Option<ActivityResultHandler>;
33
34    fn set_activity_result(&self, value: Option<ActivityResultHandler>);
35
36    fn request_permissions_result(&self) -> Option<RequestPermissionsResultHandler>;
37
38    fn set_request_permissions_result(&self, value: Option<RequestPermissionsResultHandler>);
39}