Parcourir la source

Update android JNI bindings

Andrii Danylchenko il y a 2 ans
Parent
commit
9f9798d3a4

+ 7 - 1
client/Client.cpp

@@ -770,8 +770,14 @@ void CClient::reinitScripting()
 #endif
 }
 
-
 #ifdef VCMI_ANDROID
+extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_clientSetupJNI(JNIEnv * env, jobject cls)
+{
+	logNetwork->info("Received clientSetupJNI");
+
+	CAndroidVMHelper::cacheVM(env);
+}
+
 extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerClosed(JNIEnv * env, jobject cls)
 {
 	logNetwork->info("Received server closed signal");

+ 0 - 37
client/widgets/TextControls.cpp

@@ -488,9 +488,6 @@ CKeyboardFocusListener::CKeyboardFocusListener(CTextInput * textInput)
 void CKeyboardFocusListener::focusGot()
 {
 	CSDL_Ext::startTextInput(&textInput->pos);
-#ifdef VCMI_ANDROID
-	textInput->notifyAndroidTextInputChanged(textInput->text);
-#endif
 	usageIndex++;
 }
 
@@ -552,9 +549,6 @@ void CTextInput::keyPressed(const SDL_KeyboardEvent & key)
 	{
 		redraw();
 		cb(text);
-#ifdef VCMI_ANDROID
-		notifyAndroidTextInputChanged(text);
-#endif
 	}
 }
 
@@ -563,10 +557,6 @@ void CTextInput::setText(const std::string & nText, bool callCb)
 	CLabel::setText(nText);
 	if(callCb)
 		cb(text);
-
-#ifdef VCMI_ANDROID
-	notifyAndroidTextInputChanged(text);
-#endif
 }
 
 bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
@@ -592,10 +582,6 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event)
 		cb(text);
 	}
 	newText.clear();
-
-#ifdef VCMI_ANDROID
-	notifyAndroidTextInputChanged(text);
-#endif
 }
 
 void CTextInput::textEdited(const SDL_TextEditingEvent & event)
@@ -606,11 +592,6 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event)
 	newText = event.text;
 	redraw();
 	cb(text + newText);
-
-#ifdef VCMI_ANDROID
-	auto editedText = text + newText;
-	notifyAndroidTextInputChanged(editedText);
-#endif
 }
 
 void CTextInput::filenameFilter(std::string & text, const std::string &)
@@ -657,24 +638,6 @@ void CTextInput::numberFilter(std::string & text, const std::string & oldText, i
 	}
 }
 
-#ifdef VCMI_ANDROID
-void CTextInput::notifyAndroidTextInputChanged(std::string & text)
-{
-	if(!focus)
-		return;
-
-	auto fun = [&text](JNIEnv * env, jclass cls, jmethodID method)
-	{
-		auto jtext = env->NewStringUTF(text.c_str());
-		env->CallStaticVoidMethod(cls, method, jtext);
-		env->DeleteLocalRef(jtext);
-	};
-	CAndroidVMHelper vmHelper;
-	vmHelper.callCustomMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "notifyTextInputChanged",
-		"(Ljava/lang/String;)V", fun, true);
-}
-#endif //VCMI_ANDROID
-
 CFocusable::CFocusable()
 	:CFocusable(std::make_shared<IFocusListener>())
 {

+ 0 - 3
client/widgets/TextControls.h

@@ -198,9 +198,6 @@ class CTextInput : public CLabel, public CFocusable
 protected:
 	std::string visibleText() override;
 
-#ifdef VCMI_ANDROID
-	void notifyAndroidTextInputChanged(std::string & text);
-#endif
 public:
 	CFunctionList<void(const std::string &)> cb;
 	CFunctionList<void(std::string &, const std::string &)> filters;

+ 0 - 5
lib/CAndroidVMHelper.cpp

@@ -21,11 +21,6 @@ void CAndroidVMHelper::cacheVM(JNIEnv * env)
 	env->GetJavaVM(&vmCache);
 }
 
-void CAndroidVMHelper::cacheVM(JavaVM * vm)
-{
-	vmCache = vm;
-}
-
 CAndroidVMHelper::CAndroidVMHelper()
 {
 	auto res = vmCache->GetEnv((void **) &envPtr, JNI_VERSION_1_1);

+ 0 - 2
lib/CAndroidVMHelper.h

@@ -42,8 +42,6 @@ public:
 
 	static void cacheVM(JNIEnv * env);
 
-	static void cacheVM(JavaVM * vm);
-
 	static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
 };