mod.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use miniquad::native::android::{self, ndk_sys, ndk_utils};
  19. use parking_lot::Mutex as SyncMutex;
  20. use std::{collections::HashMap, path::PathBuf, sync::LazyLock};
  21. pub mod insets;
  22. pub mod textinput;
  23. mod util;
  24. pub mod vid;
  25. macro_rules! call_mainactivity_int_method {
  26. ($method:expr, $sig:expr $(, $args:expr)*) => {{
  27. unsafe {
  28. let env = android::attach_jni_env();
  29. ndk_utils::call_int_method!(env, android::ACTIVITY, $method, $sig $(, $args)*)
  30. }
  31. }};
  32. }
  33. macro_rules! call_mainactivity_str_method {
  34. ($method:expr) => {{
  35. unsafe {
  36. let env = android::attach_jni_env();
  37. let text = ndk_utils::call_object_method!(
  38. env,
  39. android::ACTIVITY,
  40. $method,
  41. "()Ljava/lang/String;"
  42. );
  43. ndk_utils::get_utf_str!(env, text)
  44. }
  45. }};
  46. }
  47. macro_rules! call_mainactivity_float_method {
  48. ($method:expr) => {{
  49. unsafe {
  50. let env = android::attach_jni_env();
  51. ndk_utils::call_method!(CallFloatMethod, env, android::ACTIVITY, $method, "()F")
  52. }
  53. }};
  54. }
  55. macro_rules! call_mainactivity_bool_method {
  56. ($method:expr) => {{
  57. unsafe {
  58. let env = android::attach_jni_env();
  59. ndk_utils::call_method!(CallBooleanMethod, env, android::ACTIVITY, $method, "()Z") !=
  60. 0u8
  61. }
  62. }};
  63. }
  64. pub fn get_appdata_path() -> PathBuf {
  65. call_mainactivity_str_method!("getAppDataPath").into()
  66. }
  67. pub fn get_external_storage_path() -> PathBuf {
  68. call_mainactivity_str_method!("getExternalStoragePath").into()
  69. }
  70. pub fn get_keyboard_height() -> usize {
  71. call_mainactivity_int_method!("getKeyboardHeight", "()I") as usize
  72. }
  73. pub fn get_screen_density() -> f32 {
  74. call_mainactivity_float_method!("getScreenDensity")
  75. }
  76. pub fn is_ime_visible() -> bool {
  77. call_mainactivity_bool_method!("isImeVisible")
  78. }