[tor-commits] [orbot/master] tweaked root request on/off preference UI

n8fr8 at torproject.org n8fr8 at torproject.org
Thu Jan 12 20:49:44 UTC 2012


commit 331c4956d718a889415fb2be3135758b91b6d68f
Author: Nathan Freitas <nathan at freitas.net>
Date:   Thu Jan 12 15:46:54 2012 -0500

    tweaked root request on/off preference UI
---
 src/org/torproject/android/Orbot.java              |    2 +-
 .../android/settings/SettingsPreferences.java      |   45 +++++++++++++++-----
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index a93586d..5452a5a 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -107,7 +107,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
         mItemOnOff.setAlphabeticShortcut('t');
         
         mItem = menu.add(0, 4, Menu.NONE, getString(R.string.menu_settings));
-        mItem.setIcon(R.drawable.ic_menu_register);
+        mItem.setIcon(R.drawable.ic_menu_settings);
        
         mItem = menu.add(0, 7, Menu.NONE, getString(R.string.menu_verify));
         mItem.setIcon(R.drawable.ic_menu_check);
diff --git a/src/org/torproject/android/settings/SettingsPreferences.java b/src/org/torproject/android/settings/SettingsPreferences.java
index c3b5942..bb5b24b 100644
--- a/src/org/torproject/android/settings/SettingsPreferences.java
+++ b/src/org/torproject/android/settings/SettingsPreferences.java
@@ -18,6 +18,7 @@ import android.preference.PreferenceManager;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceCategory;
+import android.widget.Toast;
 
 
 public class SettingsPreferences 
@@ -27,11 +28,13 @@ public class SettingsPreferences
 	private CheckBoxPreference prefcBTransProxyAll = null;
 	private Preference prefTransProxyApps = null;
 	private CheckBoxPreference prefHiddenServices = null;
+	private CheckBoxPreference prefRequestRoot = null;
 	
 	private boolean hasRoot = false;
 	
 
 	private final static int HIDDEN_SERVICE_PREF_IDX = 6;
+	private final static int TRANSPROXY_GROUP_IDX = 1;
 	
 	protected void onCreate(Bundle savedInstanceState)
 	{
@@ -55,27 +58,31 @@ public class SettingsPreferences
 	
 		super.onResume();
 	
+		int REQUEST_ROOT_IDX = 1;
+		int GENERAL_GROUP_IDX = 0;
+		
+		prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(REQUEST_ROOT_IDX));
+		prefRequestRoot.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);
+
 
-		int transProxyGroupIdx = 1;
+		prefCBTransProxy.setOnPreferenceClickListener(this);
+		prefcBTransProxyAll.setOnPreferenceClickListener(this);
+		prefTransProxyApps.setOnPreferenceClickListener(this);
 		
 		if (!hasRoot)
 		{
-			getPreferenceScreen().getPreference(transProxyGroupIdx).setEnabled(false);
+			getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX).setEnabled(false);
 		}
 		else
 		{
-			prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(0));
-			prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(1);
-			prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(2);
 
 			prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
-			
 			prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
 			
-			prefCBTransProxy.setOnPreferenceClickListener(this);
-			prefcBTransProxyAll.setOnPreferenceClickListener(this);
-			prefTransProxyApps.setOnPreferenceClickListener(this);
-			
 		}
 		
 		
@@ -105,7 +112,23 @@ public class SettingsPreferences
 		
 		setResult(1010);
 		
-		if (preference == prefTransProxyApps)
+		if (preference == prefRequestRoot)
+		{
+
+			if (prefRequestRoot.isChecked())
+			{
+				boolean canRoot = TorServiceUtils.isRootPossible();
+				
+				getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX).setEnabled(canRoot);
+				prefRequestRoot.setChecked(canRoot);
+
+				if (!canRoot)
+				{
+					Toast.makeText(this, R.string.wizard_permissions_no_root_msg, Toast.LENGTH_LONG).show();
+				}
+			}
+		}
+		else if (preference == prefTransProxyApps)
 		{
 			startActivity(new Intent(this, AppManager.class));
 			





More information about the tor-commits mailing list