本文整理汇总了Java中java.util.Locale.getDefault方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.getDefault方法的具体用法?Java Locale.getDefault怎么用?Java Locale.getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stringForTime
import java.util.Locale; //导入方法依赖的package包/类
public static String stringForTime(int timeMs) {
if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
return "00:00";
}
int totalSeconds = timeMs / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
StringBuilder stringBuilder = new StringBuilder();
Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault());
if (hours > 0) {
return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
} else {
return mFormatter.format("%02d:%02d", minutes, seconds).toString();
}
}
示例2: doInBackground
import java.util.Locale; //导入方法依赖的package包/类
@Nullable
@Override
protected Address doInBackground(String... strings) {
Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
Address result = null;
double latitude = mLocation.getLatitude();
double longitude = mLocation.getLongitude();
try {
List<Address> geocodedAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if (geocodedAddresses != null && !geocodedAddresses.isEmpty()) {
result = geocodedAddresses.get(0);
}
} catch (IOException e) {
Throwable cause = e.getCause();
Log.i(TAG, "Error " + (cause != null ? cause.getClass().getSimpleName()
: '(' + e.getClass().getSimpleName() + ": " + e.getMessage() + ')')
+ " getting locality with Geocoder. "
+ "Trying with HTTP/GET on Google Maps API.");
result = geolocateFromGoogleApis(latitude, longitude);
}
return result;
}
示例3: initViews
import java.util.Locale; //导入方法依赖的package包/类
private void initViews(Context context) {
inflate(context, R.layout.pr, this);
updateVisibility();
this.mPauseButton = (ImageView) findViewById(R.id.play);
this.mExpandButton = (ImageView) findViewById(R.id.expand);
this.mProgress = (SeekBar) findViewById(R.id.progress);
this.mTime = (TextView) findViewById(R.id.time);
this.mProgress.setMax(1000);
this.mProgress.setOnSeekBarChangeListener(this.mOnSeekBarChangeListener);
this.mFormatBuilder = new StringBuilder();
this.mFormatter = new Formatter(this.mFormatBuilder, Locale.getDefault());
this.mPauseButton.requestFocus();
this.mPauseButton.setOnClickListener(this.mPauseListener);
}
示例4: timeAddSubtract
import java.util.Locale; //导入方法依赖的package包/类
/**
* 时间加减
*
* @param day 如"2015-09-22"
* @param dayAddNum 加减值
* @return 结果
*/
public static String timeAddSubtract(String day, int dayAddNum) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
try {
Date newDate = new Date(simpleDateFormat.parse(day).getTime() + dayAddNum * 24 * 60 * 60 * 1000);
return simpleDateFormat.format(newDate);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例5: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
test(ENGLISH, DATA.getBytes());
test(TURKISH, DATA.getBytes());
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}
示例6: initView
import java.util.Locale; //导入方法依赖的package包/类
protected void initView() {
controllerView = LayoutInflater.from(getContext()).inflate(getLayoutId(), this);
mCenterView = new CenterView(getContext());
mCenterView.setVisibility(GONE);
addView(mCenterView);
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mFormatBuilder = new StringBuilder();
mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
setClickable(true);
setFocusable(true);
mGestureDetector = new GestureDetector(getContext(), new MyGestureListener());
this.setOnTouchListener((v, event) -> mGestureDetector.onTouchEvent(event));
}
示例7: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
Locale.Builder builder = new Locale.Builder();
base = builder.setLanguage(System.getProperty("user.language", ""))
.setScript(System.getProperty("user.script", ""))
.setRegion(System.getProperty("user.country", ""))
.setVariant(System.getProperty("user.variant", "")).build();
disp = builder.setLanguage(
System.getProperty("user.language.display",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.display",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.display",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.display",
Locale.getDefault().getVariant())).build();
fmt = builder.setLanguage(System.getProperty("user.language.format",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.format",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.format",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.format",
Locale.getDefault().getVariant())).build();
checkDefault();
testGetSetDefault();
testBug7079486();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}
示例8: executeDataMigration
import java.util.Locale; //导入方法依赖的package包/类
@SuppressWarnings("nls")
@Override
protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session)
{
// set locale to the server default when there is none
final Locale locale = Locale.getDefault();
final String lang = locale.getLanguage();
session.createQuery("UPDATE LanguageString SET locale = :lang WHERE locale IS NULL").setParameter("lang", lang)
.executeUpdate();
result.incrementStatus();
}
示例9: getNextEpDate
import java.util.Locale; //导入方法依赖的package包/类
/**
* Formats the epotch time to a pretty data
* <br/>
* @return string such as "EP 6 Airing in 2 hours"
* @param airing - the current airing object of a series
*/
public static String getNextEpDate(Airing airing){
if(airing == null)
return "N/A";
else {
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
String from_now = prettyTime.format(new Date(System.currentTimeMillis()+(airing.getCountdown()*1000L)));
return String.format(Locale.getDefault(), "EP %d - %s",airing.getNext_episode(), from_now);
}
}
示例10: getSystemLanguage
import java.util.Locale; //导入方法依赖的package包/类
private static String getSystemLanguage() {
Locale locale = Locale.getDefault();
if (locale == null) {
return DEFAULT_LANGUAGE;
}
String language = locale.getLanguage();
// Special case Chinese
if (Locale.SIMPLIFIED_CHINESE.getLanguage().equals(language)) {
return language + "-r" + getSystemCountry();
}
return language;
}
示例11: getPrettyDate
import java.util.Locale; //导入方法依赖的package包/类
/**
* Generates a pretty data "x y from now" where y can be minutes, hours, days or even weeks e.t.c
* <br/>
* @return Pretty Date (x hours from now / x hours ago)
* @param date - a date with the format of yyyy-MM-dd HH:mm:ss
*/
public static String getPrettyDate(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
try {
Date converted = format.parse(date);
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
return prettyTime.format(converted);
} catch (ParseException e) {
e.printStackTrace();
}
return "Unknown Time";
}
示例12: setCurrentLocale
import java.util.Locale; //导入方法依赖的package包/类
public void setCurrentLocale(Locale locale) {
if (locale == null) {
locale = Locale.getDefault();
}
this.currentBundles = getBundles(locale);
this.currentLocale = locale;
}
示例13: BootstrapManager
import java.util.Locale; //导入方法依赖的package包/类
BootstrapManager(EvernoteSession.EvernoteService service, EvernoteSession session) {
this(service, session, Locale.getDefault());
}
示例14: getAppLabelEn
import java.util.Locale; //导入方法依赖的package包/类
@TargetApi(17)
public static String getAppLabelEn(Context context, String pkgName, String def) {
if (context == null || TextUtils.isEmpty(pkgName)) {
return def;
}
String result = def;
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = packageManager.getPackageInfo(pkgName, 0).applicationInfo;
Configuration configuration = new Configuration();
// It's better, I think, to use Locale.ENGLISH
// instead of Locale.ROOT (although I want to do).
if (C.SDK >= 17) {
configuration.setLocale(Locale.ENGLISH);
} else {
configuration.locale = Locale.ENGLISH;
}
// The result is a value in disorder maybe if using:
// packageManager.getResourcesForApplication(PACKAGE_NAME)
Resources resources = packageManager.getResourcesForApplication(applicationInfo);
resources.updateConfiguration(configuration,
context.getResources().getDisplayMetrics());
int labelResId = applicationInfo.labelRes;
if (labelResId != 0) {
// If the localized label is not added, the default is returned.
// NOTICE!!!If the default were empty, Resources$NotFoundException would be called.
result = resources.getString(labelResId);
}
/*
* NOTICE!!!
* We have to restore the locale.
* On the one hand,
* it will influence the label of Activity, etc..
* On the other hand,
* the got "resources" equals the one "this.getResources()" if the current .apk file
* happens to be this APK Checker(com.by_syk.apkchecker).
* We need to restore the locale, or the language of APK Checker will change to English.
*/
if (C.SDK >= 17) {
configuration.setLocale(Locale.getDefault());
} else {
configuration.locale = Locale.getDefault();
}
resources.updateConfiguration(configuration, context.getResources().getDisplayMetrics());
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例15: LoadApplication
import java.util.Locale; //导入方法依赖的package包/类
public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks)
{
synchronized (lock) {
if (context instanceof android.app.Application) {
Context = context;
}
if (!initialized) {
android.content.IntentFilter timezoneChangedFilter = new android.content.IntentFilter (
android.content.Intent.ACTION_TIMEZONE_CHANGED
);
context.registerReceiver (new mono.android.app.NotifyTimeZoneChanges (), timezoneChangedFilter);
System.loadLibrary("monodroid");
Locale locale = Locale.getDefault ();
String language = locale.getLanguage () + "-" + locale.getCountry ();
String filesDir = context.getFilesDir ().getAbsolutePath ();
String cacheDir = context.getCacheDir ().getAbsolutePath ();
String dataDir = getNativeLibraryPath (context);
ClassLoader loader = context.getClassLoader ();
Runtime.init (
language,
apks,
getNativeLibraryPath (runtimePackage),
new String[]{
filesDir,
cacheDir,
dataDir,
},
loader,
new java.io.File (
android.os.Environment.getExternalStorageDirectory (),
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath (),
MonoPackageManager_Resources.Assemblies,
context.getPackageName ());
mono.android.app.ApplicationRegistration.registerApplications ();
initialized = true;
}
}
}