forked from ob-f/OpenBot
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSharedPreferencesManager.java
More file actions
148 lines (114 loc) · 4.5 KB
/
SharedPreferencesManager.java
File metadata and controls
148 lines (114 loc) · 4.5 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package org.openbot.env;
import android.content.Context;
import android.content.SharedPreferences;
import org.openbot.tflite.Network;
import org.openbot.utils.Enums;
public class SharedPreferencesManager {
private static final String PREFERENCES_NAME = "openbot_settings";
private static final int DEFAULT_BAUD_RATE = 115200;
private static final String BAUD_RATE = "BAUD_RATE";
private static final int DEFAULT_LOG_MODE = Enums.LogMode.CROP_IMG.ordinal();
private static final String LOG_MODE = "LOG_MODE";
private static final int DEFAULT_CONTROL_MODE = Enums.ControlMode.GAMEPAD.getValue();
private static final String CONTROL_MODE = "CONTROL_MODE";
private static final int DEFAULT_SPEED_MODE = Enums.SpeedMode.NORMAL.getValue();
private static final String SPEED_MODE = "SPEED_MODE";
private static final int DEFAULT_DRIVE_MODE = Enums.DriveMode.GAME.getValue();
private static final String DRIVE_MODE = "DRIVE_MODE";
private static final String DEFAULT_MODEL = "DEFAULT_MODEL_NAME";
private static final String OBJECT_NAV_MODEL = "OBJECT_NAV_MODEL_NAME";
private static final String AUTOPILOT_MODEL = "AUTOPILOT_MODEL_NAME";
private static final String OBJECT_TYPE = "OBJECT_TYPE";
private static final String DEFAULT_OBJECT_TYPE = "person";
private static final int DEFAULT_DEVICE = Network.Device.CPU.ordinal();
private static final String DEVICE = "DEVICE";
private static final int DEFAULT_NUM_THREAD = 4;
private static final String NUM_THREAD = "NUM_THREAD";
private static final String CAMERA_SWITCH = "CAMERA_SWITCH";
private static final String SHEET_EXPANDED = "SHEET_EXPANDED";
private final SharedPreferences preferences;
public SharedPreferencesManager(Context context) {
preferences =
context
.getApplicationContext()
.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
}
public int getBaudrate() {
return preferences.getInt(BAUD_RATE, DEFAULT_BAUD_RATE);
}
public int getDevice() {
return preferences.getInt(DEVICE, DEFAULT_DEVICE);
}
public int getDriveMode() {
return preferences.getInt(DRIVE_MODE, DEFAULT_DRIVE_MODE);
}
public int getLogMode() {
return preferences.getInt(LOG_MODE, DEFAULT_LOG_MODE);
}
public int getControlMode() {
return preferences.getInt(CONTROL_MODE, DEFAULT_CONTROL_MODE);
}
public int getSpeedMode() {
return preferences.getInt(SPEED_MODE, DEFAULT_SPEED_MODE);
}
public int getNumThreads() {
return preferences.getInt(NUM_THREAD, DEFAULT_NUM_THREAD);
}
public boolean getCameraSwitch() {
return preferences.getBoolean(CAMERA_SWITCH, false);
}
public boolean getSheetExpanded() {
return preferences.getBoolean(SHEET_EXPANDED, false);
}
public void setBaudrate(int baudRate) {
preferences.edit().putInt(BAUD_RATE, baudRate).apply();
}
public void setDefaultModel(String model) {
preferences.edit().putString(DEFAULT_MODEL, model).apply();
}
public String getDefaultModel() {
return preferences.getString(DEFAULT_MODEL, "");
}
public void setObjectNavModel(String model) {
preferences.edit().putString(OBJECT_NAV_MODEL, model).apply();
}
public String getObjectNavModel() {
return preferences.getString(OBJECT_NAV_MODEL, "");
}
public void setAutopilotModel(String model) {
preferences.edit().putString(AUTOPILOT_MODEL, model).apply();
}
public String getAutopilotModel() {
return preferences.getString(AUTOPILOT_MODEL, "");
}
public void setObjectType(String model) {
preferences.edit().putString(OBJECT_TYPE, model).apply();
}
public String getObjectType() {
return preferences.getString(OBJECT_TYPE, DEFAULT_OBJECT_TYPE);
}
public void setDevice(int device) {
preferences.edit().putInt(DEVICE, device).apply();
}
public void setDriveMode(int mode) {
preferences.edit().putInt(DRIVE_MODE, mode).apply();
}
public void setLogMode(int mode) {
preferences.edit().putInt(LOG_MODE, mode).apply();
}
public void setControlMode(int mode) {
preferences.edit().putInt(CONTROL_MODE, mode).apply();
}
public void setSpeedMode(int mode) {
preferences.edit().putInt(SPEED_MODE, mode).apply();
}
public void setNumThreads(int numThreads) {
preferences.edit().putInt(NUM_THREAD, numThreads).apply();
}
public void setCameraSwitch(boolean isChecked) {
preferences.edit().putBoolean(CAMERA_SWITCH, isChecked).apply();
}
public void setSheetExpanded(boolean expanded) {
preferences.edit().putBoolean(SHEET_EXPANDED, expanded).apply();
}
}