File tree 3 files changed +40
-0
lines changed
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 7
7
//! javadoc](https://developer.android.com/reference/android/content/res/Configuration.html) may
8
8
//! also have useful information.
9
9
10
+ use crate :: asset:: AssetManager ;
10
11
use num_enum:: { IntoPrimitive , TryFromPrimitive } ;
11
12
use std:: convert:: TryInto ;
12
13
use std:: fmt;
@@ -92,6 +93,14 @@ impl Configuration {
92
93
self . ptr
93
94
}
94
95
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
+
95
104
/// Create a new `Configuration`, with none of the values set.
96
105
pub fn new ( ) -> Self {
97
106
unsafe {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use std::ptr;
5
5
use std:: ptr:: NonNull ;
6
6
7
7
use crate :: event:: InputEvent ;
8
+ use crate :: looper:: ForeignLooper ;
8
9
9
10
// TODO docs
10
11
#[ derive( Debug ) ]
@@ -69,4 +70,22 @@ impl InputQueue {
69
70
ffi:: AInputQueue_finishEvent ( self . ptr . as_ptr ( ) , event. ptr ( ) . as_ptr ( ) , handled as c_int ) ;
70
71
}
71
72
}
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
+ }
72
91
}
Original file line number Diff line number Diff line change @@ -53,6 +53,18 @@ impl fmt::Display for LooperError {
53
53
impl std:: error:: Error for LooperError { }
54
54
55
55
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
+
56
68
/// Returns the looper associated with the current thread, if any.
57
69
pub fn for_thread ( ) -> Option < Self > {
58
70
Some ( Self {
You can’t perform that action at this time.
0 commit comments