Skip to main content

ferroui_android/automation/
i_node_info_provider.rs

1use super::node_info::NodeInfo;
2use ferroui_controls::automation::ElementNotEnabledException;
3
4/// The arguments of an action of a node: what the access helper reads of
5/// the bundle of the system.
6#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub struct NodeActionArguments {
8    /// The text of `ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE`.
9    pub set_text_char_sequence: Option<String>,
10}
11
12/// Why an action of a node was not performed. The access helper answers
13/// the system with "not performed" for each of them.
14#[derive(Debug)]
15pub enum NodeActionError {
16    /// The element of the peer is not enabled.
17    ElementNotEnabled(ElementNotEnabledException),
18    /// The peer cannot do what was asked in its state.
19    InvalidOperation(String),
20    /// The peer does not support what was asked.
21    NotSupported(String),
22}
23
24impl From<ElementNotEnabledException> for NodeActionError {
25    fn from(error: ElementNotEnabledException) -> Self {
26        Self::ElementNotEnabled(error)
27    }
28}
29
30impl std::fmt::Display for NodeActionError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Self::ElementNotEnabled(_) => f.write_str("Element not enabled."),
34            Self::InvalidOperation(message) | Self::NotSupported(message) => f.write_str(message),
35        }
36    }
37}
38
39impl std::error::Error for NodeActionError {}
40
41pub trait INodeInfoProvider {
42    fn virtual_view_id(&self) -> i32;
43
44    fn perform_node_action(&self, action: i32, arguments: Option<&NodeActionArguments>) -> Result<bool, NodeActionError>;
45
46    fn populate_node_info(&self, node_info: &mut NodeInfo) -> Result<(), NodeActionError>;
47}