mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
android: set preferred OS language on first start
This commit is contained in:
parent
ffb07f3076
commit
a5e52bd3c7
@ -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
|
||||
|
@ -163,6 +163,7 @@ struct android_app
|
||||
jmethodID getBatteryLevel;
|
||||
jmethodID setSustainedPerformanceMode;
|
||||
jmethodID setScreenOrientation;
|
||||
jmethodID getUserLanguageString;
|
||||
jmethodID doVibrate;
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user