1 package ai.suanzi.rtmpclient;
3 import android.content.Context;
4 import android.util.Log;
5 import android.widget.Toast;
7 import java.io.BufferedReader;
8 import java.io.BufferedWriter;
10 import java.io.FileReader;
11 import java.io.FileWriter;
12 import java.io.IOException;
13 import java.io.InputStream;
15 import org.json.JSONException;
16 import org.json.JSONObject;
18 public class UserInfo {
20 public String server = "";
21 public String user = "suanzi";
22 public String macAddr = "ac83f34ead90";
23 public String cameraId = "cameraId";
24 private static String configPath;
26 private static UserInfo instance = null;
27 private UserInfo () {}
29 public static void setConfigPath(String fname){
33 public static UserInfo getConfig() {
34 if (instance != null) return instance;
35 File file = new File(configPath);
36 StringBuilder text = new StringBuilder();
38 BufferedReader br = new BufferedReader(new FileReader(file));
40 while((line = br.readLine()) != null){
44 }catch (IOException e){
48 String json = text.toString();
50 UserInfo info = new UserInfo();
53 JSONObject jobj = new JSONObject(json);
54 info.server = jobj.getString("server");
55 info.user = jobj.getString("user");
56 info.macAddr = jobj.getString("macAddr");
57 info.cameraId = jobj.getString("cameraId");
58 } catch (JSONException e){
65 public boolean saveConfig() {
67 String jstring = toString();
69 Log.e("Config", "xxxxxxxxx " + jstring);
71 File file = new File(configPath);
73 BufferedWriter bw = new BufferedWriter(new FileWriter(file));
76 } catch (IOException e){
83 public void update(String server, String user, String macAddr, String cameraId) {
86 this.macAddr = macAddr;
87 this.cameraId = cameraId;
90 public String toString () {
91 JSONObject obj = toJsonObj();
92 if (obj.equals(null)) return "";
93 return obj.toString();
96 private JSONObject toJsonObj () {
98 JSONObject obj = new JSONObject();
99 obj.put("server", this.server);
100 obj.put("user", this.user);
101 obj.put("macAddr", this.macAddr);
102 obj.put("cameraId", this.cameraId);
104 } catch (JSONException e) {