Skip to content

refactor!: Simplify the core Android adapter API #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions platforms/android/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ accesskit = { version = "0.18.0", path = "../../common" }
accesskit_consumer = { version = "0.27.0", path = "../../consumer" }
jni = "0.21.1"
log = "0.4.17"
once_cell = "1.17.1"

Binary file modified platforms/android/classes.dex
Binary file not shown.
357 changes: 22 additions & 335 deletions platforms/android/java/dev/accesskit/android/Delegate.java

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions platforms/android/src/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2025 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use jni::{objects::JObject, sys::jint, JNIEnv};

use crate::util::*;

pub(crate) enum PlatformActionInner {
Simple {
action: jint,
},
SetTextSelection {
anchor: jint,
focus: jint,
},
CollapseTextSelection,
TraverseText {
granularity: jint,
forward: bool,
extend_selection: bool,
},
}

pub struct PlatformAction(pub(crate) PlatformActionInner);

impl PlatformAction {
pub fn from_java(env: &mut JNIEnv, action: jint, arguments: &JObject) -> Option<Self> {
match action {
ACTION_SET_SELECTION => {
if !(!arguments.is_null()
&& bundle_contains_key(env, arguments, ACTION_ARGUMENT_SELECTION_START_INT)
&& bundle_contains_key(env, arguments, ACTION_ARGUMENT_SELECTION_END_INT))
{
return Some(Self(PlatformActionInner::CollapseTextSelection));
}
let anchor = bundle_get_int(env, arguments, ACTION_ARGUMENT_SELECTION_START_INT);
let focus = bundle_get_int(env, arguments, ACTION_ARGUMENT_SELECTION_END_INT);
Some(Self(PlatformActionInner::SetTextSelection {
anchor,
focus,
}))
}
ACTION_NEXT_AT_MOVEMENT_GRANULARITY | ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY => {
if arguments.is_null()
|| !bundle_contains_key(
env,
arguments,
ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
)
{
return None;
}
let granularity =
bundle_get_int(env, arguments, ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT);
let forward = action == ACTION_NEXT_AT_MOVEMENT_GRANULARITY;
let extend_selection =
bundle_get_bool(env, arguments, ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN);
Some(Self(PlatformActionInner::TraverseText {
granularity,
forward,
extend_selection,
}))
}
_ => Some(Self(PlatformActionInner::Simple { action })),
}
}
}
Loading
Loading