Skip to content

Commit 52c80a6

Browse files
committed
Add some missing functions.
* ThreadLooper::prepare * InputQueue::attach_looper * InputQueue::detach_looper * Configuration::from_asset_manager
1 parent e9349a3 commit 52c80a6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

android-ndk/src/configuration.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! javadoc](https://developer.android.com/reference/android/content/res/Configuration.html) may
88
//! also have useful information.
99
10+
use crate::asset::AssetManager;
1011
use num_enum::{IntoPrimitive, TryFromPrimitive};
1112
use std::convert::TryInto;
1213
use std::fmt;
@@ -92,6 +93,14 @@ impl Configuration {
9293
self.ptr
9394
}
9495

96+
pub fn from_asset_manager(am: &AssetManager) -> Self {
97+
let config = Self::new();
98+
unsafe {
99+
ffi::AConfiguration_fromAssetManager(config.ptr().as_mut(), am.ptr().as_mut());
100+
}
101+
config
102+
}
103+
95104
/// Create a new `Configuration`, with none of the values set.
96105
pub fn new() -> Self {
97106
unsafe {

android-ndk/src/input_queue.rs

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::ptr;
55
use std::ptr::NonNull;
66

77
use crate::event::InputEvent;
8+
use crate::looper::ForeignLooper;
89

910
// TODO docs
1011
#[derive(Debug)]
@@ -69,4 +70,22 @@ impl InputQueue {
6970
ffi::AInputQueue_finishEvent(self.ptr.as_ptr(), event.ptr().as_ptr(), handled as c_int);
7071
}
7172
}
73+
74+
pub fn attach_looper(&self, looper: &ForeignLooper, id: u32) {
75+
unsafe {
76+
ffi::AInputQueue_attachLooper(
77+
self.ptr.as_ptr(),
78+
looper.ptr().as_ptr(),
79+
id as _,
80+
None,
81+
id as _,
82+
);
83+
}
84+
}
85+
86+
pub fn detach_looper(&self) {
87+
unsafe {
88+
ffi::AInputQueue_detachLooper(self.ptr.as_ptr());
89+
}
90+
}
7291
}

android-ndk/src/looper.rs

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ impl fmt::Display for LooperError {
5353
impl std::error::Error for LooperError {}
5454

5555
impl ThreadLooper {
56+
/// Prepares a looper for the current thread and returns it
57+
pub fn prepare() -> Self {
58+
unsafe {
59+
let ptr = ffi::ALooper_prepare(ffi::ALOOPER_PREPARE_ALLOW_NON_CALLBACKS as _);
60+
let foreign = ForeignLooper::from_ptr(NonNull::new(ptr).expect("looper non null"));
61+
Self {
62+
_marker: std::marker::PhantomData,
63+
foreign,
64+
}
65+
}
66+
}
67+
5668
/// Returns the looper associated with the current thread, if any.
5769
pub fn for_thread() -> Option<Self> {
5870
Some(Self {

0 commit comments

Comments
 (0)