List of usage examples for android.content.res Configuration Configuration
public Configuration()
Construct an invalid Configuration.
From source file:Main.java
public static void setLocale(final Context ctx, final String lang) { final Locale loc = new Locale(lang); Locale.setDefault(loc);//from w ww .ja v a 2 s.com final Configuration cfg = new Configuration(); cfg.locale = loc; ctx.getResources().updateConfiguration(cfg, null); }
From source file:Main.java
public static void setLanguge(Context ctx, String languageToLoad) { Locale locale = new Locale(languageToLoad); Locale.setDefault(locale);/* w ww.ja v a 2 s .c om*/ Configuration config = new Configuration(); config.locale = locale; ctx.getResources().updateConfiguration(config, ctx.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Update language//from ww w.ja v a 2 s . c o m * * @param code The language code. Like: en, cz, iw, ... */ public static void updateLanguage(Context context, String code) { Locale locale = new Locale(code); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Change the default locale of the application for this activity * * @param locale To set in the configuration *//*from ww w . j ava 2s . c om*/ public static void setDefaultLocale(Context context, String locale) { Locale locJa = new Locale(locale); Locale.setDefault(locJa); Configuration config = new Configuration(); config.locale = locJa; if (context != null) { context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } }
From source file:Main.java
public static void setLanguage(Context context, String language) { Locale locale;/* ww w. j av a 2s . c o m*/ if (TextUtils.isEmpty(language)) { locale = Locale.getDefault(); } else if (language.length() == 5 && language.charAt(2) == '_') { // language is in the form: en_US locale = new Locale(language.substring(0, 2), language.substring(3)); } else { locale = new Locale(language); } Configuration config = new Configuration(); config.locale = locale; Resources resources = context.getResources(); resources.updateConfiguration(config, resources.getDisplayMetrics()); }
From source file:Main.java
public static void setCurrent(Context context, Locale locale) { Locale.setDefault(locale);//from w w w .jav a 2s. c o m Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); }
From source file:com.becapps.easydownloader.utils.Utils.java
public static void langInit(Context context) { String storedDefLang = settings.getString("DEF_LANG", ""); if (storedDefLang.isEmpty() && storedDefLang != null) { Locale defLocale = Locale.getDefault(); String defLang = defLocale.getLanguage(); settings.edit().putString("DEF_LANG", defLang).commit(); }/* w w w . ja v a2 s . co m*/ String lang = settings.getString("lang", "default"); Locale locale; 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(settings.getString("DEF_LANG", "")); Locale.setDefault(locale); } Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, null); }
From source file:com.loadsensing.app.ImatgeXarxaSensors.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Definimos idioma SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ImatgeXarxaSensors.this); Locale locale = new Locale(settings.getString("location", "es")); Locale.setDefault(locale);//from ww w. ja v a 2s .c om Configuration config = new Configuration(); config.locale = locale; getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); setContentView(new TouchView(this)); }
From source file:com.example.adbird.MenuTabActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_menu);/*from w w w .j a v a 2s . c o m*/ mContext = this.getApplicationContext(); SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE); String lang = prefs.getString("lang", null); Locale locale = new Locale(lang); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title)); s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setTitle(s); actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position)); s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionBar.setTitle(s); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { actionBar.addTab( actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this)); } }