update SettingsActivity to use simpler findPreferences() method
This commit is contained in:
parent
237366cd27
commit
fba09263b4
|
@ -16,10 +16,11 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.EditTextPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceCategory;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,45 +33,28 @@ public class SettingsPreferences
|
||||||
|
|
||||||
private Preference prefTransProxyApps = null;
|
private Preference prefTransProxyApps = null;
|
||||||
private CheckBoxPreference prefHiddenServices = null;
|
private CheckBoxPreference prefHiddenServices = null;
|
||||||
|
private EditTextPreference prefHiddenServicesPorts;
|
||||||
|
private EditTextPreference prefHiddenServicesHostname;
|
||||||
private CheckBoxPreference prefRequestRoot = null;
|
private CheckBoxPreference prefRequestRoot = null;
|
||||||
private Preference prefLocale = null;
|
private ListPreference prefLocale = null;
|
||||||
|
|
||||||
private boolean hasRoot = false;
|
protected void onCreate(Bundle 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);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
|
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
|
||||||
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
||||||
|
|
||||||
hasRoot = prefs.getBoolean("has_root",false);
|
prefRequestRoot = (CheckBoxPreference) findPreference("has_root");
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init ()
|
|
||||||
{
|
|
||||||
int SET_LOCALE_IDX = 3;
|
|
||||||
|
|
||||||
int GENERAL_GROUP_IDX = 0;
|
|
||||||
|
|
||||||
prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0));
|
|
||||||
prefRequestRoot.setOnPreferenceClickListener(this);
|
prefRequestRoot.setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
prefLocale = (((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(SET_LOCALE_IDX));
|
prefLocale = (ListPreference) findPreference("pref_default_locale");
|
||||||
prefLocale.setOnPreferenceClickListener(this);
|
prefLocale.setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(1));
|
prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent");
|
||||||
prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2);
|
prefcBTransProxyAll = (CheckBoxPreference) findPreference("pref_transparent_all");
|
||||||
|
|
||||||
prefTransProxyFlush = (Preference)((PreferenceCategory)this.getPreferenceScreen().getPreference(DEBUG_GROUP_IDX)).getPreference(8);
|
prefTransProxyFlush = (Preference) findPreference("pref_transproxy_flush");
|
||||||
prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,30 +70,22 @@ public class SettingsPreferences
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(3);
|
prefTransProxyApps = findPreference("pref_transparent_app_list");
|
||||||
|
prefTransProxyApps.setOnPreferenceClickListener(this);
|
||||||
|
prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked()
|
||||||
|
&& (!prefcBTransProxyAll.isChecked()));
|
||||||
|
|
||||||
prefCBTransProxy.setOnPreferenceClickListener(this);
|
prefCBTransProxy.setOnPreferenceClickListener(this);
|
||||||
prefcBTransProxyAll.setOnPreferenceClickListener(this);
|
prefcBTransProxyAll.setOnPreferenceClickListener(this);
|
||||||
prefTransProxyApps.setOnPreferenceClickListener(this);
|
|
||||||
|
|
||||||
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
|
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
|
||||||
prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
|
|
||||||
|
|
||||||
|
prefHiddenServices = (CheckBoxPreference) findPreference("pref_hs_enable");
|
||||||
prefHiddenServices = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(0));
|
|
||||||
prefHiddenServices.setOnPreferenceClickListener(this);
|
prefHiddenServices.setOnPreferenceClickListener(this);
|
||||||
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
|
prefHiddenServicesPorts = (EditTextPreference) findPreference("pref_hs_ports");
|
||||||
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
|
prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked());
|
||||||
|
prefHiddenServicesHostname = (EditTextPreference) findPreference("pref_hs_hostname");
|
||||||
|
prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked());
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
|
||||||
|
@ -147,10 +123,8 @@ public class SettingsPreferences
|
||||||
}
|
}
|
||||||
else if (preference == prefHiddenServices)
|
else if (preference == prefHiddenServices)
|
||||||
{
|
{
|
||||||
|
prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked());
|
||||||
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
|
prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked());
|
||||||
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (preference == prefLocale)
|
else if (preference == prefLocale)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue