2012-02-12 06:23:29 +00:00
|
|
|
package org.torproject.android;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-04-25 16:44:21 +00:00
|
|
|
import org.torproject.android.service.TorServiceUtils;
|
|
|
|
|
2012-02-12 06:23:29 +00:00
|
|
|
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();
|
|
|
|
|
2014-04-25 16:44:21 +00:00
|
|
|
settings = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
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);
|
2013-02-07 08:24:01 +00:00
|
|
|
|
|
|
|
Configuration myConfig = new Configuration(config);
|
|
|
|
myConfig.locale = locale;
|
|
|
|
|
|
|
|
getResources().updateConfiguration(myConfig, getResources().getDisplayMetrics());
|
2012-02-12 06:23:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 08:24:01 +00:00
|
|
|
|
2012-02-12 06:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
Locale.setDefault(locale);
|
2013-02-07 08:24:01 +00:00
|
|
|
|
|
|
|
Configuration myConfig = new Configuration(newConfig);
|
|
|
|
myConfig.locale = locale;
|
|
|
|
|
|
|
|
getResources().updateConfiguration(myConfig, getResources().getDisplayMetrics());
|
2012-02-12 06:23:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|