mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-09 08:17:28 +00:00
Add show/hide_soft_input methods
This adds `AndroidApp::show/hide_soft_input` APIs for showing or hiding the user's on-screen keyboard. (supported for NativeActivity and GameActivity) Addresses: #18
This commit is contained in:
@@ -320,6 +320,32 @@ impl AndroidAppInner {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move into a trait
|
||||
pub fn show_soft_input(&self, show_implicit: bool) {
|
||||
unsafe {
|
||||
let activity = (*self.native_app.as_ptr()).activity;
|
||||
let flags = if show_implicit {
|
||||
ffi::ShowImeFlags_SHOW_IMPLICIT
|
||||
} else {
|
||||
0
|
||||
};
|
||||
ffi::GameActivity_showSoftInput(activity, flags);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move into a trait
|
||||
pub fn hide_soft_input(&self, hide_implicit_only: bool) {
|
||||
unsafe {
|
||||
let activity = (*self.native_app.as_ptr()).activity;
|
||||
let flags = if hide_implicit_only {
|
||||
ffi::HideImeFlags_HIDE_IMPLICIT_ONLY
|
||||
} else {
|
||||
0
|
||||
};
|
||||
ffi::GameActivity_hideSoftInput(activity, flags);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enable_motion_axis(&mut self, axis: Axis) {
|
||||
unsafe { ffi::GameActivityPointerAxes_enableAxis(axis as i32) }
|
||||
}
|
||||
|
||||
@@ -442,10 +442,35 @@ impl AndroidApp {
|
||||
self.inner.write().unwrap().enable_motion_axis(axis);
|
||||
}
|
||||
|
||||
/// Disable input axis
|
||||
///
|
||||
/// To reduce overhead, by default only [`input::Axis::X`] and [`input::Axis::Y`] are enabled
|
||||
/// and other axis should be enabled explicitly.
|
||||
pub fn disable_motion_axis(&self, axis: input::Axis) {
|
||||
self.inner.write().unwrap().disable_motion_axis(axis);
|
||||
}
|
||||
|
||||
/// Explicitly request that the current input method's soft input area be
|
||||
/// shown to the user, if needed.
|
||||
///
|
||||
/// Call this if the user interacts with your view in such a way that they
|
||||
/// have expressed they would like to start performing input into it.
|
||||
pub fn show_soft_input(&self, show_implicit: bool) {
|
||||
self.inner.read().unwrap().show_soft_input(show_implicit);
|
||||
}
|
||||
|
||||
/// Request to hide the soft input window from the context of the window
|
||||
/// that is currently accepting input.
|
||||
///
|
||||
/// This should be called as a result of the user doing some action that
|
||||
/// fairly explicitly requests to have the input window hidden.
|
||||
pub fn hide_soft_input(&self, hide_implicit_only: bool) {
|
||||
self.inner
|
||||
.read()
|
||||
.unwrap()
|
||||
.hide_soft_input(hide_implicit_only);
|
||||
}
|
||||
|
||||
/// Query and process all out-standing input event
|
||||
///
|
||||
/// Applications are generally either expected to call this in-sync with their rendering or
|
||||
|
||||
@@ -369,6 +369,32 @@ 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 {
|
||||
ffi::ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT
|
||||
} else {
|
||||
0
|
||||
};
|
||||
ffi::ANativeActivity_showSoftInput(na as *mut _, flags);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move into a trait
|
||||
pub fn hide_soft_input(&self, hide_implicit_only: bool) {
|
||||
let na = self.native_activity();
|
||||
unsafe {
|
||||
let flags = if hide_implicit_only {
|
||||
ffi::ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY
|
||||
} else {
|
||||
0
|
||||
};
|
||||
ffi::ANativeActivity_hideSoftInput(na as *mut _, flags);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enable_motion_axis(&self, _axis: input::Axis) {
|
||||
// NOP - The InputQueue API doesn't let us optimize which axis values are read
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user