[ion/simulator/android] Get the language directly

Without using the "--language" command-line option
This commit is contained in:
Romain Goyet
2020-08-31 15:41:29 -04:00
committed by Léa Saviot
parent 09a7b9daca
commit 22b6990e63
3 changed files with 37 additions and 8 deletions

View File

@@ -1,12 +1,12 @@
ion_src += $(addprefix ion/src/simulator/android/src/cpp/, \
haptics_enabled.cpp \
platform_images.cpp \
platform_language.cpp \
)
ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/journal.cpp \
dummy/keyboard_callback.cpp \
dummy/language.cpp \
dummy/window_callback.cpp \
clipboard_helper.cpp \
haptics.cpp \

View File

@@ -0,0 +1,32 @@
#include "../../../shared/platform.h"
#include <jni.h>
namespace Ion {
namespace Simulator {
namespace Platform {
const char * languageCode() {
static char buffer[4] = {0};
if (buffer[0] == 0) {
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
jmethodID j_methodId = env->GetMethodID(
j_class,
"retrieveLanguage",
"(V)Ljava/lang/String;"
);
jstring j_language = static_cast<jstring>(env->CallObjectMethod(activity, j_methodId));
const char * language = env->GetStringUTFChars(j_language, nullptr);
memcpy(buffer, language, 4);
buffer[3] = 0;
env->ReleaseStringUTFChars(j_language, language);
}
return buffer;
}
}
}
}

View File

@@ -28,13 +28,6 @@ public class EpsilonActivity extends SDLActivity {
};
}
@Override
protected String[] getArguments() {
Locale currentLocale = getResources().getConfiguration().locale;
String[] arguments = {"--language", currentLocale.getLanguage()};
return arguments;
}
public Bitmap retrieveBitmapAsset(String identifier) {
Bitmap bitmap = null;
try {
@@ -47,6 +40,10 @@ public class EpsilonActivity extends SDLActivity {
return bitmap;
}
public String retrieveLanguage() {
return getResources().getConfiguration().locale.getLanguage();
}
public void telemetryInit() {
sAnalytics = GoogleAnalytics.getInstance(this);
sTracker = sAnalytics.newTracker("UA-93775823-3");