yinds 1 miesiąc temu
rodzic
commit
8342d2c98d

+ 1 - 1
app/src/main/java/com/hw/nativeapp/ui/activity/InfoEnterActivity.java

@@ -193,7 +193,7 @@ public class InfoEnterActivity extends BaseActivity  {
         public void onServiceConnected(ComponentName name, IBinder service) {
             mService = IDCardServiceAidl.Stub.asInterface(service);
             Log.e("id_card", " 服务已连接");
-            Toast.makeText(InfoEnterActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
+//            Toast.makeText(InfoEnterActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
             autoFu();
         }
 

+ 115 - 95
app/src/main/java/com/hw/nativeapp/ui/activity/IssueTicketsActivity.java

@@ -1,4 +1,5 @@
 package com.hw.nativeapp.ui.activity;
+import android.annotation.SuppressLint;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -8,7 +9,6 @@ import android.os.Bundle;
 import android.os.CountDownTimer;
 import android.os.IBinder;
 import android.os.RemoteException;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.View;
 import android.view.WindowManager;
@@ -16,7 +16,6 @@ import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.blankj.utilcode.util.ToastUtils;
@@ -27,8 +26,11 @@ import com.hw.nativeapp.R;
 import com.hw.nativeapp.httpnet.ErrorConsumer;
 import com.hw.nativeapp.httpnet.ResponseConsumer;
 import com.hw.nativeapp.utils.RxUtil;
+import com.hw.nativeapp.utils.StringUtils;
 import com.sunmi.extprinterservice.ExtPrinterService;
 
+import java.util.List;
+
 import butterknife.BindView;
 
 
@@ -95,6 +97,7 @@ public class IssueTicketsActivity extends BaseActivity  {
         if (serviceConnection != null) {
             try {
                 unbindService(serviceConnection);
+                serviceConnection = null;
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -124,16 +127,21 @@ public class IssueTicketsActivity extends BaseActivity  {
     }
 
     private void initPageView() {
-//        print_num.setText(printNum +"/"+viewerList.size());
         getTicketOut();
     }
 
     // 出票完成
-    private void finishView() {
-        Toast.makeText(IssueTicketsActivity.this, "出票完成!", Toast.LENGTH_SHORT).show();
-        tx_issue_status_text.setText("出票完成~");
-        tx_issue_txt.setText("请取票!");
-//        img_issue_tickets.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ticket_collection));
+    private void finishView( boolean isSuccess) {
+        if (isSuccess){
+            Toast.makeText(IssueTicketsActivity.this, "出票完成!", Toast.LENGTH_SHORT).show();
+            tx_issue_status_text.setText("出票完成~");
+            tx_issue_txt.setText("请取票!");
+        }else {
+            Toast.makeText(IssueTicketsActivity.this, "出票失败!", Toast.LENGTH_SHORT).show();
+//            tx_issue_status_text.setText("出票失败~");
+//            tx_issue_txt.setText("即将退出!");
+            finish();
+        }
     }
 
     private void selfIndex(){
@@ -151,6 +159,7 @@ public class IssueTicketsActivity extends BaseActivity  {
                 }, new ErrorConsumer());
     }
 
+    @SuppressLint("CheckResult")
     private void getTicketOut(){
         JSONObject options = new JSONObject();
         options.put("source", "1");
@@ -164,9 +173,16 @@ public class IssueTicketsActivity extends BaseActivity  {
                 .subscribe(new ResponseConsumer<JSONObject>() {
                     @Override
                     public void onSuccess(JSONObject data) throws RemoteException {
-                        JSONArray rows = data.getJSONArray("printInfo");
-                        printInfo = rows;
-                        startPrinting(printInfo.getJSONObject(printNum - 1));
+                        if (data.containsKey("printInfo")){
+                            List<JSONObject> printList = data.getJSONArray("printInfo").toJavaList(JSONObject.class);
+                            if (printList != null && !printList.isEmpty()){
+                                printListHandle(printList);
+                            }else {
+                                finishView(false);
+                            }
+                        }else{
+                            finishView(false);
+                        }
                     }
 
                     @Override
@@ -176,20 +192,22 @@ public class IssueTicketsActivity extends BaseActivity  {
                 }, new ErrorConsumer());
     }
 
-    // 开始打印
-    private void startPrinting(JSONObject obj) throws RemoteException {
-//        print_num.setText(printNum +"/"+viewerList.size());
+    private void printListHandle(List<JSONObject> printList) throws RemoteException {
+        if (ext == null){
+            finishView(true);
+            return;
+        }
         /*
-        * 打印机状态
-        * -1 打印机脱机或打印服务还未连接打印机
-        * 0 打印机运⾏正常
-        * 1 打印机开盖
-        * 2 打印机缺纸
-        * 3 打印机即将缺纸
-        * 4 打印机过热
-        * */
+         * 打印机状态
+         * -1 打印机脱机或打印服务还未连接打印机
+         * 0 打印机运⾏正常
+         * 1 打印机开盖
+         * 2 打印机缺纸
+         * 3 打印机即将缺纸
+         * 4 打印机过热
+         * */
         int printerStatus = ext.getPrinterStatus(); //
-        Toast.makeText(IssueTicketsActivity.this, "printerStatus" + printerStatus, Toast.LENGTH_SHORT).show();
+        Toast.makeText(IssueTicketsActivity.this, "printerStatus=" + printerStatus, Toast.LENGTH_SHORT).show();
         if(printerStatus == 2) {
             tx_issue_not.setVisibility(View.VISIBLE);
             tx_issue_txt.setVisibility(View.GONE);
@@ -197,7 +215,6 @@ public class IssueTicketsActivity extends BaseActivity  {
         }
         if(printerStatus != 0 && printerStatus != 3){
             String msg = printerStatus == -1 ? "打印机脱机或打印服务还未连接打印机" : printerStatus == 1 ? "打印机开盖" : printerStatus == 2 ? "打印机缺纸" : printerStatus == 3 ? "打印机即将缺纸" : "打印机过热";
-//            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
             ToastUtils Toast = new ToastUtils();
             Toast.setGravity(Gravity.TOP, 0, 200);
             Toast.setTextSize(32);
@@ -205,83 +222,86 @@ public class IssueTicketsActivity extends BaseActivity  {
             Toast.show(msg);
             return;
         }
-        JSONArray rowItem = obj.getJSONArray("printList");
-        if(rowItem != null && rowItem.size() > 0) {
+        try {
             ext.startTransBuffer(); //启⽤事务模式
-            for (int i = 0; i < rowItem.size(); i++) {
-                // 打印文本
-                if(rowItem.getJSONObject(i).getString("printType").equals("text")){
-                    int hori = rowItem.getJSONObject(i).get("hori") == null ? 1 : rowItem.getJSONObject(i).getInteger("hori");
-                    int veri = rowItem.getJSONObject(i).get("veri")== null ? 1 : rowItem.getJSONObject(i).getInteger("veri");
-                    ext.setFontZoom(hori, veri);
-                    // 对其方式
-                    int alignMode =rowItem.getJSONObject(i).get("alignMode") == null ? 1 : rowItem.getJSONObject(i).getInteger("alignMode");
-                    ext.setAlignMode(alignMode);
-                    ext.printText(rowItem.getJSONObject(i).getString("printContent"));
-                }
-                // 打印二维码
-                if(rowItem.getJSONObject(i).getString("printType").equals("qrcode")){
-                    // 对其方式
-                    int alignMode = rowItem.getJSONObject(i).get("alignMode") == null ? 1 : rowItem.getJSONObject(i).getInteger("alignMode");
-                    ext.setAlignMode(alignMode);
+            int index = 1;
+            for (JSONObject it : printList){
+                Toast.makeText(IssueTicketsActivity.this, "开始打印:" + index, Toast.LENGTH_SHORT).show();
+                printExecute(it);
+                index++;
+            }
+            ext.endTransBuffer(); //结束事务模式
+        } catch (Exception ignored) {}
+        finishView(true);
+    }
 
-                    String eqCode = rowItem.getJSONObject(i).get("printContent") == null ? "" : rowItem.getJSONObject(i).getString("printContent");
-                    int qrcodeSize = rowItem.getJSONObject(i).get("qrcodeSize") == null ? 0 : rowItem.getJSONObject(i).getInteger("qrcodeSize");
-                    ext.printQrCode(eqCode, qrcodeSize, 0);
-                }
-                // 打印条形码
-                if(rowItem.getJSONObject(i).getString("printType").equals("barCode")){
-                    // 对其方式
-                    int alignMode = rowItem.getJSONObject(i).get("alignMode") == null ? 0 : rowItem.getJSONObject(i).getInteger("alignMode");
-                    ext.setAlignMode(alignMode);
 
-                    String barCode = rowItem.getJSONObject(i).get("printContent") == null ? "" :  rowItem.getJSONObject(i).getString("printContent");
-                    int barCodeType = rowItem.getJSONObject(i).get("barCodeType") == null ? 0 :  rowItem.getJSONObject(i).getInteger("barCodeType");
-                    int width =rowItem.getJSONObject(i).get("width") == null ? 0 :  rowItem.getJSONObject(i).getInteger("width");
-                    int height = rowItem.getJSONObject(i).get("height") == null ? 0 :  rowItem.getJSONObject(i).getInteger("height");
-                    ext.printBarCode(barCode, barCodeType, width, height, 1);
-                }
-                // 打印走纸
-                if(rowItem.getJSONObject(i).getString("printType").equals("wrpe")){
-                    // 走纸类型: 1-按行 2-按像素
-                    int wrapType = rowItem.getJSONObject(i).get("wrapType") == null ? 0 : rowItem.getJSONObject(i).getInteger("wrapType");
-                    int wrapLen = rowItem.getJSONObject(i).get("wrapLen") == null ? 0 :  rowItem.getJSONObject(i).getInteger("wrapLen");
-                    if(wrapType == 1) {
-                       ext.lineWrap(wrapLen);
-                    } else if (wrapType == 2) {
-                       ext.pixelWrap(wrapLen);
+
+    private void printExecute(JSONObject ptObj)throws RemoteException{
+        if (ptObj.containsKey("printList")){
+            List<JSONObject> rowItem = ptObj.getJSONArray("printList")
+                    .toJavaList(JSONObject.class);
+            if (rowItem != null && !rowItem.isEmpty()){
+                for (JSONObject itemJson : rowItem){
+                    // 打印文本
+                    String printType = itemJson.getString("printType");
+                    if(!StringUtils.isEmpty(printType) && printType.equals("text")){
+                        int hori = itemJson.get("hori") == null ? 1 : itemJson.getInteger("hori");
+                        int veri = itemJson.get("veri")== null ? 1 : itemJson.getInteger("veri");
+                        ext.setFontZoom(hori, veri);
+                        // 对其方式
+                        int alignMode =itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
+                        ext.setAlignMode(alignMode);
+                        String printContent = itemJson.containsKey("printContent")?itemJson.getString("printContent"):"";
+                        ext.printText(printContent);
+                    }
+                    // 打印二维码
+                    if(!StringUtils.isEmpty(printType) &&  printType.equals("qrcode")){
+                        // 对其方式
+                        int alignMode = itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
+                        ext.setAlignMode(alignMode);
+
+                        String eqCode = itemJson.get("printContent") == null ? "" : itemJson.getString("printContent");
+                        int qrcodeSize = itemJson.get("qrcodeSize") == null ? 0 : itemJson.getInteger("qrcodeSize");
+                        ext.printQrCode(eqCode, qrcodeSize, 0);
+                    }
+                    // 打印条形码
+                    if(!StringUtils.isEmpty(printType) &&  printType.equals("barCode")){
+                        // 对其方式
+                        int alignMode = itemJson.get("alignMode") == null ? 0 : itemJson.getInteger("alignMode");
+                        ext.setAlignMode(alignMode);
+
+                        String barCode = itemJson.get("printContent") == null ? "" :  itemJson.getString("printContent");
+                        int barCodeType = itemJson.get("barCodeType") == null ? 0 :  itemJson.getInteger("barCodeType");
+                        int width =itemJson.get("width") == null ? 0 :  itemJson.getInteger("width");
+                        int height = itemJson.get("height") == null ? 0 :  itemJson.getInteger("height");
+                        ext.printBarCode(barCode, barCodeType, width, height, 1);
+                    }
+                    // 打印走纸
+                    if(!StringUtils.isEmpty(printType) &&  printType.equals("wrpe")){
+                        // 走纸类型: 1-按行 2-按像素
+                        int wrapType = itemJson.get("wrapType") == null ? 0 : itemJson.getInteger("wrapType");
+                        int wrapLen = itemJson.get("wrapLen") == null ? 0 :  itemJson.getInteger("wrapLen");
+                        if(wrapType == 1) {
+                            ext.lineWrap(wrapLen);
+                        } else if (wrapType == 2) {
+                            ext.pixelWrap(wrapLen);
+                        }
+                    }
+                    // 打印切纸
+                    if(!StringUtils.isEmpty(printType) &&  printType.equals("cut")){
+                        int cutPx = itemJson.get("cutPx") == null ? 0 : itemJson.getInteger("cutPx");
+                        int cutType = itemJson.get("cutType") == null ? 0 : itemJson.getInteger("cutType");
+                        ext.cutPaper(cutType, cutPx);
                     }
                 }
-                // 打印切纸
-                if(rowItem.getJSONObject(i).getString("printType").equals("cut")){
-                    int cutPx = rowItem.getJSONObject(i).get("cutPx") == null ? 0 : rowItem.getJSONObject(i).getInteger("cutPx");
-                    int cutType = rowItem.getJSONObject(i).get("cutType") == null ? 0 : rowItem.getJSONObject(i).getInteger("cutType");
-                    ext.cutPaper(cutType, cutPx);
-                }
+            }else {
+                Toast.makeText(IssueTicketsActivity.this, "打印数据为空", Toast.LENGTH_SHORT).show();
+                finishView(true);
             }
-            ext.endTransBuffer(); //结束事务模式
-//            Boolean endTransBuffer = ext.endTransBuffer(); //结束事务模式
-//            Toast.makeText(IssueTicketsActivity.this, "endTransBuffer!" + endTransBuffer, Toast.LENGTH_SHORT).show();
-//            if(!endTransBuffer){
-//                tx_issue_status_text.setText("打印失败,请检查打印机请联系工作人员");
-//                tx_issue_txt.setText("打印失败");
-//                Toast.makeText(IssueTicketsActivity.this, "打印失败", Toast.LENGTH_SHORT).show();
-//                return;
-//            }
-            if(printNum  < viewerList.size()){
-                //  打印完成,开始打印下一张
-                printNum++;
-                startPrinting(printInfo.getJSONObject(printNum - 1));
-            } else {
-                finishView();
-            }
-        } else {
-//            Toast.makeText(IssueTicketsActivity.this, "打印小票数据为空!" + rowItem, Toast.LENGTH_SHORT).show();
-            ToastUtils Toast = new ToastUtils();
-            Toast.setGravity(Gravity.TOP, 0, 200);
-            Toast.setTextSize(32);
-            Toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
-            Toast.show("打印小票数据为空");
+        }else {
+            Toast.makeText(IssueTicketsActivity.this, "打印数据不存在", Toast.LENGTH_SHORT).show();
+            finishView(true);
         }
     }
 

+ 12 - 3
app/src/main/java/com/hw/nativeapp/ui/activity/TakeActivity.java

@@ -26,6 +26,7 @@ import androidx.core.app.ActivityCompat;
 
 import com.hjq.bar.OnTitleBarListener;
 import com.hjq.bar.TitleBar;
+import com.hw.nativeapp.utils.RegexUtil;
 import com.sunmi.idcardservice.CardCallback;
 import com.sunmi.idcardservice.IDCardInfo;
 import com.sunmi.idcardservice.IDCardServiceAidl;
@@ -153,8 +154,16 @@ public class TakeActivity extends BaseActivity  {
                     return;
                 }
                 Bundle bundle = new Bundle();
-                bundle.putString("qrcodeNo", et_modify_quantity.getText().toString());
-                ActivityUtils.launchActivity(this, TicketCollectionActivity.class, bundle);
+                String code = et_modify_quantity.getText().toString();
+                if (RegexUtil.isMobile(code)){
+                    bundle.putString("mobile", code);
+                    ActivityUtils.launchActivity(this, TicketCollectionActivity.class, bundle);
+                }else if (code.startsWith("00") || code.startsWith("01")){
+                    bundle.putString("qrcodeNo", code);
+                    ActivityUtils.launchActivity(this, TicketCollectionActivity.class, bundle);
+                }else {
+                    Toast.makeText(TakeActivity.this, "输入格式错误", Toast.LENGTH_SHORT).show();
+                }
                 break;
             case R.id.num_01:
                 et_modify_quantity.setText(et_modify_quantity.getText().toString()+"1");
@@ -298,7 +307,7 @@ public class TakeActivity extends BaseActivity  {
         public void onServiceConnected(ComponentName name, IBinder service) {
             mService = IDCardServiceAidl.Stub.asInterface(service);
             Log.e("id_card", " 服务已连接");
-            Toast.makeText(TakeActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
+//            Toast.makeText(TakeActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
             readCardAutoFu();
         }
 

+ 5 - 0
app/src/main/java/com/hw/nativeapp/ui/activity/TicketCollectionActivity.java

@@ -77,6 +77,7 @@ public class TicketCollectionActivity extends BaseActivity  {
     private handleBean operLocation;
     private TicketCollectionAdapter adapter;
     private String qrcodeNo;
+    private String mMobile;
     private String idcard = "";
     private String orderId = "";
     private int initNum = 0;
@@ -160,6 +161,7 @@ public class TicketCollectionActivity extends BaseActivity  {
         qrcodeNo = transmitIntent.getStringExtra("qrcodeNo");
         idcard = transmitIntent.getStringExtra("idcard");
         orderId = transmitIntent.getStringExtra("orderId");
+        mMobile = transmitIntent.getStringExtra("mobile");
     }
 
     private void reflashFinish(){
@@ -238,6 +240,9 @@ public class TicketCollectionActivity extends BaseActivity  {
         if(idcard != null && !idcard.isEmpty()){
             options.put("idcard", idcard);
         }
+        if (!StringUtils.isEmpty(mMobile)){
+            options.put("mobile", mMobile);
+        }
         if(orderId != null && !orderId.isEmpty()){
             options.put("orderId", orderId);
         }

+ 2 - 2
app/src/main/res/layout/activity_issue_tickets.xml

@@ -118,7 +118,7 @@
                     <TextView
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:text="正在为您打印"
+                        android:text="正在为您打印,"
                         android:textColor="@color/black"
                         android:textSize="@dimen/inedx_btn_size" />
 
@@ -133,7 +133,7 @@
                     <TextView
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:text="张,请注意下方出票口取票..."
+                        android:text="注意下方出票口取票"
                         android:textColor="@color/black"
                         android:textSize="@dimen/inedx_btn_size" />
                 </LinearLayout>