android: set preferred OS language on first start

This commit is contained in:
Brad Parker 2019-04-16 02:09:38 -04:00
parent ffb07f3076
commit a5e52bd3c7
3 changed files with 37 additions and 1 deletions

View File

@ -2052,6 +2052,8 @@ static void frontend_unix_init(void *data)
"setScreenOrientation", "(I)V");
GET_METHOD_ID(env, android_app->doVibrate, class,
"doVibrate", "(IIII)V");
GET_METHOD_ID(env, android_app->getUserLanguageString, class,
"getUserLanguageString", "()Ljava/lang/String;");
CALL_OBJ_METHOD(env, obj, android_app->activity->clazz,
android_app->getIntent);
@ -2499,7 +2501,25 @@ enum retro_language frontend_unix_get_user_language(void)
enum retro_language lang = RETRO_LANGUAGE_ENGLISH;
#ifdef HAVE_LANGEXTRA
#ifdef ANDROID
return RETRO_LANGUAGE_ENGLISH;
jstring jstr = NULL;
JNIEnv *env = jni_thread_getenv();
if (!env || !g_android)
return lang;
if (g_android->getUserLanguageString)
{
CALL_OBJ_METHOD(env, jstr, g_android->activity->clazz, g_android->getUserLanguageString);
if (jstr)
{
const char *langStr = (*env)->GetStringUTFChars(env, jstr, 0);
lang = rarch_get_language_from_iso(langStr);
(*env)->ReleaseStringUTFChars(env, jstr, langStr);
}
}
#else
lang = rarch_get_language_from_iso(getenv("LANG"));
#endif

View File

@ -163,6 +163,7 @@ struct android_app
jmethodID getBatteryLevel;
jmethodID setSustainedPerformanceMode;
jmethodID setScreenOrientation;
jmethodID getUserLanguageString;
jmethodID doVibrate;
};

View File

@ -21,6 +21,7 @@ import android.os.VibrationEffect;
import android.util.Log;
import java.lang.Math;
import java.util.concurrent.CountDownLatch;
import java.util.Locale;
/**
* Class which provides common methods for RetroActivity related classes.
@ -153,6 +154,20 @@ public class RetroActivityCommon extends RetroActivityLocation
});
}
public String getUserLanguageString()
{
String lang = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry();
if (lang.length() == 0)
return "en";
if (country.length() == 0)
return lang;
return lang + '_' + country;
}
@TargetApi(24)
public void setSustainedPerformanceMode(boolean on)
{