Bläddra i källkod

联调SMT功能接口, 优化部门代码

songw 2 månader sedan
förälder
incheckning
dba095766a

+ 1 - 3
app/src/main/java/com/uas/pda_wps/fragment/SCSMTInspectionFragment.java

@@ -383,11 +383,9 @@ public class SCSMTInspectionFragment extends BaseFragment implements View.OnClic
                                     tvMsgNotice.setText(spannableString);
                                 }
                             }
-
                         } catch (Exception e) {
-
+                            e.printStackTrace();
                         }
-
                     }
                 },
                 new Response.ErrorListener() {

+ 6 - 0
app/src/main/java/com/uas/pda_wps/util/CommonUtil.java

@@ -566,6 +566,12 @@ public class CommonUtil {
      */
     public static String showErrorToast(VolleyError volleyError, boolean showOrNot) {
         String errorStr = "请求失败";
+        try {
+            String s = new String(volleyError.networkResponse.data);
+
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
         if (volleyError != null && volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
             ErrorMsg errorMsg = JsonTools.parseJsonToBean(new String(volleyError.networkResponse.data), ErrorMsg.class);
             if (errorMsg != null && errorMsg.exceptionInfo != null) {

+ 161 - 0
app/src/main/java/com/uas/pda_wps/util/MyLog.java

@@ -0,0 +1,161 @@
+package com.uas.pda_wps.util;
+
+import android.annotation.SuppressLint;
+import android.util.Log;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 带日志文件输入,又可控开关的日志调试
+ */
+@SuppressLint("SimpleDateFormat")
+public class MyLog {
+	public static Boolean MYLOG_SWITCH = true; // 日志文件总开关
+	private static Boolean MYLOG_WRITE_TO_FILE = true;// 日志写入文件开关
+	private static char MYLOG_TYPE = 'v';// 输入日志类型,w代表只输出告警信息等,v代表输出所有信息
+	@SuppressLint("SdCardPath")
+	private static String MYLOG_PATH_SDCARD_DIR1 = "/sdcard/MSShow";    // 日志文件在sdcard中的路径
+	private static String MYLOG_PATH_SDCARD_DIR2 = "/Log";
+	private static String MYLOG_PATH_SDCARD_DIR = MYLOG_PATH_SDCARD_DIR1+MYLOG_PATH_SDCARD_DIR2;
+	private static String MYLOGFILEName = "Log.txt";// 本类输出的日志文件名称
+
+	@SuppressLint("SimpleDateFormat")
+	private static SimpleDateFormat myLogSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 日志的输出格式
+
+	private static boolean isDebug = true;		//普通log的开关
+	private static String TAG = "英唐" +"-----------";
+
+	public static void e(String msg){
+		if(isDebug){
+			Log.e(TAG, msg);
+		}
+	}
+
+	public static void w(String msg){
+		if(isDebug){
+			Log.w(TAG, msg);
+		}
+	}
+
+	public static void d(String msg){
+		if(isDebug){
+			Log.d(TAG, msg);
+		}
+	}
+
+	public static void i(String msg){
+		if(isDebug){
+			Log.i(TAG, msg);
+		}
+	}
+
+	public static void w(String tag, Object msg) { // 警告信息
+		log(tag, msg.toString(), 'w');
+	}
+
+	public static void e(String tag, Object msg) { // 错误信息
+		log(tag, msg.toString(), 'e');
+	}
+
+	public static void d(String tag, Object msg) {// 调试信息
+		log(tag, msg.toString(), 'd');
+	}
+
+	public static void i(String tag, Object msg) {//
+		log(tag, msg.toString(), 'i');
+	}
+
+	public static void v(String tag, Object msg) {
+		log(tag, msg.toString(), 'v');
+	}
+
+	public static void w(String tag, String text) {
+		log(tag, text, 'w');
+	}
+
+	public static void e(String tag, String text) {
+		log(tag, text, 'e');
+	}
+
+	public static void d(String tag, String text) {
+		log(tag, text, 'd');
+	}
+
+	public static void i(String tag, String text) {
+		log(tag, text, 'i');
+	}
+
+	public static void v(String tag, String text) {
+		log(tag, text, 'v');
+	}
+
+	/**
+	 * 根据tag, msg和等级,输出日志
+	 */
+	private static void log(String tag, String msg, char level) {
+		msg = "\r\n"+msg;
+		if (MYLOG_SWITCH) {
+			if ('e' == level && ('e' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) { // 输出错误信息
+				Log.e(tag, msg);
+			} else if ('w' == level && ('w' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) {
+				Log.w(tag, msg);
+			} else if ('d' == level && ('d' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) {
+				Log.d(tag, msg);
+			} else if ('i' == level && ('d' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) {
+				Log.i(tag, msg);
+			} else {
+				Log.v(tag, msg);
+			}
+			if (MYLOG_WRITE_TO_FILE) {
+				writeLogtoFile(String.valueOf(level), tag, msg);
+			}
+		}
+	}
+
+	/**
+	 * 打开日志文件并写入日志
+	 * **/
+	private static void writeLogtoFile(String mylogtype, String tag, String text) {// 新建或打开日志文件
+		isExist(MYLOG_PATH_SDCARD_DIR1);
+		isExist(MYLOG_PATH_SDCARD_DIR);
+		Date nowtime = new Date();
+//		String needWriteFiel = logfile.format(nowtime);
+		String needWriteMessage = myLogSdf.format(nowtime) + "    " + mylogtype
+				+ "    " + tag + "    " + text;
+		File file = new File(MYLOG_PATH_SDCARD_DIR, MYLOGFILEName);
+		try {
+			FileWriter filerWriter = new FileWriter(file, true);// 后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
+			BufferedWriter bufWriter = new BufferedWriter(filerWriter);
+			bufWriter.write(needWriteMessage);
+			bufWriter.newLine();
+			bufWriter.close();
+			filerWriter.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 删除制定的日志文件
+	 * */
+	public static void delFile() {// 删除日志文件
+		File file = new File(MYLOG_PATH_SDCARD_DIR, MYLOGFILEName);
+		if (file.exists()) {
+			file.delete();
+		}
+	}
+
+	public static void isExist(String path) {
+		File file = new File(path);
+		// 判断文件夹是否存在,如果不存在则创建文件夹
+		if (!file.exists()) {
+			file.mkdir();
+		}
+
+	}
+}

+ 0 - 1
app/src/main/java/com/uas/pda_wps/util/VollyRequest.java

@@ -20,7 +20,6 @@ import java.util.Set;
  * @describe
  * @date 2018/4/27 11:26
  */
-
 public class VollyRequest {
     private static VollyRequest instance;