[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] updates for manually setting locales



commit 3a9a26929613014399e1a484a140857f8266904c
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Fri Feb 24 00:13:27 2012 -0500

    updates for manually setting locales
---
 res/values/strings.xml                             |    4 +++
 res/xml/preferences.xml                            |   13 +++++++++-
 src/org/torproject/android/Orbot.java              |   24 ++++++++++++++++++++
 src/org/torproject/android/OrbotApp.java           |    8 +++++-
 .../android/settings/SettingsPreferences.java      |   23 +++++++++++++++++++
 5 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/res/values/strings.xml b/res/values/strings.xml
index 46ba1dc..61ba4fa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -260,4 +260,8 @@
 
 <string name="notification_using_bridges">Bridges enabled!</string>
 <string name="default_bridges"></string>
+
+<string name="set_locale_title">Set Locale</string>
+<string name="set_locale_summary">Choose the locale and language for Orbot</string>
+
 </resources>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index b7b5a43..c6bfcab 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -23,6 +23,15 @@ android:summary="@string/pref_use_persistent_notifications"
 android:enabled="true" 
 android:title="@string/pref_use_persistent_notifications_title"/>
 
+
+ <ListPreference android:title="@string/set_locale_title"
+   android:key="pref_default_locale"
+   android:entryValues="@array/languages_values"
+   android:entries="@array/languages"
+   android:summary="@string/set_locale_summary"
+   android:defaultValue="en">
+ </ListPreference>
+
 <!-- 
 <CheckBoxPreference 
 android:defaultValue="false" 
@@ -92,12 +101,12 @@ android:summary="@string/use_only_these_specified_nodes"/>
 </PreferenceCategory> 
 <PreferenceCategory android:title="@string/bridges">
 
-<CheckBoxPreference android:defaultValue="true" 
+<CheckBoxPreference android:defaultValue="false" 
 android:title="@string/use_bridges" android:key="pref_bridges_enabled" 
 android:summary="@string/enable_alternate_entrance_nodes_into_the_tor_network"/>
 
 <CheckBoxPreference android:key="pref_bridges_obfuscated"
-     android:defaultValue="true" 
+     android:defaultValue="false" 
 android:title="@string/bridges_obfuscated"
 android:summary="@string/enable_if_configured_bridges_are_obfuscated_bridges"/>
 
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index 93013ba..d71567f 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -3,6 +3,8 @@
 
 package org.torproject.android;
 
+import java.util.Locale;
+
 import org.torproject.android.service.ITorService;
 import org.torproject.android.service.ITorServiceCallback;
 import org.torproject.android.service.TorServiceConstants;
@@ -22,6 +24,7 @@ import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -74,6 +77,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
       //might want to look at whether we need to call this every time
       //or whether binding to the service is enough
            	
+        	setLocale();
         
         	bindService();
            	startService(new Intent(INTENT_TOR_SERVICE));
@@ -342,6 +346,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
 	protected void onResume() {
 		super.onResume();
 		
+		setLocale();
+		
 		if (getIntent() == null)
 			return;
 		
@@ -897,4 +903,22 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
                 
     }
     
+    private void setLocale ()
+    {
+    	
+    	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+
+        Configuration config = getResources().getConfiguration();
+
+        String lang = settings.getString(PREF_DEFAULT_LOCALE, "");
+        
+        if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
+        {
+        	Locale locale = new Locale(lang);
+            Locale.setDefault(locale);
+            config.locale = locale;
+            getResources().updateConfiguration(config, getResources().getDisplayMetrics());
+        }
+    }
+    
 }
diff --git a/src/org/torproject/android/OrbotApp.java b/src/org/torproject/android/OrbotApp.java
index 8d78a06..c5528c9 100644
--- a/src/org/torproject/android/OrbotApp.java
+++ b/src/org/torproject/android/OrbotApp.java
@@ -12,12 +12,13 @@ public class OrbotApp extends Application implements TorConstants
 
 	private Locale locale;
 	private final static String DEFAULT_LOCALE = "en";
+	private SharedPreferences settings;
 	
 	@Override
     public void onCreate() {
         super.onCreate();
         
-        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+        settings = PreferenceManager.getDefaultSharedPreferences(this);
 
         Configuration config = getResources().getConfiguration();
 
@@ -38,8 +39,11 @@ public class OrbotApp extends Application implements TorConstants
     {
         super.onConfigurationChanged(newConfig);
 
-        if (locale != null)
+        String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE);
+
+        if (! "".equals(lang) && ! newConfig.locale.getLanguage().equals(lang))
         {
+            locale = new Locale(lang);
             newConfig.locale = locale;
             Locale.setDefault(locale);
             getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());
diff --git a/src/org/torproject/android/settings/SettingsPreferences.java b/src/org/torproject/android/settings/SettingsPreferences.java
index 35c4314..aa93e5a 100644
--- a/src/org/torproject/android/settings/SettingsPreferences.java
+++ b/src/org/torproject/android/settings/SettingsPreferences.java
@@ -3,6 +3,8 @@
 
 package org.torproject.android.settings;
 
+import java.util.Locale;
+
 import org.torproject.android.R;
 import org.torproject.android.R.xml;
 import org.torproject.android.TorConstants;
@@ -12,6 +14,7 @@ import org.torproject.android.service.TorTransProxy;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
@@ -31,6 +34,7 @@ public class SettingsPreferences
 	private Preference prefTransProxyApps = null;
 	private CheckBoxPreference prefHiddenServices = null;
 	private CheckBoxPreference prefRequestRoot = null;
+	private Preference prefLocale = null;
 	
 	private boolean hasRoot = false;
 	
@@ -61,11 +65,16 @@ public class SettingsPreferences
 		super.onResume();
 	
 		int REQUEST_ROOT_IDX = 1;
+		int SET_LOCALE_IDX = 3;
+
 		int GENERAL_GROUP_IDX = 0;
 		
 		prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(REQUEST_ROOT_IDX));
 		prefRequestRoot.setOnPreferenceClickListener(this);
 
+		prefLocale = (((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(SET_LOCALE_IDX));
+		prefLocale.setOnPreferenceClickListener(this);
+				
 		prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0));
 		prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(1);
 		prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2);
@@ -155,6 +164,20 @@ public class SettingsPreferences
 			((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
 			
 		}
+		else if (preference == prefLocale)
+		{
+			 SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+
+		        Configuration config = getResources().getConfiguration();
+
+		        String lang = settings.getString("pref_default_locale", "");
+		     
+	        	Locale locale = new Locale(lang);
+	            Locale.setDefault(locale);
+	            config.locale = locale;
+	            getResources().updateConfiguration(config, getResources().getDisplayMetrics());
+	            
+		}
 		else
 		{
 			prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits