mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Update android JNI bindings
This commit is contained in:
parent
b1082aa621
commit
9f9798d3a4
@ -770,8 +770,14 @@ void CClient::reinitScripting()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
#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)
|
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerClosed(JNIEnv * env, jobject cls)
|
||||||
{
|
{
|
||||||
logNetwork->info("Received server closed signal");
|
logNetwork->info("Received server closed signal");
|
||||||
|
@ -488,9 +488,6 @@ CKeyboardFocusListener::CKeyboardFocusListener(CTextInput * textInput)
|
|||||||
void CKeyboardFocusListener::focusGot()
|
void CKeyboardFocusListener::focusGot()
|
||||||
{
|
{
|
||||||
CSDL_Ext::startTextInput(&textInput->pos);
|
CSDL_Ext::startTextInput(&textInput->pos);
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
textInput->notifyAndroidTextInputChanged(textInput->text);
|
|
||||||
#endif
|
|
||||||
usageIndex++;
|
usageIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,9 +549,6 @@ void CTextInput::keyPressed(const SDL_KeyboardEvent & key)
|
|||||||
{
|
{
|
||||||
redraw();
|
redraw();
|
||||||
cb(text);
|
cb(text);
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
notifyAndroidTextInputChanged(text);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,10 +557,6 @@ void CTextInput::setText(const std::string & nText, bool callCb)
|
|||||||
CLabel::setText(nText);
|
CLabel::setText(nText);
|
||||||
if(callCb)
|
if(callCb)
|
||||||
cb(text);
|
cb(text);
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
notifyAndroidTextInputChanged(text);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
|
bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
|
||||||
@ -592,10 +582,6 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event)
|
|||||||
cb(text);
|
cb(text);
|
||||||
}
|
}
|
||||||
newText.clear();
|
newText.clear();
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
notifyAndroidTextInputChanged(text);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTextInput::textEdited(const SDL_TextEditingEvent & event)
|
void CTextInput::textEdited(const SDL_TextEditingEvent & event)
|
||||||
@ -606,11 +592,6 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event)
|
|||||||
newText = event.text;
|
newText = event.text;
|
||||||
redraw();
|
redraw();
|
||||||
cb(text + newText);
|
cb(text + newText);
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
auto editedText = text + newText;
|
|
||||||
notifyAndroidTextInputChanged(editedText);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTextInput::filenameFilter(std::string & text, const std::string &)
|
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::CFocusable()
|
||||||
:CFocusable(std::make_shared<IFocusListener>())
|
:CFocusable(std::make_shared<IFocusListener>())
|
||||||
{
|
{
|
||||||
|
@ -198,9 +198,6 @@ class CTextInput : public CLabel, public CFocusable
|
|||||||
protected:
|
protected:
|
||||||
std::string visibleText() override;
|
std::string visibleText() override;
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
void notifyAndroidTextInputChanged(std::string & text);
|
|
||||||
#endif
|
|
||||||
public:
|
public:
|
||||||
CFunctionList<void(const std::string &)> cb;
|
CFunctionList<void(const std::string &)> cb;
|
||||||
CFunctionList<void(std::string &, const std::string &)> filters;
|
CFunctionList<void(std::string &, const std::string &)> filters;
|
||||||
|
@ -21,11 +21,6 @@ void CAndroidVMHelper::cacheVM(JNIEnv * env)
|
|||||||
env->GetJavaVM(&vmCache);
|
env->GetJavaVM(&vmCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAndroidVMHelper::cacheVM(JavaVM * vm)
|
|
||||||
{
|
|
||||||
vmCache = vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAndroidVMHelper::CAndroidVMHelper()
|
CAndroidVMHelper::CAndroidVMHelper()
|
||||||
{
|
{
|
||||||
auto res = vmCache->GetEnv((void **) &envPtr, JNI_VERSION_1_1);
|
auto res = vmCache->GetEnv((void **) &envPtr, JNI_VERSION_1_1);
|
||||||
|
@ -42,8 +42,6 @@ public:
|
|||||||
|
|
||||||
static void cacheVM(JNIEnv * env);
|
static void cacheVM(JNIEnv * env);
|
||||||
|
|
||||||
static void cacheVM(JavaVM * vm);
|
|
||||||
|
|
||||||
static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
|
static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user