| 90 |
Kevin |
1 |
package ioio.debugger;
|
|
|
2 |
|
|
|
3 |
import android.content.SharedPreferences;
|
|
|
4 |
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
|
5 |
import android.os.Bundle;
|
|
|
6 |
import android.preference.EditTextPreference;
|
|
|
7 |
import android.preference.PreferenceManager;
|
|
|
8 |
import android.text.InputType;
|
|
|
9 |
|
|
|
10 |
public class GlobalPreferenceActivity extends android.preference.PreferenceActivity implements OnSharedPreferenceChangeListener {
|
|
|
11 |
|
|
|
12 |
private EditTextPreference _pref_serverIP;
|
|
|
13 |
private EditTextPreference _pref_serverPort;
|
|
|
14 |
// private CheckBoxPreference _pref_serverReconnect;
|
|
|
15 |
private EditTextPreference _pref_serverReconnectInterval;
|
|
|
16 |
private EditTextPreference _pref_graphLength;
|
|
|
17 |
private SharedPreferences sharedPrefs;
|
|
|
18 |
|
|
|
19 |
@Override
|
|
|
20 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
21 |
super.onCreate(savedInstanceState);
|
|
|
22 |
addPreferencesFromResource(R.xml.preference);
|
|
|
23 |
|
|
|
24 |
_pref_serverIP = (EditTextPreference) findPreference("pref_serverIP");
|
|
|
25 |
_pref_serverPort = (EditTextPreference) findPreference("pref_serverPort");
|
|
|
26 |
// _pref_serverReconnect = (CheckBoxPreference) findPreference("pref_serverReconnect");
|
|
|
27 |
_pref_serverReconnectInterval = (EditTextPreference) findPreference("pref_serverReconnectInterval");
|
|
|
28 |
_pref_graphLength = (EditTextPreference) findPreference("pref_graphLength");
|
|
|
29 |
|
|
|
30 |
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Override
|
|
|
34 |
public void onResume() {
|
|
|
35 |
super.onResume();
|
|
|
36 |
|
|
|
37 |
// Set the summary text to the current value
|
|
|
38 |
_pref_serverIP.setSummary("Current Value: " + sharedPrefs.getString("pref_serverIP", ""));
|
|
|
39 |
_pref_serverPort.setSummary("Current Value: " + sharedPrefs.getString("pref_serverPort", ""));
|
|
|
40 |
_pref_serverReconnectInterval.setSummary("Current Value: " + sharedPrefs.getString("pref_serverReconnectInterval", ""));
|
|
|
41 |
_pref_graphLength.setSummary("Current Value: " + sharedPrefs.getString("pref_graphLength", ""));
|
|
|
42 |
|
|
|
43 |
_pref_serverPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
44 |
_pref_graphLength.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
45 |
_pref_serverReconnectInterval.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
46 |
|
|
|
47 |
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
@Override
|
|
|
51 |
public void onPause() {
|
|
|
52 |
super.onPause();
|
|
|
53 |
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
@Override
|
|
|
57 |
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
58 |
// Change the summary text when the value is changed
|
|
|
59 |
if (key.compareTo("pref_serverIP") == 0) {
|
|
|
60 |
_pref_serverIP.setSummary("Current Value: " + sharedPreferences.getString(key, ""));
|
|
|
61 |
} else if (key.compareTo("pref_serverPort") == 0) {
|
|
|
62 |
_pref_serverPort.setSummary("Current Value: " + sharedPreferences.getString(key, ""));
|
|
|
63 |
} else if (key.compareTo("pref_serverReconnectInterval") == 0) {
|
|
|
64 |
_pref_serverReconnectInterval.setSummary("Current Value: " + sharedPreferences.getString(key, ""));
|
|
|
65 |
} else if (key.compareTo("pref_graphLength") == 0) {
|
|
|
66 |
_pref_graphLength.setSummary("Current Value: " + sharedPrefs.getString("pref_graphLength", ""));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
}
|
|
|
70 |
}
|