jni.rs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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::ndk_sys;
  19. use super::gametextinput::{GameTextInput, GAME_TEXT_INPUT};
  20. /// Set the InputConnection for GameTextInput (called from Java)
  21. ///
  22. /// This follows the official Android GameTextInput integration pattern:
  23. /// https://developer.android.com/games/agdk/add-support-for-text-input
  24. ///
  25. /// Called from MainActivity when the InputConnection is created. It passes
  26. /// the Java InputConnection object to the native GameTextInput library.
  27. #[no_mangle]
  28. pub extern "C" fn Java_darkfi_darkfi_1app_MainActivity_setInputConnectionNative(
  29. _env: *mut ndk_sys::JNIEnv,
  30. _class: ndk_sys::jclass,
  31. input_connection: ndk_sys::jobject,
  32. ) {
  33. debug!(target: "android::textinput::jni", "Setting input connection");
  34. // Initialize GameTextInput on first call
  35. let gti = GAME_TEXT_INPUT.get_or_init(|| GameTextInput::new());
  36. gti.set_input_connection(input_connection);
  37. }
  38. /// Process IME state event from Java Listener.stateChanged()
  39. ///
  40. /// This follows the official Android GameTextInput integration pattern.
  41. /// Called from the Java InputConnection's Listener whenever the IME sends
  42. /// a state change (text typed, cursor moved, etc.).
  43. #[no_mangle]
  44. pub extern "C" fn Java_darkfi_darkfi_1app_MainActivity_onTextInputEventNative(
  45. _env: *mut ndk_sys::JNIEnv,
  46. _class: ndk_sys::jclass,
  47. soft_keyboard_event: ndk_sys::jobject,
  48. ) {
  49. let gti = GAME_TEXT_INPUT.get().unwrap();
  50. gti.process_event(soft_keyboard_event);
  51. }