whyclj
2019-12-31 e6a31a391c7167caab17b750eb2f85798849f2b6
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
package com.mytestapp;
 
import android.content.Context;
import android.content.SharedPreferences;
 
public class ServerInfo {
    private String server_ip;                          //服务器ip地址
    private int server_port;                           //服务器端口号
    private String server_name;                         //服务器项目名称
 
 
    //获取服务器信息
    public static ServerInfo readServerInfo(Context context){
        ServerInfo serverInfo = null;
        if(context != null){
            serverInfo = new ServerInfo();
            SharedPreferences pref    = context.getSharedPreferences("data",    Context.MODE_PRIVATE);
            serverInfo.server_ip = pref.getString("server_ip","");
            serverInfo.server_port = pref.getInt("server_port",0);
            serverInfo.server_name = pref.getString("server_name","");
        }
        return  serverInfo;
    }
 
    //保存服务器参数信息
    public static void WriteServerInfo(Context context,ServerInfo serverInfo){
        SharedPreferences.Editor    editor    =    context.getSharedPreferences("data",Context.MODE_PRIVATE).edit();
        editor.putString("server_ip",serverInfo.server_ip);
        editor.putInt("server_port",serverInfo.server_port);
        editor.apply();
    }
 
    public String createServerUrl(){
        return "http://"+server_ip+":"+server_port+"/Device_Manage/index.html";
        //return "http://"+server_ip+":"+server_port+"/";
    }
 
    public String getServer_ip() {
        return server_ip;
    }
 
    public void setServer_ip(String server_ip) {
        this.server_ip = server_ip;
    }
 
    public int getServer_port() {
        return server_port;
    }
 
    public void setServer_port(int server_port) {
        this.server_port = server_port;
    }
 
    public String getServer_name() {
        return server_name;
    }
 
    public void setServer_name(String server_name) {
        this.server_name = server_name;
    }
 
    @Override
    public String toString() {
        return "ServerInfo{" +
                "server_ip='" + server_ip + '\'' +
                ", server_port=" + server_port +
                ", server_name='" + server_name + '\'' +
                '}';
    }
}