@@ -371,6 +371,7 @@ static jmethodID midShowTextInput;
371
371
static jmethodID midSupportsRelativeMouse ;
372
372
static jmethodID midOpenFileDescriptor ;
373
373
static jmethodID midShowFileDialog ;
374
+ static jmethodID midGetPreferredLocales ;
374
375
375
376
// audio manager
376
377
static jclass mAudioManagerClass ;
@@ -660,6 +661,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
660
661
midSupportsRelativeMouse = (* env )-> GetStaticMethodID (env , mActivityClass , "supportsRelativeMouse" , "()Z" );
661
662
midOpenFileDescriptor = (* env )-> GetStaticMethodID (env , mActivityClass , "openFileDescriptor" , "(Ljava/lang/String;Ljava/lang/String;)I" );
662
663
midShowFileDialog = (* env )-> GetStaticMethodID (env , mActivityClass , "showFileDialog" , "([Ljava/lang/String;ZZI)Z" );
664
+ midGetPreferredLocales = (* env )-> GetStaticMethodID (env , mActivityClass , "getPreferredLocales" , "()Ljava/lang/String;" );
663
665
664
666
if (!midClipboardGetText ||
665
667
!midClipboardHasText ||
@@ -691,7 +693,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
691
693
!midShowTextInput ||
692
694
!midSupportsRelativeMouse ||
693
695
!midOpenFileDescriptor ||
694
- !midShowFileDialog ) {
696
+ !midShowFileDialog ||
697
+ !midGetPreferredLocales ) {
695
698
__android_log_print (ANDROID_LOG_WARN , "SDL" , "Missing some Java callbacks, do you have the latest version of SDLActivity.java?" );
696
699
}
697
700
@@ -2585,65 +2588,22 @@ bool Android_JNI_ShowToast(const char *message, int duration, int gravity, int x
2585
2588
2586
2589
bool Android_JNI_GetLocale (char * buf , size_t buflen )
2587
2590
{
2588
- AConfiguration * cfg ;
2589
-
2590
- SDL_assert (buflen > 6 );
2591
-
2592
- // Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED)
2593
- Internal_Android_Destroy_AssetManager ();
2594
-
2595
- if (!asset_manager ) {
2596
- Internal_Android_Create_AssetManager ();
2597
- }
2598
-
2599
- if (!asset_manager ) {
2600
- return false;
2601
- }
2602
-
2603
- cfg = AConfiguration_new ();
2604
- if (!cfg ) {
2605
- return false;
2606
- }
2607
-
2608
- {
2609
- char language [2 ] = {};
2610
- char country [2 ] = {};
2611
- size_t id = 0 ;
2612
-
2613
- AConfiguration_fromAssetManager (cfg , asset_manager );
2614
- AConfiguration_getLanguage (cfg , language );
2615
- AConfiguration_getCountry (cfg , country );
2616
-
2617
- // Indonesian is "id" according to ISO 639.2, but on Android is "in" because of Java backwards compatibility
2618
- if (language [0 ] == 'i' && language [1 ] == 'n' ) {
2619
- language [1 ] = 'd' ;
2620
- }
2621
-
2622
- // copy language (not null terminated)
2623
- if (language [0 ]) {
2624
- buf [id ++ ] = language [0 ];
2625
- if (language [1 ]) {
2626
- buf [id ++ ] = language [1 ];
2627
- }
2628
- }
2629
-
2630
- buf [id ++ ] = '_' ;
2631
-
2632
- // copy country (not null terminated)
2633
- if (country [0 ]) {
2634
- buf [id ++ ] = country [0 ];
2635
- if (country [1 ]) {
2636
- buf [id ++ ] = country [1 ];
2591
+ bool result = false;
2592
+ if (buf && buflen > 0 ) {
2593
+ * buf = '\0' ;
2594
+ JNIEnv * env = Android_JNI_GetEnv ();
2595
+ jstring string = (jstring )(* env )-> CallStaticObjectMethod (env , mActivityClass , midGetPreferredLocales );
2596
+ if (string ) {
2597
+ const char * utf8string = (* env )-> GetStringUTFChars (env , string , NULL );
2598
+ if (utf8string ) {
2599
+ result = true;
2600
+ SDL_strlcpy (buf , utf8string , buflen );
2601
+ (* env )-> ReleaseStringUTFChars (env , string , utf8string );
2637
2602
}
2603
+ (* env )-> DeleteLocalRef (env , string );
2638
2604
}
2639
-
2640
- buf [id ++ ] = '\0' ;
2641
- SDL_assert (id <= buflen );
2642
2605
}
2643
-
2644
- AConfiguration_delete (cfg );
2645
-
2646
- return true;
2606
+ return result ;
2647
2607
}
2648
2608
2649
2609
bool Android_JNI_OpenURL (const char * url )
0 commit comments