Browse Source

热敏A4打印测试

xulh 6 months ago
parent
commit
76846cffb7
29 changed files with 1361 additions and 98 deletions
  1. 4 0
      LocalRepo/build.gradle
  2. 0 0
      LocalRepo/printlib-debug.aar
  3. BIN
      LocalRepo/sdk_800r09_library-release-108.aar
  4. 4 1
      app/build.gradle
  5. 55 10
      app/src/main/java/com/hh/arome/bean/ampe/AmpeAppletRequestBean.java
  6. 5 16
      app/src/main/java/com/hh/arome/ui/MainActivity.java
  7. 8 0
      build.gradle
  8. 16 3
      lib_print/build.gradle
  9. BIN
      lib_print/libs/printlib-debug.aar
  10. 10 45
      lib_print/src/main/AndroidManifest.xml
  11. 22 0
      lib_print/src/main/assets/200x200.pdf
  12. 34 0
      lib_print/src/main/assets/a4_cs.pdf
  13. 26 0
      lib_print/src/main/assets/a4_p.pdf
  14. 10 0
      lib_print/src/main/assets/a5.pdf
  15. 83 0
      lib_print/src/main/assets/testpdf2page.pdf
  16. 15 12
      lib_print/src/main/java/com/common/print/BasePrinter.java
  17. 9 0
      lib_print/src/main/java/com/common/print/IPrinter.java
  18. 23 0
      lib_print/src/main/java/com/common/print/PrintApplication.java
  19. 106 0
      lib_print/src/main/java/com/common/print/bean/PrintBean.java
  20. 1 1
      lib_print/src/main/java/com/common/print/bean/PrintContentBean.java
  21. 8 9
      lib_print/src/main/java/com/common/print/many/Mla80Printer.java
  22. 631 0
      lib_print/src/main/java/com/common/print/many/MlaFCDD215Printer.java
  23. 288 0
      lib_print/src/main/java/com/common/print/utils/BitmapUtils.java
  24. 1 0
      lib_print/src/main/java/com/telpo/tps508/PrintUtile.java
  25. 1 1
      lib_print/src/main/java/com/telpo/tps508/base/IPrintBase.java
  26. BIN
      lib_print/src/main/res/drawable/a4_img.jpg
  27. BIN
      lib_print/src/main/res/drawable/test_100.jpg
  28. BIN
      lib_print/src/main/res/font/songti.ttf
  29. 1 0
      settings.gradle

+ 4 - 0
LocalRepo/build.gradle

@@ -0,0 +1,4 @@
+configurations.maybeCreate("default")
+artifacts.add("default", file('sdk_800r09_library-release-108.aar'))
+artifacts.add("default", file('printlib-debug.aar'))
+//artifacts.add("default", file('sdk_800r09_library-release-104.aar'))

+ 0 - 0
app/libs/printlib-debug.aar → LocalRepo/printlib-debug.aar


BIN
LocalRepo/sdk_800r09_library-release-108.aar


+ 4 - 1
app/build.gradle

@@ -167,6 +167,7 @@ android {
     repositories {
         flatDir {
             dirs 'libs'
+//            , '../lib_print/libs'
         }
     }
     sourceSets {
@@ -187,6 +188,8 @@ android {
         pickFirst 'lib/armeabi-v7a/libandroid_serial_port.so'
         pickFirst 'lib/armeabi-v7a/libserial_port.so'
         pickFirst 'lib/armeabi/libserial_port.so'
+
+        // pickFirst 'org.greenrobot.eventbus'
     }
 
 }
@@ -208,7 +211,7 @@ dependencies {
     implementation project(path: ':lib_base')
 //    implementation project(path: ':lib_print')
     // 打印
-    implementation(name: 'printlib-debug', ext: 'aar')
+//    implementation(name: 'printlib-debug', ext: 'aar')
     implementation project(path: ':lib_print')
 
     // USB二维码

+ 55 - 10
app/src/main/java/com/hh/arome/bean/ampe/AmpeAppletRequestBean.java

@@ -43,7 +43,16 @@ public class AmpeAppletRequestBean {
 
     public static class ParamsDTO {
 
-        private ExtInfo extInfo;
+
+        // 打印浓度
+        int printPotency;
+        // 打印速度
+        int printSpeed;
+        // 打印纸张大小
+        int printPageType;
+
+
+        // 具体打印内容
         private List<PrintListBean> printList;
 
         public List<PrintListBean> getPrintList() {
@@ -128,6 +137,35 @@ public class AmpeAppletRequestBean {
                 this.width = width;
             }
         }
+
+
+        public int getPrintPotency() {
+            return printPotency;
+        }
+
+        public void setPrintPotency(int printPotency) {
+            this.printPotency = printPotency;
+        }
+
+        public int getPrintSpeed() {
+            return printSpeed;
+        }
+
+        public void setPrintSpeed(int printSpeed) {
+            this.printSpeed = printSpeed;
+        }
+
+        public int getPrintPageType() {
+            return printPageType;
+        }
+
+        public void setPrintPageType(int printPageType) {
+            this.printPageType = printPageType;
+        }
+
+        // ampe配置
+        private ExtInfo extInfo;
+
         public ExtInfo getExtInfo() {
             return extInfo;
         }
@@ -137,6 +175,7 @@ public class AmpeAppletRequestBean {
         }
 
         public static class ExtInfo {
+            // 授权参数
             String scopes;
             String merchantAppId;
 
@@ -281,6 +320,21 @@ public class AmpeAppletRequestBean {
         }
 
 
+
+
+        // 录音
+        Integer intervalTime = 1000;
+
+        public Integer getIntervalTime() {
+            return intervalTime;
+        }
+
+        public void setIntervalTime(Integer intervalTime) {
+            this.intervalTime = intervalTime;
+        }
+
+
+
         @Override
         public String toString() {
             return "ParamsDTO{" +
@@ -300,16 +354,7 @@ public class AmpeAppletRequestBean {
         }
 
 
-        // 录音
-        Integer intervalTime = 1000;
 
-        public Integer getIntervalTime() {
-            return intervalTime;
-        }
-
-        public void setIntervalTime(Integer intervalTime) {
-            this.intervalTime = intervalTime;
-        }
     }
     public static class PrintDTO{
 

File diff suppressed because it is too large
+ 5 - 16
app/src/main/java/com/hh/arome/ui/MainActivity.java


+ 8 - 0
build.gradle

@@ -9,6 +9,7 @@ buildscript {
         mavenCentral()
         mavenLocal()
         maven { url 'https://jitpack.io' }
+        maven { url 'https://dl.bintray.com/jenly/maven' }
         maven { url 'https://maven.aliyun.com/nexus/content/groups/public/'}
         maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
     }
@@ -29,8 +30,15 @@ allprojects {
         mavenCentral()
         mavenLocal()
         maven { url 'https://jitpack.io' }
+        maven { url 'https://dl.bintray.com/jenly/maven' }
         maven { url 'https://maven.aliyun.com/nexus/content/groups/public/'}
         maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
+
+
+//        flatDir {
+//            dirs project(':lib_print').file('libs') // 我的aar文件已放置到 lib_ffmpeg 模块的libs目录下
+//        }
+
     }
 }
 

+ 16 - 3
lib_print/build.gradle

@@ -1,4 +1,6 @@
 apply plugin: 'com.android.library'
+apply plugin: 'org.jetbrains.kotlin.android'
+apply plugin: 'kotlin-android'
 
 android {
     compileSdkVersion rootProject.ext.android["compileSdkVersion"]
@@ -42,7 +44,10 @@ android {
 }
 
 dependencies {
-    implementation fileTree(include: ['*.jar'], dir: 'libs')
+    // 已有改行,不需要再特别引入aar
+    implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
+
+
     implementation 'androidx.appcompat:appcompat:1.1.0'
     implementation 'com.google.android.material:material:1.1.0'
     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
@@ -61,6 +66,7 @@ dependencies {
     implementation 'com.caverock:androidsvg:1.4+'
 
 
+    compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"
 
     api files('libs/telpo_sdk_20240108_noserial.jar')
 
@@ -70,14 +76,21 @@ dependencies {
 //    api files('libs/posutil_sdk_20231226.jar')
 
 
-    implementation project(':lib_arome')
+
 
 
     // y9打印
-    implementation(name: 'printlib-debug', ext: 'aar')
+//    implementation(name: 'printlib-debug', ext: 'aar')
+    // y9打印-a4
+//    implementation(name: 'sdk_800r09_library-release-1.0.4', ext: 'aar')
 
 
     // 添加base依赖
     implementation project(path: ':lib_base')
 
+    implementation project(path: ':lib_arome')
+
+    implementation project(path: ':LocalRepo')
+
+
 }

BIN
lib_print/libs/printlib-debug.aar


+ 10 - 45
lib_print/src/main/AndroidManifest.xml

@@ -1,49 +1,14 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.telpo.tps508">
-<!--    <uses-feature-->
-<!--        android:name="android.hardware.camera" />-->
-<!--    <uses-feature-->
-<!--        android:name="android.hardware.camera.autofocus"-->
-<!--        android:required="true" />-->
-<!--    <uses-permission android:name="android.permission.CAMERA" />-->
-<!--    <uses-permission android:name="android.permission.RESTART_PACKAGES" />-->
-<!--    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />-->
-<!--    <uses-permission android:name="android.permission.WRITE_SETTINGS" />-->
-<!--    <uses-permission android:name="android.permission.CALL_PHONE" />-->
-<!--    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />-->
-<!--    <uses-permission android:name="android.permission.VIBRATE" />-->
-<!--    <uses-permission android:name="android.permission.WAKE_LOCK" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->
-<!--    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
-<!--    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />-->
-<!--    <uses-permission android:name="android.permission.INTERNET" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />-->
-<!--    <uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
-<!--    <uses-permission android:name="android.permission.SET_TIME_ZONE" />-->
-<!--    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
-<!--    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />-->
-<!--    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />-->
-<!--    <uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
-<!--    <uses-permission android:name="android.permission.CAMERA" />-->
-<!--    <uses-permission android:name="android.permission.FLASHLIGHT" />-->
-<!--    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />-->
-<!--    &lt;!&ndash; 授予读联系人ContentProvider的权限 &ndash;&gt;-->
-<!--    <uses-permission android:name="android.permission.READ_CONTACTS" />-->
-<!--    &lt;!&ndash; 授予写联系人ContentProvider的权限 &ndash;&gt;-->
-<!--    <uses-permission android:name="android.permission.WRITE_CONTACTS" />-->
-<!--    <uses-permission android:name="android.permission.WRITE_SMS" />-->
-<!--    <uses-permission android:name="android.permission.READ_SMS" />-->
-<!--    <uses-permission android:name="android.permission.GET_TASKS" />-->
-<!--    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
-<!--    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>-->
-<!--    <uses-permission android:name="android.permission.RECORD_AUDIO"/>-->
-<!--    <uses-permission android:name="android.permission.BLUETOOTH"/>-->
-<!--    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>-->
-<!--    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>-->
-<!--    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>-->
+    xmlns:tools="http://schemas.android.com/tools"
+    package="com.common.print">
+
+
+
+    <application
+        android:allowBackup="true"
+        android:name=".PrintApplication"
+        tools:replace="android:allowBackup"
+        />
 
 </manifest>

+ 22 - 0
lib_print/src/main/assets/200x200.pdf

@@ -0,0 +1,22 @@
+硫酸铜
+
+含铜废物/HW22
+
+304-001-22  固体
+硫酸铜
+                                 ✔
+
+                     Sulfuric acid copper(2+) salt (1:1)、
+Copper(II) sulfate、Copper monosulfate
+
+                     1.勿使用鋁或鍍鋅容器。2.使用聚乙烯或聚丙烯材質的容器儲存。
+3.與不相容物質分開儲放,包括醇、水、濕氣、金屬細粉、鎂羥胺
+
+410329B82073040012221478197
+
+     厦门 XX 科技有限公司(测试)
+
+     黄 XXX/180XXXXXXXX
+
+2023-09-20  2.2 吨
+

+ 34 - 0
lib_print/src/main/assets/a4_cs.pdf

@@ -0,0 +1,34 @@
+         某某市妇幼保健院 儿童医院
+               超声检查报告单
+
+姓名:杨 XX  性别: 女  年龄: 40 岁  超声号:
+门诊号:     住院号:   病区:       床号:
+
+       诊断描述:
+        双顶径 6cm 头围 20.93cm 腹围 19.84cm 股骨径 3.89cm 肱骨径 3.75cm 小脑横径
+
+        脐血流指数:PSV=41.38cm/s,EDV=13.05cm/s,RI=0.68,PI=1.09,S/D=3.17
+
+        MCA 指数:PSV=30.13cm/s,EDV=7.61cm/s,RI=0.75,PI=1.40,S/D=3.96
+               1.增大的子宫内探及一个胎儿,胎头位于耻骨上,头颅光环完整,脑中线居中,两侧丘脑可见,小脑半球
+
+        形态未见明显异常,颅后窝池未见明显扩张,侧脑室宽 0.67cm。
+               2.胎儿闭口时上唇皮肤连续性未见明显中断。
+               3.脊柱位于右侧前方,双强回声带平行排列,整齐连续。胎心搏动可见,瞬间心率 160 次/分,律齐。四腔心切
+
+        面显示尚清楚,左、右房室大小基本对称,连接一致。心脏中央十字交叉存在。左、右心室流出道显示清楚。
+
+               4.胎儿腹部内脏:腹壁连续性未见明显中断,肝、胆、胃泡、膀胱显示可.胎儿双肾集合系统未见明显分离。
+               5.胎儿双侧上臂及其内的肱骨可见,双侧前臂及其内的尺、桡骨可见,双手呈握拳状。双侧大腿及
+        其内的股骨可见,双侧小腿及其内的胫、腓骨可见,双足可见
+
+               6.胎盘附着于后壁为主,厚约 2.3cm,0 级胎盘。胎盘下缘距宫颈内口约>3.0cm。
+               7.胎儿脐带:脐动脉两条,颈部未探及明显压迹。
+超声提示:
+        宫内妊娠,单活胎,头位,超声孕龄约 23 周 0 天
+        备注:本次超声检查只检查“超声描述”内容,没有描述的胎儿结构不在超声检查范围内,比如目前技术条件耳、指、
+        趾、甲状腺等众多结构尚不能做为常规条件进行检查,超声也不能见到胎儿染色体,胎儿性别及生殖器有关的问题不
+        在检查范围内。胎儿畸形或异常是动态发展的,本次检查仅说明目前的胎儿状况。特此声明!
+
+                    1.本报告仅供临床参考,不做任何证明。
+

+ 26 - 0
lib_print/src/main/assets/a4_p.pdf

@@ -0,0 +1,26 @@
+      长沙市天心区先锋街道社区卫生服务中心检验报告单
+
+姓名:谭绍言   送检科室:门诊全科                            就诊类型:门诊        标本类型:全血
+
+性别:男     住院编号:20240603000173                  送检医生:张晶        标本号:25
+                                              临床诊断:发热        备注:
+年龄:10岁   床号:
+
+检验项目名称                 英文名称  检验结果             状态       参考区间        单位
+
+1 C反应蛋白                CRP   <5                        0-10        mg/L
+                             2.64
+2 超敏C反应蛋白 hs-CRP             15.37            ↑        0-1         mg/L
+                             5.82
+3 血清淀粉样蛋白A SAA                                                     mg/L
+
+4 C反应蛋白/血清淀粉SAA/CRP                                    0-10
+
+样蛋白A
+
+检验时间:2024-06-03 10:21  审核时间:2024-06-03 10:21
+
+                                              检验者:           审核者:
+
+此结果仅对本份检验标本负责!
+

+ 10 - 0
lib_print/src/main/assets/a5.pdf

@@ -0,0 +1,10 @@
+91321183MA1WNLAW6D                                  2023 03 22
+91440300597793399Q
+                    /1*<376*8>591+0-58*70862>72
+                    8//</51/>/-8883185<>9/66923
+                    78963/79518>7*541+4<2+/-*15
+                    2/3+1>><1*7*/5-/>2698189095
+
+                    ¥174.13             ¥22.65
+                               ¥196.78
+

+ 83 - 0
lib_print/src/main/assets/testpdf2page.pdf

@@ -0,0 +1,83 @@
+测试页          xxxxxx
+
+黑体二号 (黑体小六)  xx1 科技打印测试页
+
+      五号===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携热敏打印机。
+宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热敏打印机。黑体,这是世界
+上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上最轻的 A4 便携热敏打印机。五号粗体===等线中文,这
+是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携热敏打印机。宋体,这是世界上最轻的
+A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印
+机。微软雅黑,这是世界上最轻的 A4 便携热敏打印机。
+
+      小四===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携
+热敏打印机。宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热
+
+敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上最轻的 A4 便携
+
+热敏打印机。小四粗体===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上
+最轻的 A4 便携热敏打印机。宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最
+
+轻的 A4 便携热敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上
+
+最轻的 A4 便携热敏打印机。
+
+      10.5 号 === 等 线 ,Hello World , This is the world lightest portable A4 Thermal Printer-JXM800R-08Times New
+Roman, This is the world lightest portable A4 Thermal Priner-JXM800R-08Arial, This is the world lightest portable
+A4 Thermal Priner-JXM800R-08Verdana, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Calibri, This is the world lightest portable A4 Thermal Priner-JXM800R-08Cambria, This is the
+
+world lightest portable A4 Thermal Priner-JXM800R-08Adobe Devanagari, This is the world lightest
+
+portable A4 Thermal Priner-JXM800R-08
+
+      12 号等线,Hello World,This is the world lightest portable A4 Thermal Printer-JXM800R-08Times
+New Roman, This is the world lightest portable A4 Thermal Priner-JXM800R-08Arial, This is the
+world lightest portable A4 Thermal Priner-JXM800R-08Verdana, This is the world lightest
+portable A4 Thermal Priner-JXM800R-08Calibri, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Cambria, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Adobe Devanagari, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08
+
+             第1页
+测试页          xxxxxx
+
+黑体二号 (黑体小六)  xx2 科技打印测试页
+
+      五号===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携热敏打印机。
+宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热敏打印机。黑体,这是世界
+上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上最轻的 A4 便携热敏打印机。五号粗体===等线中文,这
+是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携热敏打印机。宋体,这是世界上最轻的
+A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印
+机。微软雅黑,这是世界上最轻的 A4 便携热敏打印机。
+
+      小四===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上最轻的 A4 便携
+热敏打印机。宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最轻的 A4 便携热
+
+敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上最轻的 A4 便携
+
+热敏打印机。小四粗体===等线中文,这是世界上最轻的 A4 便携热敏打印机。楷体,这是世界上
+最轻的 A4 便携热敏打印机。宋体,这是世界上最轻的 A4 便携热敏打印机。仿宋,这是世界上最
+
+轻的 A4 便携热敏打印机。黑体,这是世界上最轻的 A4 便携热敏打印机。微软雅黑,这是世界上
+
+最轻的 A4 便携热敏打印机。
+
+      10.5 号 === 等 线 ,Hello World , This is the world lightest portable A4 Thermal Printer-JXM800R-08Times New
+Roman, This is the world lightest portable A4 Thermal Priner-JXM800R-08Arial, This is the world lightest portable
+A4 Thermal Priner-JXM800R-08Verdana, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Calibri, This is the world lightest portable A4 Thermal Priner-JXM800R-08Cambria, This is the
+
+world lightest portable A4 Thermal Priner-JXM800R-08Adobe Devanagari, This is the world lightest
+
+portable A4 Thermal Priner-JXM800R-08
+
+      12 号等线,Hello World,This is the world lightest portable A4 Thermal Printer-JXM800R-08Times
+New Roman, This is the world lightest portable A4 Thermal Priner-JXM800R-08Arial, This is the
+world lightest portable A4 Thermal Priner-JXM800R-08Verdana, This is the world lightest
+portable A4 Thermal Priner-JXM800R-08Calibri, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Cambria, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08Adobe Devanagari, This is the world lightest portable A4 Thermal
+Priner-JXM800R-08
+
+             第1页
+

+ 15 - 12
lib_print/src/main/java/com/common/print/BasePrinter.java

@@ -3,17 +3,19 @@ package com.common.print;
 
 import android.content.Context;
 import android.os.Handler;
-import android.util.Log;
 
 import com.common.arome.Constants;
 import com.common.arome.DeviceUtils;
 import com.common.lib_base.common.async.ThreadPoolManager;
 import com.common.lib_base.utils.StringUtils;
+import com.common.lib_base.utils.log.CommonLogUtils;
 import com.common.print.callback.PrintInitResultCallback;
-import com.common.print.many.MlaPrinter;
+//import com.common.print.many.KMlaA4Printer;
+//import com.common.print.many.MlaA4Printer;
+import com.common.print.many.MlaFCDD215Printer;
 import com.common.print.many.NullPrinter;
 import com.common.print.many.TbPrinter;
-import com.telpo.tps508.PrintContentBean;
+import com.common.print.bean.PrintContentBean;
 //import com.telpo.tps550.api.printer.UsbThermalPrinter;
 
 import java.util.ArrayList;
@@ -51,11 +53,13 @@ public class BasePrinter {
 
     public IPrinter getPrinter(Context context) {
         String model = DeviceUtils.getDeviceModel();
-        Log.e(mTag,"model:"+model);
+        CommonLogUtils.e(mTag,"model:"+model);
 
         if (Constants.DeviceModel.T1YB01.equals(model)) {
             // y9
-            iPrinter = MlaPrinter.getInstance(context);
+//            iPrinter = MlaPrinter.getInstance(context);
+            iPrinter = MlaFCDD215Printer.getInstance(context);
+//            iPrinter = KMlaA4Printer.Companion.getInstance(context);
         } else if(Constants.DeviceModel.D2.equals(model)) {
             // 天波
             iPrinter = TbPrinter.getInstance(context);
@@ -104,12 +108,12 @@ public class BasePrinter {
 
         if(printContentData == null || printContentData.size() == 0){
 
-            Log.e(mTag,"printContentData == null");
+            CommonLogUtils.e("printContentData == null");
             return;
         }
 
         if(iPrinter == null){
-            Log.e(mTag,"iPrinter == null");
+            CommonLogUtils.e("iPrinter == null");
             return;
         }
 
@@ -126,19 +130,18 @@ public class BasePrinter {
             }
         });
 
-
-
-
     }
 
     private void startPrint() {
 
 
-        Log.e(mTag,"startPrint");
+        CommonLogUtils.e("startPrint");
 
         iPrinter.startPrint();
 
+        // 打印时间
         int printTotalTime = 0;
+        // 循环打印,并累计打印时间
         for (int i = 0; i < printContentList.size(); i++) {
             PrintContentBean printContentBean = printContentList.get(i);
 
@@ -192,7 +195,7 @@ public class BasePrinter {
 
         }
 
-        Log.e(mTag,"cutPaper");
+        CommonLogUtils.e("cutPaper");
         // 打印完并切纸
         iPrinter.cutPaper();
 

+ 9 - 0
lib_print/src/main/java/com/common/print/IPrinter.java

@@ -1,7 +1,10 @@
 package com.common.print;
 
+import com.common.print.bean.PrintBean;
 import com.common.print.callback.PrintInitResultCallback;
 
+import java.util.List;
+
 /**
  * 打印基本接口
  */
@@ -37,6 +40,12 @@ public interface IPrinter {
      */
     void printBitmap(String base64,int width,int height);
 
+    /**
+     * 将所有文字和图片转成一个Bitmap去打印
+     * @param printBean
+     */
+//    void printTextBitmap(PrintBean.PrintListDTO printBean);
+
     /**
      * 走纸
      * 打印空行

+ 23 - 0
lib_print/src/main/java/com/common/print/PrintApplication.java

@@ -0,0 +1,23 @@
+package com.common.print;
+
+import com.common.lib_base.CommonApplication;
+import com.common.lib_base.utils.log.CommonLogUtils;
+import com.jx800r09.sdk_800r09_library.listener.UsbDeviceListener;
+import com.jx800r09.sdk_800r09_library.usb.UsbDeviceManager;
+
+public class PrintApplication extends CommonApplication {
+
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+
+        CommonLogUtils.e("PrintApplication");
+
+        UsbDeviceManager.getInstance().init(this);
+        UsbDeviceManager.getInstance().setUsbDeviceCallBack(new UsbDeviceListener());
+
+
+
+    }
+}

+ 106 - 0
lib_print/src/main/java/com/common/print/bean/PrintBean.java

@@ -0,0 +1,106 @@
+package com.common.print.bean;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.List;
+
+public class PrintBean {
+
+
+    private PrintConfigDTO printConfig;
+    private List<PrintListDTO> printList;
+
+    public PrintConfigDTO getPrintConfig() {
+        return printConfig;
+    }
+
+    public void setPrintConfig(PrintConfigDTO printConfig) {
+        this.printConfig = printConfig;
+    }
+
+    public List<PrintListDTO> getPrintList() {
+        return printList;
+    }
+
+    public void setPrintList(List<PrintListDTO> printList) {
+        this.printList = printList;
+    }
+
+    public static class PrintConfigDTO {
+        private int printPageType;
+        private int printPotency;
+        private int printSpeed;
+
+        public int getPrintPageType() {
+            return printPageType;
+        }
+
+        public void setPrintPageType(int printPageType) {
+            this.printPageType = printPageType;
+        }
+
+        public int getPrintPotency() {
+            return printPotency;
+        }
+
+        public void setPrintPotency(int printPotency) {
+            this.printPotency = printPotency;
+        }
+
+        public int getPrintSpeed() {
+            return printSpeed;
+        }
+
+        public void setPrintSpeed(int printSpeed) {
+            this.printSpeed = printSpeed;
+        }
+    }
+
+    public static class PrintListDTO {
+        private String text;
+        private int textSize;
+        private boolean bold;
+        private int xPosition;
+        private int yPosition;
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+
+        public int getTextSize() {
+            return textSize;
+        }
+
+        public void setTextSize(int textSize) {
+            this.textSize = textSize;
+        }
+
+        public boolean isBold() {
+            return bold;
+        }
+
+        public void setBold(boolean bold) {
+            this.bold = bold;
+        }
+
+        public int getXPosition() {
+            return xPosition;
+        }
+
+        public void setXPosition(int xPosition) {
+            this.xPosition = xPosition;
+        }
+
+        public int getYPosition() {
+            return yPosition;
+        }
+
+        public void setYPosition(int yPosition) {
+            this.yPosition = yPosition;
+        }
+    }
+}

+ 1 - 1
lib_print/src/main/java/com/telpo/tps508/PrintContentBean.java → lib_print/src/main/java/com/common/print/bean/PrintContentBean.java

@@ -1,4 +1,4 @@
-package com.telpo.tps508;
+package com.common.print.bean;
 
 public class PrintContentBean {
     private String text;

+ 8 - 9
lib_print/src/main/java/com/common/print/many/MlaPrinter.java → lib_print/src/main/java/com/common/print/many/Mla80Printer.java

@@ -6,7 +6,6 @@ import android.hardware.usb.UsbDevice;
 import android.hardware.usb.UsbManager;
 import android.util.Log;
 
-import com.common.lib_base.common.async.ThreadPoolManager;
 import com.common.print.IPrinter;
 import com.common.print.callback.PrintInitResultCallback;
 import com.common.print.utils.BitmapUtils;
@@ -19,37 +18,37 @@ import java.util.Map;
  *
  * 是乐易的打印机
  * 适用于以下设备
- * 马里奥-y9
+ * 马里奥-y9-80
  */
-public class MlaPrinter implements IPrinter {
+public class Mla80Printer implements IPrinter {
 
 
     // 当前类名
     public String mTag = "HHArome--"+getClass().getSimpleName() + "--";
 
     //用volatile关键字确保 instance 在多线程下的可见性
-    private static volatile MlaPrinter instance = null;
+    private static volatile Mla80Printer instance = null;
 
     //将构造方法私有化,禁止外部通过构造方法创建实例
-    private MlaPrinter() {
+    private Mla80Printer() {
     }
 
     //提供一个公共的访问方法,用于获取该类的唯一实例
-    public static MlaPrinter getInstance(Context context) {
+    public static Mla80Printer getInstance(Context context) {
         //如果instance为空,就进行实例化
         if (instance == null) {
             //保证多线程下只有一个线程进行实例化
-            synchronized (MlaPrinter.class) {
+            synchronized (Mla80Printer.class) {
                 //第二次判断,避免多线程下创建多个实例
                 if (instance == null) {
-                    instance = new MlaPrinter(context);
+                    instance = new Mla80Printer(context);
                 }
             }
         }
         return instance;
     }
 
-    private MlaPrinter(Context context) {
+    private Mla80Printer(Context context) {
         this.mContext = context;
     }
 

+ 631 - 0
lib_print/src/main/java/com/common/print/many/MlaFCDD215Printer.java

@@ -0,0 +1,631 @@
+package com.common.print.many;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.hardware.usb.UsbDevice;
+import android.os.Handler;
+
+import com.common.lib_base.utils.StringUtils;
+import com.common.lib_base.utils.log.CommonLogUtils;
+import com.common.lib_base.utils.ui.ToastUtils;
+import com.common.print.IPrinter;
+import com.common.print.callback.PrintInitResultCallback;
+import com.common.print.utils.BitmapUtils;
+import com.common.print.utils.CodeUtils;
+import com.jx800r09.sdk_800r09_library.bean.PrintDataBean;
+import com.jx800r09.sdk_800r09_library.enumdata.PageTypeEnum;
+import com.jx800r09.sdk_800r09_library.enumdata.PrintingStateEnum;
+import com.jx800r09.sdk_800r09_library.listener.UsbDeviceListener;
+import com.jx800r09.sdk_800r09_library.task.UsbPrintPdfThreadTask;
+import com.jx800r09.sdk_800r09_library.task.UsbPrintPictureThreadTask;
+import com.jx800r09.sdk_800r09_library.usb.UsbDeviceManager;
+import com.jx800r09.sdk_800r09_library.utils.PrinterNameUtil;
+import com.jx800r09.sdk_800r09_library.utils.ThreadUtils;
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 是福创达(富芯)科技的打印机-型号FCD-D215
+ * 适用于以下设备
+ * 马里奥-y9-A4热敏
+ */
+public class MlaFCDD215Printer implements IPrinter {
+
+
+    // 当前类名
+    public String mTag = "HHArome--" + getClass().getSimpleName() + "--";
+
+    //用volatile关键字确保 instance 在多线程下的可见性
+    private static volatile MlaFCDD215Printer instance = null;
+
+    //将构造方法私有化,禁止外部通过构造方法创建实例
+    private MlaFCDD215Printer() {
+    }
+
+    //提供一个公共的访问方法,用于获取该类的唯一实例
+    public static MlaFCDD215Printer getInstance(Context context) {
+        //如果instance为空,就进行实例化
+        if (instance == null) {
+            //保证多线程下只有一个线程进行实例化
+            synchronized (MlaFCDD215Printer.class) {
+                //第二次判断,避免多线程下创建多个实例
+                if (instance == null) {
+                    instance = new MlaFCDD215Printer(context);
+                }
+            }
+        }
+        return instance;
+    }
+
+    private MlaFCDD215Printer(Context context) {
+        this.mContext = context;
+
+        init(context);
+    }
+
+
+    Context mContext;
+
+
+    int retryCount = 0;
+    boolean isInitSuccess;
+
+    Handler mHandler = new Handler();
+
+    public void init(Context context) {
+
+
+        CommonLogUtils.e("A4-init");
+
+        UsbDeviceManager.getInstance().init(context);
+        UsbDeviceManager.getInstance().setUsbDeviceCallBack(new UsbDeviceListener());
+
+
+        mHandler.postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                CommonLogUtils.e("执行getDevice");
+                getDevice(UsbDeviceManager.getInstance().getAllUseDeviceHp());
+            }
+        },2000);
+
+
+
+
+        // printInitResultCallback.onPrintInitSuccess();
+        // printInitResultCallback.onPrintInitError("-1","找不到USB打印机,请检查USB线连接");
+
+
+    }
+
+
+    PrintInitResultCallback printInitResultCallback;
+
+    @Override
+    public void initPrint(PrintInitResultCallback printInitResultCallback) {
+
+        this.printInitResultCallback = printInitResultCallback;
+
+        init(mContext);
+
+    }
+
+
+    List<PrintDataBean> picturePrintTask = new ArrayList();
+
+    @Override
+    public void printText(String text, int align, int textSize, boolean isBold) {
+
+
+        CommonLogUtils.e("text--" + text);
+
+        PrintDataBean printDataBean = new PrintDataBean();
+
+
+        // 文字转Bitmap
+//        Bitmap textToBimtap = BitmapUtils.createTextToBimtap(text, 2397, 1678);
+
+
+
+        if(0 == textSize){
+            textSize = 18;
+        }else if(textSize > 20){
+            textSize = textSize-20;
+        }
+
+        Bitmap textToBimtap = BitmapUtils.textPositionToBitmap(mContext,text,80,100,200);
+
+        // 设定打印浓度,不设置默认为5
+        printDataBean.setPotency(5);
+        // 设定打印速度,不设置默认为5
+        printDataBean.setSpeed(3);
+
+        printDataBean.setBitmap(textToBimtap);
+        // 给定想打印的纸张规格
+        printDataBean.setPageTypeEnum(PageTypeEnum.Page_Type_A5_Normal);
+        // 设定打印居中位置 0左边 1居中 2居右 不设置默认1
+        printDataBean.setHorAlignment(align);
+        //当出现打印过程中缺纸,是否重新打印上一页 默认为false ,不会重新打印该页
+        printDataBean.setReprintLastPage(true);
+
+        picturePrintTask.clear();
+        picturePrintTask.add(printDataBean);
+
+
+        UsbPrintPictureThreadTask pictureThreadTask = new UsbPrintPictureThreadTask(picturePrintTask, new UsbPrintPictureThreadTask.IPrinterListener() {
+            @Override
+            public void onPage(int i, int i1) {
+
+            }
+
+            @Override
+            public void onPrintCopies(int i, int i1) {
+
+            }
+
+            @Override
+            public void onStep(int i, int i1) {
+
+            }
+
+            @Override
+            public void onDeviceStatus(String s) {
+
+            }
+
+            @Override
+            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+
+            }
+
+
+            @Override
+            public void onCompleted() {
+
+            }
+        });
+
+        // 应该是打印次数
+        pictureThreadTask.setPrintCopies(1);
+
+
+        ThreadUtils.executeByCpu(pictureThreadTask);
+
+
+    }
+
+    @Override
+    public void printBarCode(String text, int width, int height) {
+
+
+    }
+
+    @Override
+    public void printQrCode(String text, int width, int height) {
+
+        Bitmap bitmap = CodeUtils.createQRCodeBitmap(text,
+                800,
+                800,
+                "UTF-8",
+                "M",
+                "1",
+                Color.BLACK, Color
+                        .WHITE
+                , null,
+                0.2F,
+                null);
+
+        if (width == 0) {
+            width = 376;
+        }
+        if (height == 0) {
+            height = 376;
+        }
+        Bitmap zoomImg = BitmapUtils.zoomImg(bitmap,
+                width,
+                height);
+
+
+        PrintDataBean printDataBean = new PrintDataBean();
+
+
+        // 设定打印浓度,不设置默认为5
+        printDataBean.setPotency(5);
+        // 设定打印速度,不设置默认为5
+        printDataBean.setSpeed(3);
+
+        printDataBean.setBitmap(zoomImg);
+        // 给定想打印的纸张规格
+        printDataBean.setPageTypeEnum(PageTypeEnum.Page_Type_A4_Normal);
+        // 设定打印居中位置 0左边 1居中 2居右 不设置默认1
+        printDataBean.setHorAlignment(1);
+        //当出现打印过程中缺纸,是否重新打印上一页 默认为false ,不会重新打印该页
+        printDataBean.setReprintLastPage(true);
+
+        picturePrintTask.clear();
+        picturePrintTask.add(printDataBean);
+
+
+        UsbPrintPictureThreadTask pictureThreadTask = new UsbPrintPictureThreadTask(picturePrintTask, new UsbPrintPictureThreadTask.IPrinterListener() {
+            @Override
+            public void onPage(int i, int i1) {
+
+            }
+
+            @Override
+            public void onPrintCopies(int i, int i1) {
+
+            }
+
+            @Override
+            public void onStep(int i, int i1) {
+
+            }
+
+            @Override
+            public void onDeviceStatus(String s) {
+
+            }
+
+            @Override
+            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+
+            }
+
+
+            @Override
+            public void onCompleted() {
+
+            }
+        });
+
+        // 应该是打印次数
+        pictureThreadTask.setPrintCopies(1);
+
+
+        ThreadUtils.executeByCpu(pictureThreadTask);
+
+
+    }
+
+    @Override
+    public void printBitmap(String base64, int width, int height) {
+
+        CommonLogUtils.e("printBitmap");
+
+        if(StringUtils.isNull(base64)){
+            ToastUtils.showLongToast("图片参数为空");
+            return;
+        }
+
+        picturePrintTask.clear();
+
+        Bitmap bitmap;
+
+
+        // 横屏图片
+//        base64 = "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1oTBz1.img?w=604&h=486&m=6&x=194&y=159&s=183&d=183";
+
+        // 竖屏
+        base64 = "https://tse4-mm.cn.bing.net/th/id/OIP-C.VC96IQ53w1EhF5yR442lGAHaNK?w=115&h=180&c=7&r=0&o=5&dpr=1.5&pid=1.7";
+
+        if(base64.contains("http")){
+            bitmap = BitmapUtils.urlToBitmap(base64);
+        }else{
+            bitmap = BitmapUtils.stringToBitmap(base64);
+        }
+
+//        Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.a4_img);
+
+        PrintDataBean printDataBean = new PrintDataBean();
+
+        // 设定打印浓度,不设置默认为5
+        printDataBean.setPotency(3);
+        // 设定打印速度,不设置默认为5。打印速度越低,对电压要求越低
+        printDataBean.setSpeed(2);
+        // 给定想打印的纸张规格
+        printDataBean.setPageTypeEnum(PageTypeEnum.Page_Type_A4_Normal);
+        // 设定打印居中位置 0左边 1居中 2居右 不设置默认1
+        printDataBean.setHorAlignment(1);
+        //当出现打印过程中缺纸,是否重新打印上一页 默认为false ,不会重新打印该页
+        printDataBean.setReprintLastPage(true);
+        // 设置打印的图片
+        printDataBean.setBitmap(bitmap);
+
+
+        picturePrintTask.add(printDataBean);
+
+
+        UsbPrintPictureThreadTask pictureThreadTask = new UsbPrintPictureThreadTask(picturePrintTask, new UsbPrintPictureThreadTask.IPrinterListener() {
+            @Override
+            public void onPage(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onPrintCopies(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onStep(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onDeviceStatus(String s) {
+                CommonLogUtils.e("s = " + s);
+            }
+
+            @Override
+            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+
+            }
+
+//            @Override
+//            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+//                CommonLogUtils.e("printingStateEnum = " + printingStateEnum.getMsg());
+//            }
+
+            @Override
+            public void onCompleted() {
+                CommonLogUtils.e("onCompleted = ");
+
+                cutPaper();
+            }
+        });
+
+        // 应该是打印次数
+        pictureThreadTask.setPrintCopies(1);
+
+
+        ThreadUtils.executeByCpu(pictureThreadTask);
+
+    }
+
+
+
+    public void printPdf(){
+
+        CommonLogUtils.e("printPdf");
+
+        picturePrintTask.clear();
+//        Bitmap bitmap = BitmapUtils.stringToBitmap(base64);
+
+
+        PrintDataBean printDataBean = new PrintDataBean();
+
+        // 设定打印浓度,不设置默认为5
+        printDataBean.setPotency(5);
+        // 设定打印速度,不设置默认为5
+        printDataBean.setSpeed(3);
+        // 给定想打印的纸张规格
+        printDataBean.setPageTypeEnum(PageTypeEnum.Page_Type_A4_Normal);
+        // 设定打印居中位置 0左边 1居中 2居右 不设置默认1   设置该行,会导致右边的一部分内容会移动到左边
+//        printDataBean.setHorAlignment(1);
+        //当出现打印过程中缺纸,是否重新打印上一页 默认为false ,不会重新打印该页
+        printDataBean.setReprintLastPage(true);
+        // 设置打印的pdf
+//        printDataBean.setFilePath(copyAssetGetFilePath("a4_p.pdf"));
+        printDataBean.setFilePath(copyAssetGetFilePath("a4_cs.pdf"));
+
+
+        UsbPrintPdfThreadTask pdfThreadTask = new UsbPrintPdfThreadTask(printDataBean, new UsbPrintPdfThreadTask.IPrinterListener() {
+            @Override
+            public void onPage(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onPrintCopies(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onStep(int i, int i1) {
+//                CommonLogUtils.e("i = "+i,
+//                        "i1 = "+i1);
+            }
+
+            @Override
+            public void onDeviceStatus(String s) {
+                CommonLogUtils.e("s = " + s);
+            }
+
+            @Override
+            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+
+            }
+
+//            @Override
+//            public void onPrintProcessState(PrintingStateEnum printingStateEnum) {
+//                CommonLogUtils.e("printingStateEnum = " + printingStateEnum.getMsg());
+//            }
+
+            @Override
+            public void onCompleted() {
+                CommonLogUtils.e("onCompleted = ");
+            }
+        });
+
+        // 应该是打印次数
+        pdfThreadTask.setPrintCopies(1);
+
+
+        ThreadUtils.executeByCpu(pdfThreadTask);
+
+    }
+
+
+
+    @Override
+    public void feed(int line) {
+        // 走纸
+        if(0 == line){
+            line = 1;
+        }
+
+        for (int i = 0; i < line; i++) {
+            UsbDeviceManager.getInstance().sendPrinterStep();
+        }
+
+
+
+    }
+
+    @Override
+    public void cutPaper() {
+
+
+        feed(1);
+
+        CommonLogUtils.e("cutPaper");
+
+        mHandler.postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                UsbDeviceManager.getInstance().sendCutter();
+            }
+        },1000);
+
+
+    }
+
+    @Override
+    public void disconnect() {
+
+
+    }
+
+    @Override
+    public void startPrint() {
+
+
+    }
+
+
+    private void getDevice(HashMap<String, UsbDevice> allUseDevice) {
+
+        CommonLogUtils.e("allUseDevice.size = " + allUseDevice.size());
+
+
+
+        boolean isContain09 = false;
+
+        Iterator<Map.Entry<String, UsbDevice>> iterator = allUseDevice.entrySet().iterator();
+
+
+        while (iterator.hasNext()) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String key = (String) entry.getKey();
+            UsbDevice value = (UsbDevice) entry.getValue();
+
+            CommonLogUtils.e("key = " + key,
+                    "key = " + value);
+
+            if (PrinterNameUtil.startWithName(value.getProductName())) {
+                isContain09 = true;
+
+                UsbDeviceManager.getInstance().reqPermission(value);
+
+                CommonLogUtils.e(
+                        "deviceName=" + value.getDeviceName(),
+                        "productName =" + value.getProductName());
+            }
+        }
+
+
+        for (String key : allUseDevice.keySet()) {
+            CommonLogUtils.e("for-map-key:" + key);
+            UsbDevice usbDevice = allUseDevice.get(key);
+            if (PrinterNameUtil.startWithName(usbDevice.getProductName())){
+                CommonLogUtils.e(
+                        "for-deviceName=" + usbDevice.getDeviceName(),
+                        "for-productName =" + usbDevice.getProductName());
+            }
+
+        }
+
+
+        if (UsbDeviceManager.getInstance().isConnect()) {
+            CommonLogUtils.e("A4-已连接");
+            if(printInitResultCallback!=null){
+                printInitResultCallback.onPrintInitSuccess();
+            }
+        } else {
+            CommonLogUtils.e("A4-未连接");
+            if(printInitResultCallback!=null){
+                printInitResultCallback.onPrintInitError("-1","A4热敏打印机未连接");
+            }
+        }
+
+
+    }
+
+
+    public String copyAssetGetFilePath(String fileName){
+
+        try {
+            File cacheDir = mContext.getCacheDir();
+            if (!cacheDir.exists()) {
+                cacheDir.mkdirs();
+            }
+
+            File outFile = new File(cacheDir, fileName);
+            if (!outFile.exists()) {
+                    boolean res = outFile.createNewFile();
+                if (!res) {
+                    return null;
+                }
+            } else {
+                if (outFile.length() > 10) { //表示已经写入一次
+                    return outFile.getPath();
+                }
+            }
+
+            InputStream is = mContext.getAssets().open(fileName);
+            FileOutputStream fos = new FileOutputStream(outFile);
+
+            byte[] buffer = new byte[1024]; // 一个字节数组
+
+            int byteCount=0;
+            while (( byteCount=is.read(buffer) ) != -1 ){
+                fos.write(buffer,0,byteCount);
+            }
+
+            fos.flush();
+            is.close();
+            fos.close();
+            return outFile.getPath();
+        }catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+
+
+
+    }
+
+
+
+
+
+
+
+
+}

+ 288 - 0
lib_print/src/main/java/com/common/print/utils/BitmapUtils.java

@@ -1,29 +1,62 @@
 package com.common.print.utils;
 
+import android.annotation.SuppressLint;
+import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
 import android.os.Build;
+import android.os.Handler;
+import android.text.Layout;
+import android.text.StaticLayout;
+import android.text.TextPaint;
 import android.util.Base64;
 import android.util.Log;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.content.res.ResourcesCompat;
+
 import com.blankj.utilcode.util.FileIOUtils;
 import com.blankj.utilcode.util.FileUtils;
 import com.blankj.utilcode.util.PathUtils;
+import com.blankj.utilcode.util.ToastUtils;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.target.CustomTarget;
+import com.bumptech.glide.request.transition.Transition;
 import com.common.lib_base.common.async.ThreadPoolManager;
+import com.common.print.R;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParser;
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Hashtable;
 import java.util.Locale;
+import java.util.concurrent.ExecutionException;
+
+import static android.graphics.Bitmap.createBitmap;
 
 public class BitmapUtils {
 
@@ -57,6 +90,8 @@ public class BitmapUtils {
 
 //        fileName = "a1.png";
 
+
+
         return fileName;
     }
 
@@ -132,4 +167,257 @@ public class BitmapUtils {
 
 
 
+    /**
+     * 根据文字创建一个 bitmap  , 打印的位图需要 黑字 白底
+     *
+     * @param text
+     * @param height
+     * @param width
+     * @return
+     */
+    public static Bitmap createTextToBimtap(String text, int height, int width) {
+        Bitmap newBitmap = createBitmap(width, height, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(newBitmap);
+        canvas.drawColor(Color.WHITE);
+
+        canvas.drawBitmap(newBitmap, 0, 0, null);
+        TextPaint textPaint = new TextPaint();
+        //       String familyName ="宋体";
+        //  Typeface font = Typeface.create(familyName,Typeface.BOLD);
+        // textPaint.setTypeface(font);
+        textPaint.setAntiAlias(true);
+        textPaint.setTextSize(height * 2 / 3);
+//        textPaint.setColor(Color.rgb(0, 0, 0));
+        textPaint.setColor(Color.BLACK);
+        //     "在Android开发中,Canvas.drawText不会换行,即使一个很长的字符串也只会显示一行,超出部分会隐藏在屏幕之外.StaticLayout是android中处理文字的一个工具类,StaticLayout 处理了文字换行的问题";
+        StaticLayout sl = new StaticLayout(text, textPaint, newBitmap.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
+        textPaint.setStyle(Paint.Style.FILL);
+        canvas.translate(0, height / 10);
+        sl.draw(canvas);
+        return newBitmap;
+    }
+
+
+
+    public static Bitmap generateBitmap(String text,int textSizePx){
+        TextPaint textPaint = new TextPaint();
+        textPaint.setTextSize(textSizePx);
+        textPaint.setColor(Color.WHITE);
+        int width = (int) Math.ceil(textPaint.measureText(text));
+        Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
+        int height = (int) Math.ceil(Math.abs(fontMetrics.bottom) + Math.abs(fontMetrics.top));
+        Bitmap bitmap = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(bitmap);
+        canvas.drawText(text,0,Math.abs(fontMetrics.ascent),textPaint);
+        return bitmap;
+    }
+
+
+
+    public static Bitmap textToBimtap(String text,int textSizePx){
+
+        TextPaint textPaint = new TextPaint();
+        textPaint.setTextSize(20);
+        textPaint.setColor(Color.BLACK);
+        int width = (int) Math.ceil(textPaint.measureText(text));
+        Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
+        int height = (int) Math.ceil(Math.abs(fontMetrics.bottom) + Math.abs(fontMetrics.top));
+
+        Bitmap bitmap = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(bitmap);
+
+        canvas.rotate(180);
+        canvas.save();
+
+        canvas.drawColor(Color.WHITE);
+        canvas.drawText(text,0,Math.abs(fontMetrics.ascent),textPaint);
+
+        return bitmap;
+    }
+
+
+    public static Bitmap textPositionToBitmap(Context context,String text,int textSize,int xPosition,int yPosition){
+
+
+        TextPaint textPaint = new TextPaint();
+        // 80
+        textPaint.setTextSize(textSize);
+        textPaint.setColor(Color.BLACK);
+
+        Typeface typeface = ResourcesCompat.getFont(context, R.font.songti);
+        textPaint.setTypeface(typeface);// 采用自定义的字体
+//        int width = (int) Math.ceil(textPaint.measureText(text));
+//        Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
+//        int height = (int) Math.ceil(Math.abs(fontMetrics.bottom) + Math.abs(fontMetrics.top));
+
+        // bitmap的width=1678 height=2397
+        Bitmap bitmap = Bitmap.createBitmap(2000,2000, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(bitmap);
+
+        canvas.drawColor(Color.WHITE);
+//        canvas.drawText(text,0,Math.abs(fontMetrics.ascent),textPaint);
+
+        canvas.drawText(text,xPosition,yPosition,textPaint);
+
+        canvas.save();
+
+        return bitmap;
+
+    }
+
+
+
+//    public static Bitmap textPositionToBitmap(String text,int pos1,int pos2){
+//
+//
+//        TextPaint textPaint = new TextPaint();
+//        textPaint.setTextSize(80);
+//        textPaint.setColor(Color.BLACK);
+//        int width = (int) Math.ceil(textPaint.measureText(text));
+//        Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
+//        int height = (int) Math.ceil(Math.abs(fontMetrics.bottom) + Math.abs(fontMetrics.top));
+//
+//
+//        ToastUtils.showLong("text:"+text+"   width:"+width+"  height:"+height);
+//
+//        Bitmap bitmap = Bitmap.createBitmap(2000,2000, Bitmap.Config.ARGB_8888);
+//        Canvas canvas = new Canvas(bitmap);
+//
+////        canvas.rotate(180);
+////        canvas.save();
+//
+//        canvas.drawColor(Color.WHITE);
+////        canvas.drawText(text,0,Math.abs(fontMetrics.ascent),textPaint);
+//
+//        canvas.drawText(text,pos1,pos2,textPaint);
+//
+//        canvas.save();
+//
+//        return bitmap;
+//
+//    }
+
+
+
+    /**
+     * 生成二维码bitmap 要转换的地址或字符串,可以是中文
+     *
+     * @param url
+     * @param width
+     *
+     * @param height
+     * @return
+     */
+    public static Bitmap createQRImage(String url, final int width, final int height) {
+        try {
+            // 判断URL合法性
+            if (url == null || "".equals(url) || url.length() < 1) {
+                return null;
+            }
+            Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
+            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
+            // 图像数据转换,使用了矩阵转换
+            BitMatrix bitMatrix = new QRCodeWriter().encode(url,
+                    BarcodeFormat.QR_CODE, width, height, hints);
+            int[] pixels = new int[width * height];
+            // 下面这里按照二维码的算法,逐个生成二维码的图片,
+            // 两个for循环是图片横列扫描的结果
+            for (int y = 0; y < height; y++) {
+                for (int x = 0; x < width; x++) {
+                    if (bitMatrix.get(x, y)) {
+                        pixels[y * width + x] = 0xff000000;
+                    } else {
+                        pixels[y * width + x] = 0xffffffff;
+                    }
+                }
+            }
+            // 生成二维码图片的格式,使用ARGB_8888
+            Bitmap bitmap = createBitmap(width, height,
+                    Bitmap.Config.ARGB_8888);
+            bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
+            return bitmap;
+        } catch (WriterException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+
+//    static Handler mHandler = new Handler();
+//
+//    public static Bitmap urlToBitmap(final Context context,final String imgUrl){
+//
+//
+//        final Bitmap bitmap = null;
+//
+//        ThreadPoolManager.getInstance().executeIOTask(new Runnable() {
+//            @Override
+//            public void run() {
+//                try {
+//
+//                    // 子线程获取url对应的bitmap
+//                    final Bitmap curBitmap = Glide.with(context)
+//                            .asBitmap()
+//                            .load(imgUrl)
+//                            .submit().get();
+//
+//                    bitmap = curBitmap;
+//
+//                    return curBitmap;
+//
+//
+//                } catch (ExecutionException e) {
+//                    e.printStackTrace();
+//                } catch (InterruptedException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//        });
+//    }
+
+
+
+
+
+    private static Bitmap bitmap;
+
+    public static Bitmap urlToBitmap(final String url){
+
+
+        ThreadPoolManager.getInstance().executeIOTask(new Runnable() {
+            @Override
+            public void run() {
+                URL imageurl = null;
+
+                try {
+
+                    imageurl = new URL(url);
+                } catch (MalformedURLException e) {
+
+                    e.printStackTrace();
+                }
+                try {
+
+                    HttpURLConnection conn = (HttpURLConnection)imageurl.openConnection();
+                    conn.setDoInput(true);
+                    conn.connect();
+                    InputStream is = conn.getInputStream();
+                    bitmap = BitmapFactory.decodeStream(is);
+                    is.close();
+                } catch (IOException e) {
+
+                    e.printStackTrace();
+                }
+            }
+        });
+
+
+        return bitmap;
+    }
+
+
+
+
+
 }

+ 1 - 0
lib_print/src/main/java/com/telpo/tps508/PrintUtile.java

@@ -16,6 +16,7 @@ import androidx.fragment.app.FragmentActivity;
 
 import com.caverock.androidsvg.SVG;
 import com.caverock.androidsvg.SVGParseException;
+import com.common.print.bean.PrintContentBean;
 import com.common.print.utils.CodeUtils;
 import com.telpo.tps550.api.TelpoException;
 import com.telpo.tps550.api.printer.UsbThermalPrinter;

+ 1 - 1
lib_print/src/main/java/com/telpo/tps508/base/IPrintBase.java

@@ -4,7 +4,7 @@ import android.content.Context;
 import android.os.Build;
 import android.util.Log;
 
-import com.telpo.tps508.PrintContentBean;
+import com.common.print.bean.PrintContentBean;
 import com.telpo.tps508.PrintUtile;
 
 import java.util.List;

BIN
lib_print/src/main/res/drawable/a4_img.jpg


BIN
lib_print/src/main/res/drawable/test_100.jpg


BIN
lib_print/src/main/res/font/songti.ttf


+ 1 - 0
settings.gradle

@@ -1,3 +1,4 @@
+include ':LocalRepo'
 include ':lib_usb_qr'
 include ':lib_arome'
 include ':MultiReaderLib',':idCard',":recorderlib"

Some files were not shown because too many files changed in this diff