-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prefs.java
52 lines (37 loc) · 1.11 KB
/
Prefs.java
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
package ronidea.viewonphone;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.Random;
/**
* Store stuff
*/
public class Prefs {
private static SharedPreferences prefs;
private static SharedPreferences.Editor editor;
static final String KEY_PASSWORD = "password";
static final String KEY_IP_ADR = "ip_address";
Prefs(Context context) {
prefs = context.getSharedPreferences("generalPrefs", 0);
}
static String getString(String key) {
return prefs.getString(key, "");
}
static void saveString(String key, String value) {
editor = prefs.edit();
editor.putString(key, value);
editor.apply();
}
static String getPassword() {
String pw = prefs.getString(KEY_PASSWORD, "");
if (pw.equals("")) {
Random random = new Random();
for (int i = 0; i < 6; i++) {
pw += random.nextInt(10);
}
editor = prefs.edit();
editor.putString(KEY_PASSWORD, pw);
editor.apply();
}
return pw;
}
}