blob: 4ea8f00c56a8207ac3b21886777b05d3769190e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package de.blinkt.openvpn.fragments;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.widget.Toast;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
private CheckBoxPreference mUseRandomHostName;
private CheckBoxPreference mUseFloat;
private CheckBoxPreference mUseCustomConfig;
private EditTextPreference mCustomConfig;
private EditTextPreference mMssFixValue;
private CheckBoxPreference mMssFixCheckBox;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.vpn_obscure);
mUseRandomHostName = (CheckBoxPreference) findPreference("useRandomHostname");
mUseFloat = (CheckBoxPreference) findPreference("useFloat");
mUseCustomConfig = (CheckBoxPreference) findPreference("enableCustomOptions");
mCustomConfig = (EditTextPreference) findPreference("customOptions");
mMssFixCheckBox = (CheckBoxPreference) findPreference("mssFix");
mMssFixValue = (EditTextPreference) findPreference("mssFixValue");
mMssFixValue.setOnPreferenceChangeListener(this);
loadSettings();
}
protected void loadSettings() {
mUseRandomHostName.setChecked(mProfile.mUseRandomHostname);
mUseFloat.setChecked(mProfile.mUseFloat);
mUseCustomConfig.setChecked(mProfile.mUseCustomConfig);
mCustomConfig.setText(mProfile.mCustomConfigOptions);
if (mProfile.mMssFix == 0) {
mMssFixValue.setText(String.valueOf(VpnProfile.DEFAULT_MSSFIX_SIZE));
mMssFixCheckBox.setChecked(false);
setMssSummary(VpnProfile.DEFAULT_MSSFIX_SIZE);
} else {
mMssFixValue.setText(String.valueOf(mProfile.mMssFix));
mMssFixCheckBox.setChecked(true);
setMssSummary(mProfile.mMssFix);
}
}
private void setMssSummary(int value) {
mMssFixValue.setSummary(String.format("Configured MSS value: %d", value));
}
protected void saveSettings() {
mProfile.mUseRandomHostname = mUseRandomHostName.isChecked();
mProfile.mUseFloat = mUseFloat.isChecked();
mProfile.mUseCustomConfig = mUseCustomConfig.isChecked();
mProfile.mCustomConfigOptions = mCustomConfig.getText();
if (mMssFixCheckBox.isChecked())
mProfile.mMssFix=Integer.parseInt(mMssFixValue.getText());
else
mProfile.mMssFix=0;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.getKey().equals("mssFixValue"))
try {
int v = Integer.parseInt((String) newValue);
if (v < 0 || v > 9000)
throw new NumberFormatException("mssfix value");
setMssSummary(v);
} catch(NumberFormatException e) {
Toast.makeText(getActivity(), R.string.mssfix_invalid_value, Toast.LENGTH_LONG).show();
return false;
}
return true;
}
}
|