[android] Enable init and detection change of system locale
Signed-off-by: Gonzalo Pesquero <gpesquero@yahoo.es>
This commit is contained in:
parent
bdfc5fe2de
commit
ebd1ea9f4f
3 changed files with 32 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "android/app/src/main/cpp/app/organicmaps/core/jni_helper.hpp"
|
||||
#include "platform/measurement_utils.hpp"
|
||||
#include "platform/preferred_languages.hpp"
|
||||
|
||||
extern "C"
|
||||
|
@ -9,4 +10,10 @@ Java_app_organicmaps_util_Language_nativeNormalize(JNIEnv *env, jclass type, jst
|
|||
std::string locale = languages::Normalize(jni::ToNativeString(env, lang));
|
||||
return jni::ToJavaString(env, locale);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_app_organicmaps_util_Language_nativeRefreshSystemLocale(JNIEnv *, jclass)
|
||||
{
|
||||
measurement_utils::RefreshSystemLocale();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@ import static app.organicmaps.location.LocationState.LOCATION_TAG;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -41,6 +44,7 @@ import app.organicmaps.settings.StoragePathManager;
|
|||
import app.organicmaps.sound.TtsPlayer;
|
||||
import app.organicmaps.util.Config;
|
||||
import app.organicmaps.util.ConnectionState;
|
||||
import app.organicmaps.util.Language;
|
||||
import app.organicmaps.util.SharedPropertiesUtils;
|
||||
import app.organicmaps.util.StorageUtils;
|
||||
import app.organicmaps.util.ThemeSwitcher;
|
||||
|
@ -89,6 +93,8 @@ public class MwmApplication extends Application implements Application.ActivityL
|
|||
@Nullable
|
||||
private WeakReference<Activity> mTopActivity;
|
||||
|
||||
private BroadcastReceiver mLocaleChangeReceiver;
|
||||
|
||||
@UiThread
|
||||
@Nullable
|
||||
public Activity getTopActivity()
|
||||
|
@ -213,6 +219,22 @@ public class MwmApplication extends Application implements Application.ActivityL
|
|||
Config.setStoragePath(writablePath);
|
||||
Config.setStatisticsEnabled(SharedPropertiesUtils.isStatisticsEnabled(this));
|
||||
|
||||
// Force native system locale initialization at app start-up.
|
||||
Language.nativeRefreshSystemLocale();
|
||||
|
||||
// Setup BroadcastReceiver to receive changes of system locale.
|
||||
mLocaleChangeReceiver = new BroadcastReceiver()
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
// Refresh the native c++ system locale.
|
||||
Language.nativeRefreshSystemLocale();
|
||||
}
|
||||
};
|
||||
|
||||
registerReceiver(mLocaleChangeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
|
||||
|
||||
mPlatformInitialized = true;
|
||||
Logger.i(TAG, "Platform initialized");
|
||||
}
|
||||
|
|
|
@ -58,4 +58,7 @@ public class Language
|
|||
|
||||
@NonNull
|
||||
public static native String nativeNormalize(@NonNull String locale);
|
||||
|
||||
@NonNull
|
||||
public static native void nativeRefreshSystemLocale();
|
||||
}
|
||||
|
|
Reference in a new issue