blob: 41c943ced6432f2bcc0fd67dace76bc6142678ee (
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
|
package com.javispedro.rempe;
import android.content.SharedPreferences;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import static android.content.ContentValues.TAG;
class Preferences {
public final static String PREFS_DEVICES = "devices";
public static List<Integer> getDeviceNumbers(SharedPreferences prefs) {
ArrayList<Integer> result = new ArrayList<Integer>();
try {
StringTokenizer st = new StringTokenizer(prefs.getString(PREFS_DEVICES, ""), ",");
while (st.hasMoreTokens()) {
result.add(Integer.parseInt(st.nextToken()));
}
} catch (java.lang.Exception ex) {
// Ensure that at least we can recover from a corrupted preferences situation...
Log.e(TAG, ex.toString());
}
return result;
}
public static void saveDeviceNumbers(SharedPreferences prefs, List<Integer> list) {
StringBuilder sb = new StringBuilder();
for (Integer i : list) {
sb.append(i.toString());
sb.append(",");
}
final String pref = sb.toString();
Log.d(TAG, "saveDeviceNumbers: " + pref);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREFS_DEVICES, pref);
editor.apply();
}
}
|