aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android
diff options
context:
space:
mode:
authorThanasis Antoniou2019-11-08 16:59:52 +0200
committerThanasis Antoniou2019-11-08 16:59:52 +0200
commitb8c26508c90b7926ea44b40e5bcb2f530b8d1464 (patch)
tree1dbf0770ea0ed31685469cdefdcecf3feb930e81 /backends/platform/android
parent6fde4e89f85b8091b40569ac5d8e4a34b6007ace (diff)
downloadscummvm-rg350-b8c26508c90b7926ea44b40e5bcb2f530b8d1464.tar.gz
scummvm-rg350-b8c26508c90b7926ea44b40e5bcb2f530b8d1464.tar.bz2
scummvm-rg350-b8c26508c90b7926ea44b40e5bcb2f530b8d1464.zip
ANDROID: Fix OSD message display crash or fail
For translated message text. Android expected UTF-8 format for the message Also makeToast for OSD needed to be run from the main UI thread
Diffstat (limited to 'backends/platform/android')
-rw-r--r--backends/platform/android/jni.cpp20
-rw-r--r--backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java12
2 files changed, 28 insertions, 4 deletions
diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp
index 8c330c0e89..cedee38b7e 100644
--- a/backends/platform/android/jni.cpp
+++ b/backends/platform/android/jni.cpp
@@ -46,6 +46,7 @@
#include "common/error.h"
#include "common/textconsole.h"
#include "common/translation.h"
+#include "common/encoding.h"
#include "engines/engine.h"
#include "backends/platform/android/android.h"
@@ -225,8 +226,24 @@ void JNI::getDPI(float *values) {
}
void JNI::displayMessageOnOSD(const char *msg) {
+ // called from common/osd_message_queue, method: OSDMessageQueue::pollEvent()
JNIEnv *env = JNI::getEnv();
- jstring java_msg = env->NewStringUTF(msg);
+// LOGD("OSD orig MESSAGE: %s", msg);
+ Common::String fromEncoding = "ISO-8859-1";
+#ifdef USE_TRANSLATION
+ if (TransMan.getCurrentCharset() != "ASCII") {
+ fromEncoding = TransMan.getCurrentCharset();
+ }
+#endif
+ Common::Encoding converter("UTF-8", fromEncoding.c_str());
+
+ const char *utf8Msg = converter.convert(msg, converter.stringLength(msg, fromEncoding) );
+ if (utf8Msg == nullptr) {
+ LOGE("Failed to convert message to UTF-8 for OSD!");
+ return;
+ }
+// LOGD("OSD target MESSAGE: %s", utf8Msg);
+ jstring java_msg = env->NewStringUTF(utf8Msg);
env->CallVoidMethod(_jobj, _MID_displayMessageOnOSD, java_msg);
@@ -693,6 +710,7 @@ void JNI::setPause(JNIEnv *env, jobject self, jboolean value) {
jstring JNI::getCurrentCharset(JNIEnv *env, jobject self) {
#ifdef USE_TRANSLATION
if (TransMan.getCurrentCharset() != "ASCII") {
+// LOGD("getCurrentCharset: %s", TransMan.getCurrentCharset().c_str());
return env->NewStringUTF(TransMan.getCurrentCharset().c_str());
}
#endif
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
index dca52a92f3..f55639f60b 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -76,9 +76,15 @@ public class ScummVMActivity extends Activity {
}
@Override
- protected void displayMessageOnOSD(String msg) {
- Log.i(LOG_TAG, "OSD: " + msg);
- Toast.makeText(ScummVMActivity.this, msg, Toast.LENGTH_LONG).show();
+ protected void displayMessageOnOSD(final String msg) {
+ if (msg != null) {
+ Log.i(LOG_TAG, "MessageOnOSD: " + msg + " " + getCurrentCharset());
+ runOnUiThread(new Runnable() {
+ public void run() {
+ Toast.makeText(ScummVMActivity.this, msg, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
}
@Override