diff options
Diffstat (limited to 'backends/platform/android/jni.cpp')
-rw-r--r-- | backends/platform/android/jni.cpp | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index 256ae09ef8..3b84726dbd 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -45,6 +45,7 @@ #include "common/config-manager.h" #include "common/error.h" #include "common/textconsole.h" +#include "common/translation.h" #include "engines/engine.h" #include "backends/platform/android/android.h" @@ -77,6 +78,9 @@ bool JNI::_ready_for_events = 0; jmethodID JNI::_MID_getDPI = 0; jmethodID JNI::_MID_displayMessageOnOSD = 0; jmethodID JNI::_MID_openUrl = 0; +jmethodID JNI::_MID_hasTextInClipboard = 0; +jmethodID JNI::_MID_getTextFromClipboard = 0; +jmethodID JNI::_MID_setTextInClipboard = 0; jmethodID JNI::_MID_isConnectionLimited = 0; jmethodID JNI::_MID_setWindowCaption = 0; jmethodID JNI::_MID_showVirtualKeyboard = 0; @@ -109,7 +113,9 @@ const JNINativeMethod JNI::_natives[] = { { "enableZoning", "(Z)V", (void *)JNI::enableZoning }, { "setPause", "(Z)V", - (void *)JNI::setPause } + (void *)JNI::setPause }, + { "getCurrentCharset", "()Ljava/lang/String;", + (void *)JNI::getCurrentCharset } }; JNI::JNI() { @@ -253,6 +259,66 @@ bool JNI::openUrl(const char *url) { return success; } +bool JNI::hasTextInClipboard() { + bool hasText = false; + JNIEnv *env = JNI::getEnv(); + hasText = env->CallBooleanMethod(_jobj, _MID_hasTextInClipboard); + + if (env->ExceptionCheck()) { + LOGE("Failed to check the contents of the clipboard"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + hasText = true; + } + + return hasText; +} + +Common::String JNI::getTextFromClipboard() { + JNIEnv *env = JNI::getEnv(); + + jbyteArray javaText = (jbyteArray)env->CallObjectMethod(_jobj, _MID_getTextFromClipboard); + + if (env->ExceptionCheck()) { + LOGE("Failed to retrieve text from the clipboard"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + + return Common::String(); + } + + int len = env->GetArrayLength(javaText); + char* buf = new char[len]; + env->GetByteArrayRegion(javaText, 0, len, reinterpret_cast<jbyte*>(buf)); + Common::String text(buf, len); + delete[] buf; + + return text; +} + +bool JNI::setTextInClipboard(const Common::String &text) { + bool success = true; + JNIEnv *env = JNI::getEnv(); + + jbyteArray javaText = env->NewByteArray(text.size()); + env->SetByteArrayRegion(javaText, 0, text.size(), reinterpret_cast<const jbyte*>(text.c_str())); + + success = env->CallBooleanMethod(_jobj, _MID_setTextInClipboard, javaText); + + if (env->ExceptionCheck()) { + LOGE("Failed to add text to the clipboard"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + success = false; + } + + env->DeleteLocalRef(javaText); + return success; +} + bool JNI::isConnectionLimited() { bool limited = false; JNIEnv *env = JNI::getEnv(); @@ -449,6 +515,9 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager, FIND_METHOD(, getDPI, "([F)V"); FIND_METHOD(, displayMessageOnOSD, "(Ljava/lang/String;)V"); FIND_METHOD(, openUrl, "(Ljava/lang/String;)V"); + FIND_METHOD(, hasTextInClipboard, "()Z"); + FIND_METHOD(, getTextFromClipboard, "()[B"); + FIND_METHOD(, setTextInClipboard, "([B)Z"); FIND_METHOD(, isConnectionLimited, "()Z"); FIND_METHOD(, showVirtualKeyboard, "(Z)V"); FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;"); @@ -611,4 +680,13 @@ void JNI::setPause(JNIEnv *env, jobject self, jboolean value) { } } +jstring JNI::getCurrentCharset(JNIEnv *env, jobject self) { +#ifdef USE_TRANSLATION + if (TransMan.getCurrentCharset() != "ASCII") { + return env->NewStringUTF(TransMan.getCurrentCharset().c_str()); + } +#endif + return env->NewStringUTF("ISO-8859-1"); +} + #endif |