Skip to content
Snippets Groups Projects
Commit 442134d8 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Set Locale on activity re-creation

Should fix locale failure on multiwindowing with recent Android versions
parent 6dd396fc
No related branches found
No related tags found
No related merge requests found
......@@ -83,45 +83,13 @@ public class VLCApplication extends Application {
private static int sDialogCounter = 0;
public static void setLocale(Context context){
// Are we using advanced debugging - locale?
String p = mSettings.getString("set_locale", "");
if (!p.equals("")) {
Locale locale;
// workaround due to region code
if(p.equals("zh-TW")) {
locale = Locale.TRADITIONAL_CHINESE;
} else if(p.startsWith("zh")) {
locale = Locale.CHINA;
} else if(p.equals("pt-BR")) {
locale = new Locale("pt", "BR");
} else if(p.equals("bn-IN") || p.startsWith("bn")) {
locale = new Locale("bn", "IN");
} else {
/**
* Avoid a crash of
* java.lang.AssertionError: couldn't initialize LocaleData for locale
* if the user enters nonsensical region codes.
*/
if(p.contains("-"))
p = p.substring(0, p.indexOf('-'));
locale = new Locale(p);
}
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
}
@Override
public void onCreate() {
super.onCreate();
instance = this;
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
setLocale(this);
setLocale();
runBackground(new Runnable() {
@Override
......@@ -145,7 +113,7 @@ public class VLCApplication extends Application {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setLocale(this);
setLocale();
}
/**
......@@ -264,4 +232,36 @@ public class VLCApplication extends Application {
}
return sMedialibraryInstance;
}
public static void setLocale(){
// Are we using advanced debugging - locale?
String p = mSettings.getString("set_locale", "");
if (!p.equals("")) {
Locale locale;
// workaround due to region code
if(p.equals("zh-TW")) {
locale = Locale.TRADITIONAL_CHINESE;
} else if(p.startsWith("zh")) {
locale = Locale.CHINA;
} else if(p.equals("pt-BR")) {
locale = new Locale("pt", "BR");
} else if(p.equals("bn-IN") || p.startsWith("bn")) {
locale = new Locale("bn", "IN");
} else {
/**
* Avoid a crash of
* java.lang.AssertionError: couldn't initialize LocaleData for locale
* if the user enters nonsensical region codes.
*/
if(p.contains("-"))
p = p.substring(0, p.indexOf('-'));
locale = new Locale(p);
}
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getAppResources().updateConfiguration(config,
getAppResources().getDisplayMetrics());
}
}
}
......@@ -56,7 +56,7 @@ public class AboutFragment extends Fragment {
//Fix android 7 Locale problem with webView
//https://stackoverflow.com/questions/40398528/android-webview-locale-changes-abruptly-on-android-n
if (AndroidUtil.isNougatOrLater)
VLCApplication.setLocale(getContext());
VLCApplication.setLocale();
View aboutMain = v.findViewById(R.id.about_main);
WebView webView = (WebView)v.findViewById(R.id.webview);
......
......@@ -99,6 +99,7 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba
protected void onCreate(Bundle savedInstanceState) {
//Init Medialibrary if KO
if (savedInstanceState != null) {
VLCApplication.setLocale();
if (!VLCApplication.getMLInstance().isInitiated() && Permissions.canReadStorage())
startService(new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment