mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-06 18:06:26 +00:00
Android: send SDL_LOCALECHANGED when locale changes
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:alwaysRetainTaskState="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
|
||||
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.Math;
|
||||
|
||||
@@ -62,6 +63,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
protected static final int SDL_ORIENTATION_PORTRAIT_FLIPPED = 4;
|
||||
|
||||
protected static int mCurrentOrientation;
|
||||
protected static Locale mCurrentLocale;
|
||||
|
||||
// Handle the state of the native layer
|
||||
public enum NativeState {
|
||||
@@ -258,6 +260,15 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
// Only record current orientation
|
||||
SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT < 24) {
|
||||
mCurrentLocale = getContext().getResources().getConfiguration().locale;
|
||||
} else {
|
||||
mCurrentLocale = getContext().getResources().getConfiguration().getLocales().get(0);
|
||||
}
|
||||
} catch(Exception ignored) {
|
||||
}
|
||||
|
||||
setContentView(mLayout);
|
||||
|
||||
setWindowStyle(false);
|
||||
@@ -407,6 +418,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
SDLActivity.nativeLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
Log.v(TAG, "onConfigurationChanged()");
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
if (!mCurrentLocale.equals(newConfig.locale)) {
|
||||
mCurrentLocale = newConfig.locale;
|
||||
SDLActivity.onNativeLocaleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.v(TAG, "onDestroy()");
|
||||
@@ -784,6 +806,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
public static native void onNativeOrientationChanged(int orientation);
|
||||
public static native void nativeAddTouch(int touchId, String name);
|
||||
public static native void nativePermissionResult(int requestCode, boolean result);
|
||||
public static native void onNativeLocaleChanged();
|
||||
|
||||
/**
|
||||
* This method is called by SDL using JNI.
|
||||
|
Reference in New Issue
Block a user