Skip to content

Commit

Permalink
native_activity: Add set_window_format() setter
Browse files Browse the repository at this point in the history
Allows setting the window format before a window is created, directly
through the `NativeActivity`.
  • Loading branch information
MarijnS95 committed May 20, 2022
1 parent 5bac4a1 commit 0369d85
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ndk/src/native_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! See also [the NDK
//! docs](https://developer.android.com/ndk/reference/struct/a-native-activity.html)
use crate::hardware_buffer::HardwareBufferFormat;
use std::ffi::CStr;
use std::os::raw::c_void;
use std::ptr::NonNull;
Expand All @@ -11,6 +12,8 @@ use std::ptr::NonNull;
///
/// This is either provided in `ANativeActivity_onCreate`, or accessible in
/// `android_native_app_glue`'s android_app.
///
/// <https://developer.android.com/ndk/reference/group/native-activity>
#[derive(Debug)]
pub struct NativeActivity {
ptr: NonNull<ffi::ANativeActivity>,
Expand Down Expand Up @@ -169,11 +172,13 @@ impl NativeActivity {
unsafe { ffi::ANativeActivity_hideSoftInput(self.ptr.as_ptr(), flag) }
}

/*/// Set the window format. Performs the Java `.getWindow().setFormat()`.
/// Change the window format of the given activity.
///
/// Calls [`getWindow().setFormat()`] of the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.
///
/// See also [the relevant
/// javadoc](https://developer.android.com/reference/android/view/Window#setFormat(int))
pub unsafe fn set_window_format(&self, format: WindowFormat) {
unsafe { ffi::ANativeActivity_setWindowFormat(self.ptr.as_ptr(), format.into()) }
}*/
/// [`getWindow().setFormat()`]: https://developer.android.com/reference/android/view/Window#setFormat(int)
pub fn set_window_format(&self, format: HardwareBufferFormat) {
let format: u32 = format.into();
unsafe { ffi::ANativeActivity_setWindowFormat(self.ptr.as_ptr(), format as i32) }
}
}

0 comments on commit 0369d85

Please sign in to comment.