List of usage examples for android.content.res Configuration Configuration
public Configuration()
Construct an invalid Configuration.
From source file:edu.mit.ll.dcds.android.AboutActivity.java
private void setLocale() { Locale locale = DataManager.getInstance().getLocale(); Locale.setDefault(locale);/*from www . j a v a 2s .com*/ Configuration config = new Configuration(); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); config.locale = locale; res.updateConfiguration(config, dm); }
From source file:com.desno365.mods.DesnoUtils.java
public static void setSavedLanguage(Context context) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String[] language = sharedPrefs.getString("selected_language", "not_changed").split("-r"); if (!language[0].equals("default") && !language[0].equals("not_changed")) { Locale locale;/*w w w . j a v a 2 s . c o m*/ if (language.length == 1) locale = new Locale(language[0]); else locale = new Locale(language[0], language[1]); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } // this will be removed when languages become more accurate // languages that I'm sure are accurate are not affected if (language[0].equals("not_changed") && !Locale.getDefault().getCountry().equals("IT")) { Locale locale = new Locale("en"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } }
From source file:org.liberty.android.fantastischmemo.AMActivity.java
private void updateInterfaceLanguage() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); String localeSetting = settings.getString(AMPrefKeys.INTERFACE_LOCALE_KEY, "AUTO"); Locale locale;// w w w . jav a2s . c om /* Force to use the a language */ if (localeSetting.equals("EN")) { locale = Locale.US; } else if (localeSetting.equals("SC")) { locale = Locale.SIMPLIFIED_CHINESE; } else if (localeSetting.equals("TC")) { locale = Locale.TRADITIONAL_CHINESE; } else if (localeSetting.equals("CS")) { locale = new Locale("CS"); } else if (localeSetting.equals("PL")) { locale = new Locale("PL"); } else if (localeSetting.equals("RU")) { locale = new Locale("RU"); } else if (localeSetting.equals("DE")) { locale = new Locale("DE"); } else if (localeSetting.equals("KO")) { locale = new Locale("KO"); } else if (localeSetting.equals("FR")) { locale = new Locale("FR"); } else if (localeSetting.equals("PT")) { locale = new Locale("PT"); } else if (localeSetting.equals("JA")) { locale = new Locale("JA"); } else if (localeSetting.equals("ES")) { locale = new Locale("ES"); } else if (localeSetting.equals("IT")) { locale = Locale.ITALIAN; } else { locale = Locale.getDefault(); } Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); }
From source file:dentex.youtube.downloader.utils.Utils.java
public static void langInit(Context context) { String lang = YTD.settings.getString("lang", "default"); Locale locale;// ww w.j av a2s. co m if (!lang.equals("default")) { String[] fLang = filterLang(lang); locale = new Locale(fLang[0], fLang[1]); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; } else { locale = new Locale(YTD.settings.getString("DEF_LANG", "")); Locale.setDefault(locale); } Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, null); }
From source file:com.perm.DoomPlay.AbstractReceiver.java
private void prepareLang() { String lang = PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance()) .getString("languages", Locale.getDefault().getLanguage()); Locale locale = new Locale(lang); Locale.setDefault(locale);/*from w w w. j a v a 2 s . c om*/ Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, null); }
From source file:io.github.mkjung.ivi.VLCApplication.java
@Override public void onCreate() { super.onCreate(); // Are we using advanced debugging - locale? mSettings = PreferenceManager.getDefaultSharedPreferences(this); String p = mSettings.getString("set_locale", ""); if (!p.equals("")) { Locale locale;/*from ww w .j a va 2s .c om*/ // 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; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } instance = this; // Initialize the database soon enough to avoid any race condition and crash MediaDatabase.getInstance(); // Prepare cache folder constants AudioUtil.prepareCacheFolder(this); sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp(); Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks); // Disable remote control receiver on Fire TV. // if (!AndroidDevices.hasTsp()) // AndroidDevices.setRemoteControlReceiverEnabled(false); }
From source file:org.videolan.vlc.VLCApp.java
public void onCreate() { // Are we using advanced debugging - locale? mSettings = PreferenceManager.getDefaultSharedPreferences(context); String p = mSettings.getString("set_locale", ""); if (!p.equals("")) { Locale locale;/*from w w w . j av a 2s . c o m*/ // 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()); } // Initialize the database soon enough to avoid any race condition and crash // MediaDatabase.getInstance(); // Prepare cache folder constants AudioUtil.prepareCacheFolder(context); sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp(); Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks); // Disable remote control receiver on Fire TV. if (!AndroidDevices.hasTsp()) AndroidDevices.setRemoteControlReceiverEnabled(false); }
From source file:net.bible.android.BibleApplication.java
/** If locale is overridden then need to set the locale again on any configuration change; see following link * http://stackoverflow.com/questions/2264874/android-changing-locale-within-the-app-itself *//*from w w w. j a va 2 s .c o m*/ @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (overrideLocale != null) { if (!overrideLocale.getLanguage().equals(newConfig.locale.getLanguage())) { Log.d(TAG, "re-applying changed Locale"); Locale.setDefault(overrideLocale); Configuration config = new Configuration(); config.locale = overrideLocale; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } } }
From source file:eu.focusnet.app.util.ApplicationHelper.java
/** * Load the proper language based on the value found in the {@link AppContentInstance} * and modify the current {@link Configuration}. This method must be called when appropriate, * but will impact all the rest of the life of the application. It does not impact the UI * directly but is typically called from an Activity's on Resume() method, or just before * redirecting to another Activity./*from w w w. jav a 2s . c o m*/ */ public static void changeLanguage(String language) { Locale targetLocale = ApplicationHelper.getDefaultLocale(); if (ApplicationHelper.getSupportedLanguages().contains(language)) { // ok targetLocale = new Locale(language); } else { // perhaps we have a cousin locale (e.g. fr if fr_CH was requested)? // // FIXME FIXME FIXME // that is not optimal. We change the language but also the l10n // For Switzerland, for example, we may prefer to keep the fr_CH locale // (so that Date/number formatting is like we do in CH), but only change the // language to French or German // -> would be solved if we could define a parent translation set in our translation // sets, e.g. fr_CH is child of fr, but we still set fr_CH as an app locale, and // therefore we will have good formatting without having to translate everything // again in French. // alternate solution: symlinks on the filesystem. UNIX-only. Pattern p = Pattern.compile("^([a-z]{2})_.*"); Matcher m = p.matcher(language); if (m.matches()) { targetLocale = new Locale(m.group(1)); } else { FocusApplication.reportError(new FocusNotImplementedException( "Non fatal: Attempting to initialize an application content with unsupported language |" + language + "|")); } } // set the language Locale.setDefault(targetLocale); Configuration config = new Configuration(); config.locale = targetLocale; getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics()); }
From source file:org.videolan.vlc.VLCApplication.java
@Override public void onCreate() { super.onCreate(); // Are we using advanced debugging - locale? mSettings = PreferenceManager.getDefaultSharedPreferences(this); String p = mSettings.getString("set_locale", ""); if (!p.equals("")) { Locale locale;/* w w w .j a va 2 s . c o m*/ // 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; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } instance = this; // Initialize the database soon enough to avoid any race condition and crash MediaDatabase.getInstance(); // Prepare cache folder constants AudioUtil.prepareCacheFolder(this); sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp(); if (!VLCInstance.testCompatibleCPU(this)) return; Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks); // Disable remote control receiver on Fire TV. if (!AndroidDevices.hasTsp()) AndroidDevices.setRemoteControlReceiverEnabled(false); if (Permissions.canReadStorage()) discoverStorages(getMLInstance()); }