blob: 8563fc8f49a86a9aaaa6f396acdd151dacb301fc (
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
|
/*
* Copyright (c) 2012-2014 Arne Schwabe
* Distributed under the GNU GPL v2. For full terms see the file doc/LICENSE.txt
*/
package de.blinkt.openvpn.fragments;
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 de.blinkt.openvpn.R;
public class Settings_Behaviour extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
private CheckBoxPreference mPersistent;
private ListPreference mConnectretrymax;
private EditTextPreference mConnectretry;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.vpn_behaviour);
mPersistent = (CheckBoxPreference) findPreference("usePersistTun");
mConnectretrymax = (ListPreference) findPreference("connectretrymax");
mConnectretry = (EditTextPreference) findPreference("connectretry");
mConnectretrymax.setOnPreferenceChangeListener(this);
mConnectretrymax.setSummary("%s");
mConnectretry.setOnPreferenceChangeListener(this);
loadSettings();
}
protected void loadSettings() {
mPersistent.setChecked(mProfile.mPersistTun);
mConnectretrymax.setValue(mProfile.mConnectRetryMax);
onPreferenceChange(mConnectretrymax, mProfile.mConnectRetryMax);
mConnectretry.setText(mProfile.mConnectRetry);
onPreferenceChange(mConnectretry, mProfile.mConnectRetry);
}
protected void saveSettings() {
mProfile.mConnectRetryMax = mConnectretrymax.getValue();
mProfile.mPersistTun = mPersistent.isChecked();
mProfile.mConnectRetry = mConnectretry.getText();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mConnectretrymax) {
if(newValue==null) {
newValue="5";
}
mConnectretrymax.setDefaultValue(newValue);
for(int i=0;i<mConnectretrymax.getEntryValues().length;i++){
if(mConnectretrymax.getEntryValues().equals(newValue))
mConnectretrymax.setSummary(mConnectretrymax.getEntries()[i]);
}
} else if (preference == mConnectretry) {
if(newValue==null || newValue=="")
newValue="5";
mConnectretry.setSummary(String.format("%s s" , newValue));
}
return true;
}
}
|