From a6f5c1af90b631809dcc8b1d3b8076499446fd08 Mon Sep 17 00:00:00 2001 From: “wangming” <“wangming@antissoft.com”> Date: Sun, 22 Mar 2026 13:59:13 +0800 Subject: [PATCH] 开发了安卓基座 --- Footsafety-Android | 1 + 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/AndroidSDKAPI.7z | Bin 0 -> 74127 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo-V3.3.1.apk | Bin 0 -> 4825671 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/.gitignore | 14 ++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/.gitignore | 1 + 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/build.gradle | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/libs/SDKLib.jar | Bin 0 -> 440661 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/proguard-rules.pro | 21 +++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/androidTest/java/com/printer/tscdemo/ExampleInstrumentedTest.java | 27 +++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/AndroidManifest.xml | 35 +++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/TSPL.bin | Bin 0 -> 2928 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/WalmartFile.pdf | Bin 0 -> 87512 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/esc.pdf | Bin 0 -> 777144 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BlueToothDeviceActivity.java | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BluetoothDeviceAdapter.java | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/MainActivity.java | 494 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PermissionUtils.java | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent.java | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent2.java | 413 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Printer.java | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SerialPortDeviceActivity.java | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SharedPreferencesUtil.java | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadFactoryBuilder.java | 30 ++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadPoolManager.java | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/UsbDeviceActivity.java | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Utils.java | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/WifiDeviceActivity.java | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/bean/BluetoothParameter.java | 30 ++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/arm64-v8a/libserial_port.so | Bin 0 -> 9904 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi-v7a/libserial_port.so | Bin 0 -> 13728 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi/libserial_port.so | Bin 0 -> 13488 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml | 34 ++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/flower.jpg | Bin 0 -> 15693 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/head.jpg | Bin 0 -> 29310 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/test.bmp | Bin 0 -> 791678 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_blue_tooth_device_list.xml | 11 +++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_bluetooth.xml | 18 ++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_main.xml | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_serial_port.xml | 39 +++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_usb.xml | 11 +++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_usb_list.xml | 11 +++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_wifi.xml | 32 ++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/bluetooth_list_item.xml | 43 +++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/dialog_wifi_config.xml | 21 +++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/page.xml | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/text_item.xml | 10 ++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml | 5 +++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml | 5 +++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_priter.png | Bin 0 -> 4194 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values-zh-rCN/strings.xml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/colors.xml | 6 ++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/strings.xml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/styles.xml | 11 +++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/test/java/com/printer/tscdemo/ExampleUnitTest.java | 17 +++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/build.gradle | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle.properties | 20 ++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle/wrapper/gradle-wrapper.properties | 6 ++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradlew | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradlew.bat | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/settings.gradle | 2 ++ 打印机安卓基座/README.md | 16 ++++++++++++++++ 打印机安卓基座/native-fast-printer/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/build-aar.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/PluginResult.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/SafeJson.java | 33 +++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/ThrowableUtils.java | 24 ++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/template/NativeTemplateCommandBuilder.java | 690 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/transport/GprinterBluetoothTransport.java | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/android/native_fast_printer-release.aar | Bin 0 -> 435668 bytes 打印机安卓基座/native-fast-printer/package.json | 37 +++++++++++++++++++++++++++++++++++++ 打印机安卓基座/native-fast-printer/sync-to-uniapp.sh | 15 +++++++++++++++ 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/android/native_fast_printer-release.aar | Bin 0 -> 435668 bytes 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/package.json | 37 +++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/manifest.json | 18 ++++++++++++++++-- 美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue | 35 +++++++++++++++++++++++++++++++---- 美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue | 5 +---- 美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 美国版/Food Labeling Management App UniApp/src/utils/print/nativeBitmapPatch.ts | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts | 262 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/protocols/escPosBuilder.ts | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ 美国版/Food Labeling Management App UniApp/src/utils/print/systemTemplateAdapter.ts | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 美国版/Food Labeling Management App UniApp/src/utils/print/templates/test.json | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- 美国版/Food Labeling Management App UniApp/src/utils/print/templates/testPrintTemplate.ts | 5 +---- 美国版/Food Labeling Management App UniApp/src/utils/print/tscLabelBuilder.ts | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- 美国版/Food Labeling Management App UniApp/src/utils/print/types/printer.ts | 8 ++++++++ 99 files changed, 6353 insertions(+), 109 deletions(-) create mode 160000 Footsafety-Android create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/AndroidSDKAPI.7z create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo-V3.3.1.apk create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/.gitignore create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/.gitignore create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/build.gradle create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/libs/SDKLib.jar create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/proguard-rules.pro create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/androidTest/java/com/printer/tscdemo/ExampleInstrumentedTest.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/AndroidManifest.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/TSPL.bin create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/WalmartFile.pdf create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/esc.pdf create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BlueToothDeviceActivity.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BluetoothDeviceAdapter.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/MainActivity.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PermissionUtils.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent2.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Printer.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SerialPortDeviceActivity.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SharedPreferencesUtil.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadFactoryBuilder.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadPoolManager.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/UsbDeviceActivity.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Utils.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/WifiDeviceActivity.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/bean/BluetoothParameter.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/arm64-v8a/libserial_port.so create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi-v7a/libserial_port.so create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi/libserial_port.so create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/flower.jpg create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/head.jpg create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/ic_launcher_background.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/test.bmp create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_blue_tooth_device_list.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_bluetooth.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_main.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_serial_port.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_usb.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_usb_list.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_wifi.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/bluetooth_list_item.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/dialog_wifi_config.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/page.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/text_item.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xhdpi/ic_priter.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values-zh-rCN/strings.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/colors.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/strings.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/values/styles.xml create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/test/java/com/printer/tscdemo/ExampleUnitTest.java create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/build.gradle create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle.properties create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle/wrapper/gradle-wrapper.jar create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradle/wrapper/gradle-wrapper.properties create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradlew create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/gradlew.bat create mode 100755 打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/settings.gradle create mode 100644 打印机安卓基座/README.md create mode 100644 打印机安卓基座/native-fast-printer/README.md create mode 100755 打印机安卓基座/native-fast-printer/android-src/build-aar.sh create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/PluginResult.java create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/SafeJson.java create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/support/ThrowableUtils.java create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/template/NativeTemplateCommandBuilder.java create mode 100644 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/transport/GprinterBluetoothTransport.java create mode 100644 打印机安卓基座/native-fast-printer/android/native_fast_printer-release.aar create mode 100644 打印机安卓基座/native-fast-printer/package.json create mode 100755 打印机安卓基座/native-fast-printer/sync-to-uniapp.sh create mode 100644 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/README.md create mode 100644 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/android/native_fast_printer-release.aar create mode 100644 美国版/Food Labeling Management App UniApp/nativeplugins/native-fast-printer/package.json create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/nativeBitmapPatch.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts diff --git a/Footsafety-Android b/Footsafety-Android new file mode 160000 index 0000000..f7a1368 --- /dev/null +++ b/Footsafety-Android @@ -0,0 +1 @@ +Subproject commit f7a136823cefd858d2d25a5e26e6a684cc1cbdcb diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/AndroidSDKAPI.7z b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/AndroidSDKAPI.7z new file mode 100755 index 0000000..45f07aa Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/AndroidSDKAPI.7z differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo-V3.3.1.apk b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo-V3.3.1.apk new file mode 100755 index 0000000..63b334b Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo-V3.3.1.apk differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/.gitignore b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/.gitignore new file mode 100755 index 0000000..603b140 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/.gitignore b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/.gitignore new file mode 100755 index 0000000..796b96d --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/build.gradle b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/build.gradle new file mode 100755 index 0000000..93a32c5 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.printer.tscdemo" + minSdkVersion 18 + targetSdkVersion 29 + versionCode 32 + versionName "3.3.1" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + android.applicationVariants.all { variant -> + variant.outputs.all { + if (variant.buildType.name.equals("release")) { + outputFileName = "TscDemo-release-${variant.versionName}.apk" + } else { + outputFileName = "TscDemo-debug-${variant.versionName}.apk" + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} +repositories { + flatDir { + dirs 'libs' // 声明添加libs文件夹为库 + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation 'androidx.test:runner:1.2.0' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.gainscha:jzint:0.4.1' + implementation files('libs/SDKLib.jar') + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/libs/SDKLib.jar b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/libs/SDKLib.jar new file mode 100755 index 0000000..276aecc Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/libs/SDKLib.jar differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/proguard-rules.pro b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/proguard-rules.pro new file mode 100755 index 0000000..f1b4245 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/androidTest/java/com/printer/tscdemo/ExampleInstrumentedTest.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/androidTest/java/com/printer/tscdemo/ExampleInstrumentedTest.java new file mode 100755 index 0000000..84ec560 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/androidTest/java/com/printer/tscdemo/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.printer.tscdemo; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.printer.tscdemo", appContext.getPackageName()); + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/AndroidManifest.xml b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/AndroidManifest.xml new file mode 100755 index 0000000..f1d0b05 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/TSPL.bin b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/TSPL.bin new file mode 100755 index 0000000..8df20e0 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/TSPL.bin differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/WalmartFile.pdf b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/WalmartFile.pdf new file mode 100755 index 0000000..0262ede Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/WalmartFile.pdf differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/esc.pdf b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/esc.pdf new file mode 100755 index 0000000..b239ce1 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/assets/esc.pdf differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BlueToothDeviceActivity.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BlueToothDeviceActivity.java new file mode 100755 index 0000000..f62d119 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BlueToothDeviceActivity.java @@ -0,0 +1,289 @@ +package com.printer.tscdemo; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.location.LocationManager; +import android.os.Build; +import android.os.Bundle; +import android.provider.Settings; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; +import com.printer.tscdemo.bean.BluetoothParameter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class BlueToothDeviceActivity extends AppCompatActivity { + private String TAG= BlueToothDeviceActivity.class.getSimpleName(); + private ListView lvDevices = null; + private BluetoothDeviceAdapter adapter; + //已配对列表 + private List pairedDevices =new ArrayList<>(); + //新设备列表 + private List newDevices = new ArrayList<>(); + private BluetoothAdapter mBluetoothAdapter; + public static final String EXTRA_DEVICE_ADDRESS ="address"; + public static final int REQUEST_ENABLE_BT = 2; + public static final int REQUEST_ENABLE_GPS = 3; + private PermissionUtils permissionUtils; + private LocationManager manager ; + private Button btn_search; + /** + * changes the title when discovery is finished + */ + private final BroadcastReceiver mFindBlueToothReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + // When discovery finds a device + if (BluetoothDevice.ACTION_FOUND.equals(action)) { + // Get the BluetoothDevice object from the Intent + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + // If it's already paired, skip it, because it's been listed + // already + BluetoothParameter parameter = new BluetoothParameter(); + int rssi = intent.getExtras().getShort(BluetoothDevice.EXTRA_RSSI);//获取蓝牙信号强度 + if (device != null && device.getName() != null) { + parameter.setBluetoothName(device.getName()); + } else { + parameter.setBluetoothName("unKnow"); + } + parameter.setBluetoothMac(device.getAddress()); + parameter.setBluetoothStrength(rssi+ ""); + Log.e(TAG,"\nBlueToothName:\t"+device.getName()+"\nMacAddress:\t"+device.getAddress()+"\nrssi:\t"+rssi); + if (device.getBondState() != BluetoothDevice.BOND_BONDED) {//未配对 + for (BluetoothParameter p:newDevices) { + if (p.getBluetoothMac().equals(parameter.getBluetoothMac())){//防止重复添加 + return; + } + } + newDevices.add(parameter); + Collections.sort(newDevices,new Signal()); + adapter.notifyDataSetChanged(); + } else {//更新已配对蓝牙 + for (int i = 0; i < pairedDevices.size(); i++) { + if (pairedDevices.get(i).getBluetoothMac().equals(parameter.getBluetoothMac())){ + pairedDevices.get(i).setBluetoothStrength(parameter.getBluetoothStrength()); + adapter.notifyDataSetChanged(); + return; + } + } + pairedDevices.add(parameter); + adapter.notifyDataSetChanged(); + } + // When discovery is finished, change the Activity title + } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED + .equals(action)) { + setProgressBarIndeterminateVisibility(false); + setTitle(R.string.complete); + Log.i("tag", "finish discovery" + (adapter.getCount()-2)); + }else if(BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){ + int bluetooth_state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, + BluetoothAdapter.ERROR); + if (bluetooth_state==BluetoothAdapter.STATE_OFF) {//关闭 + finish(); + } + if (bluetooth_state==BluetoothAdapter.STATE_ON) {//开启 + + } + } + } + }; + + + + // 自定义比较器:按信号强度排序 + static class Signal implements Comparator { + public int compare(Object object1, Object object2) {// 实现接口中的方法 + BluetoothParameter p1 = (BluetoothParameter) object1; // 强制转换 + BluetoothParameter p2 = (BluetoothParameter) object2; + return p1.getBluetoothStrength().compareTo(p2.getBluetoothStrength()); + } + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Request progress bar + //启用窗口特征 + requestWindowFeature(Window.FEATURE_PROGRESS); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + setContentView(R.layout.activity_bluetooth); + setTitle(getString(R.string.blue_label)); + initView(); + initBluetooth(); + initBroadcast(); + } + + + /** + * 搜索蓝牙 + */ + public void searchBlueTooth(){ + btn_search.setVisibility(View.GONE); + setTitle(getString(R.string.searching)); + setProgressBarIndeterminateVisibility(true); + mBluetoothAdapter.startDiscovery(); + } + /** + * 初始化广播 + */ + private void initBroadcast() { + try { + // Register for broadcasts when a device is discovered + IntentFilter filter = new IntentFilter(); + filter.addAction(BluetoothDevice.ACTION_FOUND); + filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); + // Register for broadcasts when discovery has finished + filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);//蓝牙状态改变 + this.registerReceiver(mFindBlueToothReceiver, filter); + }catch (Exception e){ + + } + } + + private void initView() { + lvDevices=(ListView)findViewById(R.id.lv_devices); + btn_search=(Button)findViewById(R.id.btn_search); + btn_search.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + initBluetooth(); + } + }); + adapter = new BluetoothDeviceAdapter(pairedDevices,newDevices, BlueToothDeviceActivity.this); + lvDevices.setAdapter(adapter); + lvDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + //点击已配对设备、新设备title不响应 + if (position == 0 || position == pairedDevices.size() + 1) { + return; + } + String mac=null; + if (position <= pairedDevices.size()) {//点击已配对设备列表 + mac= pairedDevices.get(position-1).getBluetoothMac(); + } + else {//点击新设备列表 + mac=newDevices.get(position-2- pairedDevices.size()).getBluetoothMac(); + } + mBluetoothAdapter.cancelDiscovery(); + + // Create the result Intent and include the MAC address + Intent intent = new Intent(); + intent.putExtra(EXTRA_DEVICE_ADDRESS, mac); + // Set result and finish this Activity + setResult(Activity.RESULT_OK, intent); + finish(); + + } + }); + } + private void initBluetooth(){ + // Get the local Bluetooth adapter + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + // If the adapter is null, then Bluetooth is not supported + if (mBluetoothAdapter == null) { + Toast.makeText(this, "Bluetooth is not supported by the device",Toast.LENGTH_LONG).show(); + } else { + // If BT is not on, request that it be enabled. + // setupChat() will then be called during onActivityResult + if (!mBluetoothAdapter.isEnabled()) { + Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); + startActivityForResult(enableIntent, REQUEST_ENABLE_BT); + } else { + manager= (LocationManager)BlueToothDeviceActivity.this .getSystemService(LOCATION_SERVICE); + permissionUtils=new PermissionUtils(BlueToothDeviceActivity.this); + permissionUtils.requestPermissions(getString(R.string.permission), + new PermissionUtils.PermissionListener(){ + @Override + public void doAfterGrand(String... permission) { + if ((Build.VERSION.SDK_INT>=29)&&! manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ + AlertDialog alertDialog = new AlertDialog.Builder(BlueToothDeviceActivity.this) + .setTitle(getString(R.string.tip)) + .setMessage(getString(R.string.gps_permission)) + .setIcon(R.mipmap.ic_launcher) + .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {//添加"Yes"按钮 + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivityForResult(intent,REQUEST_ENABLE_GPS); + } + }) + .create(); + alertDialog.show(); + }else { + searchBlueTooth(); + } + } + @Override + public void doAfterDenied(String... permission) { + for (String p:permission) { + switch (p){ + case Manifest.permission.ACCESS_FINE_LOCATION: + Utils.shortToast(BlueToothDeviceActivity.this,getString(R.string.no_permission)); + break; + + } + } + } + }, Manifest.permission.ACCESS_FINE_LOCATION); + } + } + } + + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_ENABLE_BT) { + if (resultCode == Activity.RESULT_OK) { + // bluetooth is opened + initBluetooth(); + } else { + // bluetooth is not open + Toast.makeText(this, R.string.bluetooth_is_not_enabled, Toast.LENGTH_SHORT).show(); + finish(); + } + }else if (requestCode==REQUEST_ENABLE_GPS){ + if (resultCode == Activity.RESULT_OK) { + // bluetooth is opened + initBluetooth(); + } else { + // bluetooth is not open + } + } + } + @Override + protected void onDestroy() { + super.onDestroy(); + try { + // Make sure we're not doing discovery anymore + if (mBluetoothAdapter != null) { + mBluetoothAdapter.cancelDiscovery(); + } + // Unregister broadcast listeners + if (mFindBlueToothReceiver != null) { + unregisterReceiver(mFindBlueToothReceiver); + } + }catch (Exception e){ + + } + } +} \ No newline at end of file diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BluetoothDeviceAdapter.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BluetoothDeviceAdapter.java new file mode 100755 index 0000000..ced965f --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/BluetoothDeviceAdapter.java @@ -0,0 +1,99 @@ +package com.printer.tscdemo; + +import android.content.Context; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.printer.tscdemo.bean.BluetoothParameter; + +import java.util.List; + + +/** + * 作者: Circle + * 创造于 2018/5/24. + */ +public class BluetoothDeviceAdapter extends BaseAdapter { + + private List pairedDevices; + private List newDevices; + private Context mContext; + private static final int TITLE = 0; + private static final int CONTENT = 1; + public BluetoothDeviceAdapter(List pairedDevices, List newDevices, Context context) { + this.pairedDevices = pairedDevices; + this.newDevices = newDevices; + this.mContext = context; + } + + @Override + public int getCount() { + return pairedDevices.size() + newDevices.size() + 2; + } + + @Override + public Object getItem(int position) { + return position; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + switch (getItemViewType(position)) { + case TITLE: + convertView = LayoutInflater.from(mContext).inflate(R.layout.text_item, parent, false); + TextView tv_title = (TextView) convertView.findViewById(R.id.text); + tv_title.setTextColor(mContext.getResources().getColor(R.color.colorAccent)); + tv_title.setGravity(Gravity.LEFT); + if (position == 0) { + tv_title.setText(mContext.getResources().getString(R.string.paired)); + } else { + tv_title.setText(mContext.getResources().getString(R.string.unpaired)); + } + break; + case CONTENT: + BluetoothParameter bluetoothParameter = null; + if (position < pairedDevices.size() + 1) { + bluetoothParameter = pairedDevices.get(position - 1); + } + if (position > pairedDevices.size()+1 && newDevices.size() > 0) { + bluetoothParameter = newDevices.get(position - pairedDevices.size() - 2); + } + + if (bluetoothParameter!=null) { + convertView = LayoutInflater.from(mContext).inflate(R.layout.bluetooth_list_item, parent, false); + TextView tvName = (TextView) convertView.findViewById(R.id.b_name); + TextView tvMac = (TextView) convertView.findViewById(R.id.b_mac); + TextView tvStrength = (TextView) convertView.findViewById(R.id.b_info); + tvName.setText(bluetoothParameter.getBluetoothName()); + tvMac.setText(bluetoothParameter.getBluetoothMac()); + tvStrength.setText(bluetoothParameter.getBluetoothStrength()); + } + break; + } + + return convertView; + } + + @Override + public int getViewTypeCount() { + return 2; + } + + @Override + public int getItemViewType(int position) { + if ((position == pairedDevices.size()+1) || (position == 0)) { + return TITLE; + } else { + return CONTENT; + } + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/MainActivity.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/MainActivity.java new file mode 100755 index 0000000..bee1bcd --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/MainActivity.java @@ -0,0 +1,494 @@ +package com.printer.tscdemo; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.hardware.usb.UsbDevice; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.SystemClock; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; +import com.gprinter.bean.PrinterDevices; +import com.gprinter.command.LabelCommand; +import com.gprinter.utils.CallbackListener; +import com.gprinter.utils.Command; +import com.gprinter.utils.ConnMethod; +import com.gprinter.utils.LogUtils; +import com.gprinter.utils.PDFUtils; +import com.gprinter.utils.SDKUtils; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Vector; + +public class MainActivity extends AppCompatActivity implements CallbackListener { + TextView tvState; + CheckBox swState; + Printer printer=null; + Context context; + Spinner sp_gap; + String TAG=MainActivity.class.getSimpleName(); + PermissionUtils permissionUtils; + Handler handler=new Handler(Looper.getMainLooper()){ + @Override + public void handleMessage(@NonNull Message msg) { + switch (msg.what){ + case 0x00: + String tip=(String)msg.obj; + Toast.makeText(context,tip,Toast.LENGTH_SHORT).show(); + break; + case 0x01: + int status=msg.arg1; + if (status==-1){//获取状态失败 + AlertDialog alertDialog = new AlertDialog.Builder(context) + .setTitle(getString(R.string.tip)) + .setMessage(getString(R.string.status_fail)) + .setIcon(R.mipmap.ic_launcher) + .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {//添加"Yes"按钮 + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }) + .create(); + alertDialog.show(); + return; + }else if (status==1){ + Toast.makeText(context,getString(R.string.status_feed),Toast.LENGTH_SHORT).show(); + return; + }else if (status==0){//状态正常 + Toast.makeText(context,getString(R.string.status_normal),Toast.LENGTH_SHORT).show(); + return; + }else if (status==-2){//状态缺纸 + Toast.makeText(context,getString(R.string.status_out_of_paper),Toast.LENGTH_SHORT).show(); + return; + }else if (status==-3){//状态开盖 + Toast.makeText(context,getString(R.string.status_open),Toast.LENGTH_SHORT).show(); + return; + }else if (status==-4){ + Toast.makeText(context,getString(R.string.status_overheated),Toast.LENGTH_SHORT).show(); + return; + } + break; + case 0x02://关闭连接 + new Thread(new Runnable() { + @Override + public void run() { + if (printer.getPortManager()!=null){ + printer.close(); + } + } + }).start(); + + tvState.setText(getString(R.string.not_connected)); + break; + case 0x03: + String message=(String)msg.obj; + AlertDialog alertDialog = new AlertDialog.Builder(context) + .setTitle(getString(R.string.tip)) + .setMessage(message) + .setIcon(R.mipmap.ic_launcher) + .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {//添加"Yes"按钮 + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }) + .create(); + alertDialog.show(); + break; + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initView(); + initPermission(); + } + + /** + * 初始化权限 + */ + private void initPermission() { + permissionUtils.requestPermissions(getString(R.string.permission), + new PermissionUtils.PermissionListener(){ + @Override + public void doAfterGrand(String... permission) { + + } + @Override + public void doAfterDenied(String... permission) { + for (String p:permission) { + switch (p){ + case Manifest.permission.READ_EXTERNAL_STORAGE: + Utils.shortToast(context,getString(R.string.no_read)); + break; + case Manifest.permission.ACCESS_FINE_LOCATION: + Utils.shortToast(context,getString(R.string.no_permission)); + break; + } + } + } + }, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION); + } + + private void initView() { + context=MainActivity.this; + permissionUtils=new PermissionUtils(context); + setTitle(getString(R.string.app_name)+"V"+Utils.getVersionName(context)); + tvState=(TextView)findViewById(R.id.tvState); + swState=(CheckBox)findViewById(R.id.swState); + sp_gap=(Spinner)findViewById(R.id.sp_gap) ; + printer=Printer.getInstance();//获取管理对象 + } + /** + * 断开连接 + * @param view + */ + public void disconnect(View view) { + handler.obtainMessage(0x02).sendToTarget(); + } + + /** + * 蓝牙设备 + * @param view + */ + public void blueToothDevices(View view) { + startActivityForResult(new Intent(context, BlueToothDeviceActivity.class),0x00); + } + /** + * usb设备 + * @param view + */ + public void usbDevices(View view) { + startActivityForResult(new Intent(context, UsbDeviceActivity.class),0x01); + } + /** + * wifi接口 + * @param view + */ + public void wifiDevices(View view) { + startActivityForResult(new Intent(context, WifiDeviceActivity.class),0x02); + } + /** + * 串口接口 + * @param view + */ + public void serialPortDevices(View view) { + startActivityForResult(new Intent(context, SerialPortDeviceActivity.class),0x03); + } + /** + * 打印案例 + * @param view + */ + public void print(View view) { + ThreadPoolManager.getInstance().addTask(new Runnable() { + @Override + public void run() { + try { + if (printer.getPortManager()==null){ + tipsToast(getString(R.string.conn_first)); + return; + } + //打印前后查询打印机状态,部分老款打印机不支持查询请去除下面查询代码 + //****************** 查询状态 *************************** + if (swState.isChecked()) { + Command command = printer.getPortManager().getCommand(); + int status = printer.getPrinterState(command,2000); + if (status != 0) {//打印机处于不正常状态,则不发送打印任务 + Message msg = new Message(); + msg.what = 0x01; + msg.arg1 = status; + handler.sendMessage(msg); + return; + } + } + //*************************************************************** + boolean result=printer.getPortManager().writeDataImmediately(PrintContent.getLabel(context,sp_gap.getSelectedItemPosition())); + if (result) { + tipsDialog(getString(R.string.send_success)); + }else { + tipsDialog(getString(R.string.send_fail)); + } + LogUtils.e("send result",result); + } catch (IOException e) { + tipsDialog(getString(R.string.print_fail)+e.getMessage()); + }catch (Exception e){ + tipsDialog(getString(R.string.print_fail)+e.getMessage()); + }finally { + if (printer.getPortManager()==null) { + printer.close(); + } + } + } + }); + + } + + /** + * 打印xml 布局 + * @param view + */ + public void xml(View view) { + ThreadPoolManager.getInstance().addTask(new Runnable() { + @Override + public void run() { + if (printer.getPortManager()==null){ + tipsToast(getString(R.string.conn_first)); + return; + } + try { + + printer.getPortManager().writeDataImmediately(PrintContent.getXmlBitmap(context)); + } catch (IOException e) { + tipsDialog(getString(R.string.status_error)+e.getMessage()); + }catch (Exception e){ + tipsDialog(getString(R.string.status_error)+e.getMessage()); + } + } + }); + } + /** + * 打印PDF + * @param view + */ + public void printPDF(View view) { + if (!permissionUtils.hasPermissions(context,Manifest.permission.READ_EXTERNAL_STORAGE)){ + Utils.shortToast(context,getString(R.string.no_read)); + return; + } + ThreadPoolManager.getInstance().addTask(new Runnable() { + @Override + public void run() { + try { + if (printer.getPortManager()==null){ + tipsToast(getString(R.string.conn_first)); + return; + } + //打印前后查询打印机状态,部分老款打印机不支持查询请去除下面查询代码 + //****************** 查询状态 *************************** + if (swState.isChecked()) { + Command command = printer.getPortManager().getCommand(); + int status = printer.getPrinterState(command,2000); + if (status != 0) {//打印机处于不正常状态、则不发送打印 + Message msg = new Message(); + msg.what = 0x01; + msg.arg1 = status; + handler.sendMessage(msg); + return; + } + } + //*************************************************************** + File file = null; + try { + file= new File(context.getExternalCacheDir(), "WalmartFile.pdf"); + if (!file.exists()) { + // Since PdfRenderer cannot handle the compressed asset file directly, we copy it into + // the cache directory. + InputStream asset = context.getAssets().open("WalmartFile.pdf"); + FileOutputStream output = new FileOutputStream(file); + final byte[] buffer = new byte[1024]; + int size; + while ((size = asset.read(buffer)) != -1) { + output.write(buffer, 0, size); + } + asset.close(); + output.close(); + } + }catch (IOException e){ + tipsToast(getString(R.string.pdf_error)); + return; + } + boolean result= printer.getPortManager().writePDFToTsc(file,576,0,true,true,false,160); + if (result) { + tipsDialog(getString(R.string.send_success)); + }else { + tipsDialog(getString(R.string.send_fail)); + } + LogUtils.e("send result",result); + } catch (IOException e) { + tipsDialog(getString(R.string.disconnect)+"\n"+getString(R.string.print_fail)+e.getMessage()); + }catch (Exception e){ + tipsDialog(getString(R.string.print_fail)+e.getMessage()); + } + } + }); + } + + /** + * 检查标签打印机状态 + * @param view + */ + public void checkState(View view) { + ThreadPoolManager.getInstance().addTask(new Runnable() { + @Override + public void run() { + if (printer.getPortManager()==null){ + tipsToast(getString(R.string.conn_first)); + return; + } + try { + Command command=printer.getPortManager().getCommand(); + int status=printer.getPrinterState(command,2000); + Message msg=new Message(); + msg.what=0x01; + msg.arg1=status; + handler.sendMessage(msg); + } catch (IOException e) { + tipsDialog(getString(R.string.status_error)+e.getMessage()); + }catch (Exception e){ + tipsDialog(getString(R.string.status_error)+e.getMessage()); + } + } + }); + } + /** + * 提示弹框 + * @param message + */ + private void tipsToast(String message){ + Message msg =new Message(); + msg.what=0x00; + msg.obj=message; + handler.sendMessage(msg); + } + /** + * 提示弹框 + * @param message + */ + private void tipsDialog(String message){ + Message msg =new Message(); + msg.what=0x03; + msg.obj=message; + handler.sendMessage(msg); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if (resultCode== Activity.RESULT_OK){ + switch (requestCode){ + case 0x00://蓝牙返回mac地址 + String mac =data.getStringExtra(BlueToothDeviceActivity.EXTRA_DEVICE_ADDRESS); + Log.e(TAG, SDKUtils.bytesToHexString(mac.getBytes())); + PrinterDevices blueTooth=new PrinterDevices.Build() + .setContext(context) + .setConnMethod(ConnMethod.BLUETOOTH) + .setMacAddress(mac) + .setCommand(Command.TSC) + .setCallbackListener(this) + .build(); + printer.connect(blueTooth); + break; + case 0x01://usb返回USB名称 + String name =data.getStringExtra(UsbDeviceActivity.USB_NAME); + UsbDevice usbDevice = Utils.getUsbDeviceFromName(context, name); + PrinterDevices usb=new PrinterDevices.Build() + .setContext(context) + .setConnMethod(ConnMethod.USB) + .setUsbDevice(usbDevice) + .setCommand(Command.TSC) + .setCallbackListener(this) + .build(); + printer.connect(usb); + break; + case 0x02://WIFI返回ip + String ip =data.getStringExtra(WifiDeviceActivity.IP); + PrinterDevices wifi=new PrinterDevices.Build() + .setContext(context) + .setConnMethod(ConnMethod.WIFI) + .setIp(ip) + .setPort(9100)//打印唯一端口9100 + .setCommand(Command.TSC) + .setCallbackListener(this) + .build(); + printer.connect(wifi); + break; + case 0x03://串口返回路径、波特率 + int baudRate = data.getIntExtra(SerialPortDeviceActivity.SERIALPORT_BAUDRATE, 9600); + String path = data.getStringExtra(SerialPortDeviceActivity.SERIALPORT_PATH); + PrinterDevices serialPort=new PrinterDevices.Build() + .setContext(context) + .setConnMethod(ConnMethod.SERIALPORT) + .setSerialPort(path) + .setBaudrate(baudRate) + .setCommand(Command.TSC) + .setCallbackListener(this) + .build(); + printer.connect(serialPort); + break; + } + } + } + + @Override + public void onConnecting() {//连接打印机中 + tvState.setText(getString(R.string.conning)); + } + + @Override + public void onCheckCommand() {//查询打印机指令 + tvState.setText(getString(R.string.checking)); + } + + @Override + public void onSuccess(PrinterDevices devices) {//连接成功 + Toast.makeText(context,getString(R.string.conn_success),Toast.LENGTH_SHORT).show(); + tvState.setText(devices.toString()); + } + + @Override + public void onReceive(byte[] bytes) { + + } + + @Override + public void onFailure() {//连接失败 + Toast.makeText(context,getString(R.string.conn_fail),Toast.LENGTH_SHORT).show(); + handler.obtainMessage(0x02).sendToTarget(); + } + + @Override + public void onDisconnect() {//断开连接 + Toast.makeText(context,getString(R.string.disconnect),Toast.LENGTH_SHORT).show(); + handler.obtainMessage(0x02).sendToTarget(); + } + //申请权限返回 + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + permissionUtils.handleRequestPermissionsResult(requestCode, permissions, grantResults); + } + @Override + protected void onDestroy() { + super.onDestroy(); + if (printer.getPortManager()!=null){ + printer.close(); + } + } + + + +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PermissionUtils.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PermissionUtils.java new file mode 100755 index 0000000..81318a8 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PermissionUtils.java @@ -0,0 +1,236 @@ +package com.printer.tscdemo; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Fragment; +import android.content.DialogInterface; +import android.content.pm.PackageManager; +import android.os.Build; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import java.util.Arrays; +import java.util.List; + +/** + * @author deadline + * @time 2016-10-28 + * @usage android >=M 的权限申请统一处理 + *

+ * notice: + * 很多手机对原生系统做了修改,比如小米4的6.0的shouldShowRequestPermissionRationale + * 就一直返回false,而且在申请权限时,如果用户选择了拒绝,则不会再弹出对话框了, 因此有了 + * void doAfterDenied(String... permission); + */ + +public class PermissionUtils { + + private static final int REQUEST_PERMISSION_CODE = 1000; + + private Object mContext; + + private PermissionListener mListener; + + private List mPermissionList; + + public PermissionUtils(@NonNull Object object) { + checkCallingObjectSuitability(object); + this.mContext = object; + + } + + + /** + * 权限授权申请 + * + * @param hintMessage 要申请的权限的提示 + * @param permissions 要申请的权限 + * @param listener 申请成功之后的callback + */ + public void requestPermissions(@NonNull CharSequence hintMessage, + @Nullable PermissionListener listener, + @NonNull final String... permissions) { + if (listener != null) { + mListener = listener; + } + mPermissionList = Arrays.asList(permissions); + //没全部权限 + if (!hasPermissions(mContext, permissions)) { + //需要向用户解释为什么申请这个权限 + boolean shouldShowRationale = false; + for (String perm : permissions) { + shouldShowRationale = + shouldShowRationale || shouldShowRequestPermissionRationale(mContext, perm); + } + + if (shouldShowRationale) { + showMessageOKCancel(hintMessage, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + executePermissionsRequest(mContext, permissions, + REQUEST_PERMISSION_CODE); + + } + }); + } else { + executePermissionsRequest(mContext, permissions, + REQUEST_PERMISSION_CODE); + } + } else if (mListener != null) { //有全部权限 + mListener.doAfterGrand(permissions); + } + } + + /** + * 处理onRequestPermissionsResult + * + * @param requestCode + * @param permissions + * @param grantResults + */ + public void handleRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + switch (requestCode) { + case REQUEST_PERMISSION_CODE: + boolean allGranted = true; + for (int grant : grantResults) { + if (grant != PackageManager.PERMISSION_GRANTED) { + allGranted = false; + break; + } + } + + if (allGranted && mListener != null) { + + mListener.doAfterGrand((String[]) mPermissionList.toArray()); + + } else if (!allGranted && mListener != null) { + mListener.doAfterDenied((String[]) mPermissionList.toArray()); + } + break; + } + } + + /** + * 判断是否具有某权限 + * + * @param object + * @param perms + * @return + */ + public static boolean hasPermissions(@NonNull Object object, @NonNull String... perms) { + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return true; + } + for (String perm : perms) { + boolean hasPerm = (ContextCompat.checkSelfPermission(getActivity(object), perm) == + PackageManager.PERMISSION_GRANTED); + if (!hasPerm) { + return false; + } + } + + return true; + } + + + /** + * 兼容fragment + * + * @param object + * @param perm + * @return + */ + @TargetApi(23) + private static boolean shouldShowRequestPermissionRationale(@NonNull Object object, @NonNull String perm) { + if (object instanceof Activity) { + return ActivityCompat.shouldShowRequestPermissionRationale((Activity) object, perm); + } else if (object instanceof Fragment) { + return ((Fragment) object).shouldShowRequestPermissionRationale(perm); + } else if (object instanceof Fragment) { + return ((Fragment) object).shouldShowRequestPermissionRationale(perm); + } else { + return false; + } + } + + /** + * 执行申请,兼容fragment + * + * @param object + * @param perms + * @param requestCode + */ + @TargetApi(23) + private void executePermissionsRequest(@NonNull Object object, @NonNull String[] perms, int requestCode) { + if (object instanceof Activity) { + ActivityCompat.requestPermissions((Activity) object, perms, requestCode); + } else if (object instanceof Fragment) { + ((Fragment) object).requestPermissions(perms, requestCode); + } else if (object instanceof Fragment) { + ((Fragment) object).requestPermissions(perms, requestCode); + } + } + + /** + * 检查传递Context是否合法 + * + * @param object + */ + private void checkCallingObjectSuitability(@Nullable Object object) { + if (object == null) { + throw new NullPointerException("Activity or Fragment should not be null"); + } + + boolean isActivity = object instanceof Activity; + boolean isSupportFragment = object instanceof Fragment; + boolean isAppFragment = object instanceof Fragment; + if (!(isSupportFragment || isActivity || (isAppFragment && isNeedRequest()))) { + if (isAppFragment) { + throw new IllegalArgumentException( + "Target SDK needs to be greater than 23 if caller is android.app.Fragment"); + } else { + throw new IllegalArgumentException("Caller must be an Activity or a Fragment."); + } + } + } + + + @TargetApi(11) + private static Activity getActivity(@NonNull Object object) { + if (object instanceof Activity) { + return ((Activity) object); + } else if (object instanceof Fragment) { + return ((Fragment) object).getActivity(); + } else if (object instanceof Fragment) { + return ((Fragment) object).getActivity(); + } else { + return null; + } + } + + public static boolean isNeedRequest() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; + } + + public void showMessageOKCancel(CharSequence message, DialogInterface.OnClickListener okListener) { + new AlertDialog.Builder(getActivity(mContext)) + .setMessage(message) + .setPositiveButton(getActivity(mContext).getString(android.R.string.ok), okListener) + .setNegativeButton(getActivity(mContext).getString(android.R.string.cancel), null) + .setCancelable(false) + .create() + .show(); + } + + public interface PermissionListener { + + void doAfterGrand(String... permission); + + void doAfterDenied(String... permission); + } +} \ No newline at end of file diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent.java new file mode 100755 index 0000000..8148145 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent.java @@ -0,0 +1,196 @@ +package com.printer.tscdemo; + +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.view.View; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; +import com.gprinter.command.LabelCommand; +import com.gprinter.utils.GpUtils; +import com.gprinter.utils.PDFUtils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.security.PublicKey; +import java.util.Vector; + +/** + * Copyright (C), 2012-2020, 珠海佳博科技股份有限公司 + * FileName: PrintConntent + * Author: Circle + * Date: 2020/7/20 10:04 + * Description: 打印内容 + */ +public class PrintContent { + /** + * 标签打印测试页 + * + * @return + */ + public static Vector getLabel(Context context,int gap) { + LabelCommand tsc = new LabelCommand(); + // 设置标签尺寸宽高,按照实际尺寸设置 单位mm + tsc.addUserCommand("\r\n"); + tsc.addSize(58, 70); + // 设置标签间隙,按照实际尺寸设置,如果为无间隙纸则设置为0 单位mm + tsc.addGap(gap); + //设置纸张类型为黑标,发送BLINE 指令不能同时发送GAP指令 +// tsc.addBline(2); + // 设置打印方向 + tsc.addDirection(LabelCommand.DIRECTION.FORWARD, LabelCommand.MIRROR.NORMAL); + // 设置原点坐标 + tsc.addReference(0, 0); + //设置浓度 + tsc.addDensity(LabelCommand.DENSITY.DNESITY4); + // 撕纸模式开启 + tsc.addTear(LabelCommand.RESPONSE_MODE.ON); + // 清除打印缓冲区 + tsc.addCls(); + // 绘制简体中文 + tsc.addText(30, 20, LabelCommand.FONTTYPE.SIMPLIFIED_24_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1, + "欢迎使用Printer"); + //打印繁体 + tsc.addUnicodeText(30,50, LabelCommand.FONTTYPE.TRADITIONAL_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"BIG5碼繁體中文","BIG5"); + //打印韩文 + tsc.addUnicodeText(30,80, LabelCommand.FONTTYPE.KOREAN, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"Korean 지아보 하성","EUC_KR"); + //英数字 + tsc.addText(240,20, LabelCommand.FONTTYPE.FONT_1, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"1"); + tsc.addText(250,20, LabelCommand.FONTTYPE.FONT_2, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"2"); + tsc.addText(270,20, LabelCommand.FONTTYPE.FONT_3, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"3"); + tsc.addText(300,20, LabelCommand.FONTTYPE.FONT_4, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"4"); + tsc.addText(330,20, LabelCommand.FONTTYPE.FONT_5, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"5"); + tsc.addText(240,40, LabelCommand.FONTTYPE.FONT_6, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"6"); + tsc.addText(250,40, LabelCommand.FONTTYPE.FONT_7, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"7"); + tsc.addText(270,40, LabelCommand.FONTTYPE.FONT_8, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"8"); + tsc.addText(300,60, LabelCommand.FONTTYPE.FONT_9, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"9"); + tsc.addText(330,80, LabelCommand.FONTTYPE.FONT_10, LabelCommand.ROTATION.ROTATION_0,LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,"10"); + Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_priter); + // 绘制图片 + tsc.drawImage(30, 100, 300, b); + Bitmap b2= BitmapFactory.decodeResource(context.getResources(), R.drawable.flower); + tsc.drawJPGImage(200,250,200,b2); + //绘制二维码 + tsc.addQRCode(30,250, LabelCommand.EEC.LEVEL_L, 5, LabelCommand.ROTATION.ROTATION_0, " www.smarnet.cc"); + // 绘制一维条码 + tsc.add1DBarcode(30, 380, LabelCommand.BARCODETYPE.CODE128, 80, LabelCommand.READABEL.EANBEL, LabelCommand.ROTATION.ROTATION_0, "12345678"); + // 打印标签 + tsc.addPrint(1, 1); + // 打印标签后 蜂鸣器响 + tsc.addSound(2, 100); + //开启钱箱 + tsc.addCashdrwer(LabelCommand.FOOT.F5, 255, 255); + Vector datas = tsc.getCommand(); + // 发送数据 + return datas; + } + + + /** + * 获取图片 + * @param context + * @return + */ + public static Bitmap getBitmap(Context context) { + View v = View.inflate(context, R.layout.page, null); + TableLayout tableLayout = (TableLayout) v.findViewById(R.id.line); + TextView total = (TextView) v.findViewById(R.id.total); + TextView cashier = (TextView) v.findViewById(R.id.cashier); + tableLayout.addView(ctv(context, "红茶\n加热\n加糖", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 899, 109)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + tableLayout.addView(ctv(context, "红茶", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 8, 10)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + total.setText("998"); + cashier.setText("张三"); + final Bitmap bitmap = convertViewToBitmap(v); + return bitmap; + } + /** + * mxl转bitmap图片 + * @return + */ + public static Bitmap convertViewToBitmap(View view){ + view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); + view.buildDrawingCache(); + Bitmap bitmap = view.getDrawingCache(); + return bitmap; + } + + public static TableRow ctv(Context context, String name, int k, int n){ + TableRow tb=new TableRow(context); + tb.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT ,TableLayout.LayoutParams.WRAP_CONTENT)); + TextView tv1=new TextView(context); + tv1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv1.setText(name); + tv1.setTextColor(Color.BLACK); + tb.addView(tv1); + TextView tv2=new TextView(context); + tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv2.setText(k+""); + tv2.setTextColor(Color.BLACK); + tb.addView(tv2); + TextView tv3=new TextView(context); + tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv3.setText(n+""); + tv3.setTextColor(Color.BLACK); + tb.addView(tv3); + return tb; + } + /** + * 获取Assets文件 + * @param fileName + * @return + */ + public static String getFromAssets(Context context,String fileName) { + String result = ""; + try { + InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName)); + BufferedReader bufReader = new BufferedReader(inputReader); + String line = ""; + while ((line = bufReader.readLine()) != null) + result += line+"\r\n"; + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + public static Vector getXmlBitmap(Context context){ + LabelCommand tsc = new LabelCommand(); + // 设置标签尺寸宽高,按照实际尺寸设置 单位mm + tsc.addUserCommand("\r\n"); + tsc.addSize(58, 100); + // 设置标签间隙,按照实际尺寸设置,如果为无间隙纸则设置为0 单位mm + tsc.addGap(0); + // 设置打印方向 + tsc.addDirection(LabelCommand.DIRECTION.FORWARD, LabelCommand.MIRROR.NORMAL); + // 设置原点坐标 + tsc.addReference(0, 0); + //设置浓度 + tsc.addDensity(LabelCommand.DENSITY.DNESITY4); + // 撕纸模式开启 + tsc.addTear(LabelCommand.RESPONSE_MODE.ON); + // 清除打印缓冲区 + tsc.addCls(); + Bitmap bitmap=getBitmap(context); + // 绘制图片 + /** + * x:打印起始横坐标 + * y:打印起始纵坐标 + * mWidth:打印宽度以dot为单位 + * nbitmap:源图 + */ + tsc.drawXmlImage(10,10,bitmap.getWidth(),bitmap); + // 打印标签 + tsc.addPrint(1, 1); + return tsc.getCommand(); + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent2.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent2.java new file mode 100755 index 0000000..c17ea6f --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/PrintContent2.java @@ -0,0 +1,413 @@ +package com.printer.tscdemo; + +import static com.gprinter.bean.BarCodeType.BARCODE_CODE128; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.view.View; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; + +import com.gprinter.command.EscCommand; +import com.gprinter.command.EscForDotCommand; +import com.gprinter.command.LabelCommand; +import com.gprinter.utils.Menu58Utils; +import com.gprinter.utils.Menu80Utils; + +import java.util.Vector; + +/** + * Copyright (C), 2012-2020, 打印机有限公司 + * FileName: PrintConntent + * Author: Circle + * Date: 2020/7/20 10:04 + * Description: 打印内容 + */ +public class PrintContent2 { + /** + * 小票案例 + * @param context + * + * @return + */ + public static Vector getReceiptChinese(Context context,int width) { + EscCommand esc = new EscCommand(); + //初始化打印机 + esc.addInitializePrinter(); + // 设置打印居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + //字体放大两倍 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_2, EscCommand.HEIGHT_ZOOM.MUL_2); + // 打印文字 + esc.addText("票据测试\n"); + + //字体正常 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_1, EscCommand.HEIGHT_ZOOM.MUL_1); + //打印并换行 + esc.addPrintAndLineFeed(); + // 设置打印左对齐 + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + // 打印文字 + esc.addText("打印文字测试:\n"); + +// esc.addSetKanjiUnderLine(EscCommand.UNDERLINE_MODE.UNDERLINE_2DOT);//汉字下划线 + esc.addTurnUnderlineModeOnOrOff(EscCommand.UNDERLINE_MODE.UNDERLINE_2DOT);//非汉字下划线 + esc.addText("125545AA测试下划线\n"); + esc.addTurnUnderlineModeOnOrOff(EscCommand.UNDERLINE_MODE.OFF);//非汉字取消下划线 + + // 打印文字 + esc.addText("欢迎使用打印机!\n"); + esc.addPrintAndLineFeed(); + //对齐方式 + esc.addText("打印对齐方式测试:\n"); + //设置居左 + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addText("居左"); + esc.addPrintAndLineFeed(); + //设置居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + esc.addText("居中"); + esc.addPrintAndLineFeed(); + //设置居右 + esc.addSelectJustification(EscCommand.JUSTIFICATION.RIGHT); + esc.addText("居右"); + esc.addPrintAndLineFeed(); + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + // 打印图片 + esc.addText("打印Bitmap图测试:\n"); + Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_priter);//二维码图片,图片类型bitmap + // 打印图片,58打印机图片宽度最大为384dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + //打印图片,80打印机图片宽度最大为576dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + esc.drawImage(b, width); + esc.addPrintAndLineFeed(); + //打印条码 + esc.addText("打印条码测试:\n"); + // 设置条码可识别字符位置在条码下方 + esc.addSelectPrintingPositionForHRICharacters(EscCommand.HRI_POSITION.BELOW); + // 设置条码高度为60点 + esc.addSetBarcodeHeight((byte) 60); + // 设置条码单元宽度为1 + esc.addSetBarcodeWidth((byte) 1); + // 打印Code128码内容 + esc.addCODE128(esc.genCodeB("barcode128")); + esc.addPrintAndLineFeed(); + // 打印二维码 + esc.addText("打印二维码测试:\n"); + // 设置纠错等级 + esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); + // 设置qrcode模块大小 + esc.addSelectSizeOfModuleForQRCode((byte) 4); + // 设置qrcode内容 + esc.addStoreQRCodeData("www.baidu.com"); + // 打印QRCode + esc.addPrintQRCode(); + esc.addPrintAndLineFeed(); + + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + //打印文字 + esc.addSelectCharacterFont(EscCommand.FONT.FONTB); + esc.addText("测试完成!\r\n"); + // 设置打印居左 + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addPrintAndLineFeed(); + esc.addPrintAndFeedLines((byte) 4); + //切纸(带切刀打印机才可用) + esc.addCutPaper(); + // 开钱箱 + esc.addGeneratePlus(LabelCommand.FOOT.F2, (byte) 255, (byte) 255); + esc.addInitializePrinter(); + //返回指令集 + return esc.getCommand(); + } + + + public static Vector getImgRes(Context context,int res) { + EscCommand esc = new EscCommand(); + //初始化打印机 + esc.addInitializePrinter(); + // 设置打印居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + Bitmap b = BitmapFactory.decodeResource(context.getResources(), res); + // 打印图片,图片宽度为384dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + esc.drawJpgImage(b, 200); + esc.addText("\n\n\n\n"); + esc.addPrintAndLineFeed(); + //切纸(带切刀打印机才可用) + esc.addCutPaper(); + // 开钱箱 + esc.addGeneratePlus(LabelCommand.FOOT.F2, (byte) 255, (byte) 255); + esc.addInitializePrinter(); + return esc.getCommand(); + } + + + /** + * 针式打印指令 + * @param qrCode + * @param barCode + * @return + */ + public static Vector getDotPrintCommand(String qrCode,String barCode) { + EscForDotCommand esc = new EscForDotCommand(); + //初始化打印机 + esc.addInitializePrinter(); + // 设置打印居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + esc.addText("二维码打印"); + esc.addText("\n\n"); + esc.addQrcode(100,100,qrCode); + // 打印图片,图片宽度为384dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + esc.addText("\n\n"); + esc.addText("条形码打印"); + esc.addText("\n\n"); + esc.addBarcode(BARCODE_CODE128,200,50,true,12,barCode); + esc.addText("\n\n\n\n"); + esc.addPrintAndLineFeed(); + //切纸(带切刀打印机才可用) + esc.addCutPaper(); + // 开钱箱 + esc.addGeneratePlus(LabelCommand.FOOT.F2, (byte) 255, (byte) 255); + esc.addInitializePrinter(); + return esc.getCommand(); + } + + + /** + * 菜单样例 + * @param context + * @return + */ + public static Vector get58Menu(Context context) { + EscCommand esc = new EscCommand(); + //初始化打印机 + esc.addInitializePrinter(); + // 设置打印居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.flower);//二维码图片,图片类型bitmap + // 打印图片,图片宽度为384dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + esc.drawJpgImage(b, 200); + // 设置为倍高倍宽 + //字体放大两倍 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_2, EscCommand.HEIGHT_ZOOM.MUL_2); + // 打印文字 + esc.addText("爱情餐厅\n\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addText("520号桌\n\n"); + //字体正常 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_1, EscCommand.HEIGHT_ZOOM.MUL_1); + esc.addText("点菜时间 2020-05-20 5:20\n"); + esc.addText("上菜时间 2020-05-20 13:14\n"); + esc.addText("人数:2人 点菜员:新疆包工头\n"); + esc.addText("--------------------------------\n"); + //开启加粗 + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.ON); + esc.addText(Menu58Utils.printThreeData("菜名", "数量", "金额")); + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.OFF); + esc.addText(Menu58Utils.printThreeData("北京烤鸭", "1", "99.99")); + esc.addText(Menu58Utils.printThreeData("四川麻婆豆腐", "1", "39.99")); + esc.addText(Menu58Utils.printThreeData("西湖醋鱼", "1", "59.99")); + esc.addText(Menu58Utils.printThreeData("飞龙汤", "1", "66.66")); + esc.addText(Menu58Utils.printThreeData("无为熏鸭", "1", "88.88")); + esc.addText(Menu58Utils.printThreeData("东坡肉", "1", "39.99")); + esc.addText(Menu58Utils.printThreeData("辣子鸡", "1", "66.66")); + esc.addText(Menu58Utils.printThreeData("腊味合蒸", "1", "108.00")); + esc.addText(Menu58Utils.printThreeData("东安子鸡", "1", "119.00")); + esc.addText(Menu58Utils.printThreeData("清蒸武昌鱼", "1", "88.88")); + esc.addText(Menu58Utils.printThreeData("再来两瓶82年的快乐肥宅水(去冰)", "1", "9.99")); + esc.addText(Menu58Utils.printThreeData("老干妈拌饭(加辣、加香菜)", "1", "6.66")); + esc.addText("--------------------------------\n\n"); + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.ON); + esc.addText(Menu58Utils.printTwoData("合计:", "1314.00")); + esc.addText(Menu58Utils.printTwoData("抹零:", "14.00")); + esc.addText(Menu58Utils.printTwoData("应收:", "1300.00")); + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.OFF); + esc.addText("--------------------------------\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.RIGHT); + esc.addText("收银员:广东包租公\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addText("宣言:我点个鸡蛋都是爱你的形状哦"); + esc.addPrintAndLineFeed(); + esc.addPrintAndLineFeed(); + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + // 设置纠错等级 + esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); + // 设置qrcode模块大小 + esc.addSelectSizeOfModuleForQRCode((byte) 4); + // 设置qrcode内容 + esc.addStoreQRCodeData("https://www.baidu.com"); + // 打印QRCode + esc.addPrintQRCode(); + esc.addText("\n(扫二维码送手机)\n"); + esc.addText("\n\n\n\n"); + esc.addPrintAndLineFeed(); + //切纸(带切刀打印机才可用) + esc.addCutPaper(); + // 开钱箱 + esc.addGeneratePlus(LabelCommand.FOOT.F2, (byte) 255, (byte) 255); + esc.addInitializePrinter(); + //返回指令集 + return esc.getCommand(); + } + /** + * 菜单样例 + * @param context + * @return + */ + public static Vector get80Menu(Context context) { + EscCommand esc = new EscCommand(); + //初始化打印机 + esc.addInitializePrinter(); + // 设置打印居中 + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.flower);//二维码图片,图片类型bitmap + // 打印图片,图片宽度为384dot 1mm=8dot 用尺子量取图片的宽度单位为Xmm 传入宽度值为 X*8 + esc.drawJpgImage(b, 200); + // 设置为倍高倍宽 + //字体放大两倍 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_2, EscCommand.HEIGHT_ZOOM.MUL_2); + // 打印文字 + esc.addText("爱情餐厅\n\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addText("520号桌\n\n"); + //字体正常 + esc.addSetCharcterSize(EscCommand.WIDTH_ZOOM.MUL_1, EscCommand.HEIGHT_ZOOM.MUL_1); + esc.addText("点菜时间 2020-05-20 5:20\n"); + esc.addText("上菜时间 2020-05-20 13:14\n"); + esc.addText("人数:2人 点菜员:新疆包工头\n"); + esc.addText("------------------三行菜单案例------------------\n"); + esc.addText(Menu80Utils.printThreeData("菜名", "数量", "金额")); + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.OFF); + esc.addText(Menu80Utils.printThreeData("北京烤鸭", "1", "99.99")); + esc.addText(Menu80Utils.printThreeData("四川麻婆豆腐", "1", "39.99")); + esc.addText(Menu80Utils.printThreeData("西湖醋鱼", "1", "59.99")); + esc.addText(Menu80Utils.printThreeData("飞龙汤", "1", "66.66")); + esc.addText(Menu80Utils.printThreeData("无为熏鸭", "1", "88.88")); + esc.addText(Menu80Utils.printThreeData("东坡肉", "1", "39.99")); + esc.addText("------------------四行菜单案例------------------\n"); + //开启加粗 + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.ON); + esc.addText(Menu80Utils.printFourData("菜名", "单价","数量", "金额")); + esc.addTurnEmphasizedModeOnOrOff(EscCommand.ENABLE.OFF); + esc.addText(Menu80Utils.printFourData("北京烤鸭", "99.99","1", "99.99")); + esc.addText(Menu80Utils.printFourData("四川麻婆豆腐", "39.99","1", "39.99")); + esc.addText(Menu80Utils.printFourData("西湖醋鱼", "59.99","1", "59.99")); + esc.addText(Menu80Utils.printFourData("飞龙汤", "66.66","1", "66.66")); + esc.addText(Menu80Utils.printFourData("无为熏鸭", "88.88","1", "88.88")); + esc.addText(Menu80Utils.printFourData("东坡肉", "39.99","1", "39.99")); + esc.addText(Menu80Utils.printFourData("辣子鸡", "66.66","1", "66.66")); + esc.addText(Menu80Utils.printFourData("腊味合蒸", "108.00","1", "108.00")); + esc.addText(Menu80Utils.printFourData("东安子鸡", "119.00","1", "119.00")); + esc.addText(Menu80Utils.printFourData("清蒸武昌鱼", "88.88","1", "88.88")); + esc.addText(Menu80Utils.printFourData("再来两瓶82年的快乐肥宅水(去冰)", "9.00","11", "99.00")); + esc.addText(Menu80Utils.printFourData("老干妈拌饭", "6.66","1", "6.66")); + esc.addText("------------------------------------------------\n"); + esc.addText(Menu80Utils.printTwoData("合计:", "1314.00")); + esc.addText(Menu80Utils.printTwoData("抹零:", "14.00")); + esc.addText(Menu80Utils.printTwoData("应收:", "1300.00")); + esc.addText("------------------------------------------------\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.RIGHT); + esc.addText("收银员:广东包租公\n"); + esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT); + esc.addText("宣言:我点个鸡蛋都是爱你的形状哦\n"); + + esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER); + // 设置纠错等级 + esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); + // 设置qrcode模块大小 + esc.addSelectSizeOfModuleForQRCode((byte) 4); + // 设置qrcode内容 + esc.addStoreQRCodeData("www.baidu.com"); + // 打印QRCode + esc.addPrintQRCode(); + esc.addText("\n(扫二维码送手机)\n"); + esc.addText("\n\n\n\n\n"); + esc.addPrintAndLineFeed(); + //切纸(带切刀打印机才可用) + esc.addCutPaper(); + // 开钱箱 + esc.addGeneratePlus(LabelCommand.FOOT.F2, (byte) 255, (byte) 255); + esc.addInitializePrinter(); + //返回指令集 + return esc.getCommand(); + } + + /** + * 打印自检页 + * @return + */ + public static Vector getSelfTest() { + EscCommand esc = new EscCommand(); + byte[] escSelfTestCommand = {0x1f, 0x1b, 0x1f, (byte) 0x93, 0x10, 0x11, 0x12, 0x15, 0x16, 0x17, 0x10, 0x00}; + esc.addUserCommand(escSelfTestCommand); + return esc.getCommand(); + } + /** + * 获取图片 + * @param context + * @return + */ + public static Bitmap getBitmap(Context context) { + View v = View.inflate(context, R.layout.page, null); + TableLayout tableLayout = (TableLayout) v.findViewById(R.id.line); + TextView total = (TextView) v.findViewById(R.id.total); + TextView cashier = (TextView) v.findViewById(R.id.cashier); + tableLayout.addView(ctv(context, "红茶\n加热\n加糖", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 899, 109)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + tableLayout.addView(ctv(context, "红茶", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 8, 10)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + tableLayout.addView(ctv(context, "红茶", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 8, 10)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + tableLayout.addView(ctv(context, "红茶", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 8, 10)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + tableLayout.addView(ctv(context, "红茶", 3, 8)); + tableLayout.addView(ctv(context, "绿茶", 8, 10)); + tableLayout.addView(ctv(context, "咖啡", 4, 15)); + total.setText("998"); + cashier.setText("张三"); + final Bitmap bitmap = convertViewToBitmap(v); + return bitmap; + } + /** + * mxl转bitmap图片 + * @param view + * @return + */ + public static Bitmap convertViewToBitmap(View view){ + view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); + view.buildDrawingCache(); + Bitmap bitmap = view.getDrawingCache(); + return bitmap; + } + + public static TableRow ctv(Context context, String name, int k, int n){ + TableRow tb=new TableRow(context); + tb.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT ,TableLayout.LayoutParams.WRAP_CONTENT)); + TextView tv1=new TextView(context); + tv1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv1.setText(name); + tv1.setTextColor(Color.BLACK); + tv1.setTextSize(30); + tb.addView(tv1); + TextView tv2=new TextView(context); + tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv2.setText(k+""); + tv2.setTextColor(Color.BLACK); + tv2.setTextSize(30); + tb.addView(tv2); + TextView tv3=new TextView(context); + tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT ,TableRow.LayoutParams.WRAP_CONTENT)); + tv3.setText(n+""); + tv3.setTextColor(Color.BLACK); + tv3.setTextSize(30); + tb.addView(tv3); + return tb; + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Printer.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Printer.java new file mode 100755 index 0000000..efca8a3 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Printer.java @@ -0,0 +1,166 @@ +package com.printer.tscdemo; + +import com.gprinter.bean.PrinterDevices; +import com.gprinter.io.BluetoothPort; +import com.gprinter.io.EthernetPort; +import com.gprinter.io.PortManager; +import com.gprinter.io.SerialPort; +import com.gprinter.io.UsbPort; +import com.gprinter.utils.Command; + +import java.io.IOException; +import java.util.Vector; + +/** + * Copyright (C), 2012-2019, 打印机有限公司 + * FileName: Printer + * Author: Circle + * Date: 2019/12/25 19:46 + * Description: 打印机使用单例 + */ +public class Printer { + public static Printer printer=null; + public static PortManager portManager=null; + public final PrinterDevices devices=null; + public Printer(){ + } + /** + * 单例 + * @return + */ + public static Printer getInstance(){ + if (printer==null){ + printer=new Printer(); + } + return printer; + } + + /** + * 获取打印机管理类 + * @return + */ + public static PortManager getPortManager(){ + return portManager; + } + + /** + * 获取连接状态 + * @return + */ + public static boolean getConnectState(){ + return portManager.getConnectStatus(); + } + + /** + * 连接 + * @param devices + */ + public static void connect(final PrinterDevices devices){ + ThreadPoolManager.getInstance().addTask(new Runnable() { + @Override + public void run() { + if (portManager!=null) {//先close上次连接 + portManager.closePort(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } + } + if (devices!=null) { + switch (devices.getConnMethod()) { + case BLUETOOTH://蓝牙 + portManager = new BluetoothPort(devices); + portManager.openPort(); + break; + case USB://USB + portManager = new UsbPort(devices); + portManager.openPort(); + break; + case WIFI://WIFI + portManager = new EthernetPort(devices); + portManager.openPort(); + break; + case SERIALPORT://串口 + portManager=new SerialPort(devices); + portManager.openPort(); + break; + default: + break; + } + } + + } + }); + } + /** + * 发送数据到打印机 字节数据 + * @param vector + * @return true发送成功 false 发送失败 + * 打印机连接异常或断开发送时会抛异常,可以捕获异常进行处理 + */ + public static boolean sendDataToPrinter(byte [] vector) throws IOException { + if (portManager==null){ + return false; + } + return portManager.writeDataImmediately(vector); + } + + /** + * 获取打印机状态 + * @param printerCommand 打印机命令 ESC为小票,TSC为标签 ,CPCL为面单 + * @return 返回值常见文档说明 + * @throws IOException + */ + public static int getPrinterState(Command printerCommand, long delayMillis)throws IOException { + return portManager.getPrinterStatus(printerCommand); + } + + /** + * 获取打印机电量 + * @return + * @throws IOException + */ + public static int getPower() throws IOException { + return portManager.getPower(); + } + /** + * 获取打印机指令 + * @return + */ + public static Command getPrinterCommand(){ + return portManager.getCommand(); + } + + /** + * 设置使用指令 + * @param printerCommand + */ + public static void setPrinterCommand(Command printerCommand){ + if (portManager==null){ + return; + } + portManager.setCommand(printerCommand); + } + /** + * 发送数据到打印机 指令集合内容 + * @param vector + * @return true发送成功 false 发送失败 + * 打印机连接异常或断开发送时会抛异常,可以捕获异常进行处理 + */ + public static boolean sendDataToPrinter(Vector vector) throws IOException { + if (portManager==null){ + return false; + } + return portManager.writeDataImmediately(vector); + } + /** + * 关闭连接 + * @return + */ + public static void close(){ + if (portManager!=null){ + portManager.closePort(); + portManager=null; + } + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SerialPortDeviceActivity.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SerialPortDeviceActivity.java new file mode 100755 index 0000000..2f16bfa --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SerialPortDeviceActivity.java @@ -0,0 +1,109 @@ +package com.printer.tscdemo; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; + +import com.gprinter.utils.SerialPortFinder; + + +/** + * Copyright (C), 2012-2019, 打印机有限公司 + * FileName: Printer + * Author: Circle + * Date: 2019/12/25 19:46 + * Description: 打印机使用单例 + */ +public class SerialPortDeviceActivity extends Activity { + public static String SERIALPORT_PATH="SERIAL_PORT_PATH"; + public static String SERIALPORT_BAUDRATE="SERIAL_PORT_BAUD_RATE"; + private SerialPortFinder mSerialPortFinder; + private String[] entries; + private String[] entryValues; + private Spinner spSerialPortPath; + private Spinner spBaudrate; + private String path; + private int selectBaudrate; + private String[] baudrates; + private Button btnConfirm; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_serial_port); + baudrates = this.getResources().getStringArray(R.array.baudrate); + mSerialPortFinder = new SerialPortFinder(); + entries = mSerialPortFinder.getAllDevices(); + //获取串口路径 + entryValues = mSerialPortFinder.getAllDevicesPath(); + initView(); + initListener(); + } + + private void initView() { + //串口路径初始化 + spSerialPortPath = (Spinner) findViewById(R.id.sp_serialport_path); + ArrayAdapter arrayAdapter; + if (entries != null) { + arrayAdapter = new ArrayAdapter(this, R.layout.text_item, entries); + } else { + arrayAdapter = new ArrayAdapter(this, R.layout.text_item, new String[]{this.getString(R.string.str_no_serialport)}); + } + spSerialPortPath.setAdapter(arrayAdapter); + //波特率数据初始化 + spBaudrate = (Spinner) findViewById(R.id.sp_baudrate); + ArrayAdapter portAdapter = new ArrayAdapter(this, R.layout.text_item, this.getResources().getStringArray(R.array.baudrate)); + spBaudrate.setAdapter(portAdapter); + btnConfirm = (Button) findViewById(R.id.btn_confirm); + } + + private void initListener() { + spBaudrate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + //保存当前选择的波特率 + selectBaudrate = Integer.parseInt(baudrates[position]); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + + spSerialPortPath.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (entryValues != null) { + path = entryValues[position]; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + + btnConfirm.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!TextUtils.isEmpty(path)) { + Intent intent = new Intent(); + Bundle bundle = new Bundle(); + bundle.putString(SERIALPORT_PATH, path); + bundle.putInt(SERIALPORT_BAUDRATE, selectBaudrate); + intent.putExtras(bundle); + setResult(RESULT_OK, intent); + } + finish(); + } + }); + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SharedPreferencesUtil.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SharedPreferencesUtil.java new file mode 100755 index 0000000..668f3b9 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/SharedPreferencesUtil.java @@ -0,0 +1,69 @@ +package com.printer.tscdemo; + +import android.content.Context; +import android.content.SharedPreferences; + +/** + * Created by Administrator + */ +public class SharedPreferencesUtil { + private static final String NAME = "Configs"; + private static SharedPreferences sharedPreferences; + private static SharedPreferencesUtil sharedPreferencesUtil; + + private SharedPreferencesUtil(){ + + } + + public static SharedPreferencesUtil getInstantiation(Context context) { + if (sharedPreferences == null) { + sharedPreferencesUtil = new SharedPreferencesUtil(); + getSharedPreferences(context); + } + return sharedPreferencesUtil; + } + + private static void getSharedPreferences(Context context) { + sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); + } + + public void putInt(int value, String key) { + sharedPreferences.edit().putInt(key, value).apply(); + } + + public void putString(String value, String key) { + sharedPreferences.edit().putString(key, value).apply(); + } + + public void putBoolean(boolean value, String key) { + sharedPreferences.edit().putBoolean(key, value).apply(); + } + + public void putFloat(float value, String key) { + sharedPreferences.edit().putFloat(key, value).apply(); + } + + public void putLong(long value, String key) { + sharedPreferences.edit().putLong(key, value).apply(); + } + + public int getInt(int defaultValue, String key) { + return sharedPreferences.getInt(key, defaultValue); + } + + public String getString(String defaultValue, String key) { + return sharedPreferences.getString(key, defaultValue); + } + + public boolean getBoolean(boolean defaultValue, String key) { + return sharedPreferences.getBoolean(key, defaultValue); + } + + public float getFloat(float defaultValue, String key) { + return sharedPreferences.getFloat(key, defaultValue); + } + + public void clear() { + sharedPreferences.edit().clear().apply(); + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadFactoryBuilder.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadFactoryBuilder.java new file mode 100755 index 0000000..9a175c9 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadFactoryBuilder.java @@ -0,0 +1,30 @@ +package com.printer.tscdemo; + + +import java.util.concurrent.ThreadFactory; + +/** + * Created by Circle on 2018/5/24. + */ + +/** + * 作者: Circle + * 创造于 2018/5/24. + */ +public class ThreadFactoryBuilder implements ThreadFactory { + + private String name; + private int counter; + + public ThreadFactoryBuilder(String name) { + this.name = name; + counter = 1; + } + + @Override + public Thread newThread(Runnable runnable) { + Thread thread = new Thread(runnable, name); + thread.setName("ThreadFactoryBuilder_" + name + "_" + counter); + return thread; + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadPoolManager.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadPoolManager.java new file mode 100755 index 0000000..0f61795 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/ThreadPoolManager.java @@ -0,0 +1,92 @@ +package com.printer.tscdemo; + +import android.util.Log; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Created by Circle on 2019/9/17. + * 线程池管理类 + */ + +public class ThreadPoolManager { + String TAG=ThreadPoolManager.class.getSimpleName(); + private static ThreadPoolManager threadPoolManager=null; + + public static ThreadPoolManager getInstance(){ + if (threadPoolManager == null) { + threadPoolManager =new ThreadPoolManager(); + } + return threadPoolManager; + } + //线程安全 + private LinkedBlockingDeque mQueue=new LinkedBlockingDeque<>(); + + private ThreadPoolExecutor mThreadPoolExecutor; + //创建线程池 + private ThreadPoolManager(){ + mThreadPoolExecutor=new ThreadPoolExecutor(1, 100, 15, TimeUnit.SECONDS, new ArrayBlockingQueue(100), new RejectedExecutionHandler() { + @Override + public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { + addTask(r); + } + }); + new Thread(coreTread).start(); +// mThreadPoolExecutor.execute(coreTread);//执行核心线程池 + } + + + //将请求添加到队列中 + public void addTask(Runnable runnable){ + Log.e(TAG,runnable.getClass().getSimpleName()); + if (runnable!=null){ + try { + mQueue.put(runnable); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + public void addTopTask(Runnable runnable){ + if (runnable!=null){ + try { + mQueue.putFirst(runnable); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + //创建核心线程 + public Runnable coreTread=new Runnable() { + Runnable runn=null; + @Override + public void run() { + while (true) { + try { + runn = mQueue.take(); + synchronized(this){ + mThreadPoolExecutor.execute(runn);//执行线程 + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }; + + /** + * 结束线程池 + */ + public void stopThreadPool() { + if (mThreadPoolExecutor != null) { + mThreadPoolExecutor.shutdown(); + mQueue.clear(); + mThreadPoolExecutor = null; + threadPoolManager = null; + } + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/UsbDeviceActivity.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/UsbDeviceActivity.java new file mode 100755 index 0000000..b5bb629 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/UsbDeviceActivity.java @@ -0,0 +1,124 @@ +package com.printer.tscdemo; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbManager; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; + +import java.util.HashMap; +import java.util.Iterator; + +/** + * Copyright (C), 2012-2020, 打印机有限公司 + * FileName: UsbDeviceListActivity + * Author: Circle + * Date: 2020/7/18 16:17 + * Description: 获取USB设备列表 + */ +public class UsbDeviceActivity extends AppCompatActivity { + + private static final String TAG = UsbDeviceActivity.class.getSimpleName(); + /** + * Member fields + */ + private ListView lvDevices = null; + private ArrayAdapter adapter; + public static final String USB_NAME = "usb_name"; + UsbManager manager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_usb); + setTitle(getString(R.string.usb_label)); + initView(); + getUsbDeviceList(); + } + /** + * 初始化视图、控件 + */ + private void initView() { + lvDevices = (ListView) findViewById(R.id.lv_usb); + adapter = new ArrayAdapter(this,R.layout.text_item); + lvDevices.setOnItemClickListener(mDeviceClickListener); + lvDevices.setAdapter(adapter); + } + + /** + * 检查USB设备的PID与VID + * @param dev + * @return + */ + boolean checkUsbDevicePidVid(UsbDevice dev) { + int pid = dev.getProductId(); + int vid = dev.getVendorId(); + return ((vid == 34918 && pid == 256) || (vid == 1137 && pid == 85) + || (vid == 6790 && pid == 30084) + || (vid == 26728 && pid == 256) || (vid == 26728 && pid == 512) + || (vid == 26728 && pid == 256) || (vid == 26728 && pid == 768) + || (vid == 26728 && pid == 1024) || (vid == 26728 && pid == 1280) + || (vid == 26728 && pid == 1536)); + } + + /** + * 获取USB设备列表 + */ + public void getUsbDeviceList() { + manager = (UsbManager) getSystemService(Context.USB_SERVICE); + // Get the list of attached devices + HashMap devices = manager.getDeviceList(); + Iterator deviceIterator = devices.values().iterator(); + int count = devices.size(); + Log.d(TAG, "count " + count); + if (count > 0) { + while (deviceIterator.hasNext()) { + UsbDevice device = deviceIterator.next(); + String devicename = device.getDeviceName(); + if (checkUsbDevicePidVid(device)) { + adapter.add(devicename); + } + } + } else { + String noDevices = getResources().getText(R.string.none_usb_device).toString(); + Log.d(TAG, "noDevices " + noDevices); + adapter.add(noDevices); + } + } + + private AdapterView.OnItemClickListener mDeviceClickListener = new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView av, View v, int arg2, long arg3) { + // Cancel discovery because it's costly and we're about to connect + // Get the device MAC address, which is the last 17 chars in the View + String info = ((TextView) v).getText().toString(); + String noDevices = getResources().getText(R.string.none_usb_device).toString(); + if (!info.equals(noDevices)) { + String address = info; + // Create the result Intent and include the MAC address + Intent intent = new Intent(); + intent.putExtra(USB_NAME, address); + // Set result and finish this Activity + setResult(Activity.RESULT_OK, intent); + } + finish(); + } + }; + + @Override + protected void onDestroy() { + super.onDestroy(); + if (manager!=null){ + manager=null; + } + } +} \ No newline at end of file diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Utils.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Utils.java new file mode 100755 index 0000000..a151f9f --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/Utils.java @@ -0,0 +1,146 @@ +package com.printer.tscdemo; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbManager; +import android.widget.Toast; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 作者: Circle + * 创造于 2018/5/24. + */ +public class Utils { + /** + * 通过USB名称获取设备 + * @param context + * @param usbName + * @return + */ + public static UsbDevice getUsbDeviceFromName(Context context, String usbName) { + UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); + HashMap usbDeviceList = usbManager.getDeviceList(); + return usbDeviceList.get(usbName); + } + /** + * 短时间吐司 + * @param context + * @param msg + */ + public static void shortToast(Context context,String msg){ + Toast.makeText(context,msg,Toast.LENGTH_SHORT).show(); + } + /** + * 合拼两个数组 + * @param first + * @param second + * @param + * @return + */ + public static byte[] concat(byte[] first, byte[] second) { + byte[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + /** + * 检测WiFi的IP是否输入正确 + * @param addr + * @return + */ + public static boolean checkIP(String addr) + + { + if(addr.length() < 7 || addr.length() > 15 || "".equals(addr)) + { + return false; + } + /** + * 判断IP格式和范围 + */ + String rexp = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}"; + Pattern pat = Pattern.compile(rexp); + Matcher mat = pat.matcher(addr); + boolean ipAddress = mat.find(); + //============对之前的ip判断的bug在进行判断 + if (ipAddress==true){ + String ips[] = addr.split("\\."); + if(ips.length==4){ + try{ + for(String ip : ips){ + if(Integer.parseInt(ip)<0||Integer.parseInt(ip)>255){ + return false; + } + } + }catch (Exception e){ + return false; + } + return true; + }else{ + return false; + } + } + return ipAddress; + } + /** + * 获取指定包名的版本号 + * + * @param context + * 本应用程序上下文 + * @return + * @throws Exception + */ + public static String getVersionName(Context context) { + // 获取packagemanager的实例 + PackageManager packageManager = context.getPackageManager(); + try { + PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0); + String version = packInfo.versionName; + return version; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return ""; + + } + public static byte [] getAssetsFile(Context context,String fileName) { + InputStream in = null; + ByteArrayOutputStream outStream = null; + byte [] data=null; + try { + in = context.getResources().getAssets().open(fileName); + outStream = new ByteArrayOutputStream(); + //创建byte数组 + byte[] buffer = new byte[1024*1024]; + //将文件中的数据读到byte数组中 + int len = 0; + while ((len = in.read(buffer)) != -1) { + outStream.write(buffer, 0, len); + } + data = outStream.toByteArray(); + return data; + } catch (IOException e) { + e.printStackTrace(); + }finally { + try { + if (in!=null){ + in.close(); + } + if (outStream!=null){ + outStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return data; + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/WifiDeviceActivity.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/WifiDeviceActivity.java new file mode 100755 index 0000000..6f8be74 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/WifiDeviceActivity.java @@ -0,0 +1,68 @@ +package com.printer.tscdemo; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + + +/** + * Copyright (C), 2012-2019, 打印机有限公司 + * FileName: Printer + * Author: Circle + * Date: 2019/12/25 19:46 + * Description: WIFI打印机设备 + */ +public class WifiDeviceActivity extends Activity { + public static String IP="IP"; + public Context context; + public EditText edWifi; + public Button btnOK; + SharedPreferencesUtil sharedPreferencesUtil; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_wifi); + context=WifiDeviceActivity.this; + sharedPreferencesUtil= SharedPreferencesUtil.getInstantiation(context); + initView(); + } + + private void initView() { + //串口路径初始化 + edWifi = (EditText)findViewById(R.id.et_wifi_ip); + btnOK=(Button)findViewById(R.id.btn_confirm) ; + String ip = sharedPreferencesUtil.getString("192.168.123.100", IP); + edWifi.setText(ip); + initListener(); + } + + private void initListener() { + btnOK.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String ip=edWifi.getText().toString().trim(); + if (TextUtils.isEmpty(ip)&&!Utils.checkIP(ip)){//ip不合法 + Utils.shortToast(context,context.getString(R.string.ip_is_illegal)); + return; + } + sharedPreferencesUtil.putString(ip,IP); + Intent intent = new Intent(); + Bundle bundle = new Bundle(); + bundle.putString(IP, ip); + intent.putExtras(bundle); + setResult(RESULT_OK, intent); + finish(); + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/bean/BluetoothParameter.java b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/bean/BluetoothParameter.java new file mode 100755 index 0000000..986e2fc --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/java/com/printer/tscdemo/bean/BluetoothParameter.java @@ -0,0 +1,30 @@ +package com.printer.tscdemo.bean; + +public class BluetoothParameter { + private String bluetoothName; + private String bluetoothMac; + private String bluetoothStrength;/*蓝牙强度*/ + public String getBluetoothName() { + return bluetoothName; + } + + public void setBluetoothName(String bluetoothName) { + this.bluetoothName = bluetoothName; + } + + public String getBluetoothMac() { + return bluetoothMac; + } + + public void setBluetoothMac(String bluetoothMac) { + this.bluetoothMac = bluetoothMac; + } + + public String getBluetoothStrength() { + return bluetoothStrength; + } + + public void setBluetoothStrength(String bluetoothStrength) { + this.bluetoothStrength = bluetoothStrength; + } +} diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/arm64-v8a/libserial_port.so b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/arm64-v8a/libserial_port.so new file mode 100755 index 0000000..e8a1f48 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/arm64-v8a/libserial_port.so differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi-v7a/libserial_port.so b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi-v7a/libserial_port.so new file mode 100755 index 0000000..78df841 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi-v7a/libserial_port.so differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi/libserial_port.so b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi/libserial_port.so new file mode 100755 index 0000000..3b03715 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/jniLibs/armeabi/libserial_port.so differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100755 index 0000000..1f6bb29 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/flower.jpg b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/flower.jpg new file mode 100755 index 0000000..cf1a061 Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/flower.jpg differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/head.jpg b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/head.jpg new file mode 100755 index 0000000..ab0d26c Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/head.jpg differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/ic_launcher_background.xml b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100755 index 0000000..0d025f9 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/test.bmp b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/test.bmp new file mode 100755 index 0000000..ad920bc Binary files /dev/null and b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/drawable/test.bmp differ diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_blue_tooth_device_list.xml b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_blue_tooth_device_list.xml new file mode 100755 index 0000000..6c51a59 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_blue_tooth_device_list.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_bluetooth.xml b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_bluetooth.xml new file mode 100755 index 0000000..d86ef45 --- /dev/null +++ b/打印机SDK/Android/标签打印机安卓SDK-V3.3.1-20230327/TscDemo/app/src/main/res/layout/activity_bluetooth.xml @@ -0,0 +1,18 @@ + + + +