List of usage examples for android.content.res Resources updateConfiguration
@Deprecated public void updateConfiguration(Configuration config, DisplayMetrics metrics)
From source file:github.madmarty.madsonic.util.Util.java
public static void changeLanguage(Context context) { Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); SharedPreferences prefs = getPreferences(context); String appLanguage = prefs.getString(Constants.PREFERENCES_KEY_LANGUAGE, "us"); if ("auto".equalsIgnoreCase(appLanguage)) { conf.locale = new Locale("en"); res.updateConfiguration(conf, dm); } else {/*from w ww . java2 s .c o m*/ conf.locale = new Locale(appLanguage); res.updateConfiguration(conf, dm); } }
From source file:com.timekeeping.app.activities.MainActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); //System setting might be changed, ie. language. Resources resources = getResources(); if (resources != null) { resources.updateConfiguration(newConfig, resources.getDisplayMetrics()); }/*from w w w.ja v a 2s .co m*/ }
From source file:im.vector.VectorApp.java
/** * Compute a localised context//w ww .jav a2 s . co m * * @param context the context * @return the localised context */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Context getLocalisedContext(Context context) { try { Resources resources = context.getResources(); Locale locale = getApplicationLocale(); Configuration configuration = resources.getConfiguration(); configuration.fontScale = getFontScaleValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { configuration.setLocale(locale); configuration.setLayoutDirection(locale); return context.createConfigurationContext(configuration); } else { configuration.locale = locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { configuration.setLayoutDirection(locale); } resources.updateConfiguration(configuration, resources.getDisplayMetrics()); return context; } } catch (Exception e) { Log.e(LOG_TAG, "## getLocalisedContext() failed : " + e.getMessage()); } return context; }
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
/** * Load user preferences/*from w w w. j av a 2 s . c o m*/ */ private void loadSavedPreferences() { assert getApplicationContext() != null; // Set the locale according to preference Locale myLocale = new Locale(PreferencesUtils.getString(this, R.string.languageKey, Config.DEFAULT_LOCALE)); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { conf.setLayoutDirection(myLocale); } res.updateConfiguration(conf, dm); }
From source file:net.e_fas.oss.tabijiman.MapsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { e_print("onCreate"); // ActionBar? if (savedInstanceState == null) { // customActionBar?? View customActionBarView = this.getActionBarView(); // ActionBar?? ActionBar actionBar = this.getSupportActionBar(); // ?????('<' <- ???) if (actionBar != null) { // ??????? actionBar.setDisplayShowTitleEnabled(false); // icon??????? actionBar.setDisplayShowHomeEnabled(false); // ActionBar?customView? actionBar.setCustomView(customActionBarView); // CutomView?? actionBar.setDisplayShowCustomEnabled(true); }/*from w w w . j a v a 2s.c o m*/ } // ????? Locale locale = Locale.getDefault(); if (locale.equals(Locale.JAPAN) || locale.equals(Locale.JAPANESE)) { locale = Locale.JAPAN; } else { locale = Locale.ENGLISH; } // ?? Locale.setDefault(locale); Configuration config = new Configuration(); // Resources?? config.locale = locale; Resources resources = getBaseContext().getResources(); // Resources?????? resources.updateConfiguration(config, null); super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); try { new CreateInitData(this).exec(locale); new SPARQL().query(AppSetting.query_place, "place"); new SPARQL().query(AppSetting.query_frame, "frame"); } catch (IOException | JSONException e) { e.printStackTrace(); } makeTempDir(); // ??? ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo == null) { Toast.makeText(getApplicationContext(), "???????????", Toast.LENGTH_LONG).show(); } buttons = new ArrayList<>(); View.OnClickListener change_button = new View.OnClickListener() { @Override public void onClick(View v) { CameraPosition cameraPos; if (v == TrainButton) { zoomLevel = 9.0f; cameraPos = new CameraPosition.Builder() .target(new LatLng(nowLocation.latitude, nowLocation.longitude)).zoom(zoomLevel) .bearing(0).build(); } else if (v == CarButton) { zoomLevel = 11.0f; cameraPos = new CameraPosition.Builder() .target(new LatLng(nowLocation.latitude, nowLocation.longitude)).zoom(zoomLevel) .bearing(0).build(); } else { zoomLevel = 14.0f; cameraPos = new CameraPosition.Builder() .target(new LatLng(nowLocation.latitude, nowLocation.longitude)).zoom(zoomLevel) .bearing(0).build(); } if (!v.isActivated()) { v.setActivated(true); for (int i = 0; i < buttons.size(); i++) { if (buttons.get(i) != v) { buttons.get(i).setActivated(false); } } } mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos)); } }; View.OnClickListener marker_change_button = new View.OnClickListener() { @Override public void onClick(View v) { if (!v.isActivated()) { v.setActivated(true); if (v == FrameSwitch) { setMarker("frame"); FrameMarkerOptions.clear(); } else { setMarker("place"); PlaceMarkerOptions.clear(); } } else { v.setActivated(false); if (v == FrameSwitch) { for (Marker m : FrameMarker) { m.remove(); } FrameMarker.clear(); } else { for (Marker m : PlaceMarker) { m.remove(); } PlaceMarker.clear(); } } } }; // LocationManager? mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); TakePicture = (ImageButton) findViewById(R.id.takePicture); TakePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent TakePictureView = new Intent(getApplicationContext(), TakePicture.class); startActivity(TakePictureView); } }); TrainButton = (ImageButton) findViewById(R.id.Train); TrainButton.setActivated(false); TrainButton.setOnClickListener(change_button); CarButton = (ImageButton) findViewById(R.id.Car); CarButton.setActivated(true); CarButton.setOnClickListener(change_button); WalkButton = (ImageButton) findViewById(R.id.Walk); WalkButton.setActivated(false); WalkButton.setOnClickListener(change_button); buttons = Arrays.asList(TrainButton, CarButton, WalkButton); FrameSwitch = (ImageButton) findViewById(R.id.showFrame); FrameSwitch.setActivated(true); FrameSwitch.setOnClickListener(marker_change_button); PlaceSwitch = (ImageButton) findViewById(R.id.showPlace); PlaceSwitch.setActivated(true); PlaceSwitch.setOnClickListener(marker_change_button); GoFukuiButton = (ImageButton) findViewById(R.id.GoFukuiButton); // new AppSetting(this); // AppSetting.context = getApplicationContext(); AppSetting.Inc_CountRun(); e_print("Run_Count >> " + AppSetting.CountRun()); if (AppSetting.CountRun() % 20 == 0) { GoFukuiButton.setVisibility(View.VISIBLE); } FrameCollectionButton = (ImageButton) findViewById(R.id.frameCollection); FrameCollectionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent collection = new Intent(getApplicationContext(), FrameCollection.class); startActivity(collection); } }); mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); // mapFragment.getMap(); helper = new SQLiteHelper(this); db = helper.getWritableDatabase(); }
From source file:dev.ukanth.ufirewall.Api.java
public static void updateLanguage(Context context, String lang) { if (!"".equals(lang)) { Locale locale = new Locale(lang); Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = locale;/* ww w . j ava 2 s. co m*/ res.updateConfiguration(conf, dm); } }
From source file:com.ifoer.expeditionphone.MainActivity.java
public void switchLanguage(Locale locale) { Resources resources = getBaseContext().getResources(); Configuration config = resources.getConfiguration(); DisplayMetrics dm = resources.getDisplayMetrics(); config.locale = locale;/*from www .j a v a 2s .c o m*/ resources.updateConfiguration(config, dm); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void initSuggest(String locale) { mInputLocale = locale;//from ww w . j a v a 2s .co m Resources orig = getResources(); Configuration conf = orig.getConfiguration(); Locale saveLocale = conf.locale; conf.locale = new Locale(locale); orig.updateConfiguration(conf, orig.getDisplayMetrics()); if (mSuggest != null) { mSuggest.close(); } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, getResources().getBoolean(R.bool.default_quick_fixes)); int[] dictionaries = getDictionary(orig); mSuggest = new Suggest(this, dictionaries); updateAutoTextEnabled(saveLocale); if (mUserDictionary != null) mUserDictionary.close(); mUserDictionary = new UserDictionary(this, mInputLocale); //if (mContactsDictionary == null) { // mContactsDictionary = new ContactsDictionary(this, // Suggest.DIC_CONTACTS); //} if (mAutoDictionary != null) { mAutoDictionary.close(); } mAutoDictionary = new AutoDictionary(this, this, mInputLocale, Suggest.DIC_AUTO); if (mUserBigramDictionary != null) { mUserBigramDictionary.close(); } mUserBigramDictionary = new UserBigramDictionary(this, this, mInputLocale, Suggest.DIC_USER); mSuggest.setUserBigramDictionary(mUserBigramDictionary); mSuggest.setUserDictionary(mUserDictionary); //mSuggest.setContactsDictionary(mContactsDictionary); mSuggest.setAutoDictionary(mAutoDictionary); updateCorrectionMode(); mWordSeparators = mResources.getString(R.string.word_separators); mSentenceSeparators = mResources.getString(R.string.sentence_separators); initSuggestPuncList(); conf.locale = saveLocale; orig.updateConfiguration(conf, orig.getDisplayMetrics()); }
From source file:com.androzic.Androzic.java
public void onCreateEx() { try {/*from w w w. ja va 2s .com*/ (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER)).mkdirs(); (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER + "/ghiam")).mkdirs(); } catch (Throwable e) { } if (initialized) return; AndroidGraphicFactory.createInstance(this); try { OzfDecoder.useNativeCalls(); } catch (UnsatisfiedLinkError e) { Toast.makeText(Androzic.this, "Failed to initialize native library: " + e.getMessage(), Toast.LENGTH_LONG).show(); } Resources resources = getResources(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); Configuration config = resources.getConfiguration(); renderingThread = new HandlerThread("RenderingThread"); renderingThread.start(); longOperationsThread = new HandlerThread("LongOperationsThread"); longOperationsThread.setPriority(Thread.MIN_PRIORITY); longOperationsThread.start(); uiHandler = new Handler(); mapsHandler = new Handler(longOperationsThread.getLooper()); // We silently initialize data uri to let location service restart after crash File datadir = new File( settings.getString(getString(R.string.pref_folder_data), Environment.getExternalStorageDirectory() + File.separator + resources.getString(R.string.def_folder_data))); setDataPath(Androzic.PATH_DATA, datadir.getAbsolutePath()); setInstance(this); String intentToCheck = "com.androzic.donate"; String myPackageName = getPackageName(); PackageManager pm = getPackageManager(); PackageInfo pi; try { pi = pm.getPackageInfo(intentToCheck, 0); isPaid = (pm.checkSignatures(myPackageName, pi.packageName) == PackageManager.SIGNATURE_MATCH); } catch (NameNotFoundException e) { // e.printStackTrace(); } File sdcard = Environment.getExternalStorageDirectory(); Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this, sdcard.getAbsolutePath())); DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); if (wm != null) { wm.getDefaultDisplay().getMetrics(displayMetrics); } else { displayMetrics.setTo(resources.getDisplayMetrics()); } BaseMap.viewportWidth = displayMetrics.widthPixels; BaseMap.viewportHeight = displayMetrics.heightPixels; charset = settings.getString(getString(R.string.pref_charset), "UTF-8"); String lang = settings.getString(getString(R.string.pref_locale), ""); if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) { locale = new Locale(lang); Locale.setDefault(locale); config.locale = locale; resources.updateConfiguration(config, resources.getDisplayMetrics()); } magInterval = resources.getInteger(R.integer.def_maginterval) * 1000; overlayManager = new OverlayManager(longOperationsThread.getLooper()); TooltipManager.initialize(this); onSharedPreferenceChanged(settings, getString(R.string.pref_unitcoordinate)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitdistance)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitspeed)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitelevation)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitangle)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitanglemagnetic)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitsunrise)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent)); onSharedPreferenceChanged(settings, getString(R.string.pref_vectormap_textscale)); onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapprescalefactor)); onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapexpiration)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder)); onSharedPreferenceChanged(settings, getString(R.string.pref_showwaypoints)); onSharedPreferenceChanged(settings, getString(R.string.pref_showcurrenttrack)); onSharedPreferenceChanged(settings, getString(R.string.pref_showaccuracy)); onSharedPreferenceChanged(settings, getString(R.string.pref_showdistance_int)); settings.registerOnSharedPreferenceChangeListener(this); initialized = true; }