use uzor::platform::{PlatformEvent, SystemTheme};
use crate::{HapticStyle, ScreenOrientation};
#[cfg(feature = "android")]
use ndk::native_window::NativeWindow;
#[cfg(feature = "android")]
use jni::{JNIEnv, JavaVM, objects::JObject};
pub struct AndroidBackend {
#[cfg(feature = "android")]
_vm: JavaVM,
#[cfg(not(feature = "android"))]
_stub: (),
}
impl AndroidBackend {
pub fn new() -> Result<Self, String> {
#[cfg(feature = "android")]
{
Err("Android backend not fully implemented yet".to_string())
}
#[cfg(not(feature = "android"))]
{
Ok(Self { _stub: () })
}
}
pub fn screen_size(&self) -> (u32, u32) {
#[cfg(feature = "android")]
{
(1080, 2400)
}
#[cfg(not(feature = "android"))]
{
(1080, 2400)
}
}
pub fn scale_factor(&self) -> f64 {
#[cfg(feature = "android")]
{
3.0
}
#[cfg(not(feature = "android"))]
{
3.0
}
}
pub fn safe_area_insets(&self) -> (f64, f64, f64, f64) {
#[cfg(feature = "android")]
{
let status_bar = 24.0 * self.scale_factor();
let nav_bar = 48.0 * self.scale_factor();
(status_bar, 0.0, nav_bar, 0.0)
}
#[cfg(not(feature = "android"))]
{
(72.0, 0.0, 144.0, 0.0) }
}
pub fn orientation(&self) -> ScreenOrientation {
#[cfg(feature = "android")]
{
ScreenOrientation::Portrait
}
#[cfg(not(feature = "android"))]
{
ScreenOrientation::Portrait
}
}
pub fn haptic_feedback(&mut self, style: HapticStyle) {
#[cfg(feature = "android")]
{
let _ = style;
}
#[cfg(not(feature = "android"))]
{
let _ = style;
}
}
pub fn poll_event(&mut self) -> Option<PlatformEvent> {
#[cfg(feature = "android")]
{
None
}
#[cfg(not(feature = "android"))]
{
None
}
}
pub fn set_title(&mut self, _title: &str) {
}
pub fn get_clipboard_text(&self) -> Option<String> {
#[cfg(feature = "android")]
{
None
}
#[cfg(not(feature = "android"))]
{
None
}
}
pub fn set_clipboard_text(&mut self, text: &str) -> Result<(), String> {
#[cfg(feature = "android")]
{
let _ = text;
Err("Android clipboard not implemented yet".to_string())
}
#[cfg(not(feature = "android"))]
{
let _ = text;
Err("Android feature not enabled".to_string())
}
}
pub fn open_url(&self, url: &str) -> Result<(), String> {
#[cfg(feature = "android")]
{
let _ = url;
Err("Android URL opening not implemented yet".to_string())
}
#[cfg(not(feature = "android"))]
{
let _ = url;
Err("Android feature not enabled".to_string())
}
}
pub fn system_theme(&self) -> Option<SystemTheme> {
#[cfg(feature = "android")]
{
Some(SystemTheme::Light)
}
#[cfg(not(feature = "android"))]
{
Some(SystemTheme::Light)
}
}
pub fn set_ime_position(&mut self, _x: f64, _y: f64) {
}
pub fn show_keyboard(&mut self) {
#[cfg(feature = "android")]
{
}
}
pub fn hide_keyboard(&mut self) {
#[cfg(feature = "android")]
{
}
}
}
#[cfg(feature = "android")]
mod jni_helpers {
use super::*;
pub fn get_context<'a>(_env: &'a JNIEnv<'a>) -> Option<JObject<'a>> {
None
}
pub fn clipboard_operation<'a>(
_env: &'a JNIEnv<'a>,
_context: JObject<'a>,
_operation: &str,
) -> Result<Option<String>, String> {
Err("Not implemented".to_string())
}
pub fn get_native_window() -> Option<NativeWindow> {
None
}
}