diff options
| author | 2024-02-05 06:07:29 -0500 | |
|---|---|---|
| committer | 2024-02-08 13:45:26 -0500 | |
| commit | e7c4c8b993ce27a50b7a56f90247056048d20f7d (patch) | |
| tree | b87c275f4ea92092f7c8b6cdcb0f50d32819490f /src/common/android/applets/software_keyboard.cpp | |
| parent | Merge pull request #12892 from liamwhite/serialization-stuff (diff) | |
| download | yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.gz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.xz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.zip | |
android: Move JNI setup and helpers to common
Diffstat (limited to '')
| -rw-r--r-- | src/common/android/applets/software_keyboard.cpp (renamed from src/android/app/src/main/jni/applets/software_keyboard.cpp) | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/android/app/src/main/jni/applets/software_keyboard.cpp b/src/common/android/applets/software_keyboard.cpp index 9943483e8..477e62b16 100644 --- a/src/android/app/src/main/jni/applets/software_keyboard.cpp +++ b/src/common/android/applets/software_keyboard.cpp | |||
| @@ -6,12 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | #include <jni.h> | 7 | #include <jni.h> |
| 8 | 8 | ||
| 9 | #include "common/android/android_common.h" | ||
| 10 | #include "common/android/applets/software_keyboard.h" | ||
| 11 | #include "common/android/id_cache.h" | ||
| 9 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 10 | #include "common/string_util.h" | 13 | #include "common/string_util.h" |
| 11 | #include "core/core.h" | 14 | #include "core/core.h" |
| 12 | #include "jni/android_common/android_common.h" | ||
| 13 | #include "jni/applets/software_keyboard.h" | ||
| 14 | #include "jni/id_cache.h" | ||
| 15 | 15 | ||
| 16 | static jclass s_software_keyboard_class; | 16 | static jclass s_software_keyboard_class; |
| 17 | static jclass s_keyboard_config_class; | 17 | static jclass s_keyboard_config_class; |
| @@ -19,10 +19,10 @@ static jclass s_keyboard_data_class; | |||
| 19 | static jmethodID s_swkbd_execute_normal; | 19 | static jmethodID s_swkbd_execute_normal; |
| 20 | static jmethodID s_swkbd_execute_inline; | 20 | static jmethodID s_swkbd_execute_inline; |
| 21 | 21 | ||
| 22 | namespace SoftwareKeyboard { | 22 | namespace Common::Android::SoftwareKeyboard { |
| 23 | 23 | ||
| 24 | static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParameters& config) { | 24 | static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParameters& config) { |
| 25 | JNIEnv* env = IDCache::GetEnvForThread(); | 25 | JNIEnv* env = GetEnvForThread(); |
| 26 | jobject object = env->AllocObject(s_keyboard_config_class); | 26 | jobject object = env->AllocObject(s_keyboard_config_class); |
| 27 | 27 | ||
| 28 | env->SetObjectField(object, | 28 | env->SetObjectField(object, |
| @@ -78,7 +78,7 @@ static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParamet | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | AndroidKeyboard::ResultData AndroidKeyboard::ResultData::CreateFromFrontend(jobject object) { | 80 | AndroidKeyboard::ResultData AndroidKeyboard::ResultData::CreateFromFrontend(jobject object) { |
| 81 | JNIEnv* env = IDCache::GetEnvForThread(); | 81 | JNIEnv* env = GetEnvForThread(); |
| 82 | const jstring string = reinterpret_cast<jstring>(env->GetObjectField( | 82 | const jstring string = reinterpret_cast<jstring>(env->GetObjectField( |
| 83 | object, env->GetFieldID(s_keyboard_data_class, "text", "Ljava/lang/String;"))); | 83 | object, env->GetFieldID(s_keyboard_data_class, "text", "Ljava/lang/String;"))); |
| 84 | return ResultData{GetJString(env, string), | 84 | return ResultData{GetJString(env, string), |
| @@ -141,7 +141,7 @@ void AndroidKeyboard::ShowNormalKeyboard() const { | |||
| 141 | 141 | ||
| 142 | // Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber. | 142 | // Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber. |
| 143 | std::thread([&] { | 143 | std::thread([&] { |
| 144 | data = ResultData::CreateFromFrontend(IDCache::GetEnvForThread()->CallStaticObjectMethod( | 144 | data = ResultData::CreateFromFrontend(GetEnvForThread()->CallStaticObjectMethod( |
| 145 | s_software_keyboard_class, s_swkbd_execute_normal, ToJKeyboardParams(parameters))); | 145 | s_software_keyboard_class, s_swkbd_execute_normal, ToJKeyboardParams(parameters))); |
| 146 | }).join(); | 146 | }).join(); |
| 147 | 147 | ||
| @@ -183,8 +183,8 @@ void AndroidKeyboard::ShowInlineKeyboard( | |||
| 183 | // Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber. | 183 | // Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber. |
| 184 | m_is_inline_active = true; | 184 | m_is_inline_active = true; |
| 185 | std::thread([&] { | 185 | std::thread([&] { |
| 186 | IDCache::GetEnvForThread()->CallStaticVoidMethod( | 186 | GetEnvForThread()->CallStaticVoidMethod(s_software_keyboard_class, s_swkbd_execute_inline, |
| 187 | s_software_keyboard_class, s_swkbd_execute_inline, ToJKeyboardParams(parameters)); | 187 | ToJKeyboardParams(parameters)); |
| 188 | }).join(); | 188 | }).join(); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| @@ -220,7 +220,7 @@ void AndroidKeyboard::SubmitInlineKeyboardText(std::u16string submitted_text) { | |||
| 220 | m_current_text += submitted_text; | 220 | m_current_text += submitted_text; |
| 221 | 221 | ||
| 222 | submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text, | 222 | submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text, |
| 223 | m_current_text.size()); | 223 | static_cast<int>(m_current_text.size())); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) { | 226 | void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) { |
| @@ -242,7 +242,7 @@ void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) { | |||
| 242 | case KEYCODE_DEL: | 242 | case KEYCODE_DEL: |
| 243 | m_current_text.pop_back(); | 243 | m_current_text.pop_back(); |
| 244 | submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text, | 244 | submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text, |
| 245 | m_current_text.size()); | 245 | static_cast<int>(m_current_text.size())); |
| 246 | break; | 246 | break; |
| 247 | } | 247 | } |
| 248 | } | 248 | } |
| @@ -274,4 +274,4 @@ void CleanupJNI(JNIEnv* env) { | |||
| 274 | env->DeleteGlobalRef(s_keyboard_data_class); | 274 | env->DeleteGlobalRef(s_keyboard_data_class); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | } // namespace SoftwareKeyboard | 277 | } // namespace Common::Android::SoftwareKeyboard |