2012-02-12 06:23:29 +00:00
|
|
|
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;
|
2012-02-12 06:23:29 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
|
2012-02-24 05:13:27 +00:00
|
|
|
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
2012-02-12 06:23:29 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-02-12 06:23:29 +00:00
|
|
|
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-12 06:23:29 +00:00
|
|
|
{
|
2012-02-24 05:13:27 +00:00
|
|
|
locale = new Locale(lang);
|
2012-02-12 06:23:29 +00:00
|
|
|
newConfig.locale = locale;
|
|
|
|
Locale.setDefault(locale);
|
|
|
|
getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|