Parcourir la source

调整蓝牙打印机文字打印格式

songw il y a 5 mois
Parent
commit
b7272627c5

+ 4 - 0
app/build.gradle

@@ -177,4 +177,8 @@ dependencies {
     implementation 'org.apache.commons:commons-text:1.9'
 
     implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+
+//    api files('android-common-sdk-v1.00.00.aar')
+//    api files('lzo-sdk-v1.00.00.aar')
+
 }

BIN
app/libs/android-common-sdk-v1.00.00.aar


BIN
app/libs/lzo-sdk-v1.00.00.aar


+ 6 - 1
app/proguard-rules.pro

@@ -30,4 +30,9 @@
 -keepclassmembers enum * {
     public static **[] values();
     public static ** valueOf(java.lang.String);
-}
+}
+
+#汉印打印机混淆
+-keep class com.common.sdk.** { *; }
+-keepnames class com.common.sdk.**
+-keeppackagenames com.common.sdk.**

+ 0 - 19
app/src/main/java/uas/erp/punaier_wms/util/MyHPRTPrinterHelper.java

@@ -1,19 +0,0 @@
-package uas.erp.punaier_wms.util;
-
-import HPRTAndroidSDKA300.HPRTPrinterHelper;
-
-public
-        /**
-         * Created by sw on 2025-05-28
-         */
-class MyHPRTPrinterHelper extends HPRTPrinterHelper {
-
-
-//    public static int Text(String var0, String var1, String var2, String var3, String var4, String var5) throws Exception {
-//        HPRTPrinterHelper hprtPrinterHelper = new MyHPRTPrinterHelper();
-//
-////        byte[] var6 = (var0 + " " + var1 + " " + var2 + " " + var3 + " " + var4 + " " + var5 + "\r\n").getBytes(LanguageEncode);
-////        return w.WriteData(var6);
-//    }
-
-}

+ 47 - 24
app/src/main/java/uas/erp/punaier_wms/util/PrintUtils.java

@@ -40,14 +40,13 @@ public class PrintUtils {
             int la_offset = FastjsonUtil.getInt(templateObj, "LA_OFFSET") == 0 ? 6 : FastjsonUtil.getInt(templateObj, "LA_OFFSET");
             int la_h = FastjsonUtil.getInt(templateObj, "LA_H") == 0 ? 400 : FastjsonUtil.getInt(templateObj, "LA_H");
             int la_y = FastjsonUtil.getInt(templateObj, "LA_Y") == 0 ? 800 : FastjsonUtil.getInt(templateObj, "LA_Y");
-            int la_height = FastjsonUtil.getInt(templateObj, "LA_HEIGHT") == 0 ? 300 : FastjsonUtil.getInt(templateObj, "LA_HEIGHT");
+            int la_height = FastjsonUtil.getInt(templateObj, "LA_HEIGHT") == 0 ? 600 : FastjsonUtil.getInt(templateObj, "LA_HEIGHT");
             int la_qty = FastjsonUtil.getInt(templateObj, "LA_QTY") == 0 ? 1 : FastjsonUtil.getInt(templateObj, "LA_QTY");
             if (templateArray != null && templateArray.size() > 0) {
 //                PrintHelper printHelper = new PrintHelper(offset, h, v, height, qty);
                 PrintHelper printHelper = new PrintHelper(la_offset, la_h, la_y, la_height, la_qty);
                 for (int i = 0; i < templateArray.size(); i++) {
                     JSONObject templateObject = templateArray.getJSONObject(i);
-
                     if (templateObject != null) {
                         String valuetype = FastjsonUtil.getText(templateObject, "LP_VALUETYPE");
                         double leftrate = FastjsonUtil.getDouble(templateObject, "LP_LEFTRATE");
@@ -80,34 +79,58 @@ public class PrintUtils {
                                             .build();
                                     break;
                                 case "text":
-                                    int textFont = 7;
-                                    if ("BAR_BATCHCODE".equals(printKey)) {
-                                        textFont = 7;
-                                    }
-                                    if (StringUtil.isEmpty(String.valueOf(fontSize))){
-                                        fontSize=1;
-                                    }
-                                    printHelper = printHelper.printText("")
-                                            .setTextAutLine(printX+"",printY + (int) ((0.6 * dpi) / 25.4)+"",lp_width,fontSize,false,false,printText)
-//                                            .setX(printX)
-//                                            .setY(printY + (int) ((0.6 * dpi) / 25.4))
-//                                            .setBold(2)
-//                                            .setTextFont(textFont)
-//                                            .setTextFont(fontSize)
-                                            .build();
-
 //                                    int textFont = 7;
 //                                    if ("BAR_BATCHCODE".equals(printKey)) {
 //                                        textFont = 7;
 //                                    }
-//                                    printHelper = printHelper.printText(printText)
-//                                            .setX(printX)
-//                                            .setY(printY)
-//                                            .setBold(1)
-//                                            .setTextFont(textFont)//字号
-//                                            .setTextSize(fontSize)//字体大小,取接口的值
+//                                    if (StringUtil.isEmpty(String.valueOf(fontSize))){
+//                                        fontSize=1;
+//                                    }
+//                                    printHelper = printHelper.printText("")
+//                                            .setTextAutLine(printX+"",printY + (int) ((0.6 * dpi) / 25.4)+"",lp_width,fontSize,false,false,printText)
+////                                            .setX(printX)
+////                                            .setY(printY + (int) ((0.6 * dpi) / 25.4))
+////                                            .setBold(2)
+////                                            .setTextFont(textFont)
+////                                            .setTextFont(fontSize)
 //                                            .build();
 
+                                    fontSize = 0;
+                                    int textFont = 0;
+                                    if ("BAR_BATCHCODE".equals(printKey)) {
+                                        textFont = 0;
+                                    }
+                                    printHelper = printHelper.printText(printText)
+                                            .setX(printX)
+                                            .setY(printY)
+                                            .setBold(1)
+                                            .setTextFont(textFont)//字号
+                                            .setTextSize(fontSize)//字体大小,取接口的值
+                                            .build();
+
+                                    ///**
+                                    //* ⽂本打印
+                                    //* @param textEnum CPCLTextEnum ⽅向(查看表4.1.2)
+                                    //  TEXT (或 T) 横向打印文本。
+                                    //  VTEXT (或 VT) 逆时针旋转 90 度, 纵向打印文本。
+                                    //  TEXT90(或 T90) (同 VTEXT。 )
+                                    //  TEXT180(或 T180) 逆时针旋转 80 度, 反转打印文本。
+                                    //  TEXT270(或 T270) 逆时针旋转 270 度, 纵向打印文本。
+                                    //* @param font String 字体⼤⼩(查看表4.1.3)
+                                    //* @param size String 暂停使⽤(固定传0)
+                                    //* @param x String 横向起始坐标
+                                    //* @param y String 纵向起始坐标
+                                    //* @param data String ⽂本数据
+                                    //* @return Boolean 是否发送
+                                    //*/
+                                    //fun text(textEnum: CPCLTextEnum, font: String, size: String,
+                                    // x: String, y: String, data: String
+//                                    printHelper.printText2("TEXT","0","0","10","10",printText);
+
+                                    Log.e("aaa", "------------------------------------------------------");
+                                    Log.e("aaa"," **** CPCLTextEnum方向:"+ "TEXT" +",字号:" + textFont + ",文字大小固定为:" + fontSize +
+                                            ",横向起始坐标:" + printX + ",纵向起始坐标:" + printY + ",文本数据:" + printText + " **** ");
+
                                     break;
                                 case "qrcode"://打印二维码
                                     printHelper = printHelper.printQr(printText)

+ 2 - 2
build.gradle

@@ -54,8 +54,8 @@ ext {
             targetSdkVersion : 31,
             compileSdkVersion: 31,
             buildToolsVersion: "35.0.0",
-            versionCode      : 8,
-            versionName      : "1.0.8"
+            versionCode      : 10,
+            versionName      : "1.1.0"
     ]
 
     depsVersion = [

+ 16 - 1
pda_libs/bluetooth/src/main/java/com/uas/bluetooth/PrintHelper.java

@@ -33,6 +33,11 @@ public class PrintHelper {
      * @param qty    重复打印次数
      */
     public PrintHelper(int offset, int h, int v, int height, int qty) throws Exception {
+        //开启日志开关,记录⽇志的路径在:
+        //  sdcard/Android/data/app包名/files/Documents/SDK_log.txt
+        HPRTPrinterHelper.isWriteLog = true;
+        HPRTPrinterHelper.isHex = true;
+        //设置标签开头参数
         HPRTPrinterHelper.printAreaSize(String.valueOf(offset),
                 "" + h,
                 "" + v,
@@ -58,10 +63,20 @@ public class PrintHelper {
 
     //打印文本
     public TextBuilder printText(CharSequence qr) {
-
         return new TextBuilder(qr, this);
     }
 
+    //打印文本
+    public void printText2(String cpcltext,String a,String b,String c,String d,String text) {
+        try {
+            String command = cpcltext + a + b + c + d + text;
+            HPRTPrinterHelper.WriteData(command.getBytes("gb2312"));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
     //打印条形码
     public BarCodeBuilder printBarCode(CharSequence qr) {
         return new BarCodeBuilder(qr, this);