Skip to content
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

JNI based show_soft_input #178

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
53 changes: 44 additions & 9 deletions android-activity/src/native_activity/mod.rs
Original file line number Diff line number Diff line change
@@ -353,15 +353,50 @@ impl AndroidAppInner {

// TODO: move into a trait
pub fn show_soft_input(&self, show_implicit: bool) {
let na = self.native_activity();
unsafe {
let flags = if show_implicit {
ndk_sys::ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT
} else {
0
};
ndk_sys::ANativeActivity_showSoftInput(na as *mut _, flags);
}
let na = unsafe { jni::objects::JObject::from_raw(self.activity_as_ptr() as _) };
let jvm = self.jvm.clone();
let mut env = jvm.attach_current_thread().unwrap();
let class_ctxt = env.find_class("android/content/Context").unwrap();
let ims = env
.get_static_field(class_ctxt, "INPUT_METHOD_SERVICE", "Ljava/lang/String;")
.unwrap();

let im_manager = env
.call_method(
&na,
"getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;",
&[ims.borrow()],
)
.unwrap()
.l()
.unwrap();

let jni_window = env
.call_method(na, "getWindow", "()Landroid/view/Window;", &[])
.unwrap()
.l()
.unwrap();
let view = env
.call_method(jni_window, "getDecorView", "()Landroid/view/View;", &[])
.unwrap()
.l()
.unwrap();

env.call_method(
im_manager,
"showSoftInput",
"(Landroid/view/View;I)Z",
&[
jni::objects::JValue::Object(&view),
if show_implicit {
(ndk_sys::ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT as i32).into()
} else {
0i32.into()
},
],
)
.unwrap();
}

// TODO: move into a trait

Unchanged files with check annotations Beta

use ndk_sys::{AAssetManager, AConfiguration, ALooper, ALooper_callbackFunc, ANativeWindow, ARect};
#[cfg(all(
any(target_os = "android", feature = "test"),

Check failure on line 20 in android-activity/src/game_activity/ffi.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `test`
any(target_arch = "arm", target_arch = "armv7")

Check failure on line 21 in android-activity/src/game_activity/ffi.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `armv7`
))]
include!("ffi_arm.rs");
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "aarch64"))]

Check failure on line 25 in android-activity/src/game_activity/ffi.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `test`
include!("ffi_aarch64.rs");
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86"))]

Check failure on line 28 in android-activity/src/game_activity/ffi.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `test`
include!("ffi_i686.rs");
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86_64"))]

Check failure on line 31 in android-activity/src/game_activity/ffi.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `test`
include!("ffi_x86_64.rs");
self.config.read().unwrap().screen_long()
}
#[cfg(feature = "api-level-30")]

Check failure on line 123 in android-activity/src/config.rs

GitHub Actions / build (stable)

unexpected `cfg` condition value: `api-level-30`
pub fn screen_round(&self) -> ScreenRound {
self.config.read().unwrap().screen_round()
}