Commit bc654b292e943704e22a183f2f28adf532bb0501

Authored by 李攀
1 parent cfa4f2e2

update log to file,流程优化

@@ -11,8 +11,8 @@ def isWindows = { @@ -11,8 +11,8 @@ def isWindows = {
11 } 11 }
12 12
13 ext { 13 ext {
14 - APP_VERSION_CODE = 2;  
15 - APP_VERSION_NAME = "v2.0"; 14 + APP_VERSION_CODE = 3;
  15 + APP_VERSION_NAME = "v2.1-0601";
16 } 16 }
17 17
18 android { 18 android {
1 package com.gimi.common.cinema.utils; 1 package com.gimi.common.cinema.utils;
2 2
3 -import android.os.Environment;  
4 import android.support.annotation.IntDef; 3 import android.support.annotation.IntDef;
5 import android.util.Log; 4 import android.util.Log;
6 import org.json.JSONArray; 5 import org.json.JSONArray;
@@ -14,6 +13,7 @@ import javax.xml.transform.TransformerFactory; @@ -14,6 +13,7 @@ import javax.xml.transform.TransformerFactory;
14 import javax.xml.transform.stream.StreamResult; 13 import javax.xml.transform.stream.StreamResult;
15 import javax.xml.transform.stream.StreamSource; 14 import javax.xml.transform.stream.StreamSource;
16 import java.io.BufferedWriter; 15 import java.io.BufferedWriter;
  16 +import java.io.ByteArrayOutputStream;
17 import java.io.File; 17 import java.io.File;
18 import java.io.FileWriter; 18 import java.io.FileWriter;
19 import java.io.IOException; 19 import java.io.IOException;
@@ -21,82 +21,109 @@ import java.io.StringReader; @@ -21,82 +21,109 @@ import java.io.StringReader;
21 import java.io.StringWriter; 21 import java.io.StringWriter;
22 import java.lang.annotation.Retention; 22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy; 23 import java.lang.annotation.RetentionPolicy;
  24 +import java.text.Format;
24 import java.text.SimpleDateFormat; 25 import java.text.SimpleDateFormat;
25 import java.util.Date; 26 import java.util.Date;
26 import java.util.Formatter; 27 import java.util.Formatter;
27 import java.util.Locale; 28 import java.util.Locale;
  29 +import java.util.concurrent.ExecutorService;
  30 +import java.util.concurrent.Executors;
  31 +import java.util.zip.DataFormatException;
  32 +import java.util.zip.Deflater;
  33 +import java.util.zip.Inflater;
28 34
29 /** 35 /**
30 * <pre> 36 * <pre>
31 * author: Blankj 37 * author: Blankj
32 * blog : http://blankj.com 38 * blog : http://blankj.com
33 - * time : 2016/9/21  
34 - * desc : 日志相关工具类 39 + * time : 2016/09/21
  40 + * desc : Log相关工具类
35 * </pre> 41 * </pre>
36 */ 42 */
37 public final class LogUtils { 43 public final class LogUtils {
38 44
39 - private LogUtils() {  
40 - throw new UnsupportedOperationException("u can't instantiate me...");  
41 - }  
42 -  
43 - public static final int V = 0x01;  
44 - public static final int D = 0x02;  
45 - public static final int I = 0x04;  
46 - public static final int W = 0x08;  
47 - public static final int E = 0x10;  
48 - public static final int A = 0x20; 45 + public static final int V = Log.VERBOSE;
  46 + public static final int D = Log.DEBUG;
  47 + public static final int I = Log.INFO;
  48 + public static final int W = Log.WARN;
  49 + public static final int E = Log.ERROR;
  50 + public static final int A = Log.ASSERT;
49 51
50 @IntDef({V, D, I, W, E, A}) 52 @IntDef({V, D, I, W, E, A})
51 @Retention(RetentionPolicy.SOURCE) 53 @Retention(RetentionPolicy.SOURCE)
52 - public @interface TYPE {  
53 - }  
54 -  
55 - private static final int FILE = 0xF1;  
56 - private static final int JSON = 0xF2;  
57 - private static final int XML = 0xF4; 54 + private @interface TYPE {
  55 + }
  56 +
  57 + private static final char[] T = new char[]{'V', 'D', 'I', 'W', 'E', 'A'};
  58 +
  59 + private static final int FILE = 0x10;
  60 + private static final int JSON = 0x20;
  61 + private static final int XML = 0x30;
  62 + private static ExecutorService executor;
  63 + private static String defaultDir;// log默认存储目录
  64 + private static String dir; // log存储目录
  65 +
  66 + private static boolean sLogSwitch = true; // log总开关,默认开
  67 + private static boolean sLog2ConsoleSwitch = true; // logcat是否打印,默认打印
  68 + private static String sGlobalTag = null; // log标签
  69 + private static boolean sTagIsSpace = true; // log标签是否为空白
  70 + private static boolean sLogHeadSwitch = true; // log头部开关,默认开
  71 + private static boolean sLog2FileSwitch = false;// log写入文件开关,默认关
  72 + private static boolean sLogBorderSwitch = true; // log边框开关,默认开
  73 + private static int sConsoleFilter = V; // log控制台过滤器
  74 + private static int sFileFilter = V; // log文件过滤器
  75 +
  76 + private static final String FILE_SEP = System.getProperty("file.separator");
  77 + private static final String LINE_SEP = System.getProperty("line.separator");
  78 + private static final String TOP_BORDER = "╔═══════════════════════════════════════════════════════════════════════════════════════════════════";
  79 + private static final String LEFT_BORDER = "║ ";
  80 + private static final String BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════════════════════════════";
  81 + private static final int MAX_LEN = 4000;
  82 + private static final Format FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS ", Locale.getDefault());
58 83
59 - private static String dir; // log存储目录  
60 - private static boolean sLogSwitch = true; // log总开关  
61 - private static String sGlobalTag = null; // log标签  
62 - private static boolean sTagIsSpace = true; // log标签是否为空白  
63 - private static boolean sLog2FileSwitch = false;// log写入文件开关  
64 - private static boolean sLogBorderSwitch = true; // log边框开关  
65 - private static int sLogFilter = V; // log过滤器  
66 -  
67 - private static final String TOP_BORDER = "╔═══════════════════════════════════════════════════════════════════════════════════════════════════";  
68 - private static final String LEFT_BORDER = "║ ";  
69 - private static final String BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════════════════════════════";  
70 - private static final String LINE_SEPARATOR = System.getProperty("line.separator");  
71 -  
72 - private static final int MAX_LEN = 4000;  
73 private static final String NULL_TIPS = "Log with null object."; 84 private static final String NULL_TIPS = "Log with null object.";
74 - private static final String NULL = "null";  
75 - private static final String ARGS = "args"; 85 + private static final String NULL = "null";
  86 + private static final String ARGS = "args";
76 87
77 - public static class Builder { 88 + private LogUtils() {
  89 + throw new UnsupportedOperationException("u can't instantiate me...");
  90 + }
78 91
  92 + public static class Builder {
79 public Builder() { 93 public Builder() {
80 - if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {  
81 -// dir = Utils.getContext().getExternalCacheDir() + File.separator + "log" + File.separator;  
82 - } else {  
83 -// dir = Utils.getContext().getCacheDir() + File.separator + "log" + File.separator;  
84 - } 94 + if (defaultDir != null) return;
  95 + defaultDir = "/sdcard/log/";
  96 +// if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  97 +// && Utils.getContext().getExternalCacheDir() != null)
  98 +// defaultDir = Utils.getContext().getExternalCacheDir() + FILE_SEP + "log" + FILE_SEP;
  99 +// else {
  100 +// defaultDir = Utils.getContext().getCacheDir() + FILE_SEP + "log" + FILE_SEP;
  101 +// }
85 } 102 }
86 103
87 - public Builder setGlobalTag(String tag) {  
88 - if (!isSpace(tag)) {  
89 - LogUtils.sGlobalTag = tag;  
90 - sTagIsSpace = false;  
91 - } else { 104 + public Builder setLogSwitch(boolean logSwitch) {
  105 + LogUtils.sLogSwitch = logSwitch;
  106 + return this;
  107 + }
  108 +
  109 + public Builder setConsoleSwitch(boolean consoleSwitch) {
  110 + LogUtils.sLog2ConsoleSwitch = consoleSwitch;
  111 + return this;
  112 + }
  113 +
  114 + public Builder setGlobalTag(final String tag) {
  115 + if (isSpace(tag)) {
92 LogUtils.sGlobalTag = ""; 116 LogUtils.sGlobalTag = "";
93 sTagIsSpace = true; 117 sTagIsSpace = true;
  118 + } else {
  119 + LogUtils.sGlobalTag = tag;
  120 + sTagIsSpace = false;
94 } 121 }
95 return this; 122 return this;
96 } 123 }
97 124
98 - public Builder setLogSwitch(boolean logSwitch) {  
99 - LogUtils.sLogSwitch = logSwitch; 125 + public Builder setLogHeadSwitch(boolean logHeadSwitch) {
  126 + LogUtils.sLogHeadSwitch = logHeadSwitch;
100 return this; 127 return this;
101 } 128 }
102 129
@@ -105,15 +132,47 @@ public final class LogUtils { @@ -105,15 +132,47 @@ public final class LogUtils {
105 return this; 132 return this;
106 } 133 }
107 134
  135 + public Builder setDir(final String dir) {
  136 + if (isSpace(dir)) {
  137 + LogUtils.dir = null;
  138 + } else {
  139 + LogUtils.dir = dir.endsWith(FILE_SEP) ? dir : dir + FILE_SEP;
  140 + }
  141 + return this;
  142 + }
  143 +
  144 + public Builder setDir(final File dir) {
  145 + LogUtils.dir = dir == null ? null : dir.getAbsolutePath() + FILE_SEP;
  146 + return this;
  147 + }
  148 +
108 public Builder setBorderSwitch(boolean borderSwitch) { 149 public Builder setBorderSwitch(boolean borderSwitch) {
109 LogUtils.sLogBorderSwitch = borderSwitch; 150 LogUtils.sLogBorderSwitch = borderSwitch;
110 return this; 151 return this;
111 } 152 }
112 153
113 - public Builder setLogFilter(@TYPE int logFilter) {  
114 - LogUtils.sLogFilter = logFilter; 154 + public Builder setConsoleFilter(@TYPE int consoleFilter) {
  155 + LogUtils.sConsoleFilter = consoleFilter;
115 return this; 156 return this;
116 } 157 }
  158 +
  159 + public Builder setFileFilter(@TYPE int fileFilter) {
  160 + LogUtils.sFileFilter = fileFilter;
  161 + return this;
  162 + }
  163 +
  164 + @Override
  165 + public String toString() {
  166 + return "switch: " + sLogSwitch
  167 + + LINE_SEP + "console: " + sLog2ConsoleSwitch
  168 + + LINE_SEP + "tag: " + (sTagIsSpace ? "null" : sGlobalTag)
  169 + + LINE_SEP + "head: " + sLogHeadSwitch
  170 + + LINE_SEP + "file: " + sLog2FileSwitch
  171 + + LINE_SEP + "dir: " + (dir == null ? defaultDir : dir)
  172 + + LINE_SEP + "border: " + sLogBorderSwitch
  173 + + LINE_SEP + "consoleFilter: " + T[sConsoleFilter - V]
  174 + + LINE_SEP + "fileFilter: " + T[sFileFilter - V];
  175 + }
117 } 176 }
118 177
119 public static void v(Object contents) { 178 public static void v(Object contents) {
@@ -165,93 +224,108 @@ public final class LogUtils { @@ -165,93 +224,108 @@ public final class LogUtils {
165 } 224 }
166 225
167 public static void file(Object contents) { 226 public static void file(Object contents) {
168 - log(FILE, sGlobalTag, contents); 227 + log(FILE | D, sGlobalTag, contents);
  228 + }
  229 +
  230 + public static void file(@TYPE int type, Object contents) {
  231 + log(FILE | type, sGlobalTag, contents);
169 } 232 }
170 233
171 public static void file(String tag, Object contents) { 234 public static void file(String tag, Object contents) {
172 - log(FILE, tag, contents); 235 + log(FILE | D, tag, contents);
  236 + }
  237 +
  238 + public static void file(@TYPE int type, String tag, Object contents) {
  239 + log(FILE | type, tag, contents);
173 } 240 }
174 241
175 public static void json(String contents) { 242 public static void json(String contents) {
176 - log(JSON, sGlobalTag, contents); 243 + log(JSON | D, sGlobalTag, contents);
  244 + }
  245 +
  246 + public static void json(@TYPE int type, String contents) {
  247 + log(JSON | type, sGlobalTag, contents);
177 } 248 }
178 249
179 public static void json(String tag, String contents) { 250 public static void json(String tag, String contents) {
180 - log(JSON, tag, contents); 251 + log(JSON | D, tag, contents);
  252 + }
  253 +
  254 + public static void json(@TYPE int type, String tag, String contents) {
  255 + log(JSON | type, tag, contents);
181 } 256 }
182 257
183 public static void xml(String contents) { 258 public static void xml(String contents) {
184 - log(XML, sGlobalTag, contents); 259 + log(XML | D, sGlobalTag, contents);
  260 + }
  261 +
  262 + public static void xml(@TYPE int type, String contents) {
  263 + log(XML | type, sGlobalTag, contents);
185 } 264 }
186 265
187 public static void xml(String tag, String contents) { 266 public static void xml(String tag, String contents) {
188 - log(XML, tag, contents);  
189 - }  
190 -  
191 - private static void log(int type, String tag, Object... contents) {  
192 - if (!sLogSwitch) return;  
193 - final String[] processContents = processContents(type, tag, contents);  
194 - tag = processContents[0];  
195 - String msg = processContents[1];  
196 - switch (type) {  
197 - case V:  
198 - case D:  
199 - case I:  
200 - case W:  
201 - case E:  
202 - case A:  
203 - if (V == sLogFilter || type >= sLogFilter) {  
204 - printLog(type, tag, msg);  
205 - }  
206 - if (sLog2FileSwitch) {  
207 - print2File(tag, msg);  
208 - }  
209 - break;  
210 - case FILE:  
211 - print2File(tag, msg);  
212 - break;  
213 - case JSON:  
214 - printLog(D, tag, msg);  
215 - break;  
216 - case XML:  
217 - printLog(D, tag, msg);  
218 - break;  
219 - } 267 + log(XML | D, tag, contents);
  268 + }
220 269
  270 + public static void xml(@TYPE int type, String tag, String contents) {
  271 + log(XML | type, tag, contents);
221 } 272 }
222 273
223 - private static String[] processContents(int type, String tag, Object... contents) {  
224 - StackTraceElement targetElement = Thread.currentThread().getStackTrace()[5];  
225 - String className = targetElement.getClassName();  
226 - String[] classNameInfo = className.split("\\.");  
227 - if (classNameInfo.length > 0) {  
228 - className = classNameInfo[classNameInfo.length - 1]; 274 + private static void log(final int type, String tag, final Object... contents) {
  275 + if (!sLogSwitch || (!sLog2ConsoleSwitch && !sLog2FileSwitch)) return;
  276 + int type_low = type & 0x0f, type_high = type & 0xf0;
  277 + if (type_low < sConsoleFilter && type_low < sFileFilter) return;
  278 + final String[] tagAndHead = processTagAndHead(tag);
  279 + String body = processBody(type_high, contents);
  280 + if (sLog2ConsoleSwitch && type_low >= sConsoleFilter) {
  281 + print2Console(type_low, tagAndHead[0], tagAndHead[1] + body);
229 } 282 }
230 - if (className.contains("$")) {  
231 - className = className.split("\\$")[0]; 283 + if (sLog2FileSwitch || type_high == FILE) {
  284 + if (type_low >= sFileFilter)
  285 + print2File(type_low, tagAndHead[0], tagAndHead[2] + body);
232 } 286 }
233 - if (!sTagIsSpace) {// 如果全局tag不为空,那就用全局tag 287 + }
  288 +
  289 + private static String[] processTagAndHead(String tag) {
  290 + if (!sTagIsSpace && !sLogHeadSwitch) {
234 tag = sGlobalTag; 291 tag = sGlobalTag;
235 - } else {// 全局tag为空时,如果传入的tag为空那就显示类名,否则显示tag  
236 - tag = isSpace(tag) ? className : tag; 292 + } else {
  293 + StackTraceElement targetElement = Thread.currentThread().getStackTrace()[5];
  294 + String className = targetElement.getClassName();
  295 + String[] classNameInfo = className.split("\\.");
  296 + if (classNameInfo.length > 0) {
  297 + className = classNameInfo[classNameInfo.length - 1];
  298 + }
  299 + if (className.contains("$")) {
  300 + className = className.split("\\$")[0];
  301 + }
  302 + if (sTagIsSpace) {
  303 + tag = isSpace(tag) ? className : tag;
  304 + }
  305 + if (sLogHeadSwitch) {
  306 + String head = new Formatter()
  307 + .format("%s, %s(%s.java:%d)",
  308 + Thread.currentThread().getName(),
  309 + targetElement.getMethodName(),
  310 + className,
  311 + targetElement.getLineNumber())
  312 + .toString();
  313 + return new String[]{tag, head + LINE_SEP, " [" + head + "]: "};
  314 + }
237 } 315 }
  316 + return new String[]{tag, "", ": "};
  317 + }
238 318
239 - String head = new Formatter()  
240 - .format("Thread: %s, %s(%s.java:%d)" + LINE_SEPARATOR,  
241 - Thread.currentThread().getName(),  
242 - targetElement.getMethodName(),  
243 - className,  
244 - targetElement.getLineNumber())  
245 - .toString();  
246 - String msg = NULL_TIPS; 319 + private static String processBody(int type, Object... contents) {
  320 + String body = NULL_TIPS;
247 if (contents != null) { 321 if (contents != null) {
248 if (contents.length == 1) { 322 if (contents.length == 1) {
249 Object object = contents[0]; 323 Object object = contents[0];
250 - msg = object == null ? NULL : object.toString(); 324 + body = object == null ? NULL : object.toString();
251 if (type == JSON) { 325 if (type == JSON) {
252 - msg = formatJson(msg); 326 + body = formatJson(body);
253 } else if (type == XML) { 327 } else if (type == XML) {
254 - msg = formatXml(msg); 328 + body = formatXml(body);
255 } 329 }
256 } else { 330 } else {
257 StringBuilder sb = new StringBuilder(); 331 StringBuilder sb = new StringBuilder();
@@ -263,20 +337,12 @@ public final class LogUtils { @@ -263,20 +337,12 @@ public final class LogUtils {
263 .append("]") 337 .append("]")
264 .append(" = ") 338 .append(" = ")
265 .append(content == null ? NULL : content.toString()) 339 .append(content == null ? NULL : content.toString())
266 - .append(LINE_SEPARATOR); 340 + .append(LINE_SEP);
267 } 341 }
268 - msg = sb.toString();  
269 - }  
270 - }  
271 - if (sLogBorderSwitch) {  
272 - StringBuilder sb = new StringBuilder();  
273 - String[] lines = msg.split(LINE_SEPARATOR);  
274 - for (String line : lines) {  
275 - sb.append(LEFT_BORDER).append(line).append(LINE_SEPARATOR); 342 + body = sb.toString();
276 } 343 }
277 - msg = sb.toString();  
278 } 344 }
279 - return new String[]{tag, head + msg}; 345 + return body;
280 } 346 }
281 347
282 private static String formatJson(String json) { 348 private static String formatJson(String json) {
@@ -300,106 +366,80 @@ public final class LogUtils { @@ -300,106 +366,80 @@ public final class LogUtils {
300 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 366 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
301 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 367 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
302 transformer.transform(xmlInput, xmlOutput); 368 transformer.transform(xmlInput, xmlOutput);
303 - xml = xmlOutput.getWriter().toString().replaceFirst(">", ">" + LINE_SEPARATOR); 369 + xml = xmlOutput.getWriter().toString().replaceFirst(">", ">" + LINE_SEP);
304 } catch (Exception e) { 370 } catch (Exception e) {
305 e.printStackTrace(); 371 e.printStackTrace();
306 } 372 }
307 return xml; 373 return xml;
308 } 374 }
309 375
310 - private static void printLog(int type, String tag, String msg) {  
311 - if (sLogBorderSwitch) printBorder(type, tag, true); 376 + private static void print2Console(final int type, String tag, String msg) {
  377 + if (sLogBorderSwitch) {
  378 + print(type, tag, TOP_BORDER);
  379 + msg = addLeftBorder(msg);
  380 + }
312 int len = msg.length(); 381 int len = msg.length();
313 int countOfSub = len / MAX_LEN; 382 int countOfSub = len / MAX_LEN;
314 if (countOfSub > 0) { 383 if (countOfSub > 0) {
315 - int index = 0; 384 + print(type, tag, msg.substring(0, MAX_LEN));
316 String sub; 385 String sub;
317 - for (int i = 0; i < countOfSub; i++) { 386 + int index = MAX_LEN;
  387 + for (int i = 1; i < countOfSub; i++) {
318 sub = msg.substring(index, index + MAX_LEN); 388 sub = msg.substring(index, index + MAX_LEN);
319 - printSubLog(type, tag, sub); 389 + print(type, tag, sLogBorderSwitch ? LEFT_BORDER + sub : sub);
320 index += MAX_LEN; 390 index += MAX_LEN;
321 } 391 }
322 - printSubLog(type, tag, msg.substring(index, len)); 392 + sub = msg.substring(index, len);
  393 + print(type, tag, sLogBorderSwitch ? LEFT_BORDER + sub : sub);
323 } else { 394 } else {
324 - printSubLog(type, tag, msg);  
325 - }  
326 - if (sLogBorderSwitch) printBorder(type, tag, false);  
327 - }  
328 -  
329 - private static void printSubLog(final int type, final String tag, String msg) {  
330 - if (sLogBorderSwitch) msg = LEFT_BORDER + msg;  
331 - switch (type) {  
332 - case V:  
333 - Log.v(tag, msg);  
334 - break;  
335 - case D:  
336 - Log.d(tag, msg);  
337 - break;  
338 - case I:  
339 - Log.i(tag, msg);  
340 - break;  
341 - case W:  
342 - Log.w(tag, msg);  
343 - break;  
344 - case E:  
345 - Log.e(tag, msg);  
346 - break;  
347 - case A:  
348 - Log.wtf(tag, msg);  
349 - break; 395 + print(type, tag, msg);
350 } 396 }
  397 + if (sLogBorderSwitch) print(type, tag, BOTTOM_BORDER);
351 } 398 }
352 399
353 - private static void printBorder(int type, String tag, boolean isTop) {  
354 - String border = isTop ? TOP_BORDER : BOTTOM_BORDER;  
355 - switch (type) {  
356 - case V:  
357 - Log.v(tag, border);  
358 - break;  
359 - case D:  
360 - Log.d(tag, border);  
361 - break;  
362 - case I:  
363 - Log.i(tag, border);  
364 - break;  
365 - case W:  
366 - Log.w(tag, border);  
367 - break;  
368 - case E:  
369 - Log.e(tag, border);  
370 - break;  
371 - case A:  
372 - Log.wtf(tag, border);  
373 - break; 400 + private static void print(final int type, final String tag, String msg) {
  401 + Log.println(type, tag, msg);
  402 + }
  403 +
  404 + private static String addLeftBorder(String msg) {
  405 + if (!sLogBorderSwitch) return msg;
  406 + StringBuilder sb = new StringBuilder();
  407 + String[] lines = msg.split(LINE_SEP);
  408 + for (String line : lines) {
  409 + sb.append(LEFT_BORDER).append(line).append(LINE_SEP);
374 } 410 }
  411 + return sb.toString();
375 } 412 }
376 413
377 - private synchronized static void print2File(final String tag, final String msg) {  
378 - Date now = new Date();  
379 - String date = new SimpleDateFormat("MM-dd", Locale.getDefault()).format(now);  
380 - final String fullPath = dir + date + ".txt"; 414 + private static void print2File(final int type, final String tag, final String msg) {
  415 + Date now = new Date(System.currentTimeMillis());
  416 + String format = FORMAT.format(now);
  417 + String date = format.substring(0, 5);
  418 + String time = format.substring(6);
  419 + final String fullPath = (dir == null ? defaultDir : dir) + date + ".txt";
381 if (!createOrExistsFile(fullPath)) { 420 if (!createOrExistsFile(fullPath)) {
382 Log.e(tag, "log to " + fullPath + " failed!"); 421 Log.e(tag, "log to " + fullPath + " failed!");
383 return; 422 return;
384 } 423 }
385 - String time = new SimpleDateFormat("MM-dd HH:mm:ss.SSS ", Locale.getDefault()).format(now);  
386 StringBuilder sb = new StringBuilder(); 424 StringBuilder sb = new StringBuilder();
387 - if (sLogBorderSwitch) sb.append(TOP_BORDER).append(LINE_SEPARATOR);  
388 sb.append(time) 425 sb.append(time)
  426 + .append(T[type - V])
  427 + .append("/")
389 .append(tag) 428 .append(tag)
390 - .append(": ")  
391 .append(msg) 429 .append(msg)
392 - .append(LINE_SEPARATOR);  
393 - if (sLogBorderSwitch) sb.append(BOTTOM_BORDER).append(LINE_SEPARATOR);  
394 - final String dateLogContent = sb.toString();  
395 - new Thread(new Runnable() { 430 + .append(LINE_SEP);
  431 + final String content = sb.toString();
  432 + if (executor == null) {
  433 + executor = Executors.newSingleThreadExecutor();
  434 + }
  435 + executor.execute(new Runnable() {
396 @Override 436 @Override
397 public void run() { 437 public void run() {
398 BufferedWriter bw = null; 438 BufferedWriter bw = null;
399 try { 439 try {
400 bw = new BufferedWriter(new FileWriter(fullPath, true)); 440 bw = new BufferedWriter(new FileWriter(fullPath, true));
401 - bw.write(dateLogContent);  
402 - Log.d(tag, "log to " + fullPath + " success!"); 441 + bw.write(content);
  442 +// Log.d(tag, "log to " + fullPath + " success!");
403 } catch (IOException e) { 443 } catch (IOException e) {
404 e.printStackTrace(); 444 e.printStackTrace();
405 Log.e(tag, "log to " + fullPath + " failed!"); 445 Log.e(tag, "log to " + fullPath + " failed!");
@@ -413,15 +453,11 @@ public final class LogUtils { @@ -413,15 +453,11 @@ public final class LogUtils {
413 } 453 }
414 } 454 }
415 } 455 }
416 - }).start(); 456 + });
417 } 457 }
418 458
419 private static boolean createOrExistsFile(String filePath) { 459 private static boolean createOrExistsFile(String filePath) {
420 - return createOrExistsFile(isSpace(filePath) ? null : new File(filePath));  
421 - }  
422 -  
423 - private static boolean createOrExistsFile(File file) {  
424 - if (file == null) return false; 460 + File file = new File(filePath);
425 if (file.exists()) return file.isFile(); 461 if (file.exists()) return file.isFile();
426 if (!createOrExistsDir(file.getParentFile())) return false; 462 if (!createOrExistsDir(file.getParentFile())) return false;
427 try { 463 try {
@@ -445,4 +481,43 @@ public final class LogUtils { @@ -445,4 +481,43 @@ public final class LogUtils {
445 } 481 }
446 return true; 482 return true;
447 } 483 }
  484 +
  485 + public static byte[] compress(byte input[]) {
  486 + ByteArrayOutputStream bos = new ByteArrayOutputStream();
  487 + Deflater compressor = new Deflater(1);
  488 + try {
  489 + compressor.setInput(input);
  490 + compressor.finish();
  491 + final byte[] buf = new byte[2048];
  492 + while (!compressor.finished()) {
  493 + int count = compressor.deflate(buf);
  494 + bos.write(buf, 0, count);
  495 + }
  496 + } finally {
  497 + compressor.end();
  498 + }
  499 + return bos.toByteArray();
  500 + }
  501 +
  502 + public static byte[] uncompress(byte[] input) {
  503 + ByteArrayOutputStream bos = new ByteArrayOutputStream();
  504 + Inflater decompressor = new Inflater();
  505 + try {
  506 + decompressor.setInput(input);
  507 + final byte[] buf = new byte[2048];
  508 + while (!decompressor.finished()) {
  509 + int count = 0;
  510 + try {
  511 + count = decompressor.inflate(buf);
  512 + } catch (DataFormatException e) {
  513 + e.printStackTrace();
  514 + }
  515 + bos.write(buf, 0, count);
  516 + }
  517 + } finally {
  518 + decompressor.end();
  519 + }
  520 + return bos.toByteArray();
  521 + }
  522 +
448 } 523 }
@@ -27,6 +27,7 @@ import com.gimi.common.cinema.model.RoomStatusInfo; @@ -27,6 +27,7 @@ import com.gimi.common.cinema.model.RoomStatusInfo;
27 import com.gimi.common.cinema.model.SambaMsg; 27 import com.gimi.common.cinema.model.SambaMsg;
28 import com.gimi.common.cinema.utils.ActivityCollector; 28 import com.gimi.common.cinema.utils.ActivityCollector;
29 import com.gimi.common.cinema.utils.CToast; 29 import com.gimi.common.cinema.utils.CToast;
  30 +import com.gimi.common.cinema.utils.LogUtils;
30 import com.gimi.common.cinema.utils.OpenMMUtils; 31 import com.gimi.common.cinema.utils.OpenMMUtils;
31 import com.gimi.common.cinema.utils.SambaFileCharge; 32 import com.gimi.common.cinema.utils.SambaFileCharge;
32 import com.gimi.common.cinema.utils.Utils; 33 import com.gimi.common.cinema.utils.Utils;
@@ -200,7 +201,7 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -200,7 +201,7 @@ public class SmartControlService extends BaseService implements EventListener<St
200 private void openDoor() { 201 private void openDoor() {
201 updateLastCompleteMovieInfo(); 202 updateLastCompleteMovieInfo();
202 presenter.getSysTime(this); 203 presenter.getSysTime(this);
203 - Log.d("room-info", "openDoor called"); 204 + LogUtils.d("room-info", "openDoor called");
204 bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() { 205 bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() {
205 @Override 206 @Override
206 public void writeSuccess() { 207 public void writeSuccess() {
@@ -208,14 +209,14 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -208,14 +209,14 @@ public class SmartControlService extends BaseService implements EventListener<St
208 Toast.makeText(SmartControlService.this, "开门成功", Toast.LENGTH_SHORT).show(); 209 Toast.makeText(SmartControlService.this, "开门成功", Toast.LENGTH_SHORT).show();
209 if (needReport) { 210 if (needReport) {
210 mHandler.postDelayed(reportRunnable, 10 * 1000); 211 mHandler.postDelayed(reportRunnable, 10 * 1000);
211 - Log.d("room-info", "user open door ,report the open success status"); 212 + LogUtils.d("room-info", "user open door ,report the open success status");
212 } 213 }
213 - Log.d("room-info", "open success"); 214 + LogUtils.d("room-info", "open success");
214 } 215 }
215 216
216 @Override 217 @Override
217 public void writeFailure(String error) { 218 public void writeFailure(String error) {
218 - Log.d("room-info", "open failure"); 219 + LogUtils.d("room-info", "open failure," + error.toString());
219 bleBroadcastReceiver.setResponseObj(null); 220 bleBroadcastReceiver.setResponseObj(null);
220 Toast.makeText(SmartControlService.this, "开门失败," + error, Toast.LENGTH_SHORT).show(); 221 Toast.makeText(SmartControlService.this, "开门失败," + error, Toast.LENGTH_SHORT).show();
221 } 222 }
@@ -343,7 +344,7 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -343,7 +344,7 @@ public class SmartControlService extends BaseService implements EventListener<St
343 // } 344 // }
344 break; 345 break;
345 case ORDER_PLAY_COMPLETE: 346 case ORDER_PLAY_COMPLETE:
346 - Log.d("room-info", messageEvent.getMessage()); 347 + LogUtils.d("room-info", messageEvent.getMessage());
347 Utils.saveString(this, "oder-play-completed", new Gson().toJson(roomStatusInfo)); 348 Utils.saveString(this, "oder-play-completed", new Gson().toJson(roomStatusInfo));
348 playEndAds(); 349 playEndAds();
349 break; 350 break;
@@ -575,6 +576,7 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -575,6 +576,7 @@ public class SmartControlService extends BaseService implements EventListener<St
575 576
576 int durationMinutes = data.getEnd_time() - data.getNow_time(); 577 int durationMinutes = data.getEnd_time() - data.getNow_time();
577 Log.d("CountService", "durationMinutes:" + durationMinutes); 578 Log.d("CountService", "durationMinutes:" + durationMinutes);
  579 + LogUtils.d("room-info", orderInfo.toString());
578 if (durationMinutes <= 1) { 580 if (durationMinutes <= 1) {
579 return; 581 return;
580 } 582 }
@@ -596,6 +598,7 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -596,6 +598,7 @@ public class SmartControlService extends BaseService implements EventListener<St
596 localMovieMessages = new NewDBManager(this).queryPlayMovie(data.getFilm_hash()); 598 localMovieMessages = new NewDBManager(this).queryPlayMovie(data.getFilm_hash());
597 if (localMovieMessages == null) { 599 if (localMovieMessages == null) {
598 show("电影信息出错,找不到相关电影"); 600 show("电影信息出错,找不到相关电影");
  601 + LogUtils.d("room-info", "file not exists:" + orderInfo.getData().getFilm_hash());
599 if (offset > 3) { 602 if (offset > 3) {
600 CToast.makeText(this, "您已迟到" + offset + "分钟,请注意把握时间,没有找到电影信息,请联系客服", 90 * 1000).show(); 603 CToast.makeText(this, "您已迟到" + offset + "分钟,请注意把握时间,没有找到电影信息,请联系客服", 90 * 1000).show();
601 } else { 604 } else {
@@ -10,14 +10,20 @@ import android.widget.Toast; @@ -10,14 +10,20 @@ import android.widget.Toast;
10 import com.gimi.common.cinema.model.MessageEvent; 10 import com.gimi.common.cinema.model.MessageEvent;
11 import com.gimi.common.cinema.model.RoomInfo; 11 import com.gimi.common.cinema.model.RoomInfo;
12 import com.gimi.common.cinema.utils.ActivityCollector; 12 import com.gimi.common.cinema.utils.ActivityCollector;
  13 +import com.gimi.common.cinema.utils.CToast;
  14 +import com.gimi.common.cinema.utils.LogUtils;
13 import com.gimi.common.cinema.utils.SystemUtils; 15 import com.gimi.common.cinema.utils.SystemUtils;
14 import com.gimi.common.cinema.utils.Utils; 16 import com.gimi.common.cinema.utils.Utils;
15 import com.google.gson.Gson; 17 import com.google.gson.Gson;
16 import com.google.gson.JsonSyntaxException; 18 import com.google.gson.JsonSyntaxException;
17 import com.qnbar.smc.utils.LightOperationUtils; 19 import com.qnbar.smc.utils.LightOperationUtils;
  20 +import com.xgimi.gimicinema.activity.AdsPreVideoPlayerActivity;
18 import com.xgimi.gimicinema.activity.MainActivity; 21 import com.xgimi.gimicinema.activity.MainActivity;
19 import com.xgimi.gimicinema.activity.QrCodeShowActivity; 22 import com.xgimi.gimicinema.activity.QrCodeShowActivity;
  23 +import com.xgimi.gimicinema.activity.SimpleAdsPlayer2;
20 import com.xgimi.gimicinema.application.FangTangApplication; 24 import com.xgimi.gimicinema.application.FangTangApplication;
  25 +import com.xgimi.gimicinema.poll.PollingUtils;
  26 +import com.xgimi.gimicinema.service.CountService;
21 import com.xgimi.smartscreen.encrypt.AuthCode; 27 import com.xgimi.smartscreen.encrypt.AuthCode;
22 import org.greenrobot.eventbus.EventBus; 28 import org.greenrobot.eventbus.EventBus;
23 29
@@ -103,7 +109,7 @@ public class SocketService1 extends BaseService { @@ -103,7 +109,7 @@ public class SocketService1 extends BaseService {
103 mHandler.postDelayed(this, HEART_BEAT_RATE); 109 mHandler.postDelayed(this, HEART_BEAT_RATE);
104 boolean isSuccess = sendMsg(new Gson().toJson(new SocketSendMsg().contractHeartBeatMsg(testRoomSn)) + END_SYMBOL);//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket 110 boolean isSuccess = sendMsg(new Gson().toJson(new SocketSendMsg().contractHeartBeatMsg(testRoomSn)) + END_SYMBOL);//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket
105 if (!isSuccess) { 111 if (!isSuccess) {
106 - Log.d(TAG, "heart beat error restart"); 112 + LogUtils.d(TAG, "heart beat error restart");
107 mHandler.removeCallbacks(heartBeatRunnable); 113 mHandler.removeCallbacks(heartBeatRunnable);
108 mReadThread.release(); 114 mReadThread.release();
109 sendRegister = false; 115 sendRegister = false;
@@ -118,12 +124,12 @@ public class SocketService1 extends BaseService { @@ -118,12 +124,12 @@ public class SocketService1 extends BaseService {
118 @Override 124 @Override
119 public void run() { 125 public void run() {
120 if (ActivityCollector.getActivity(MainActivity.class) == null) { 126 if (ActivityCollector.getActivity(MainActivity.class) == null) {
121 - Log.d(TAG, "do start main activity");  
122 -// Intent intent = new Intent(context, MainActivity.class);  
123 -// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
124 -// startActivity(intent); 127 + LogUtils.d(TAG, "do start main activity");
  128 + Intent intent = new Intent(context, MainActivity.class);
  129 + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  130 + startActivity(intent);
125 } else { 131 } else {
126 - Log.d(TAG, "already start main activity"); 132 + LogUtils.d(TAG, "already start main activity");
127 } 133 }
128 } 134 }
129 }; 135 };
@@ -140,13 +146,13 @@ public class SocketService1 extends BaseService { @@ -140,13 +146,13 @@ public class SocketService1 extends BaseService {
140 super.onCreate(); 146 super.onCreate();
141 gson = new Gson(); 147 gson = new Gson();
142 context = this; 148 context = this;
143 - Log.d(TAG, "onCreate"); 149 + LogUtils.d(TAG, "onCreate");
144 } 150 }
145 151
146 @Override 152 @Override
147 public int onStartCommand(Intent intent, int flags, int startId) { 153 public int onStartCommand(Intent intent, int flags, int startId) {
148 super.onStartCommand(intent, flags, startId); 154 super.onStartCommand(intent, flags, startId);
149 - Log.d(TAG, "onStartCommand"); 155 + LogUtils.d(TAG, "onStartCommand");
150 int ftTest = Utils.getInt(this, "ft-test", 0); 156 int ftTest = Utils.getInt(this, "ft-test", 0);
151 switch (ftTest) { 157 switch (ftTest) {
152 case 0: 158 case 0:
@@ -165,25 +171,25 @@ public class SocketService1 extends BaseService { @@ -165,25 +171,25 @@ public class SocketService1 extends BaseService {
165 171
166 String roomInfoStr = Utils.getString(this, "room-info"); 172 String roomInfoStr = Utils.getString(this, "room-info");
167 if (!TextUtils.isEmpty(roomInfoStr)) { 173 if (!TextUtils.isEmpty(roomInfoStr)) {
168 - Log.d("room-info", "room info not null"); 174 + LogUtils.d("room-info", "room info not null");
169 RoomInfo roomInfo = null; 175 RoomInfo roomInfo = null;
170 try { 176 try {
171 roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class); 177 roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class);
172 - Log.d("room-info", "room info room_sn update"); 178 + LogUtils.d("room-info", "room info room_sn update");
173 testRoomSn = roomInfo.getData().getRoom_sn(); 179 testRoomSn = roomInfo.getData().getRoom_sn();
174 } catch (JsonSyntaxException e) { 180 } catch (JsonSyntaxException e) {
175 - Log.d("room-info", "room gson parse exception return"); 181 + LogUtils.d("room-info", "room gson parse exception return");
176 Toast.makeText(this, "房间信息配置出错,请重新进入应用获取", Toast.LENGTH_SHORT).show(); 182 Toast.makeText(this, "房间信息配置出错,请重新进入应用获取", Toast.LENGTH_SHORT).show();
177 e.printStackTrace(); 183 e.printStackTrace();
178 return super.onStartCommand(intent, flags, startId); 184 return super.onStartCommand(intent, flags, startId);
179 } 185 }
180 } else { 186 } else {
181 - Log.d("room-info", "room info not exist"); 187 + LogUtils.d("room-info", "room info not exist");
182 Toast.makeText(this, "没有获取到房间信息,请查看后台配置", Toast.LENGTH_SHORT).show(); 188 Toast.makeText(this, "没有获取到房间信息,请查看后台配置", Toast.LENGTH_SHORT).show();
183 return super.onStartCommand(intent, flags, startId); 189 return super.onStartCommand(intent, flags, startId);
184 } 190 }
185 new InitSocketThread().start(); 191 new InitSocketThread().start();
186 - Log.d(TAG, "socket service onCreate"); 192 + LogUtils.d(TAG, "socket service onCreate");
187 return START_STICKY; 193 return START_STICKY;
188 } 194 }
189 195
@@ -191,7 +197,9 @@ public class SocketService1 extends BaseService { @@ -191,7 +197,9 @@ public class SocketService1 extends BaseService {
191 if (null == mSocket || null == mSocket.get()) { 197 if (null == mSocket || null == mSocket.get()) {
192 return false; 198 return false;
193 } 199 }
194 - Log.d(TAG, "send msg:" + msg); 200 + if (!msg.contains("20025")) {
  201 + LogUtils.d(TAG, "send msg:" + msg);
  202 + }
195 Socket soc = mSocket.get(); 203 Socket soc = mSocket.get();
196 try { 204 try {
197 if (!soc.isClosed() && !soc.isOutputShutdown()) { 205 if (!soc.isClosed() && !soc.isOutputShutdown()) {
@@ -202,6 +210,7 @@ public class SocketService1 extends BaseService { @@ -202,6 +210,7 @@ public class SocketService1 extends BaseService {
202 return false; 210 return false;
203 } 211 }
204 } catch (IOException e) { 212 } catch (IOException e) {
  213 + LogUtils.d(TAG, "error" + e.getMessage());
205 e.printStackTrace(); 214 e.printStackTrace();
206 return false; 215 return false;
207 } 216 }
@@ -209,7 +218,13 @@ public class SocketService1 extends BaseService { @@ -209,7 +218,13 @@ public class SocketService1 extends BaseService {
209 } 218 }
210 219
211 private void initSocket() throws IOException {//初始化Socket 220 private void initSocket() throws IOException {//初始化Socket
212 - Log.d(TAG, "serverHost:serverPort:" + serverHost + ":" + serverPort); 221 + LogUtils.d(TAG, "serverHost:serverPort:" + serverHost + ":" + serverPort);
  222 + mHandler.post(new Runnable() {
  223 + @Override
  224 + public void run() {
  225 + CToast.makeText(context, "开始连接服务器", 10 * 1000).show();
  226 + }
  227 + });
213 Socket so = new Socket(serverHost, serverPort); 228 Socket so = new Socket(serverHost, serverPort);
214 mSocket = new WeakReference<>(so); 229 mSocket = new WeakReference<>(so);
215 mReadThread = new ReadThread(so); 230 mReadThread = new ReadThread(so);
@@ -228,6 +243,7 @@ public class SocketService1 extends BaseService { @@ -228,6 +243,7 @@ public class SocketService1 extends BaseService {
228 mSocket = null; 243 mSocket = null;
229 } 244 }
230 } catch (IOException e) { 245 } catch (IOException e) {
  246 + LogUtils.d(TAG, "error" + e.getMessage());
231 e.printStackTrace(); 247 e.printStackTrace();
232 } 248 }
233 } 249 }
@@ -240,10 +256,11 @@ public class SocketService1 extends BaseService { @@ -240,10 +256,11 @@ public class SocketService1 extends BaseService {
240 initSocket(); 256 initSocket();
241 } catch (IOException e) { 257 } catch (IOException e) {
242 e.printStackTrace(); 258 e.printStackTrace();
243 - Log.d(TAG, "init socket thread error,restart again after " + HEART_BEAT_RATE / 1000 + " seconds"); 259 + LogUtils.d(TAG, "init socket thread error,restart again after " + HEART_BEAT_RATE / 1000 + " seconds");
244 try { 260 try {
245 Thread.sleep(HEART_BEAT_RATE); 261 Thread.sleep(HEART_BEAT_RATE);
246 } catch (InterruptedException e1) { 262 } catch (InterruptedException e1) {
  263 + LogUtils.d(TAG, "error" + e1.getMessage());
247 e1.printStackTrace(); 264 e1.printStackTrace();
248 } 265 }
249 this.run(); 266 this.run();
@@ -272,14 +289,14 @@ public class SocketService1 extends BaseService { @@ -272,14 +289,14 @@ public class SocketService1 extends BaseService {
272 if (null != socket) { 289 if (null != socket) {
273 try { 290 try {
274 if (!sendRegister) { 291 if (!sendRegister) {
275 - Log.d(TAG, "send register mes"); 292 + LogUtils.d(TAG, "send register mes");
276 SocketSendMsg ssm = new SocketSendMsg().contractRegisterMsg(testRoomSn); 293 SocketSendMsg ssm = new SocketSendMsg().contractRegisterMsg(testRoomSn);
277 String msg = gson.toJson(ssm) + END_SYMBOL; 294 String msg = gson.toJson(ssm) + END_SYMBOL;
278 sendMsg(msg); 295 sendMsg(msg);
279 - Log.d(TAG, "" + msg); 296 + LogUtils.d(TAG, "" + msg);
280 sendRegister = true; 297 sendRegister = true;
281 } 298 }
282 - Log.d(TAG, "send register mes end"); 299 + LogUtils.d(TAG, "send register mes end");
283 InputStream is = socket.getInputStream(); 300 InputStream is = socket.getInputStream();
284 byte[] buffer = new byte[1024 * 4]; 301 byte[] buffer = new byte[1024 * 4];
285 int length = 0; 302 int length = 0;
@@ -288,7 +305,11 @@ public class SocketService1 extends BaseService { @@ -288,7 +305,11 @@ public class SocketService1 extends BaseService {
288 if (length > 0) { 305 if (length > 0) {
289 String message = new String(Arrays.copyOf(buffer, 306 String message = new String(Arrays.copyOf(buffer,
290 length)).trim(); 307 length)).trim();
291 - Log.d(TAG, "recv msg:" + message); 308 +// if (!message.contains("9997")) {
  309 + LogUtils.d(TAG, "recv msg:" + message);
  310 +// } else {
  311 +// LogUtils.d(TAG, "heat beat success");
  312 +// }
292 try { 313 try {
293 if (message.endsWith(END_SYMBOL)) { 314 if (message.endsWith(END_SYMBOL)) {
294 message = message.replace(END_SYMBOL, ""); 315 message = message.replace(END_SYMBOL, "");
@@ -299,16 +320,16 @@ public class SocketService1 extends BaseService { @@ -299,16 +320,16 @@ public class SocketService1 extends BaseService {
299 Log.d(TAG, "SUCCESS_MESSAGE"); 320 Log.d(TAG, "SUCCESS_MESSAGE");
300 break; 321 break;
301 case VERIFY_SUCCESS: 322 case VERIFY_SUCCESS:
302 - Log.d(TAG, "VERIFY_SUCCESS"); 323 + LogUtils.d(TAG, "VERIFY_SUCCESS");
303 mHandler.post(heartBeatRunnable); 324 mHandler.post(heartBeatRunnable);
304 - Log.d(TAG, "verify success start heart beat"); 325 + LogUtils.d(TAG, "verify success start heart beat");
305 break; 326 break;
306 case HEART_BEAT_SUCCESS: 327 case HEART_BEAT_SUCCESS:
307 //每成功5次心跳判定是否启动main activity 328 //每成功5次心跳判定是否启动main activity
308 if (++mainChargeCount == 5) { 329 if (++mainChargeCount == 5) {
309 mainChargeCount = 0; 330 mainChargeCount = 0;
310 if (ActivityCollector.getActivity(MainActivity.class) == null) { 331 if (ActivityCollector.getActivity(MainActivity.class) == null) {
311 - Log.d(TAG, "charge start main activity"); 332 + LogUtils.d(TAG, "charge start main activity");
312 mHandler.postDelayed(startMainRunnable, 3 * 1000); 333 mHandler.postDelayed(startMainRunnable, 3 * 1000);
313 } 334 }
314 } 335 }
@@ -318,22 +339,22 @@ public class SocketService1 extends BaseService { @@ -318,22 +339,22 @@ public class SocketService1 extends BaseService {
318 case HEART_BEAT_ERROR_SYMBOL: 339 case HEART_BEAT_ERROR_SYMBOL:
319 case ROOM_SN_CONNECTED: 340 case ROOM_SN_CONNECTED:
320 String msg1 = socketResponse.getCode() == HEART_BEAT_ERROR_SYMBOL ? "HEART_BEAT_ERROR_SYMBOL" : "ROOM_SN_CONNECTED"; 341 String msg1 = socketResponse.getCode() == HEART_BEAT_ERROR_SYMBOL ? "HEART_BEAT_ERROR_SYMBOL" : "ROOM_SN_CONNECTED";
321 - Log.d(TAG, msg1); 342 + LogUtils.d(TAG, msg1);
322 mHandler.removeCallbacks(heartBeatRunnable); 343 mHandler.removeCallbacks(heartBeatRunnable);
323 mReadThread.release(); 344 mReadThread.release();
324 sendRegister = false; 345 sendRegister = false;
325 releaseLastSocket(mSocket); 346 releaseLastSocket(mSocket);
326 - Log.d(TAG, msg1 + " before:" + +System.currentTimeMillis()); 347 + LogUtils.d(TAG, msg1 + " before:" + +System.currentTimeMillis());
327 try { 348 try {
328 Thread.sleep(10 * 1000); 349 Thread.sleep(10 * 1000);
329 } catch (InterruptedException e) { 350 } catch (InterruptedException e) {
330 e.printStackTrace(); 351 e.printStackTrace();
331 } 352 }
332 - Log.d(TAG, msg1 + " after:" + System.currentTimeMillis()); 353 + LogUtils.d(TAG, msg1 + " after:" + System.currentTimeMillis());
333 new InitSocketThread().start(); 354 new InitSocketThread().start();
334 break; 355 break;
335 case RETURN_VERIFY_CODE: 356 case RETURN_VERIFY_CODE:
336 - Log.d(TAG, "RETURN_VERIFY_CODE"); 357 + LogUtils.d(TAG, "RETURN_VERIFY_CODE");
337 if (!TextUtils.isEmpty(socketResponse.getData().getVerify())) { 358 if (!TextUtils.isEmpty(socketResponse.getData().getVerify())) {
338 String verifyMsg = AuthCode.getDecodeStr(socketResponse.getData().getVerify()); 359 String verifyMsg = AuthCode.getDecodeStr(socketResponse.getData().getVerify());
339 SocketSendMsg ssm = new SocketSendMsg().contractVerifyMsg(testRoomSn, verifyMsg); 360 SocketSendMsg ssm = new SocketSendMsg().contractVerifyMsg(testRoomSn, verifyMsg);
@@ -342,7 +363,7 @@ public class SocketService1 extends BaseService { @@ -342,7 +363,7 @@ public class SocketService1 extends BaseService {
342 } 363 }
343 break; 364 break;
344 case CONTAIN_MESSAGE: 365 case CONTAIN_MESSAGE:
345 - Log.d(TAG, "CONTAIN_MESSAGE"); 366 + LogUtils.d(TAG, "CONTAIN_MESSAGE");
346 if (socketResponse.getData() != null) { 367 if (socketResponse.getData() != null) {
347 if (socketResponse.getCmd() == OPEN_DOOR) { 368 if (socketResponse.getCmd() == OPEN_DOOR) {
348 switch (socketResponse.getData().getUser()) { 369 switch (socketResponse.getData().getUser()) {
@@ -362,7 +383,7 @@ public class SocketService1 extends BaseService { @@ -362,7 +383,7 @@ public class SocketService1 extends BaseService {
362 break; 383 break;
363 case 20: 384 case 20:
364 if (TextUtils.isEmpty(((FangTangApplication) getApplication()).getCurrentPlayUrl())) { 385 if (TextUtils.isEmpty(((FangTangApplication) getApplication()).getCurrentPlayUrl())) {
365 - Log.d("LightOperationUtils", "admin open light"); 386 + LogUtils.d("LightOperationUtils", "admin open light");
366 LightOperationUtils.open(); 387 LightOperationUtils.open();
367 LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50)); 388 LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50));
368 } 389 }
@@ -376,24 +397,39 @@ public class SocketService1 extends BaseService { @@ -376,24 +397,39 @@ public class SocketService1 extends BaseService {
376 break; 397 break;
377 } 398 }
378 } else if (socketResponse.getCmd() == CLEAN_OVER) { 399 } else if (socketResponse.getCmd() == CLEAN_OVER) {
379 - Log.d("LightOperationUtils", "admin clean over close light"); 400 + LogUtils.d("LightOperationUtils", "admin clean over close light");
380 LightOperationUtils.setLightValue(5); 401 LightOperationUtils.setLightValue(5);
381 LightOperationUtils.close(); 402 LightOperationUtils.close();
382 new SystemUtils().closeFtLed(context.getApplicationContext()); 403 new SystemUtils().closeFtLed(context.getApplicationContext());
383 sendMessage(QrCodeShowActivity.KILL_SELF, "finish the QR CODE activity when clean over"); 404 sendMessage(QrCodeShowActivity.KILL_SELF, "finish the QR CODE activity when clean over");
  405 + if (ActivityCollector.isActivityExist(SimpleAdsPlayer2.class)) {
  406 + ActivityCollector.getActivity(SimpleAdsPlayer2.class).finish();
  407 + }
  408 + if (ActivityCollector.isActivityExist(AdsPreVideoPlayerActivity.class)) {
  409 + ActivityCollector.getActivity(AdsPreVideoPlayerActivity.class).finish();
  410 + }
  411 + if (ActivityCollector.isActivityExist(QrCodeShowActivity.class)) {
  412 + ActivityCollector.getActivity(QrCodeShowActivity.class).finish();
  413 + }
  414 + try {
  415 + PollingUtils.stopPollingService(context, CountService.class, CountService.STATUS_ACTION);
  416 + } catch (Exception e) {
  417 + e.printStackTrace();
  418 + }
384 } 419 }
385 } 420 }
386 break; 421 break;
387 default: 422 default:
388 - Log.d(TAG, "default msg:" + socketResponse.toString()); 423 + LogUtils.d(TAG, "default msg:" + socketResponse.toString());
389 } 424 }
390 } catch (JsonSyntaxException e) { 425 } catch (JsonSyntaxException e) {
391 - Log.d(TAG, message); 426 + LogUtils.d(TAG, "error" + message + e.getMessage());
392 e.printStackTrace(); 427 e.printStackTrace();
393 } 428 }
394 } 429 }
395 } 430 }
396 } catch (IOException e) { 431 } catch (IOException e) {
  432 + LogUtils.d(TAG, "error" + e.getCause());
397 e.printStackTrace(); 433 e.printStackTrace();
398 } 434 }
399 } 435 }
@@ -411,9 +447,9 @@ public class SocketService1 extends BaseService { @@ -411,9 +447,9 @@ public class SocketService1 extends BaseService {
411 447
412 @Override 448 @Override
413 public void onDestroy() { 449 public void onDestroy() {
414 -// Log.d("BaseService1", this.getClass().toString() + ""); 450 +// LogUtils.d("BaseService1", this.getClass().toString() + "");
415 // ServiceCommandCollector.removeService(this); 451 // ServiceCommandCollector.removeService(this);
416 - Log.d(TAG, "socket service destroy"); 452 + LogUtils.d(TAG, "socket service destroy");
417 super.onDestroy(); 453 super.onDestroy();
418 } 454 }
419 } 455 }
@@ -18,16 +18,21 @@ package com.xgimi.gimicinema.activity; @@ -18,16 +18,21 @@ package com.xgimi.gimicinema.activity;
18 18
19 import android.app.ListActivity; 19 import android.app.ListActivity;
20 import android.os.Bundle; 20 import android.os.Bundle;
  21 +import android.text.TextUtils;
21 import android.view.View; 22 import android.view.View;
22 import android.widget.ArrayAdapter; 23 import android.widget.ArrayAdapter;
23 import android.widget.ListView; 24 import android.widget.ListView;
24 import android.widget.Toast; 25 import android.widget.Toast;
  26 +import com.gimi.common.cinema.model.RoomInfo;
25 import com.gimi.common.cinema.model.SambaMsg; 27 import com.gimi.common.cinema.model.SambaMsg;
  28 +import com.gimi.common.cinema.utils.LogUtils;
26 import com.gimi.common.cinema.utils.NetStatusUtils; 29 import com.gimi.common.cinema.utils.NetStatusUtils;
27 import com.gimi.common.cinema.utils.ShellUtils; 30 import com.gimi.common.cinema.utils.ShellUtils;
28 import com.gimi.common.cinema.utils.SystemUtils; 31 import com.gimi.common.cinema.utils.SystemUtils;
29 import com.gimi.common.cinema.utils.TimeoutCharge; 32 import com.gimi.common.cinema.utils.TimeoutCharge;
30 import com.gimi.common.cinema.utils.Utils; 33 import com.gimi.common.cinema.utils.Utils;
  34 +import com.google.gson.Gson;
  35 +import com.google.gson.JsonSyntaxException;
31 import com.xgimi.gimicinema.R; 36 import com.xgimi.gimicinema.R;
32 37
33 import java.io.File; 38 import java.io.File;
@@ -61,6 +66,7 @@ public class CheckActivity extends ListActivity { @@ -61,6 +66,7 @@ public class CheckActivity extends ListActivity {
61 data.add("log"); 66 data.add("log");
62 data.add("结束log"); 67 data.add("结束log");
63 data.add("考出log到服务器"); 68 data.add("考出log到服务器");
  69 + data.add("考出日志文件到服务器");
64 return data; 70 return data;
65 } 71 }
66 72
@@ -129,6 +135,28 @@ public class CheckActivity extends ListActivity { @@ -129,6 +135,28 @@ public class CheckActivity extends ListActivity {
129 msg = "debug.log文件不存在"; 135 msg = "debug.log文件不存在";
130 } 136 }
131 break; 137 break;
  138 + case 6:
  139 + String roomInfoStr = Utils.getString(this, "room-info");
  140 + if (!TextUtils.isEmpty(roomInfoStr)) {
  141 + LogUtils.d("room-info", "room info not null");
  142 + RoomInfo roomInfo = null;
  143 + try {
  144 + roomInfo = new Gson().fromJson(roomInfoStr, RoomInfo.class);
  145 + SambaMsg sambaMsg = Utils.getSambaMsg(this);
  146 + LogUtils.d("room-info", "room info room_sn update");
  147 + String meshName = TextUtils.isEmpty(roomInfo.getData().getMesh_name()) ? roomInfo.getData().getImei() : roomInfo.getData().getMesh_name();
  148 + final String copy = "cp -r /sdcard/ft_log/ " + sambaMsg.getLocalPath() + "apks/" + meshName;
  149 + ShellUtils.execCommand("mkdirs " + sambaMsg.getLocalPath() + "apks/" + meshName, false);
  150 + ShellUtils.execCommand(copy, false);
  151 + msg = "正在考出";
  152 + } catch (JsonSyntaxException e) {
  153 + LogUtils.d("room-info", "room gson parse exception return");
  154 + msg = "房间信息配置出错";
  155 +// Toast.makeText(this, "房间信息配置出错,请重新进入应用获取", Toast.LENGTH_SHORT).show();
  156 + e.printStackTrace();
  157 + }
  158 + }
  159 + break;
132 } 160 }
133 Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); 161 Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
134 } 162 }
@@ -11,6 +11,7 @@ import android.widget.Toast; @@ -11,6 +11,7 @@ import android.widget.Toast;
11 import com.gimi.common.cinema.model.MessageEvent; 11 import com.gimi.common.cinema.model.MessageEvent;
12 import com.gimi.common.cinema.model.RoomQrCodeInfo; 12 import com.gimi.common.cinema.model.RoomQrCodeInfo;
13 import com.gimi.common.cinema.model.WrongMsg; 13 import com.gimi.common.cinema.model.WrongMsg;
  14 +import com.gimi.common.cinema.utils.LogUtils;
14 import com.gimi.common.cinema.utils.QRCodeUtils; 15 import com.gimi.common.cinema.utils.QRCodeUtils;
15 import com.gimi.common.cinema.utils.SystemUtils; 16 import com.gimi.common.cinema.utils.SystemUtils;
16 import com.google.zxing.WriterException; 17 import com.google.zxing.WriterException;
@@ -44,7 +45,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView { @@ -44,7 +45,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView {
44 private Runnable updateQrCodeRunnable = new Runnable() { 45 private Runnable updateQrCodeRunnable = new Runnable() {
45 @Override 46 @Override
46 public void run() { 47 public void run() {
47 - Log.d("room-info", "QrCodeShowActivity update qr code runnable run"); 48 + LogUtils.d("room-info", "QrCodeShowActivity update qr code runnable run");
48 handler.postDelayed(this, 10 * 60 * 1000); 49 handler.postDelayed(this, 10 * 60 * 1000);
49 present.getQrCode(roomSn, orderSn); 50 present.getQrCode(roomSn, orderSn);
50 } 51 }
@@ -110,7 +111,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView { @@ -110,7 +111,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView {
110 switch (messageEvent.getEventId()) { 111 switch (messageEvent.getEventId()) {
111 case KILL_SELF: 112 case KILL_SELF:
112 QrCodeShowActivity.this.finish(); 113 QrCodeShowActivity.this.finish();
113 - Log.d("room-info", messageEvent.getMessage()); 114 + LogUtils.d("room-info", messageEvent.getMessage());
114 break; 115 break;
115 } 116 }
116 } 117 }
@@ -118,7 +119,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView { @@ -118,7 +119,7 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView {
118 @Override 119 @Override
119 public void getQrCodeSuccess(RoomQrCodeInfo info) { 120 public void getQrCodeSuccess(RoomQrCodeInfo info) {
120 try { 121 try {
121 - Log.d("QrCodeShowActivity", info.getData().getCode()); 122 + LogUtils.d("QrCodeShowActivity", info.getData().getCode());
122 iv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400)); 123 iv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400));
123 } catch (WriterException e) { 124 } catch (WriterException e) {
124 e.printStackTrace(); 125 e.printStackTrace();
@@ -17,6 +17,7 @@ import android.widget.VideoView; @@ -17,6 +17,7 @@ import android.widget.VideoView;
17 import com.gimi.common.cinema.model.Constant; 17 import com.gimi.common.cinema.model.Constant;
18 import com.gimi.common.cinema.model.RoomQrCodeInfo; 18 import com.gimi.common.cinema.model.RoomQrCodeInfo;
19 import com.gimi.common.cinema.model.WrongMsg; 19 import com.gimi.common.cinema.model.WrongMsg;
  20 +import com.gimi.common.cinema.utils.LogUtils;
20 import com.gimi.common.cinema.utils.QRCodeUtils; 21 import com.gimi.common.cinema.utils.QRCodeUtils;
21 import com.google.zxing.WriterException; 22 import com.google.zxing.WriterException;
22 import com.xgimi.gimicinema.R; 23 import com.xgimi.gimicinema.R;
@@ -40,7 +41,7 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView @@ -40,7 +41,7 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView
40 private Runnable updateQrCodeRunnable = new Runnable() { 41 private Runnable updateQrCodeRunnable = new Runnable() {
41 @Override 42 @Override
42 public void run() { 43 public void run() {
43 - Log.d("room-info", "update qr code runnable run"); 44 + LogUtils.d("room-info", "update qr code runnable run");
44 handler.postDelayed(this, 10 * 60 * 1000); 45 handler.postDelayed(this, 10 * 60 * 1000);
45 presenter.getQrCode(roomSn, orderSn); 46 presenter.getQrCode(roomSn, orderSn);
46 } 47 }
@@ -96,13 +97,10 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView @@ -96,13 +97,10 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView
96 97
97 @Override 98 @Override
98 public boolean onKeyDown(int keyCode, KeyEvent event) { 99 public boolean onKeyDown(int keyCode, KeyEvent event) {
99 - if (System.currentTimeMillis() - startAdsTime < 5000) { 100 + if (keyCode == KeyEvent.KEYCODE_BACK) {
  101 + Toast.makeText(this, "请用管理端扫描或者等待清理时间结束", Toast.LENGTH_SHORT).show();
100 return true; 102 return true;
101 } 103 }
102 - if (fromService) {  
103 - return true;  
104 - }  
105 - finish();  
106 return super.onKeyDown(keyCode, event); 104 return super.onKeyDown(keyCode, event);
107 } 105 }
108 106
@@ -132,7 +130,7 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView @@ -132,7 +130,7 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView
132 @Override 130 @Override
133 public void getQrCodeSuccess(RoomQrCodeInfo info) { 131 public void getQrCodeSuccess(RoomQrCodeInfo info) {
134 try { 132 try {
135 - Log.d("SimpleAdsPlayer2", info.getData().getCode()); 133 + LogUtils.d("SimpleAdsPlayer2", info.getData().getCode());
136 cleanQrCodeIv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400)); 134 cleanQrCodeIv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400));
137 qrCodeIv.setVisibility(View.VISIBLE); 135 qrCodeIv.setVisibility(View.VISIBLE);
138 } catch (WriterException e) { 136 } catch (WriterException e) {
@@ -144,4 +142,5 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView @@ -144,4 +142,5 @@ public class SimpleAdsPlayer2 extends BaseActivity implements IUpdateQrCodeView
144 public void getQrCodeFailure(WrongMsg wrongMsg) { 142 public void getQrCodeFailure(WrongMsg wrongMsg) {
145 Toast.makeText(this, wrongMsg.getMsg(), Toast.LENGTH_SHORT).show(); 143 Toast.makeText(this, wrongMsg.getMsg(), Toast.LENGTH_SHORT).show();
146 } 144 }
  145 +
147 } 146 }
@@ -2,6 +2,7 @@ package com.xgimi.gimicinema.application; @@ -2,6 +2,7 @@ package com.xgimi.gimicinema.application;
2 2
3 import android.util.Log; 3 import android.util.Log;
4 import android.widget.Toast; 4 import android.widget.Toast;
  5 +import com.gimi.common.cinema.utils.LogUtils;
5 import com.gimi.common.cinema.utils.Utils; 6 import com.gimi.common.cinema.utils.Utils;
6 import com.google.gson.Gson; 7 import com.google.gson.Gson;
7 import com.google.gson.JsonSyntaxException; 8 import com.google.gson.JsonSyntaxException;
@@ -20,7 +21,8 @@ public class FangTangApplication extends TelinkApplication { @@ -20,7 +21,8 @@ public class FangTangApplication extends TelinkApplication {
20 super.onCreate(); 21 super.onCreate();
21 AdvanceStrategy.setDefault(new MySampleAdvanceStrategy()); 22 AdvanceStrategy.setDefault(new MySampleAdvanceStrategy());
22 // CrashHandler crashHandler = CrashHandler.getInstance(); 23 // CrashHandler crashHandler = CrashHandler.getInstance();
23 -// crashHandler.init(getApplicationContext()); 24 +// crashHandler.init(getApplicationContext());initLog\\
  25 + initLog();
24 } 26 }
25 27
26 @Override 28 @Override
@@ -73,4 +75,21 @@ public class FangTangApplication extends TelinkApplication { @@ -73,4 +75,21 @@ public class FangTangApplication extends TelinkApplication {
73 public void setCurrentPlayUrl(String currentPlayUrl) { 75 public void setCurrentPlayUrl(String currentPlayUrl) {
74 this.currentPlayUrl = currentPlayUrl; 76 this.currentPlayUrl = currentPlayUrl;
75 } 77 }
  78 +
  79 + public static void initLog() {
  80 + LogUtils.Builder builder = new LogUtils.Builder()
  81 + .setLogSwitch(true)// 设置log总开关,包括输出到控制台和文件,默认开
  82 + .setConsoleSwitch(true)// 设置是否输出到控制台开关,默认开
  83 + .setGlobalTag(null)// 设置log全局标签,默认为空
  84 + // 当全局标签不为空时,我们输出的log全部为该tag,
  85 + // 为空时,如果传入的tag为空那就显示类名,否则显示tag
  86 + .setLogHeadSwitch(true)// 设置log头信息开关,默认为开
  87 + .setLog2FileSwitch(true)// 打印log时是否存到文件的开关,默认关
  88 + .setDir("/sdcard/ft_log/")// 当自定义路径为空时,写入应用的/cache/log/目录中
  89 + .setBorderSwitch(true)// 输出日志是否带边框开关,默认开
  90 + .setConsoleFilter(LogUtils.V)// log的控制台过滤器,和logcat过滤器同理,默认Verbose
  91 + .setFileFilter(LogUtils.V);// log文件过滤器,和logcat过滤器同理,默认Verbose
  92 + LogUtils.d(builder.toString());
  93 + }
  94 +
76 } 95 }
@@ -25,6 +25,7 @@ import android.os.RemoteException; @@ -25,6 +25,7 @@ import android.os.RemoteException;
25 import android.util.Log; 25 import android.util.Log;
26 import android.widget.Toast; 26 import android.widget.Toast;
27 import com.gimi.common.cinema.model.MessageEvent; 27 import com.gimi.common.cinema.model.MessageEvent;
  28 +import com.gimi.common.cinema.utils.LogUtils;
28 import com.gimi.common.cinema.utils.Utils; 29 import com.gimi.common.cinema.utils.Utils;
29 import com.qnbar.smc.model.Light; 30 import com.qnbar.smc.model.Light;
30 import com.qnbar.smc.model.Lights; 31 import com.qnbar.smc.model.Lights;
@@ -347,8 +348,9 @@ public class CinemaControlService extends Service { @@ -347,8 +348,9 @@ public class CinemaControlService extends Service {
347 messageEvent.setEventId(SmartControlService.ORDER_PLAY_COMPLETE); 348 messageEvent.setEventId(SmartControlService.ORDER_PLAY_COMPLETE);
348 messageEvent.setMessage("电影播放完成,记录完成订单信息"); 349 messageEvent.setMessage("电影播放完成,记录完成订单信息");
349 EventBus.getDefault().post(messageEvent); 350 EventBus.getDefault().post(messageEvent);
  351 + LogUtils.d("room-info", "stop media completed");
350 } else { 352 } else {
351 - Log.d("room-info", "stop media but not completed"); 353 + LogUtils.d("room-info", "stop media but not completed");
352 } 354 }
353 } 355 }
354 } 356 }
Please register or login to post a comment