Skip to content

Commit 7ac5911

Browse files
authored
refactor!: Simplify the core Android adapter API (#558)
1 parent 10f4bd1 commit 7ac5911

File tree

12 files changed

+1053
-864
lines changed

12 files changed

+1053
-864
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platforms/android/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ accesskit = { version = "0.18.0", path = "../../common" }
1919
accesskit_consumer = { version = "0.27.0", path = "../../consumer" }
2020
jni = "0.21.1"
2121
log = "0.4.17"
22-
once_cell = "1.17.1"
23-

platforms/android/classes.dex

-6.76 KB
Binary file not shown.

platforms/android/java/dev/accesskit/android/Delegate.java

Lines changed: 22 additions & 335 deletions
Large diffs are not rendered by default.

platforms/android/src/action.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 The AccessKit Authors. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0 (found in
3+
// the LICENSE-APACHE file) or the MIT license (found in
4+
// the LICENSE-MIT file), at your option.
5+
6+
use jni::{objects::JObject, sys::jint, JNIEnv};
7+
8+
use crate::util::*;
9+
10+
pub(crate) enum PlatformActionInner {
11+
Simple {
12+
action: jint,
13+
},
14+
SetTextSelection {
15+
anchor: jint,
16+
focus: jint,
17+
},
18+
CollapseTextSelection,
19+
TraverseText {
20+
granularity: jint,
21+
forward: bool,
22+
extend_selection: bool,
23+
},
24+
}
25+
26+
pub struct PlatformAction(pub(crate) PlatformActionInner);
27+
28+
impl PlatformAction {
29+
pub fn from_java(env: &mut JNIEnv, action: jint, arguments: &JObject) -> Option<Self> {
30+
match action {
31+
ACTION_SET_SELECTION => {
32+
if !(!arguments.is_null()
33+
&& bundle_contains_key(env, arguments, ACTION_ARGUMENT_SELECTION_START_INT)
34+
&& bundle_contains_key(env, arguments, ACTION_ARGUMENT_SELECTION_END_INT))
35+
{
36+
return Some(Self(PlatformActionInner::CollapseTextSelection));
37+
}
38+
let anchor = bundle_get_int(env, arguments, ACTION_ARGUMENT_SELECTION_START_INT);
39+
let focus = bundle_get_int(env, arguments, ACTION_ARGUMENT_SELECTION_END_INT);
40+
Some(Self(PlatformActionInner::SetTextSelection {
41+
anchor,
42+
focus,
43+
}))
44+
}
45+
ACTION_NEXT_AT_MOVEMENT_GRANULARITY | ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY => {
46+
if arguments.is_null()
47+
|| !bundle_contains_key(
48+
env,
49+
arguments,
50+
ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
51+
)
52+
{
53+
return None;
54+
}
55+
let granularity =
56+
bundle_get_int(env, arguments, ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT);
57+
let forward = action == ACTION_NEXT_AT_MOVEMENT_GRANULARITY;
58+
let extend_selection =
59+
bundle_get_bool(env, arguments, ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN);
60+
Some(Self(PlatformActionInner::TraverseText {
61+
granularity,
62+
forward,
63+
extend_selection,
64+
}))
65+
}
66+
_ => Some(Self(PlatformActionInner::Simple { action })),
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)