tor-android/src/org/torproject/android/OrbotApp.java

60 lines
1.7 KiB
Java
Raw Normal View History

package org.torproject.android;
import java.util.Locale;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
public class OrbotApp extends Application implements TorConstants
{
private Locale locale;
2012-02-12 17:29:30 +00:00
private final static String DEFAULT_LOCALE = "en";
2012-02-24 05:13:27 +00:00
private SharedPreferences settings;
@Override
public void onCreate() {
super.onCreate();
2012-02-24 05:13:27 +00:00
settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getResources().getConfiguration();
String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE);
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
{
2012-02-27 03:48:30 +00:00
if (lang.equals("xx"))
{
locale = Locale.getDefault();
}
else
locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
2012-02-24 05:13:27 +00:00
String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE);
if (! "".equals(lang) && ! newConfig.locale.getLanguage().equals(lang))
{
2012-02-24 05:13:27 +00:00
locale = new Locale(lang);
newConfig.locale = locale;
Locale.setDefault(locale);
getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());
}
}
}