xloop_android 0.1.0

android impl for xloop.
Documentation
pub extern crate jnim;
pub extern crate xloop_types as types;

mod gen;
pub use gen::*;

pub mod app;
pub mod error;
pub mod rule;
pub mod win;

pub mod prelude {
	pub use super::win::WinActivity;
}
pub use rule::FmtJava;

#[derive(Debug)]
pub struct Platform;

impl types::Platform for Platform {
	type Error = error::Error;
	type AppRef<'a> = app::AppRef<'a>;
	type AppHandle = app::AppHandle;
	type AppProxy = app::AppProxy;
	type WinRef<'a> = win::WinRef<'a>;
	type WinHandle = win::WinHandle;
	type WinRaw = win::WinRaw;
	type EvtMouse<'a> = win::WinEvent<'a>;
	type EvtWheel<'a> = win::WinEvent<'a>;
	type EvtKey<'a> = win::WinEvent<'a>;
	type EvtTouch<'a> = win::WinEvent<'a>;
	fn run(delegate: impl types::AppDelegate<Self> + 'static) -> Result<Option<Self::AppHandle>, Self::Error> {
		app::set_delegate(std::rc::Rc::new(delegate));
		app::application_launched();
		Ok(None)
	}
	fn win(key: impl AsRef<str>, delegate: impl types::WinDelegate<Self> + 'static) -> Result<Self::WinHandle, Self::Error> {
		win::reg_window(key.as_ref(), std::rc::Rc::new(delegate));
		Ok(win::WinHandle(key.as_ref().to_string()))
	}
	fn log(level: log::LevelFilter) {
		android_logger::init_once(android_logger::Config::default().with_max_level(level));
	}
	fn read(path: impl AsRef<std::path::Path>) -> Option<Vec<u8>> {
		let assets = app::AppHandle::assets()?;
		let mut bytes = vec![];
		let path_java = jnim::cesu8::to_java_cesu8(path.as_ref().to_str()?);
		let path_java = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(&path_java) };
		assets.read(path_java, &mut bytes)?;
		Some(bytes)
	}
}

#[no_mangle]
#[allow(unused_unsafe)]
pub extern "C" fn init_jvm(jvm: *mut core::ffi::c_void) -> jnim::JInt {
	use jnim::*;
	JVm::singleton(JVm::from_void(jvm));
	JVm::DEFAULT_VERSION
}