forked from ob-f/OpenBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControllerConfig.java
68 lines (55 loc) · 1.66 KB
/
ControllerConfig.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.openbot.env;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
public class ControllerConfig {
private static ControllerConfig _controllerConfig;
SharedPreferences preferences;
enum VIDEO_SERVER_TYPE {
WEBRTC,
RTSP
}
private String currentServerType;
public static ControllerConfig getInstance() {
if (_controllerConfig == null) {
synchronized (PhoneController.class) {
if (_controllerConfig == null) _controllerConfig = new ControllerConfig();
}
}
return _controllerConfig;
}
void init(Context context) {
preferences = PreferenceManager.getDefaultSharedPreferences(context);
currentServerType = get("video_server", "WEBRTC");
}
private void set(String name, String value) {
SharedPreferences.Editor editor = preferences.edit();
editor.putString(name, value);
editor.apply();
}
private String get(String name, String defaultValue) {
try {
return preferences.getString(name, defaultValue);
} catch (ClassCastException e) {
return defaultValue;
}
}
private Boolean getBoolean(String name, Boolean defaultValue) {
try {
return preferences.getBoolean(name, defaultValue);
} catch (ClassCastException e) {
return defaultValue;
}
}
private void setBoolean(String name, boolean value) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(name, value);
editor.apply();
}
public String getVideoServerType() {
return get("video_server", "WEBRTC");
}
public void setVideoServerType(String type) {
set("video_server", type);
}
}