/* This file is part of DarkFi (https://dark.fi) * * Copyright (C) 2020-2026 Dyne.org foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ use miniquad::native::android::{self, ndk_utils}; use std::path::PathBuf; pub mod insets; pub mod textinput; pub(self) mod util; pub mod vid; pub use util::get_jni_env; macro_rules! call_mainactivity_int_method { ($method:expr, $sig:expr $(, $args:expr)*) => {{ unsafe { let env = get_jni_env(); ndk_utils::call_int_method!(env, android::ACTIVITY, $method, $sig $(, $args)*) } }}; } macro_rules! call_mainactivity_str_method { ($method:expr) => {{ unsafe { let env = get_jni_env(); let text = ndk_utils::call_object_method!( env, android::ACTIVITY, $method, "()Ljava/lang/String;" ); ndk_utils::get_utf_str!(env, text) } }}; } macro_rules! call_mainactivity_bool_method { ($method:expr) => {{ unsafe { let env = get_jni_env(); ndk_utils::call_method!(CallBooleanMethod, env, android::ACTIVITY, $method, "()Z") != 0u8 } }}; } pub fn get_appdata_path() -> PathBuf { call_mainactivity_str_method!("getAppDataPath").into() } pub fn get_external_storage_path() -> PathBuf { call_mainactivity_str_method!("getExternalStoragePath").into() } pub fn get_keyboard_height() -> usize { call_mainactivity_int_method!("getKeyboardHeight", "()I") as usize } pub fn get_long_press_timeout() -> u32 { call_mainactivity_int_method!("getLongPressTimeout", "()I") as u32 } pub fn is_ime_visible() -> bool { call_mainactivity_bool_method!("isImeVisible") } /// Ask Android to redispatch the current window insets to ResizingLayout, /// which triggers the onApplyInsets callback with fresh values. pub fn request_apply_insets() { unsafe { let env = get_jni_env(); ndk_utils::call_void_method!(env, android::ACTIVITY, "requestApplyInsets", "()V"); } } /// Open `url` in the platform's default handler (e.g. the browser) by calling the /// `openUrl` method on MainActivity, which fires an `ACTION_VIEW` intent. Android /// only. The URL string is converted to a Java `String` via `NewStringUTF` and the /// local reference is released after the call. pub fn open_url(url: &str) { unsafe { let env = get_jni_env(); let curl = std::ffi::CString::new(url).unwrap(); let jurl = (**env).NewStringUTF.unwrap()(env, curl.as_ptr()); ndk_utils::call_void_method!( env, android::ACTIVITY, "openUrl", "(Ljava/lang/String;)V", jurl ); let delete_local_ref = (**env).DeleteLocalRef.unwrap(); delete_local_ref(env, jurl); } }