diff options
Diffstat (limited to 'src/de/blinkt/openvpn/Settings_Obscure.java')
-rw-r--r-- | src/de/blinkt/openvpn/Settings_Obscure.java | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/src/de/blinkt/openvpn/Settings_Obscure.java b/src/de/blinkt/openvpn/Settings_Obscure.java index 83754663..55615917 100644 --- a/src/de/blinkt/openvpn/Settings_Obscure.java +++ b/src/de/blinkt/openvpn/Settings_Obscure.java @@ -1,21 +1,74 @@ package de.blinkt.openvpn; import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -public class Settings_Obscure extends PreferenceFragment { +public class Settings_Obscure extends PreferenceFragment implements OnPreferenceChangeListener { + private VpnProfile mProfile; + private CheckBoxPreference mUseRandomHostName; + private CheckBoxPreference mUseFloat; + private CheckBoxPreference mUseCustomConfig; + private EditTextPreference mCustomConfig; + private ListPreference mLogverbosity; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - // Make sure default values are applied. In a real app, you would - // want this in a shared function that is used to retrieve the - // SharedPreferences wherever they are needed. - PreferenceManager.setDefaultValues(getActivity(), - R.xml.vpn_ipsettings, false); - // Load the preferences from an XML resource addPreferencesFromResource(R.xml.vpn_obscure); + + String profileUUID = getArguments().getString(getActivity().getPackageName() + ".profileUUID"); + mProfile = ProfileManager.get(profileUUID); + + + mUseRandomHostName = (CheckBoxPreference) findPreference("useRandomHostname"); + mUseFloat = (CheckBoxPreference) findPreference("useFloat"); + mUseCustomConfig = (CheckBoxPreference) findPreference("enableCustomOptions"); + mCustomConfig = (EditTextPreference) findPreference("customOptions"); + mLogverbosity = (ListPreference) findPreference("verblevel"); + + mLogverbosity.setOnPreferenceChangeListener(this); + + loadSettings(); + + } + + private void loadSettings() { + mUseRandomHostName.setChecked(mProfile.mUseRandomHostname); + mUseFloat.setChecked(mProfile.mUseFloat); + mUseCustomConfig.setChecked(mProfile.mUseCustomConfig); + mCustomConfig.setText(mProfile.mCustomConfigOptions); + + mLogverbosity.setValue(mProfile.mVerb); + onPreferenceChange(mLogverbosity, mProfile.mVerb); } + + @Override + public void onPause() { + saveSettings(); + super.onPause(); + } + + private void saveSettings() { + mProfile.mUseRandomHostname = mUseRandomHostName.isChecked(); + mProfile.mUseFloat = mUseFloat.isChecked(); + mProfile.mUseCustomConfig = mUseCustomConfig.isChecked(); + mProfile.mCustomConfigOptions = mCustomConfig.getText(); + mProfile.mVerb = mLogverbosity.getValue(); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if(preference==mLogverbosity) { + mLogverbosity.setDefaultValue(newValue); + } + + return true; + } + }
\ No newline at end of file |