1 import java.util.HashMap;
2 import java.util.Map.Entry;
3 import java.util.Properties;
4 import java.util.Set;
5 import android.content.Context;
6 import android.content.pm.PackageInfo;
7 import android.content.pm.PackageManager.NameNotFoundException;
8 import android.content.res.Resources;
9 import android.os.Environment;
10 import android.os.Handler;
11 import android.text.StaticLayout;
12 import android.text.TextUtils;
13
14 import com.tools.ThreadPoolManager;
15
16 public class ApplicationConfig {
17
18 /** 当前应用的上下文对象*/
19 public static Context context;
20
21 /** 资源对象*/
22 public static Resources resouce;
23
24 /** 应用名名*/
25 public static String packageName;
26
27 /** handler对象*/
28 public static Handler handler;
29
30 /** 配置信息的集合*/
31 private static HashMap<String, String> configMap;
32
33 /** 切换到测试的数据*/
34 public static boolean isTest = false;
35
36 /**是否可以切换配置环境(开发环境、测试环境、正式环境)的开关*/
37 public static boolean switchable = false;
38
39 /** 国内的文件服务器url*/
40 public static String BASE_FILE_URL_SHENGZHEN = "";
41
42 /** 国外的文件服务器url*/
43 public static String BASE_FILE_URL_USA = "";
44
45 /** 登陆用户id*/
46 private static String userId = "";
47
48 /** 登陆用户token*/
49 private static String token = "";
50
51 /** 商家登陆的id,与userId不同 用于修改密码*/
52 public static String login_uid = "";
53
54
55 /** 用于判断版本更新是否为测试更新 表示是否为测试(0为不是,1为是)*/
56 public final static String UPDATEISTEST= "0" ;
57
58 /**
59 * 是否成功加载授权类库
60 */
61 public static boolean isLICENSE = false;
62 /**
63 *
64 * @Title: inifLoginUserInfo
65 * @Description: TODO(配置用户登陆的基本信息)
66 * @param: userId 用户ID
67 * @param: token 用户token
68 * @return: void
69 */
70 public static void initLoginUserBaseInfo(String userId, String token) {
71 ApplicationConfig.userId = userId;
72 ApplicationConfig.token = token;
73 }
74
75 /**
76 * @Description:
77 * @param login_uid
78 */
79 public static void initLoginUserIdForSeller(String login_uid) {
80 ApplicationConfig.login_uid = login_uid;
81 }
82
83 public static String getUserId() {
84 return userId;
85 }
86 public static String getSellerLoginUid() {
87 return login_uid;
88 }
89 public static String getUserToken() {
90 return token;
91 }
92
93 /**
94 * 判断是否存在此key
95 * @param key
96 * @return
97 */
98 private static boolean hasKey(String key){
99 if(TextUtils.isEmpty(key)) return false;
100 if(configMap!=null&&configMap.containsKey(key)) return true;
101 return false;
102 }
103
104 /**
105 * 获取应用的主界面的包名
106 * @return
107 */
108 public static String getMain_class_name() {
109 if(hasKey("main_class_name")){
110 return configMap.get("main_class_name");
111 }
112 return "";
113 }
114
115 /**
116 * 获取消息在主界面上的索引位置
117 * @return
118 */
119 public static int getMessage_index(){
120 if(hasKey("message_index")){
121 return Integer.parseInt(configMap.get("message_index"));
122 }
123 return 2;
124 }
125
126 /**
127 * 报告界面全名
128 */
129 public static String getTechnician_Report() {
130 if(hasKey("tech_report")) {
131 return configMap.get("tech_report");
132 }
133 return "";
134 }
135
136 /**
137 * 配置appinfo的信息
138 * @param context 当前的上下文
139 * @param properties 当前的应用的配置信息
140 */
141 public static void setAppInfo(Context context, Properties properties) throws NullPointerException {
142 if(context==null)
143 throw new NullPointerException("context is not null");
144 ApplicationConfig.context = context;
145 ApplicationConfig.resouce = context.getResources();
146 ApplicationConfig.packageName = context.getPackageName();
147 ApplicationConfig.handler = new Handler();
148 try {
149 PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
150 ApplicationConfig.APP_VERSION = info.versionName;
151 } catch (NameNotFoundException e) {
152 // TODO Auto-generated catch block
153 e.printStackTrace();
154 }
155 if(properties==null||properties.isEmpty())
156 throw new NullPointerException("config info is not null");
157 configMap = new HashMap<String, String>(properties.size());
158 Set<Entry<Object, Object>> set = properties.entrySet();
159 for(Entry<Object, Object> entry : set){
160 configMap.put(entry.getKey().toString(), entry.getValue().toString());
161 }
162 if(properties.containsKey("app_id"))
163 APP_ID = properties.getProperty("app_id");
164 if(properties.containsKey("debug"))
165 switchable = properties.getProperty("debug").equals("1")?true:false;
166 //将文件服务器地址重新存入缓存中
167 ThreadPoolManager.getInstance(ApplicationConfig.class.getName()).startTaskThread(new Runnable() {
168
169 @Override
170 public void run() {
171 ApplicationConfig.BASE_FILE_URL_SHENGZHEN = new InterfaceDao().getInterfaceNoThread(InterfaceConfig.AVATAR_PATH_SHENGZHENG);
172 ApplicationConfig.BASE_FILE_URL_USA = new InterfaceDao().getInterfaceNoThread(InterfaceConfig.AVATAR_PATH_USA);
173 }
174 });
175 }
176
177 }