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 = "";
22 public String macAddr = "";
23 public String 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;
36 File file = new File(configPath);
37 if (!file.exists()) return new UserInfo();
39 StringBuilder text = new StringBuilder();
41 BufferedReader br = new BufferedReader(new FileReader(file));
43 while((line = br.readLine()) != null){
47 }catch (IOException e){
51 String json = text.toString();
53 UserInfo info = new UserInfo();
56 JSONObject jobj = new JSONObject(json);
57 info.server = jobj.getString("server");
58 info.user = jobj.getString("user");
59 info.macAddr = jobj.getString("macAddr");
60 info.cameraId = jobj.getString("cameraId");
61 } catch (JSONException e){
68 public boolean saveConfig() {
70 String jstring = toString();
72 Log.e("Config", "xxxxxxxxx " + jstring);
74 File file = new File(configPath);
76 BufferedWriter bw = new BufferedWriter(new FileWriter(file));
79 } catch (IOException e){
86 public void update(String server, String user, String macAddr, String cameraId) {
89 this.macAddr = macAddr;
90 this.cameraId = cameraId;
93 public String toString () {
94 JSONObject obj = toJsonObj();
95 if (obj.equals(null)) return "";
96 return obj.toString();
99 private JSONObject toJsonObj () {
101 JSONObject obj = new JSONObject();
102 obj.put("server", this.server);
103 obj.put("user", this.user);
104 obj.put("macAddr", this.macAddr);
105 obj.put("cameraId", this.cameraId);
107 } catch (JSONException e) {