commit 411dcea837f8058904efc2bb53ffcbb0abfc597d Author: Nathan Freitas nathan@freitas.net Date: Sun Feb 12 01:23:29 2012 -0500
added app class to handle language settings --- src/org/torproject/android/OrbotApp.java | 48 ++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/src/org/torproject/android/OrbotApp.java b/src/org/torproject/android/OrbotApp.java new file mode 100644 index 0000000..10eff32 --- /dev/null +++ b/src/org/torproject/android/OrbotApp.java @@ -0,0 +1,48 @@ +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; + private final static String DEFAULT_LOCALE = "fa"; + + @Override + public void onCreate() { + super.onCreate(); + + SharedPreferences 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)) + { + locale = new Locale(lang); + Locale.setDefault(locale); + config.locale = locale; + getResources().updateConfiguration(config, getResources().getDisplayMetrics()); + } + + } + + @Override + public void onConfigurationChanged(Configuration newConfig) + { + super.onConfigurationChanged(newConfig); + + if (locale != null) + { + newConfig.locale = locale; + Locale.setDefault(locale); + getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics()); + } + } +}
tor-commits@lists.torproject.org