List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
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); }/* w ww .j av a 2 s .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:gr.ioanpier.auth.users.memorypaintings.MainActivityFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Language Locale String languageToLoad = getActivity().getIntent().getStringExtra(LANGUAGE); // your language if (languageToLoad != null) { Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;/* www.ja va 2s .co m*/ getActivity().getResources().updateConfiguration(config, getActivity().getResources().getDisplayMetrics()); } View rootView = inflater.inflate(R.layout.fragment_main, container, false); //Calculate the level and the number of cards. level = getActivity().getIntent().getIntExtra(LEVEL_TAG, 0); if (level >= layoutsPerLevel.length) level = layoutsPerLevel.length - 1; numberOfCards = cardsPerLevel[level]; numberOfBitmapWorkerTasks = numberOfCards / 2; instantiateLoadingBar(); if (!isExternalStorageReadable()) { Log.e(LOG, "External storage wasn't readable"); storedDrawables = null; } else { File[] imageFiles = getFilesFromDirectory(WelcomeScreen.IMAGES_PATH, ".jpg", ".png"); if (imageFiles.length > 0) { String descriptionsFolder = "Descriptions"; Locale locale = getActivity().getResources().getConfiguration().locale; if (locale.getDisplayLanguage().equals(Locale.ENGLISH.getDisplayLanguage())) descriptionsFolder = descriptionsFolder.concat("_en"); else descriptionsFolder = descriptionsFolder.concat("_pl"); File[] descFiles = getFilesFromDirectory(WelcomeScreen.DESCRIPTIONS_PATH, ".txt"); //getDrawables storedDrawables = getDrawables(imageFiles, descFiles); } else { Log.e(LOG, "No files found in external storage"); storedDrawables = null; } } pairs = new int[numberOfCards]; for (int i = 0; i < numberOfCards; i++) { pairs[i] = -1; } cards = new ImageViewCard[numberOfCards]; //This is where the layout magic happens. LinearLayout linearLayout; int index; for (int i = 0; i < layoutsPerLevel[level]; i++) { //The layout consists of multiple vertical LinearLayout[s] positioned horizontally next to each other. linearLayout = new LinearLayout(getActivity()); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f)); linearLayout.setOrientation(LinearLayout.VERTICAL); for (int j = 0; j < numberOfCards / layoutsPerLevel[level]; j++) { //Each LinearLayout has a number of ImageViewCard[s], each positioned evenly in inside the layout. The number depends on the level. //ImageViewCard is an extension of the ViewFlipper class with a built in flipCard method for flipping between 2 images and which also includes animation. ImageViewCard card = new ImageViewCard(getActivity()); card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f)); ((LinearLayout.LayoutParams) card.getLayoutParams()).setMargins(16, 16, 16, 16); //SquareImageView is an extension of the ImageView class that ensures that the image is square. //Two are needed, one for the back of the image and one for the front. SquareImageView image1 = new SquareImageView(getActivity()); image1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); SquareImageView image2 = new SquareImageView(getActivity()); image2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); //Add the SquareImageView[s] to the ImageViewCard and subsequently that to the LinearLayout. card.addView(image1); card.addView(image2); index = i * numberOfCards / layoutsPerLevel[level] + j; linearLayout.addView(card); cardsIndex.put(card.hashCode(), index); //Set the back of the image. ((ImageView) card.getChildAt(0)) .setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.black)); //Save the ImageViewCard for later use. cards[index] = card; } //Add the LinearLayout to the rootView. ((LinearLayout) rootView.findViewById(R.id.parent)).addView(linearLayout); } //Assign a listener for every ImageViewCard. View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { if (!stillAnimating && numberOfBitmapWorkerTasks == 0) { int cardID = cardsIndex.get(view.hashCode()); stillAnimating = true; synchronized (gameLogicLock) { if (numberOfCardsFound < numberOfCards) onCardFlipped(cardID); else onCardClicked(cardID); } //Add a delay before the listener can be activated again. new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { try { Thread.sleep(250); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(Void n) { stillAnimating = false; } }.execute(); } else if (numberOfBitmapWorkerTasks > 0) { Toast.makeText(getActivity(), getString(R.string.loading_bar_message), Toast.LENGTH_SHORT) .show(); } } }; for (int i = 0; i < numberOfCards; i++) { cards[i].setOnClickListener(onClickListener); } //Initialize found = new boolean[numberOfCards]; for (int i = 0; i < numberOfCards; i++) found[i] = false; //Initialize int[] chosenDrawables = new int[numberOfCards / 2]; cardDrawablePairs = new int[numberOfCards]; //Initialize. Holds the index of every ImageViewCard in cards. Will later be used for the pairs. ArrayList<Integer> availablePairs = new ArrayList<>(); for (int i = 0; i < numberOfCards; i++) availablePairs.add(i); Collections.shuffle(availablePairs); Random r = new Random(); int pair1, pair2; BitmapWorkerTask bitmapWorkerTask; for (int i = 0; i < numberOfCards / 2; i++) { //Choose at random one of the available images. Make sure it's unique. int range; if (storedDrawables == null) range = colors.length; else range = storedDrawables.length; boolean unique = false; while (!unique) { unique = true; //If there are a lot of images, this should be changed (there will never be a lot) chosenDrawables[i] = r.nextInt(range); for (int j = 0; j < i; j++) { if (chosenDrawables[i] == chosenDrawables[j]) unique = false; } } //availablePairs have already been shuffled, so just remove the first 2. pair1 = availablePairs.remove(0); pair2 = availablePairs.remove(0); cardDrawablePairs[pair1] = chosenDrawables[i]; cardDrawablePairs[pair2] = chosenDrawables[i]; //Assign the front of the ImageViewCard to the randomly chosen Drawable. ImageView imageView1, imageView2; String absolutePath; if (storedDrawables == null) { (cards[pair1].getChildAt(1)) .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]])); (cards[pair2].getChildAt(1)) .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]])); } else { DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut wm.getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels / (layoutsPerLevel[level]); int screenHeight = displayMetrics.heightPixels / (cardsPerLevel[level] / layoutsPerLevel[level]); absolutePath = storedDrawables[chosenDrawables[i]].absolute_path_image; imageView1 = ((ImageView) cards[pair1].getChildAt(1)); imageView2 = ((ImageView) cards[pair2].getChildAt(1)); bitmapWorkerTask = new BitmapWorkerTask(screenWidth, screenHeight, imageView1, imageView2); bitmapWorkerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, absolutePath); } //Save the pairs. pairs[pair1] = pair2; pairs[pair2] = pair1; } if (storedDrawables == null) { numberOfBitmapWorkerTasks = 0; } return rootView; }
From source file:org.jfree.data.time.MonthTest.java
/** * Some checks for the getFirstMillisecond() method. *//* ww w . j a va2 s. com*/ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(5094000000L, m.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:by.zatta.pilight.connection.ConnectionService.java
public void makeLocale(String language) { Log.w(TAG, language + " makeLocale"); Locale locale = new Locale(language); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;// w w w .j a v a2s . c om getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); }
From source file:org.jfree.data.time.junit.HourTest.java
/** * Some checks for the getFirstMillisecond() method. */// w w w . ja v a 2 s .c om public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(15, 1, 4, 2006); assertEquals(1143900000000L, h.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.agiso.tempel.Tempel.java
/** * //from www . j a v a2 s . c om * * @param properties * @throws Exception */ private Map<String, Object> addRuntimeProperties(Map<String, Object> properties) throws Exception { Map<String, Object> props = new HashMap<String, Object>(); // Okrelanie lokalizacji daty/czasu uywanej do wypenienia paramtrw szablonw // zawierajcych dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL: Locale date_locale; if (properties.containsKey(UP_DATE_LOCALE)) { date_locale = LocaleUtils.toLocale((String) properties.get(UP_DATE_LOCALE)); Locale.setDefault(date_locale); } else { date_locale = Locale.getDefault(); } TimeZone time_zone; if (properties.containsKey(UP_TIME_ZONE)) { time_zone = TimeZone.getTimeZone((String) properties.get(UP_DATE_LOCALE)); TimeZone.setDefault(time_zone); } else { time_zone = TimeZone.getDefault(); } // Wyznaczanie daty, na podstawie ktrej zostan wypenione parametry szablonw // przechowujce dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL. // Odbywa si w oparciu o wartoci parametrw 'date_format' i 'date'. Parametr // 'date_format' definiuje format uywany do parsowania acucha reprezentujcego // dat okrelon parametrem 'date'. Parametr 'date_format' moe nie by okrelony. // W takiej sytuacji uyty jest format DateFormat.LONG aktywnej lokalizacji (tj. // systemowej, ktra moe by przedefiniowana przez parametr 'date_locale'), ktry // moe by przedefiniowany przez parametry 'date_format_long' i 'time_format_long': Calendar calendar = Calendar.getInstance(date_locale); if (properties.containsKey(RP_DATE)) { String date_string = (String) properties.get(RP_DATE); if (properties.containsKey(RP_DATE_FORMAT)) { String date_format = (String) properties.get(RP_DATE_FORMAT); DateFormat formatter = new SimpleDateFormat(date_format); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else if (properties.containsKey(UP_DATE_FORMAT_LONG) && properties.containsKey(UP_TIME_FORMAT_LONG)) { // TODO: Zaoenie, e format data-czas jest zoony z acucha daty i czasu rozdzelonych spacj: // 'UP_DATE_FORMAT_LONG UP_TIME_FORMAT_LONG' DateFormat formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG) + " " + (String) properties.get(UP_TIME_FORMAT_LONG), date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else { DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } } // Jeli nie okrelono, wypenianie parametrw przechowujcych poszczeglne // skadniki daty, tj. rok, miesic i dzie: if (!properties.containsKey(TP_YEAR)) { props.put(TP_YEAR, calendar.get(Calendar.YEAR)); } if (!properties.containsKey(TP_MONTH)) { props.put(TP_MONTH, calendar.get(Calendar.MONTH)); } if (!properties.containsKey(TP_DAY)) { props.put(TP_DAY, calendar.get(Calendar.DAY_OF_MONTH)); } // Jeli nie okrelono, wypenianie parametrw przechowujcych dat i czas w // formatach SHORT, MEDIUM, LONG i FULL (na podstawie wyznaczonej lokalizacji): Date date = calendar.getTime(); if (!properties.containsKey(TP_DATE_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_DATE_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_DATE_LONG)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_LONG, formatter.format(date)); } if (!properties.containsKey(TP_DATE_FULL)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_FULL, formatter.format(date)); } if (!properties.containsKey(TP_TIME_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_TIME_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_TIME_LONG)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_LONG, formatter.format(date)); } if (!properties.containsKey(TP_TIME_FULL)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_FULL, formatter.format(date)); } return props; }
From source file:org.jfree.data.time.DayTest.java
/** * Some checks for the getFirstMillisecond() method. *///from ww w . jav a2 s . com @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 3, 1970); assertEquals(5094000000L, d.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
public void loadLanguage(LANGUAGE language) { Locale locale = new Locale(language.getLanguage()); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;//from w w w . ja va 2s .c om getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Prepares the locale. The default is the system locale. *///from w w w .j av a2s . com public static void prepareLocale() { final String locale = Config.getInstance().getLocale(); if (locale != null) Locale.setDefault(new Locale(locale)); }
From source file:com.ninetwozero.battlelog.ViewPagerDashboard.java
public void setupLocale() { if (!sharedPreferences.getString(Constants.SP_BL_LANG, "").equals("")) { Locale locale = new Locale(sharedPreferences.getString(Constants.SP_BL_LANG, "en")); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;/*from w w w .ja v a 2 s.c om*/ getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } }