Sfoglia il codice sorgente

增加自动登录

ChengJH 3 anni fa
parent
commit
5709b4a601

+ 2 - 0
app/src/main/java/com/uas/uas_mes_standard/fragment/IndexSettingFragment.java

@@ -616,6 +616,8 @@ public class IndexSettingFragment extends BaseFragment implements View.OnClickLi
         progressDialog.show();
         progressDialog.show();
         //传递Handler
         //传递Handler
         VolleyUtil.setVolleyHandler(loginHandler);
         VolleyUtil.setVolleyHandler(loginHandler);
+        SharedPreUtil.saveString(getActivity(),"userNames",mUserName);
+        SharedPreUtil.saveString(getActivity(),"passwords",mPassword);
         //Volley请求服务器
         //Volley请求服务器
         VolleyUtil.requestUserLogin(getActivity(),
         VolleyUtil.requestUserLogin(getActivity(),
                 loginDataBean.getHttp() + "://" + loginDataBean.getIp() + ":"
                 loginDataBean.getHttp() + "://" + loginDataBean.getIp() + ":"

+ 2 - 0
app/src/main/java/com/uas/uas_mes_standard/fragment/LoginFragment.java

@@ -324,6 +324,8 @@ public class LoginFragment extends BaseFragment implements AdapterView.OnItemSel
     private void connect() {
     private void connect() {
         //传递Handler
         //传递Handler
         VolleyUtil.setVolleyHandler(loginHandler);
         VolleyUtil.setVolleyHandler(loginHandler);
+        SharedPreUtil.saveString(getActivity(),"userNames",userName);
+        SharedPreUtil.saveString(getActivity(),"passwords",password);
         //Volley请求服务器
         //Volley请求服务器
         VolleyUtil.requestUserLogin(getActivity(), GloableParams.ADDRESS_LOGIN_APPLY, VolleyUtil.METHOD_POST,
         VolleyUtil.requestUserLogin(getActivity(), GloableParams.ADDRESS_LOGIN_APPLY, VolleyUtil.METHOD_POST,
                 pageType, maName, userName, password);
                 pageType, maName, userName, password);

+ 1 - 0
app/src/main/java/com/uas/uas_mes_standard/tools/VolleyUtil.java

@@ -1089,6 +1089,7 @@ public class VolleyUtil {
                     } catch (UnsupportedEncodingException e) {
                     } catch (UnsupportedEncodingException e) {
                         e.printStackTrace();
                         e.printStackTrace();
                     }
                     }
+//                    CommonUtil.toastNoRepeat(pContext, tis);
                     return Response.success(str, HttpHeaderParser.parseCacheHeaders(response));
                     return Response.success(str, HttpHeaderParser.parseCacheHeaders(response));
                 }
                 }
             };
             };

+ 11 - 10
app/src/main/java/com/uas/uas_mes_standard/util/PrintUtils.java

@@ -25,11 +25,12 @@ public class PrintUtils {
             int offset = 6,
             int offset = 6,
                     h = 400,
                     h = 400,
                     v = 800,
                     v = 800,
-                    height = 400,
+                    height = 220,//400
                     qty = 1;
                     qty = 1;
 
 
             JSONArray templateArray = JSON.parseArray(printTemplate);
             JSONArray templateArray = JSON.parseArray(printTemplate);
             if (templateArray != null && templateArray.size() > 0) {
             if (templateArray != null && templateArray.size() > 0) {
+
                 PrintHelper printHelper = new PrintHelper(offset, h, v, height, qty);
                 PrintHelper printHelper = new PrintHelper(offset, h, v, height, qty);
                 for (int i = 0; i < templateArray.size(); i++) {
                 for (int i = 0; i < templateArray.size(); i++) {
                     JSONObject templateObject = templateArray.getJSONObject(i);
                     JSONObject templateObject = templateArray.getJSONObject(i);
@@ -37,9 +38,9 @@ public class PrintUtils {
                     if (templateObject != null) {
                     if (templateObject != null) {
                         String valuetype = FastjsonUtil.getText(templateObject, "LP_VALUETYPE");
                         String valuetype = FastjsonUtil.getText(templateObject, "LP_VALUETYPE");
                         double leftrate = FastjsonUtil.getDouble(templateObject, "LP_LEFTRATE");
                         double leftrate = FastjsonUtil.getDouble(templateObject, "LP_LEFTRATE");
-                        int printX = (int) (leftrate * dpi / 25.4);
+                        int printX = (int) (leftrate * dpi / 25.4);//宽度
                         double toprate = FastjsonUtil.getDouble(templateObject, "LP_TOPRATE");
                         double toprate = FastjsonUtil.getDouble(templateObject, "LP_TOPRATE");
-                        int printY = (int) (toprate * dpi / 25.4);
+                        int printY = (int) (toprate * dpi / 25.4);//高度
                         double barHeight = FastjsonUtil.getDouble(templateObject, "LP_HEIGHT");
                         double barHeight = FastjsonUtil.getDouble(templateObject, "LP_HEIGHT");
                         int barHeightInt = (int) (barHeight * dpi / 25.4);
                         int barHeightInt = (int) (barHeight * dpi / 25.4);
                         int fontSize = FastjsonUtil.getInt(templateObject, "LP_SIZE");
                         int fontSize = FastjsonUtil.getInt(templateObject, "LP_SIZE");
@@ -49,16 +50,16 @@ public class PrintUtils {
                         Log.e("printText",printText);
                         Log.e("printText",printText);
                         if (!TextUtils.isEmpty(printText)) {
                         if (!TextUtils.isEmpty(printText)) {
                             switch (valuetype) {
                             switch (valuetype) {
-                                case "barcode":
+                                case "barcode"://条码
                                     printHelper = printHelper.printBarCode(printText)
                                     printHelper = printHelper.printBarCode(printText)
-                                            .setX(printX)
-                                            .setY(printY)
-                                            .setHeight(barHeightInt - (int) (2 * dpi / 25.4))
+                                            .setX(printX)//宽
+                                            .setY(printY)//高
+                                            .setHeight(barHeightInt - (int) (2 * dpi / 25.4))//条码单位高度
                                             .setCodeTextFont(4)
                                             .setCodeTextFont(4)
                                             .setCodeTextSize(fontSize)
                                             .setCodeTextSize(fontSize)
                                             .build();
                                             .build();
                                     break;
                                     break;
-                                case "text":
+                                case "text"://文字
                                     int textFont = 7;
                                     int textFont = 7;
                                     if ("BAR_BATCHCODE".equals(printKey)) {
                                     if ("BAR_BATCHCODE".equals(printKey)) {
                                         textFont = 7;
                                         textFont = 7;
@@ -67,8 +68,8 @@ public class PrintUtils {
                                             .setX(printX)
                                             .setX(printX)
                                             .setY(printY)
                                             .setY(printY)
                                             .setBold(1)
                                             .setBold(1)
-                                            .setTextFont(textFont)
-                                            .setTextSize(fontSize)
+                                            .setTextFont(textFont)//字号
+                                            .setTextSize(fontSize)//字体大小,取接口的值
                                             .build();
                                             .build();
                                     break;
                                     break;
                                 case "qrcode"://打印二维码
                                 case "qrcode"://打印二维码

+ 22 - 4
app/src/main/java/com/uas/uas_mes_standard/util/VolleyRequest.java

@@ -1,6 +1,8 @@
 package com.uas.uas_mes_standard.util;
 package com.uas.uas_mes_standard.util;
 
 
+import android.app.Activity;
 import android.text.TextUtils;
 import android.text.TextUtils;
+import android.util.Log;
 
 
 import com.android.volley.AuthFailureError;
 import com.android.volley.AuthFailureError;
 import com.android.volley.DefaultRetryPolicy;
 import com.android.volley.DefaultRetryPolicy;
@@ -10,6 +12,8 @@ import com.android.volley.VolleyError;
 import com.android.volley.toolbox.StringRequest;
 import com.android.volley.toolbox.StringRequest;
 import com.uas.uas_mes_standard.R;
 import com.uas.uas_mes_standard.R;
 import com.uas.uas_mes_standard.application.PdaApplication;
 import com.uas.uas_mes_standard.application.PdaApplication;
+import com.uas.uas_mes_standard.global.GloableParams;
+import com.uas.uas_mes_standard.tools.SharedPreUtil;
 import com.uas.uas_mes_standard.tools.VolleyUtil;
 import com.uas.uas_mes_standard.tools.VolleyUtil;
 
 
 import java.io.UnsupportedEncodingException;
 import java.io.UnsupportedEncodingException;
@@ -54,7 +58,12 @@ public class VolleyRequest {
             throw new IllegalArgumentException("httpParams can not be NULL");
             throw new IllegalArgumentException("httpParams can not be NULL");
         }
         }
         if (httpCallback == null) {
         if (httpCallback == null) {
-            throw new IllegalArgumentException("callback can not be NULL");
+            try {
+                throw new IllegalArgumentException("callback can not be NULL");
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+
         }
         }
         if (httpParams.getUrl() == null) {
         if (httpParams.getUrl() == null) {
             throw new IllegalArgumentException("requestUrl can not be NULL");
             throw new IllegalArgumentException("requestUrl can not be NULL");
@@ -73,14 +82,14 @@ public class VolleyRequest {
         if (!TextUtils.isEmpty(url) && httpParams.getMethod() == Request.Method.GET && httpParams.getParams().size() > 0) {
         if (!TextUtils.isEmpty(url) && httpParams.getMethod() == Request.Method.GET && httpParams.getParams().size() > 0) {
             Set<Map.Entry<String, String>> entries = httpParams.getParams().entrySet();
             Set<Map.Entry<String, String>> entries = httpParams.getParams().entrySet();
 
 
-            int index = 1;
+            int index = 0;
             for (Map.Entry<String, String> paramEntry : entries) {
             for (Map.Entry<String, String> paramEntry : entries) {
                 String value = paramEntry.getValue();
                 String value = paramEntry.getValue();
                 if (!TextUtils.isEmpty(value)
                 if (!TextUtils.isEmpty(value)
                         && value.charAt(0) == 65279) {
                         && value.charAt(0) == 65279) {
                     value = value.substring(1);
                     value = value.substring(1);
                 }
                 }
-                if (index == 1) {
+                if (index == 0) {
                     try {
                     try {
                         url += "?" + paramEntry.getKey() + "=" + (TextUtils.isEmpty(value) ? "" : URLEncoder.encode(value, "UTF-8"));
                         url += "?" + paramEntry.getKey() + "=" + (TextUtils.isEmpty(value) ? "" : URLEncoder.encode(value, "UTF-8"));
                     } catch (UnsupportedEncodingException e) {
                     } catch (UnsupportedEncodingException e) {
@@ -94,6 +103,7 @@ public class VolleyRequest {
                     }
                     }
                 }
                 }
                 index++;
                 index++;
+                Log.e("index",index+"");
             }
             }
         }
         }
 
 
@@ -118,7 +128,15 @@ public class VolleyRequest {
                         try {
                         try {
                             LogUtil.e("responErr", errorToast);
                             LogUtil.e("responErr", errorToast);
                             if (errorToast.length() >= 500) {
                             if (errorToast.length() >= 500) {
-                                httpCallback.onFail(httpParams.getFlag(), "请求异常");
+                                Log.e("重新登录1","重新登录");
+                                //Volley请求服务器重新登录
+                                Activity activity=new Activity();
+                                String maName = SharedPreUtil.getString(activity, Constants.FLAG.ACCOUNT_NAME_CACHE, null);
+                                String userName = SharedPreUtil.getString(activity, "userNames", null);
+                                String password = SharedPreUtil.getString(activity, "passwords", null);
+                                VolleyUtil.requestUserLogin(activity, GloableParams.ADDRESS_LOGIN_APPLY, VolleyUtil.METHOD_POST,
+                                        VolleyUtil.FRAGMENT_LOGIN, maName, userName, password);
+                                httpCallback.onFail(httpParams.getFlag(), "已重新登录,请再次操作");
                             } else {
                             } else {
                                 httpCallback.onFail(httpParams.getFlag(), errorToast);
                                 httpCallback.onFail(httpParams.getFlag(), errorToast);
                             }
                             }