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.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;
|
||||
|
||||
|
||||
|
@ -32,45 +33,28 @@ public class SettingsPreferences
|
|||
|
||||
private Preference prefTransProxyApps = 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;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
int GENERAL_GROUP_IDX = 0;
|
||||
|
||||
prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0));
|
||||
prefRequestRoot = (CheckBoxPreference) findPreference("has_root");
|
||||
prefRequestRoot.setOnPreferenceClickListener(this);
|
||||
|
||||
prefLocale = (((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(SET_LOCALE_IDX));
|
||||
prefLocale = (ListPreference) findPreference("pref_default_locale");
|
||||
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);
|
||||
prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent");
|
||||
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() {
|
||||
|
||||
@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);
|
||||
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 = (CheckBoxPreference) findPreference("pref_hs_enable");
|
||||
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());
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue