Java Code Examples for java.util.Locale.getDefault()

The following are Jave code examples for showing how to use getDefault() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ListVideoPlayer   File: ListVideoUtils.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 2
Project: civify-app   File: GeocoderAdapter.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: boohee_v5.6   File: MediaControllerView.java   View Source Code Vote up 5 votes
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);
}
 
Example 4
Project: GCSApp   File: TimeUtil.java   View Source Code Vote up 5 votes
/**
 * 时间加减
 *
 * @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;

}
 
Example 5
Project: openjdk-jdk10   File: Test6341798.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 6
Project: dkplayer   File: BaseVideoController.java   View Source Code Vote up 5 votes
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));
}
 
Example 7
Project: jdk8u-jdk   File: LocaleCategory.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 8
Project: Equella   File: MakeLocaleFieldNotNullable.java   View Source Code Vote up 5 votes
@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();
}
 
Example 9
Project: anitrend-app   File: DateTimeConverter.java   View Source Code Vote up 5 votes
/**
 * 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);
    }
}
 
Example 10
Project: keepass2android   File: LocaleManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: anitrend-app   File: DateTimeConverter.java   View Source Code Vote up 5 votes
/**
 * 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";
}
 
Example 12
Project: javaide   File: JavacMessages.java   View Source Code Vote up 5 votes
public void setCurrentLocale(Locale locale) {
    if (locale == null) {
        locale = Locale.getDefault();
    }
    this.currentBundles = getBundles(locale);
    this.currentLocale = locale;
}
 
Example 13
Project: add_to_evernote_note   File: BootstrapManager.java   View Source Code Vote up 4 votes
BootstrapManager(EvernoteSession.EvernoteService service, EvernoteSession session) {
  this(service, session, Locale.getDefault());
}
 
Example 14
Project: GxIconAndroid   File: PkgUtil.java   View Source Code Vote up 4 votes
@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;
}
 
Example 15
Project: Locator-CrossPlatform   File: MonoPackageManager.java   View Source Code Vote up 4 votes
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;
		}
	}
}
 
Example 16
Project: AndroidBasicLibs   File: DeviceUtils.java   View Source Code Vote up 4 votes
public static String getCountry(Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    Locale locale = Locale.getDefault();
    return tm.getSimState() == TelephonyManager.SIM_STATE_READY ? tm.getSimCountryIso().toLowerCase(Locale.getDefault()) : locale.getCountry().toLowerCase(locale);
}
 
Example 17
Project: openjdk-jdk10   File: JComponent.java   View Source Code Vote up 3 votes
/**
 * Returns the default locale used to initialize each JComponent's
 * locale property upon creation.
 *
 * The default locale has "AppContext" scope so that applets (and
 * potentially multiple lightweight applications running in a single VM)
 * can have their own setting. An applet can safely alter its default
 * locale because it will have no affect on other applets (or the browser).
 *
 * @return the default <code>Locale</code>.
 * @see #setDefaultLocale
 * @see java.awt.Component#getLocale
 * @see #setLocale
 * @since 1.4
 */
public static Locale getDefaultLocale() {
    Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale);
    if( l == null ) {
        //REMIND(bcb) choosing the default value is more complicated
        //than this.
        l = Locale.getDefault();
        JComponent.setDefaultLocale( l );
    }
    return l;
}
 
Example 18
Project: openjdk-jdk10   File: Window.java   View Source Code Vote up 3 votes
/**
 * Gets the {@code Locale} object that is associated
 * with this window, if the locale has been set.
 * If no locale has been set, then the default locale
 * is returned.
 * @return    the locale that is set for this window.
 * @see       java.util.Locale
 * @since     1.1
 */
public Locale getLocale() {
  if (this.locale == null) {
    return Locale.getDefault();
  }
  return this.locale;
}
 
Example 19
Project: android-project-gallery   File: DateUtils.java   View Source Code Vote up 2 votes
/**
 * 返回自定义格式的日期, 如: "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd HH:mm:ss",
 * "yyyy-MM-dd".
 * 
 * @param date
 * @param style
 * @return
 * @throws ParseException
 */
public static Date parseDateByStyle(String date, String style) throws ParseException
{
	SimpleDateFormat sdf = new SimpleDateFormat(style, Locale.getDefault());
	return sdf.parse(date);
}
 
Example 20
Project: java-android-websocket-client   File: DefaultHttpResponseFactory.java   View Source Code Vote up 2 votes
/**
 * Determines the locale of the response.
 * The implementation in this class always returns the default locale.
 *
 * @param context   the context from which to determine the locale, or
 *                  {@code null} to use the default locale
 *
 * @return  the locale for the response, never {@code null}
 */
protected Locale determineLocale(final HttpContext context) {
    return Locale.getDefault();
}