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::WinView; } 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::WinKey<'a>; type EvtTouch<'a> = win::WinTouch<'a>; type EvtCommit<'a> = &'a types::EvtCommit; fn run(delegate: impl types::AppDelegate + 'static) -> Result, Self::Error> { app::set_delegate(std::rc::Rc::new(delegate)); app::application_launched(); Ok(None) } fn win(key: impl AsRef, delegate: impl types::WinDelegate + 'static) -> Result { 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) -> Option> { use jnim::{JEnv, JObject}; // use std::ptr::slice_from_raw_parts_mut; // let env = JEnv::env(None)?; // let mut bytes: Vec = vec![]; // // let len = data.len(env)? as usize; // let path = path.as_ref().to_str()?; // let path_java = env.new_string(path)?; // let assets = app::AppHandle::assets_java(env)?; // let input = assets.open(env, path_java)?; // // if (env.exception_check()) == Some(true) { // // env.exception_describe(); // // env.exception_clear(); // // return None; // // } // let len = input.available(env)? as usize; // bytes.reserve(len); // unsafe { bytes.set_len(len) }; // let out = unsafe { &mut *slice_from_raw_parts_mut(bytes.as_mut_ptr() as *mut i8, len) }; // // let data = file.read_all_bytes(env)?; // // { data.copy_to(env, 0, out) }?; // Some(bytes) let env = JEnv::env(None)?; let frame: Option> = env.push_frame(32); if frame.is_none() { log::warn!("push_frame failed"); } let assets = app::AppHandle::assets()?; let path = path.as_ref().to_str()?; let path_java = jnim::cesu8::to_java_cesu8(path); let path_java = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(&path_java) }; log::info!("read:{path}"); let mut bytes = vec![]; match assets.read(path_java, &mut bytes) { Ok(_) => (), Err(s) => { log::info!("assets.read file :{}", s); return None; } } log::info!("length:{}", bytes.len()); if env.exception_check() == Some(true) { env.exception_describe(); env.exception_clear(); } 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 }