[tor-commits] [orbot/master] update SettingsActivity to use simpler findPreferences() method
n8fr8 at torproject.org
n8fr8 at torproject.org
Thu Jun 25 14:59:58 UTC 2015
commit fba09263b41c9ae2970d578801584302bc427a89
Author: Hans-Christoph Steiner <hans at eds.org>
Date: Fri Jun 5 15:16:08 2015 -0400
update SettingsActivity to use simpler findPreferences() method
---
.../android/settings/SettingsPreferences.java | 116 ++++++++------------
1 file changed, 45 insertions(+), 71 deletions(-)
diff --git a/src/org/torproject/android/settings/SettingsPreferences.java b/src/org/torproject/android/settings/SettingsPreferences.java
index 5a96c9b..5b21514 100644
--- a/src/org/torproject/android/settings/SettingsPreferences.java
+++ b/src/org/torproject/android/settings/SettingsPreferences.java
@@ -16,10 +16,11 @@ import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
-import android.preference.PreferenceCategory;
import android.widget.Toast;
@@ -31,85 +32,60 @@ public class SettingsPreferences
private Preference prefTransProxyFlush = null;
private Preference prefTransProxyApps = null;
- private CheckBoxPreference prefHiddenServices = null;
+ private CheckBoxPreference prefHiddenServices = null;
+ private EditTextPreference prefHiddenServicesPorts;
+ private EditTextPreference prefHiddenServicesHostname;
private CheckBoxPreference prefRequestRoot = null;
- private Preference prefLocale = null;
+ private ListPreference prefLocale = null;
- private boolean hasRoot = false;
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
- private final static int HIDDEN_SERVICE_PREF_IDX = 6;
- private final static int TRANSPROXY_GROUP_IDX = 1;
- private final static int DEBUG_GROUP_IDX = 8;
-
-
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.preferences);
- getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
- SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
-
- hasRoot = prefs.getBoolean("has_root",false);
-
- init();
- }
-
- private void init ()
- {
- int SET_LOCALE_IDX = 3;
+ addPreferencesFromResource(R.xml.preferences);
+ getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
+ SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- int GENERAL_GROUP_IDX = 0;
-
- prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0));
- prefRequestRoot.setOnPreferenceClickListener(this);
+ prefRequestRoot = (CheckBoxPreference) findPreference("has_root");
+ 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(1));
- prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2);
-
- prefTransProxyFlush = (Preference)((PreferenceCategory)this.getPreferenceScreen().getPreference(DEBUG_GROUP_IDX)).getPreference(8);
- prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ prefLocale = (ListPreference) findPreference("pref_default_locale");
+ prefLocale.setOnPreferenceClickListener(this);
- @Override
- public boolean onPreferenceClick(Preference arg0) {
-
- Intent data = new Intent();
- data.putExtra("transproxywipe", true);
- setResult(RESULT_OK,data);
-
- finish();
- return false;
- }
-
- });
-
- prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(3);
+ prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent");
+ prefcBTransProxyAll = (CheckBoxPreference) findPreference("pref_transparent_all");
+ prefTransProxyFlush = (Preference) findPreference("pref_transproxy_flush");
+ prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- prefCBTransProxy.setOnPreferenceClickListener(this);
- prefcBTransProxyAll.setOnPreferenceClickListener(this);
- prefTransProxyApps.setOnPreferenceClickListener(this);
-
- prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
- prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
-
-
- prefHiddenServices = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(0));
- prefHiddenServices.setOnPreferenceClickListener(this);
- ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
- ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
-
-
- };
-
+ @Override
+ public boolean onPreferenceClick(Preference arg0) {
+ Intent data = new Intent();
+ data.putExtra("transproxywipe", true);
+ setResult(RESULT_OK, data);
+ finish();
+ return false;
+ }
+ });
+ prefTransProxyApps = findPreference("pref_transparent_app_list");
+ prefTransProxyApps.setOnPreferenceClickListener(this);
+ prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked()
+ && (!prefcBTransProxyAll.isChecked()));
+ prefCBTransProxy.setOnPreferenceClickListener(this);
+ prefcBTransProxyAll.setOnPreferenceClickListener(this);
+ prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
+
+ prefHiddenServices = (CheckBoxPreference) findPreference("pref_hs_enable");
+ prefHiddenServices.setOnPreferenceClickListener(this);
+ prefHiddenServicesPorts = (EditTextPreference) findPreference("pref_hs_ports");
+ prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked());
+ prefHiddenServicesHostname = (EditTextPreference) findPreference("pref_hs_hostname");
+ prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked());
+ }
public boolean onPreferenceClick(Preference preference) {
@@ -147,10 +123,8 @@ public class SettingsPreferences
}
else if (preference == prefHiddenServices)
{
-
- ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
- ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
-
+ prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked());
+ prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked());
}
else if (preference == prefLocale)
{
More information about the tor-commits
mailing list