Jelajahi Sumber

打印机 5.7.2

SongJiaTong 2 tahun lalu
melakukan
01abaca8cc
100 mengubah file dengan 12908 tambahan dan 0 penghapusan
  1. 13 0
      .gitignore
  2. 1 0
      PrintDemoV5.7.1/.gitignore
  3. 49 0
      PrintDemoV5.7.1/build.gradle
  4. TEMPAT SAMPAH
      PrintDemoV5.7.1/gradle/wrapper/gradle-wrapper.jar
  5. 6 0
      PrintDemoV5.7.1/gradle/wrapper/gradle-wrapper.properties
  6. 160 0
      PrintDemoV5.7.1/gradlew
  7. 90 0
      PrintDemoV5.7.1/gradlew.bat
  8. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/arm64-v8a/libmupdf.so
  9. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/arm64-v8a/libserial_port_sp.so
  10. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/armeabi-v7a/libmupdf.so
  11. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/armeabi-v7a/libserial_port_sp.so
  12. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/armeabi/libmupdf.so
  13. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/armeabi/libserial_port_sp.so
  14. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/printersdkv5.7.2.jar
  15. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/x86/libmupdf.so
  16. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/x86/libserial_port_sp.so
  17. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/x86_64/libmupdf.so
  18. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/x86_64/libserial_port_sp.so
  19. TEMPAT SAMPAH
      PrintDemoV5.7.1/libs/x86_64/printersdkv5.6.9.jar
  20. 9 0
      PrintDemoV5.7.1/local.properties
  21. 21 0
      PrintDemoV5.7.1/proguard-rules.pro
  22. TEMPAT SAMPAH
      PrintDemoV5.7.1/release/PrintDemoV5.7.1-release.apk
  23. 1 0
      PrintDemoV5.7.1/release/output.json
  24. 128 0
      PrintDemoV5.7.1/src/main/AndroidManifest.xml
  25. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/assets/test.txt
  26. 161 0
      PrintDemoV5.7.1/src/main/java/com/android/print/demo/loghelper/LogcatHelper.java
  27. 19 0
      PrintDemoV5.7.1/src/main/java/com/android/print/demo/loghelper/MyDate.java
  28. 48 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/AutoFocusCallback.java
  29. 293 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/CameraConfigurationManager.java
  30. 326 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/CameraManager.java
  31. 154 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/FlashlightManager.java
  32. 134 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/PlanarYUVLuminanceSource.java
  33. 59 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/PreviewCallback.java
  34. 138 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/CaptureActivityHandler.java
  35. 106 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeFormatManager.java
  36. 112 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeHandler.java
  37. 87 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeThread.java
  38. 47 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/FinishListener.java
  39. 71 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/InactivityTimer.java
  40. 190 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/Intents.java
  41. 35 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/view/ViewfinderResultPointCallback.java
  42. 258 0
      PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/view/ViewfinderView.java
  43. 392 0
      PrintDemoV5.7.1/src/main/java/com/printer/MainActivity22.java
  44. 697 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/BarcoePrintActivity.java
  45. 93 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/BaseActivity.java
  46. 211 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/BluetoothDeviceList.java
  47. 370 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/CollectPrintActivity.java
  48. 77 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/DemoApplication.java
  49. 36 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/ExitApplication.java
  50. 174 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/IpEditActivity.java
  51. 124 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/ItemPdfPdfactivity.java
  52. 736 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/LablePrintActivity.java
  53. 401 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/MainActivity.java
  54. 339 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/MaterialTransportActivity.java
  55. 328 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/MipcaActivityCapture.java
  56. 273 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/PdfPrintActivity.java
  57. 422 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/PicturePrintActivity.java
  58. 155 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/SerialsDeviceList.java
  59. 1101 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/SettingActivity.java
  60. 185 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/TextPrintActivity.java
  61. 112 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/UsbDeviceList.java
  62. 37 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/global/GlobalContants.java
  63. 327 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/CanvasUtils.java
  64. 194 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/CodePageUtils.java
  65. 69 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PictureUtils.java
  66. 130 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrefUtils.java
  67. 22 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintBean.java
  68. 138 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel100.java
  69. 69 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel58.java
  70. 179 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80.java
  71. 179 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80_1.java
  72. 400 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80_test.java
  73. 92 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelDrink.java
  74. 258 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelExpress.java
  75. 159 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelFruit.java
  76. 811 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelMaterial.java
  77. 123 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelStorage.java
  78. 215 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLablel.java
  79. 83 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/UpdateUtils.java
  80. 481 0
      PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/XTUtils.java
  81. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/a.bmp
  82. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/ao.jpg
  83. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/ao1.bmp
  84. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/back_arrow_2.png
  85. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/barcode.png
  86. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/bbbb.png
  87. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_disabled.9.png
  88. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_focused.9.png
  89. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_normal.9.png
  90. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_pressed.9.png
  91. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/confirm_dialog_bg2.9.png
  92. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/edit_normal.9.png
  93. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/edit_pressed.9.png
  94. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/goodwork.bmp
  95. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/ic_about.png
  96. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/ic_launcher.png
  97. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/icon_back.png
  98. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/label_icon7.bmp
  99. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/lable.png
  100. TEMPAT SAMPAH
      PrintDemoV5.7.1/src/main/res/drawable-hdpi/mm_title_back_focused.9.png

+ 13 - 0
.gitignore

@@ -0,0 +1,13 @@
+*.iml
+.gradle
+/local.properties
+/.idea/workspace.xml
+/.idea/libraries
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+/.idea
+/.gradle
+/PrintDemoV5.7.1/.idea
+/projectFilesBackup

+ 1 - 0
PrintDemoV5.7.1/.gitignore

@@ -0,0 +1 @@
+/build

+ 49 - 0
PrintDemoV5.7.1/build.gradle

@@ -0,0 +1,49 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 29
+    defaultConfig {
+        applicationId "com.printer.demo"
+        minSdkVersion 15
+        targetSdkVersion 29
+        versionCode 1
+        versionName "5.7.1"
+        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
+
+        multiDexEnabled true
+//        ndk {
+//            abiFilters "armeabi", "armeabi-v7a", "x86"
+//        }
+    }
+    sourceSets {
+        main {
+            jniLibs.srcDirs = ['libs']
+        }
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+
+    lintOptions {
+        checkReleaseBuilds false
+        // Or, if you prefer, you can continue to check for errors in release builds,
+        // but continue the build even when errors are found:
+        abortOnError false
+    }
+}
+
+dependencies {
+    implementation fileTree(include: ['*.jar'], dir: 'libs')
+    implementation 'androidx.appcompat:appcompat:1.0.0'
+    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+    implementation 'com.google.android.material:material:1.0.0'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
+    compile 'com.allenliu.versionchecklib:library:2.0.5'
+    implementation files('libs/printersdkv5.7.2.jar')
+}

TEMPAT SAMPAH
PrintDemoV5.7.1/gradle/wrapper/gradle-wrapper.jar


+ 6 - 0
PrintDemoV5.7.1/gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,6 @@
+#Tue Sep 10 10:39:49 CST 2019
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip

+ 160 - 0
PrintDemoV5.7.1/gradlew

@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

+ 90 - 0
PrintDemoV5.7.1/gradlew.bat

@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

TEMPAT SAMPAH
PrintDemoV5.7.1/libs/arm64-v8a/libmupdf.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/arm64-v8a/libserial_port_sp.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/armeabi-v7a/libmupdf.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/armeabi-v7a/libserial_port_sp.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/armeabi/libmupdf.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/armeabi/libserial_port_sp.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/printersdkv5.7.2.jar


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/x86/libmupdf.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/x86/libserial_port_sp.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/x86_64/libmupdf.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/x86_64/libserial_port_sp.so


TEMPAT SAMPAH
PrintDemoV5.7.1/libs/x86_64/printersdkv5.6.9.jar


+ 9 - 0
PrintDemoV5.7.1/local.properties

@@ -0,0 +1,9 @@
+## This file must *NOT* be checked into Version Control Systems,
+# as it contains information specific to your local configuration.
+#
+# Location of the SDK. This is only used by Gradle.
+# For customization when using a Version Control System, please read the
+# header note.
+#Thu Mar 16 14:52:06 CST 2023
+sdk.dir=D\:\\Android\\androidsdk
+

+ 21 - 0
PrintDemoV5.7.1/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

TEMPAT SAMPAH
PrintDemoV5.7.1/release/PrintDemoV5.7.1-release.apk


+ 1 - 0
PrintDemoV5.7.1/release/output.json

@@ -0,0 +1 @@
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"PrintDemoV5.7.1-release.apk","properties":{"packageId":"com.printer.demo","split":"","minSdkVersion":"15"}}]

+ 128 - 0
PrintDemoV5.7.1/src/main/AndroidManifest.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.printer.demo"
+    android:versionCode="1"
+    android:versionName="5.6" >
+
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="17" />
+
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+    <uses-permission android:name="android.hardware.usb.host" />
+    <uses-permission android:name="android.permission.FLASHLIGHT" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.CAMERA" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+
+    <uses-feature android:name="android.hardware.camera" />
+    <uses-feature android:name="android.hardware.camera.autofocus" />
+    <uses-feature android:name="android.permission.WRITE_SETTINGS" />
+
+    <application
+        android:name=".DemoApplication"
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@android:style/Theme.NoTitleBar" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name=".SettingActivity"
+            android:windowSoftInputMode="stateAlwaysHidden" />
+        <activity
+            android:name=".PicturePrintActivity"
+            android:configChanges="orientation|keyboard|keyboardHidden|screenSize" />
+        <activity android:name=".TextPrintActivity" />
+        <activity
+            android:name=".BarcoePrintActivity"
+            android:windowSoftInputMode="stateHidden" />
+        <activity
+            android:name=".BluetoothDeviceList"
+            android:screenOrientation="portrait"
+            android:theme="@android:style/Theme.Dialog" />
+        <activity
+            android:name=".UsbDeviceList"
+            android:screenOrientation="portrait"
+            android:theme="@android:style/Theme.Dialog" />
+        <activity
+            android:name=".MipcaActivityCapture"
+            android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
+            android:screenOrientation="portrait"
+            android:windowSoftInputMode="stateAlwaysHidden" >
+        </activity>
+        <activity
+            android:name=".PdfPrintActivity"
+            android:label="@string/title_activity_pdf_print" >
+        </activity>
+        <activity
+            android:name=".ItemPdfPdfactivity"
+            android:label="@string/title_activity_pdf_print" >
+        </activity>
+        <activity
+            android:name=".LablePrintActivity"
+            android:label="@string/title_activity_lable_print" >
+        </activity>
+        <activity
+            android:name=".SerialsDeviceList"
+            android:label="@string/title_activity_lable_print" >
+        </activity>
+        <activity
+            android:name=".IpEditActivity"
+            android:theme="@style/MyDialogStyle" />
+
+        <activity
+            android:name=".MaterialTransportActivity"
+            android:label="@string/title_activity_material_transport"
+            android:windowSoftInputMode="stateHidden" >
+        </activity>
+
+        <activity
+            android:name=".CollectPrintActivity"
+            android:label="@string/title_activity_pdf_print" >
+        </activity>
+
+        <receiver
+            android:name="com.receiver.sprt.yxz.printservice.client.receiver.PrintServiceBroadcastReceiver"
+            android:enabled="true">
+            <intent-filter>
+                <!-- PrintService发送的广播  -->
+                <action android:name="com.sprt.yxz.printservice.service.PrinterService.start_print" />
+                <action android:name="com.sprt.yxz.printservice.service.PrinterService.end_print" />
+                <action android:name="com.sprt.yxz.printservice.service.PrinterService.parser_data" />
+                <action android:name="com.sprt.yxz.printservice.service.PrinterService.parser_data2" />
+                <action android:name="com.sprt.yxz.printservice.service.PrinterService.parser_data3" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </receiver>
+
+        <provider
+            android:name="androidx.core.content.FileProvider"
+            android:authorities="com.printer.demo.fileProvider"
+            android:grantUriPermissions="true"
+            android:exported="false">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/provider_paths" />
+        </provider>
+
+    </application>
+
+</manifest>

TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/assets/test.txt


+ 161 - 0
PrintDemoV5.7.1/src/main/java/com/android/print/demo/loghelper/LogcatHelper.java

@@ -0,0 +1,161 @@
+package com.android.print.demo.loghelper;
+
+import android.content.Context;
+import android.os.Environment;
+import android.util.Log;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * log日志统计保存
+ *
+ * @author way
+ *
+ */
+
+public class LogcatHelper {
+
+    private static LogcatHelper INSTANCE = null;
+    private static String PATH_LOGCAT;
+    private LogDumper mLogDumper = null;
+    private int mPId;
+
+    /**
+     *
+     * 初始化目录
+     *
+     * */
+    public void init(Context context) {
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// 优先保存到SD卡中
+            PATH_LOGCAT = Environment.getExternalStorageDirectory()
+                    .getAbsolutePath() + File.separator + "Logs";
+        } else {// 如果SD卡不存在,就保存到本应用的目录下
+            PATH_LOGCAT = context.getFilesDir().getAbsolutePath()
+                    + File.separator + "Logs";
+        }
+        Log.i("fdh", "PATH_LOGCAT"+PATH_LOGCAT);
+        File file = new File(PATH_LOGCAT);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+
+    }
+
+    public static LogcatHelper getInstance(Context context) {
+        if (INSTANCE == null) {
+            INSTANCE = new LogcatHelper(context);
+        }
+        return INSTANCE;
+    }
+
+    private LogcatHelper(Context context) {
+        init(context);
+        mPId = android.os.Process.myPid();
+    }
+
+    public void start() {
+        if (mLogDumper == null)
+            mLogDumper = new LogDumper(String.valueOf(mPId), PATH_LOGCAT);
+        mLogDumper.start();
+    }
+
+    public void stop() {
+        if (mLogDumper != null) {
+            mLogDumper.stopLogs();
+            mLogDumper = null;
+        }
+    }
+
+    private class LogDumper extends Thread {
+
+        private Process logcatProc;
+        private BufferedReader mReader = null;
+        private boolean mRunning = true;
+        String cmds = null;
+        private String mPID;
+        private FileOutputStream out = null;
+
+        public LogDumper(String pid, String dir) {
+            mPID = pid;
+            try {
+                out = new FileOutputStream(new File(dir, MyDate.getDateEN() + ".log"));
+            } catch (FileNotFoundException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+
+            /**
+             *
+             * 日志等级:*:v , *:d , *:w , *:e , *:f , *:s
+             *
+             * 显示当前mPID程序的 E和W等级的日志.
+             *
+             * */
+
+            // cmds = "logcat *:e *:w | grep \"(" + mPID + ")\"";
+            // cmds = "logcat  | grep \"(" + mPID + ")\"";//打印所有日志信息
+            // cmds = "logcat -s way";//打印标签过滤信息
+            cmds = "logcat *:e *:i *:w *:d| grep \"(" + mPID + ")\"";
+
+        }
+
+        public void stopLogs() {
+            mRunning = false;
+        }
+
+        @Override
+        public void run() {
+            try {
+                logcatProc = Runtime.getRuntime().exec(cmds);
+                mReader = new BufferedReader(new InputStreamReader(
+                        logcatProc.getInputStream()), 1024);
+                String line = null;
+                while (mRunning && (line = mReader.readLine()) != null) {
+                    if (!mRunning) {
+                        break;
+                    }
+                    if (line.length() == 0) {
+                        continue;
+                    }
+                    if (out != null && line.contains(mPID)) {
+                        out.write((MyDate.getDateEN() + "  " + line + "\n")
+                                .getBytes());
+                    }
+                }
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            } finally {
+                if (logcatProc != null) {
+                    logcatProc.destroy();
+                    logcatProc = null;
+                }
+                if (mReader != null) {
+                    try {
+                        mReader.close();
+                        mReader = null;
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+                if (out != null) {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                    out = null;
+                }
+
+            }
+
+        }
+
+    }
+
+}

+ 19 - 0
PrintDemoV5.7.1/src/main/java/com/android/print/demo/loghelper/MyDate.java

@@ -0,0 +1,19 @@
+package com.android.print.demo.loghelper;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class MyDate {
+    public static String getFileName() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        String date = format.format(new Date(System.currentTimeMillis()));
+        return date;// 2012年10月03日 23:41:31
+    }
+
+    public static String getDateEN() {
+        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String date1 = format1.format(new Date(System.currentTimeMillis()));
+        return date1;// 2012-10-03 23:41:31
+    }
+
+}

+ 48 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/AutoFocusCallback.java

@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.hardware.Camera;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+final class AutoFocusCallback implements Camera.AutoFocusCallback {
+
+  private static final String TAG = AutoFocusCallback.class.getSimpleName();
+
+  private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
+
+  private Handler autoFocusHandler;
+  private int autoFocusMessage;
+
+  void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
+    this.autoFocusHandler = autoFocusHandler;
+    this.autoFocusMessage = autoFocusMessage;
+  }
+
+  public void onAutoFocus(boolean success, Camera camera) {
+    if (autoFocusHandler != null) {
+      Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
+      autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
+      autoFocusHandler = null;
+    } else {
+      Log.d(TAG, "Got auto-focus callback, but no handler for it");
+    }
+  }
+
+}

+ 293 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/CameraConfigurationManager.java

@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.content.Context;
+import android.graphics.Point;
+import android.hardware.Camera;
+import android.os.Build;
+import android.util.Log;
+import android.view.Display;
+import android.view.WindowManager;
+
+import java.lang.reflect.Method;
+import java.util.regex.Pattern;
+
+final class CameraConfigurationManager {
+
+  private static final String TAG = CameraConfigurationManager.class.getSimpleName();
+
+  private static final int TEN_DESIRED_ZOOM = 27;
+  private static final int DESIRED_SHARPNESS = 30;
+
+  private static final Pattern COMMA_PATTERN = Pattern.compile(",");
+
+  private final Context context;
+  private Point screenResolution;
+  private Point cameraResolution;
+  private int previewFormat;
+  private String previewFormatString;
+
+  CameraConfigurationManager(Context context) {
+    this.context = context;
+  }
+
+  /**
+   * Reads, one time, values from the camera that are needed by the app.
+   */
+  void initFromCameraParameters(Camera camera) {
+    Camera.Parameters parameters = camera.getParameters();
+    previewFormat = parameters.getPreviewFormat();
+    previewFormatString = parameters.get("preview-format");
+    Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
+    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+    Display display = manager.getDefaultDisplay();
+    screenResolution = new Point(display.getWidth(), display.getHeight());
+    Log.d(TAG, "Screen resolution: " + screenResolution);
+    cameraResolution = getCameraResolution(parameters, screenResolution);
+    Log.d(TAG, "Camera resolution: " + screenResolution);
+  }
+
+  /**
+   * Sets the camera up to take preview images which are used for both preview and decoding.
+   * We detect the preview format here so that buildLuminanceSource() can build an appropriate
+   * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest,
+   * and the planar Y can be used for barcode scanning without a copy in some cases.
+   */
+  void setDesiredCameraParameters(Camera camera) {
+    Camera.Parameters parameters = camera.getParameters();
+    Log.d(TAG, "Setting preview size: " + cameraResolution);
+    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
+    setFlash(parameters);
+    setZoom(parameters);
+    //setSharpness(parameters);
+    //modify here
+
+//    camera.setDisplayOrientation(90);
+    //兼容2.1
+    setDisplayOrientation(camera, 90);
+    camera.setParameters(parameters);
+  }
+
+  Point getCameraResolution() {
+    return cameraResolution;
+  }
+
+  Point getScreenResolution() {
+    return screenResolution;
+  }
+
+  int getPreviewFormat() {
+    return previewFormat;
+  }
+
+  String getPreviewFormatString() {
+    return previewFormatString;
+  }
+
+  private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) {
+
+    String previewSizeValueString = parameters.get("preview-size-values");
+    // saw this on Xperia
+    if (previewSizeValueString == null) {
+      previewSizeValueString = parameters.get("preview-size-value");
+    }
+
+    Point cameraResolution = null;
+
+    if (previewSizeValueString != null) {
+      Log.d(TAG, "preview-size-values parameter: " + previewSizeValueString);
+      cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution);
+    }
+
+    if (cameraResolution == null) {
+      // Ensure that the camera resolution is a multiple of 8, as the screen may not be.
+      cameraResolution = new Point(
+              (screenResolution.x >> 3) << 3,
+              (screenResolution.y >> 3) << 3);
+    }
+
+    return cameraResolution;
+  }
+
+  private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) {
+    int bestX = 0;
+    int bestY = 0;
+    int diff = Integer.MAX_VALUE;
+    for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {
+
+      previewSize = previewSize.trim();
+      int dimPosition = previewSize.indexOf('x');
+      if (dimPosition < 0) {
+        Log.w(TAG, "Bad preview-size: " + previewSize);
+        continue;
+      }
+
+      int newX;
+      int newY;
+      try {
+        newX = Integer.parseInt(previewSize.substring(0, dimPosition));
+        newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
+      } catch (NumberFormatException nfe) {
+        Log.w(TAG, "Bad preview-size: " + previewSize);
+        continue;
+      }
+
+      int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
+      if (newDiff == 0) {
+        bestX = newX;
+        bestY = newY;
+        break;
+      } else if (newDiff < diff) {
+        bestX = newX;
+        bestY = newY;
+        diff = newDiff;
+      }
+
+    }
+
+    if (bestX > 0 && bestY > 0) {
+      return new Point(bestX, bestY);
+    }
+    return null;
+  }
+
+  private static int findBestMotZoomValue(CharSequence stringValues, int tenDesiredZoom) {
+    int tenBestValue = 0;
+    for (String stringValue : COMMA_PATTERN.split(stringValues)) {
+      stringValue = stringValue.trim();
+      double value;
+      try {
+        value = Double.parseDouble(stringValue);
+      } catch (NumberFormatException nfe) {
+        return tenDesiredZoom;
+      }
+      int tenValue = (int) (10.0 * value);
+      if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom - tenBestValue)) {
+        tenBestValue = tenValue;
+      }
+    }
+    return tenBestValue;
+  }
+
+  private void setFlash(Camera.Parameters parameters) {
+    // FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
+    // And this is a hack-hack to work around a different value on the Behold II
+    // Restrict Behold II check to Cupcake, per Samsung's advice
+    //if (Build.MODEL.contains("Behold II") &&
+    //    CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
+    if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake
+      parameters.set("flash-value", 1);
+    } else {
+      parameters.set("flash-value", 2);
+    }
+    // This is the standard setting to turn the flash off that all devices should honor.
+    parameters.set("flash-mode", "off");
+  }
+
+  private void setZoom(Camera.Parameters parameters) {
+
+    String zoomSupportedString = parameters.get("zoom-supported");
+    if (zoomSupportedString != null && !Boolean.parseBoolean(zoomSupportedString)) {
+      return;
+    }
+
+    int tenDesiredZoom = TEN_DESIRED_ZOOM;
+
+    String maxZoomString = parameters.get("max-zoom");
+    if (maxZoomString != null) {
+      try {
+        int tenMaxZoom = (int) (10.0 * Double.parseDouble(maxZoomString));
+        if (tenDesiredZoom > tenMaxZoom) {
+          tenDesiredZoom = tenMaxZoom;
+        }
+      } catch (NumberFormatException nfe) {
+        Log.w(TAG, "Bad max-zoom: " + maxZoomString);
+      }
+    }
+
+    String takingPictureZoomMaxString = parameters.get("taking-picture-zoom-max");
+    if (takingPictureZoomMaxString != null) {
+      try {
+        int tenMaxZoom = Integer.parseInt(takingPictureZoomMaxString);
+        if (tenDesiredZoom > tenMaxZoom) {
+          tenDesiredZoom = tenMaxZoom;
+        }
+      } catch (NumberFormatException nfe) {
+        Log.w(TAG, "Bad taking-picture-zoom-max: " + takingPictureZoomMaxString);
+      }
+    }
+
+    String motZoomValuesString = parameters.get("mot-zoom-values");
+    if (motZoomValuesString != null) {
+      tenDesiredZoom = findBestMotZoomValue(motZoomValuesString, tenDesiredZoom);
+    }
+
+    String motZoomStepString = parameters.get("mot-zoom-step");
+    if (motZoomStepString != null) {
+      try {
+        double motZoomStep = Double.parseDouble(motZoomStepString.trim());
+        int tenZoomStep = (int) (10.0 * motZoomStep);
+        if (tenZoomStep > 1) {
+          tenDesiredZoom -= tenDesiredZoom % tenZoomStep;
+        }
+      } catch (NumberFormatException nfe) {
+        // continue
+      }
+    }
+
+    // Set zoom. This helps encourage the user to pull back.
+    // Some devices like the Behold have a zoom parameter
+    if (maxZoomString != null || motZoomValuesString != null) {
+      parameters.set("zoom", String.valueOf(tenDesiredZoom / 10.0));
+    }
+
+    // Most devices, like the Hero, appear to expose this zoom parameter.
+    // It takes on values like "27" which appears to mean 2.7x zoom
+    if (takingPictureZoomMaxString != null) {
+      parameters.set("taking-picture-zoom", tenDesiredZoom);
+    }
+  }
+
+  public static int getDesiredSharpness() {
+    return DESIRED_SHARPNESS;
+  }
+
+  /**
+   * compatible  1.6
+   * @param camera
+   * @param angle
+   */
+  protected void setDisplayOrientation(Camera camera, int angle){
+    Method downPolymorphic;
+    try
+    {
+      downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
+      if (downPolymorphic != null)
+        downPolymorphic.invoke(camera, new Object[] { angle });
+    }
+    catch (Exception e1)
+    {
+    }
+  }
+
+}
+
+
+
+
+

+ 326 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/CameraManager.java

@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.hardware.Camera;
+import android.os.Build;
+import android.os.Handler;
+import android.util.Log;
+import android.view.SurfaceHolder;
+
+import java.io.IOException;
+
+/**
+ * This object wraps the Camera service object and expects to be the only one talking to it. The
+ * implementation encapsulates the steps needed to take preview-sized images, which are used for
+ * both preview and decoding.
+ *
+ */
+public final class CameraManager {
+
+  private static final String TAG = CameraManager.class.getSimpleName();
+
+  private static final int MIN_FRAME_WIDTH = 240;
+  private static final int MIN_FRAME_HEIGHT = 240;
+  private static final int MAX_FRAME_WIDTH = 480;
+  private static final int MAX_FRAME_HEIGHT = 360;
+
+  private static CameraManager cameraManager;
+
+  static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT
+  static {
+    int sdkInt;
+    try {
+      sdkInt = Integer.parseInt(Build.VERSION.SDK);
+    } catch (NumberFormatException nfe) {
+      // Just to be safe
+      sdkInt = 10000;
+    }
+    SDK_INT = sdkInt;
+  }
+
+  private final Context context;
+  private final CameraConfigurationManager configManager;
+  private Camera camera;
+  private Rect framingRect;
+  private Rect framingRectInPreview;
+  private boolean initialized;
+  private boolean previewing;
+  private final boolean useOneShotPreviewCallback;
+  /**
+   * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
+   * clear the handler so it will only receive one message.
+   */
+  private final PreviewCallback previewCallback;
+  /** Autofocus callbacks arrive here, and are dispatched to the Handler which requested them. */
+  private final AutoFocusCallback autoFocusCallback;
+
+  /**
+   * Initializes this static object with the Context of the calling Activity.
+   *
+   * @param context The Activity which wants to use the camera.
+   */
+  public static void init(Context context) {
+    if (cameraManager == null) {
+      cameraManager = new CameraManager(context);
+    }
+  }
+
+  /**
+   * Gets the CameraManager singleton instance.
+   *
+   * @return A reference to the CameraManager singleton.
+   */
+  public static CameraManager get() {
+    return cameraManager;
+  }
+
+  private CameraManager(Context context) {
+
+    this.context = context;
+    this.configManager = new CameraConfigurationManager(context);
+
+    // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older
+    // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use
+    // the more efficient one shot callback, as the older one can swamp the system and cause it
+    // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK.
+    //useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.CUPCAKE;
+    useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > 3; // 3 = Cupcake
+
+    previewCallback = new PreviewCallback(configManager, useOneShotPreviewCallback);
+    autoFocusCallback = new AutoFocusCallback();
+  }
+
+  /**
+   * Opens the camera driver and initializes the hardware parameters.
+   *
+   * @param holder The surface object which the camera will draw preview frames into.
+   * @throws IOException Indicates the camera driver failed to open.
+   */
+  public void openDriver(SurfaceHolder holder) throws IOException {
+    if (camera == null) {
+      camera = Camera.open();
+      if (camera == null) {
+        throw new IOException();
+      }
+      camera.setPreviewDisplay(holder);
+
+      if (!initialized) {
+        initialized = true;
+        configManager.initFromCameraParameters(camera);
+      }
+      configManager.setDesiredCameraParameters(camera);
+
+      //FIXME
+      //     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+      //是否使用前灯
+//      if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) {
+//        FlashlightManager.enableFlashlight();
+//      }
+      FlashlightManager.enableFlashlight();
+    }
+  }
+
+  /**
+   * Closes the camera driver if still in use.
+   */
+  public void closeDriver() {
+    if (camera != null) {
+      FlashlightManager.disableFlashlight();
+      camera.release();
+      camera = null;
+    }
+  }
+
+  /**
+   * Asks the camera hardware to begin drawing preview frames to the screen.
+   */
+  public void startPreview() {
+    if (camera != null && !previewing) {
+      camera.startPreview();
+      previewing = true;
+    }
+  }
+
+  /**
+   * Tells the camera to stop drawing preview frames.
+   */
+  public void stopPreview() {
+    if (camera != null && previewing) {
+      if (!useOneShotPreviewCallback) {
+        camera.setPreviewCallback(null);
+      }
+      camera.stopPreview();
+      previewCallback.setHandler(null, 0);
+      autoFocusCallback.setHandler(null, 0);
+      previewing = false;
+    }
+  }
+
+  /**
+   * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
+   * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
+   * respectively.
+   *
+   * @param handler The handler to send the message to.
+   * @param message The what field of the message to be sent.
+   */
+  public void requestPreviewFrame(Handler handler, int message) {
+    if (camera != null && previewing) {
+      previewCallback.setHandler(handler, message);
+      if (useOneShotPreviewCallback) {
+        camera.setOneShotPreviewCallback(previewCallback);
+      } else {
+        camera.setPreviewCallback(previewCallback);
+      }
+    }
+  }
+
+  /**
+   * Asks the camera hardware to perform an autofocus.
+   *
+   * @param handler The Handler to notify when the autofocus completes.
+   * @param message The message to deliver.
+   */
+  public void requestAutoFocus(Handler handler, int message) {
+    if (camera != null && previewing) {
+      autoFocusCallback.setHandler(handler, message);
+      //Log.d(TAG, "Requesting auto-focus callback");
+      camera.autoFocus(autoFocusCallback);
+    }
+  }
+
+  /**
+   * Calculates the framing rect which the UI should draw to show the user where to place the
+   * barcode. This target helps with alignment as well as forces the user to hold the device
+   * far enough away to ensure the image will be in focus.
+   *
+   * @return The rectangle to draw on screen in window coordinates.
+   */
+  public Rect getFramingRect() {
+    Point screenResolution = configManager.getScreenResolution();
+    if (framingRect == null) {
+      if (camera == null) {
+        return null;
+      }
+      int width = screenResolution.x * 3 / 4;
+      if (width < MIN_FRAME_WIDTH) {
+        width = MIN_FRAME_WIDTH;
+      } else if (width > MAX_FRAME_WIDTH) {
+        width = MAX_FRAME_WIDTH;
+      }
+      int height = screenResolution.y * 3 / 4;
+      if (height < MIN_FRAME_HEIGHT) {
+        height = MIN_FRAME_HEIGHT;
+      } else if (height > MAX_FRAME_HEIGHT) {
+        height = MAX_FRAME_HEIGHT;
+      }
+      int leftOffset = (screenResolution.x - width) / 2;
+      int topOffset = (screenResolution.y - height) / 2;
+      framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
+      Log.d(TAG, "Calculated framing rect: " + framingRect);
+    }
+    return framingRect;
+  }
+
+  /**
+   * Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
+   * not UI / screen.
+   */
+  public Rect getFramingRectInPreview() {
+    if (framingRectInPreview == null) {
+      Rect rect = new Rect(getFramingRect());
+      Point cameraResolution = configManager.getCameraResolution();
+      Point screenResolution = configManager.getScreenResolution();
+      //modify here
+//      rect.left = rect.left * cameraResolution.x / screenResolution.x;
+//      rect.right = rect.right * cameraResolution.x / screenResolution.x;
+//      rect.top = rect.top * cameraResolution.y / screenResolution.y;
+//      rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
+      rect.left = rect.left * cameraResolution.y / screenResolution.x;
+      rect.right = rect.right * cameraResolution.y / screenResolution.x;
+      rect.top = rect.top * cameraResolution.x / screenResolution.y;
+      rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
+      framingRectInPreview = rect;
+    }
+    return framingRectInPreview;
+  }
+
+  /**
+   * Converts the result points from still resolution coordinates to screen coordinates.
+   *
+   * @param points The points returned by the Reader subclass through Result.getResultPoints().
+   * @return An array of Points scaled to the size of the framing rect and offset appropriately
+   *         so they can be drawn in screen coordinates.
+   */
+  /*
+  public Point[] convertResultPoints(ResultPoint[] points) {
+    Rect frame = getFramingRectInPreview();
+    int count = points.length;
+    Point[] output = new Point[count];
+    for (int x = 0; x < count; x++) {
+      output[x] = new Point();
+      output[x].x = frame.left + (int) (points[x].getX() + 0.5f);
+      output[x].y = frame.top + (int) (points[x].getY() + 0.5f);
+    }
+    return output;
+  }
+   */
+
+  /**
+   * A factory method to build the appropriate LuminanceSource object based on the format
+   * of the preview buffers, as described by Camera.Parameters.
+   *
+   * @param data A preview frame.
+   * @param width The width of the image.
+   * @param height The height of the image.
+   * @return A PlanarYUVLuminanceSource instance.
+   */
+  public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
+    Rect rect = getFramingRectInPreview();
+    int previewFormat = configManager.getPreviewFormat();
+    String previewFormatString = configManager.getPreviewFormatString();
+    switch (previewFormat) {
+      // This is the standard Android format which all devices are REQUIRED to support.
+      // In theory, it's the only one we should ever care about.
+      case PixelFormat.YCbCr_420_SP:
+        // This format has never been seen in the wild, but is compatible as we only care
+        // about the Y channel, so allow it.
+      case PixelFormat.YCbCr_422_SP:
+        return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
+                rect.width(), rect.height());
+      default:
+        // The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
+        // Fortunately, it too has all the Y data up front, so we can read it.
+        if ("yuv420p".equals(previewFormatString)) {
+          return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
+                  rect.width(), rect.height());
+        }
+    }
+    throw new IllegalArgumentException("Unsupported picture format: " +
+            previewFormat + '/' + previewFormatString);
+  }
+
+  public Context getContext() {
+    return context;
+  }
+
+}

+ 154 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/FlashlightManager.java

@@ -0,0 +1,154 @@
+
+
+
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.os.IBinder;
+import android.util.Log;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * This class is used to activate the weak light on some camera phones (not flash)
+ * in order to illuminate surfaces for scanning. There is no official way to do this,
+ * but, classes which allow access to this function still exist on some devices.
+ * This therefore proceeds through a great deal of reflection.
+ *
+ * See <a href="http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/">
+ * http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/</a> and
+ * <a href="http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java">
+ * http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java</a>.
+ * Thanks to Ryan Alford for pointing out the availability of this class.
+ */
+final class FlashlightManager {
+
+  private static final String TAG = FlashlightManager.class.getSimpleName();
+
+  private static final Object iHardwareService;
+  private static final Method setFlashEnabledMethod;
+  static {
+    iHardwareService = getHardwareService();
+    setFlashEnabledMethod = getSetFlashEnabledMethod(iHardwareService);
+    if (iHardwareService == null) {
+      Log.v(TAG, "This device does supports control of a flashlight");
+    } else {
+      Log.v(TAG, "This device does not support control of a flashlight");
+    }
+  }
+
+  private FlashlightManager() {
+  }
+
+  /**
+   * 控制相机闪光灯开关
+   */
+  //FIXME
+  static void enableFlashlight() {
+    setFlashlight(false);
+  }
+
+  static void disableFlashlight() {
+    setFlashlight(false);
+  }
+
+  private static Object getHardwareService() {
+    Class<?> serviceManagerClass = maybeForName("android.os.ServiceManager");
+    if (serviceManagerClass == null) {
+      return null;
+    }
+
+    Method getServiceMethod = maybeGetMethod(serviceManagerClass, "getService", String.class);
+    if (getServiceMethod == null) {
+      return null;
+    }
+
+    Object hardwareService = invoke(getServiceMethod, null, "hardware");
+    if (hardwareService == null) {
+      return null;
+    }
+
+    Class<?> iHardwareServiceStubClass = maybeForName("android.os.IHardwareService$Stub");
+    if (iHardwareServiceStubClass == null) {
+      return null;
+    }
+
+    Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface", IBinder.class);
+    if (asInterfaceMethod == null) {
+      return null;
+    }
+
+    return invoke(asInterfaceMethod, null, hardwareService);
+  }
+
+  private static Method getSetFlashEnabledMethod(Object iHardwareService) {
+    if (iHardwareService == null) {
+      return null;
+    }
+    Class<?> proxyClass = iHardwareService.getClass();
+    return maybeGetMethod(proxyClass, "setFlashlightEnabled", boolean.class);
+  }
+
+  private static Class<?> maybeForName(String name) {
+    try {
+      return Class.forName(name);
+    } catch (ClassNotFoundException cnfe) {
+      // OK
+      return null;
+    } catch (RuntimeException re) {
+      Log.w(TAG, "Unexpected error while finding class " + name, re);
+      return null;
+    }
+  }
+
+  private static Method maybeGetMethod(Class<?> clazz, String name, Class<?>... argClasses) {
+    try {
+      return clazz.getMethod(name, argClasses);
+    } catch (NoSuchMethodException nsme) {
+      // OK
+      return null;
+    } catch (RuntimeException re) {
+      Log.w(TAG, "Unexpected error while finding method " + name, re);
+      return null;
+    }
+  }
+
+  private static Object invoke(Method method, Object instance, Object... args) {
+    try {
+      return method.invoke(instance, args);
+    } catch (IllegalAccessException e) {
+      Log.w(TAG, "Unexpected error while invoking " + method, e);
+      return null;
+    } catch (InvocationTargetException e) {
+      Log.w(TAG, "Unexpected error while invoking " + method, e.getCause());
+      return null;
+    } catch (RuntimeException re) {
+      Log.w(TAG, "Unexpected error while invoking " + method, re);
+      return null;
+    }
+  }
+
+  private static void setFlashlight(boolean active) {
+    if (iHardwareService != null) {
+      invoke(setFlashEnabledMethod, iHardwareService, active);
+    }
+  }
+
+}
+

+ 134 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/PlanarYUVLuminanceSource.java

@@ -0,0 +1,134 @@
+/*
+ * Copyright 2009 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.graphics.Bitmap;
+
+import com.printer.sdk.zxing.LuminanceSource;
+
+
+/**
+ * This object extends LuminanceSource around an array of YUV data returned from the camera driver,
+ * with the option to crop to a rectangle within the full data. This can be used to exclude
+ * superfluous pixels around the perimeter and speed up decoding.
+ *
+ * It works for any pixel format where the Y channel is planar and appears first, including
+ * YCbCr_420_SP and YCbCr_422_SP.
+ *
+ * @author dswitkin@google.com (Daniel Switkin)
+ */
+public final class PlanarYUVLuminanceSource extends LuminanceSource {
+  private final byte[] yuvData;
+  private final int dataWidth;
+  private final int dataHeight;
+  private final int left;
+  private final int top;
+
+  public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top,
+      int width, int height) {
+    super(width, height);
+
+    if (left + width > dataWidth || top + height > dataHeight) {
+      throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
+    }
+
+    this.yuvData = yuvData;
+    this.dataWidth = dataWidth;
+    this.dataHeight = dataHeight;
+    this.left = left;
+    this.top = top;
+  }
+
+  @Override
+  public byte[] getRow(int y, byte[] row) {
+    if (y < 0 || y >= getHeight()) {
+      throw new IllegalArgumentException("Requested row is outside the image: " + y);
+    }
+    int width = getWidth();
+    if (row == null || row.length < width) {
+      row = new byte[width];
+    }
+    int offset = (y + top) * dataWidth + left;
+    System.arraycopy(yuvData, offset, row, 0, width);
+    return row;
+  }
+
+  @Override
+  public byte[] getMatrix() {
+    int width = getWidth();
+    int height = getHeight();
+
+    // If the caller asks for the entire underlying image, save the copy and give them the
+    // original data. The docs specifically warn that result.length must be ignored.
+    if (width == dataWidth && height == dataHeight) {
+      return yuvData;
+    }
+
+    int area = width * height;
+    byte[] matrix = new byte[area];
+    int inputOffset = top * dataWidth + left;
+
+    // If the width matches the full width of the underlying data, perform a single copy.
+    if (width == dataWidth) {
+      System.arraycopy(yuvData, inputOffset, matrix, 0, area);
+      return matrix;
+    }
+
+    // Otherwise copy one cropped row at a time.
+    byte[] yuv = yuvData;
+    for (int y = 0; y < height; y++) {
+      int outputOffset = y * width;
+      System.arraycopy(yuv, inputOffset, matrix, outputOffset, width);
+      inputOffset += dataWidth;
+    }
+    return matrix;
+  }
+
+  @Override
+  public boolean isCropSupported() {
+    return true;
+  }
+
+  public int getDataWidth() {
+    return dataWidth;
+  }
+
+  public int getDataHeight() {
+    return dataHeight;
+  }
+
+  public Bitmap renderCroppedGreyscaleBitmap() {
+    int width = getWidth();
+    int height = getHeight();
+    int[] pixels = new int[width * height];
+    byte[] yuv = yuvData;
+    int inputOffset = top * dataWidth + left;
+
+    for (int y = 0; y < height; y++) {
+      int outputOffset = y * width;
+      for (int x = 0; x < width; x++) {
+        int grey = yuv[inputOffset + x] & 0xff;
+        pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
+      }
+      inputOffset += dataWidth;
+    }
+
+    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
+    return bitmap;
+  }
+}

+ 59 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/camera/PreviewCallback.java

@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.camera;
+
+import android.graphics.Point;
+import android.hardware.Camera;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+final class PreviewCallback implements Camera.PreviewCallback {
+
+  private static final String TAG = PreviewCallback.class.getSimpleName();
+
+  private final CameraConfigurationManager configManager;
+  private final boolean useOneShotPreviewCallback;
+  private Handler previewHandler;
+  private int previewMessage;
+
+  PreviewCallback(CameraConfigurationManager configManager, boolean useOneShotPreviewCallback) {
+    this.configManager = configManager;
+    this.useOneShotPreviewCallback = useOneShotPreviewCallback;
+  }
+
+  void setHandler(Handler previewHandler, int previewMessage) {
+    this.previewHandler = previewHandler;
+    this.previewMessage = previewMessage;
+  }
+
+  public void onPreviewFrame(byte[] data, Camera camera) {
+    Point cameraResolution = configManager.getCameraResolution();
+    if (!useOneShotPreviewCallback) {
+      camera.setPreviewCallback(null);
+    }
+    if (previewHandler != null) {
+      Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
+          cameraResolution.y, data);
+      message.sendToTarget();
+      previewHandler = null;
+    } else {
+      Log.d(TAG, "Got preview callback, but no handler for it");
+    }
+  }
+
+}

+ 138 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/CaptureActivityHandler.java

@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+
+import com.mining.app.zxing.camera.CameraManager;
+import com.mining.app.zxing.view.ViewfinderResultPointCallback;
+import com.printer.demo.MipcaActivityCapture;
+import com.printer.demo.R;
+import com.printer.sdk.zxing.BarcodeFormat;
+import com.printer.sdk.zxing.Result;
+
+import java.util.Vector;
+
+/**
+ * This class handles all the messaging which comprises the state machine for capture.
+ */
+public final class CaptureActivityHandler extends Handler {
+
+  private static final String TAG = CaptureActivityHandler.class.getSimpleName();
+
+  private final MipcaActivityCapture activity;
+  private final DecodeThread decodeThread;
+  private State state;
+
+  private enum State {
+    PREVIEW,
+    SUCCESS,
+    DONE
+  }
+
+  public CaptureActivityHandler(MipcaActivityCapture activity, Vector<BarcodeFormat> decodeFormats,
+      String characterSet) {
+    this.activity = activity;
+    decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
+        new ViewfinderResultPointCallback(activity.getViewfinderView()));
+    decodeThread.start();
+    state = State.SUCCESS;
+    // Start ourselves capturing previews and decoding.
+    CameraManager.get().startPreview();
+    restartPreviewAndDecode();
+  }
+
+  @Override
+  public void handleMessage(Message message) {
+    switch (message.what) {
+      case R.id.auto_focus:
+        //Log.d(TAG, "Got auto-focus message");
+        // When one auto focus pass finishes, start another. This is the closest thing to
+        // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
+        if (state == State.PREVIEW) {
+          CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
+        }
+        break;
+      case R.id.restart_preview:
+        Log.d(TAG, "Got restart preview message");
+        restartPreviewAndDecode();
+        break;
+      case R.id.decode_succeeded:
+        Log.d(TAG, "Got decode succeeded message");
+        state = State.SUCCESS;
+        Bundle bundle = message.getData();
+
+        /***********************************************************************/
+        Bitmap barcode = bundle == null ? null :
+            (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�
+
+        activity.handleDecode((Result) message.obj, barcode);//���ؽ��?        /***********************************************************************/
+        break;
+      case R.id.decode_failed:
+        // We're decoding as fast as possible, so when one decode fails, start another.
+        state = State.PREVIEW;
+        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
+        break;
+      case R.id.return_scan_result:
+        Log.d(TAG, "Got return scan result message");
+        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
+        activity.finish();
+        break;
+      case R.id.launch_product_query:
+        Log.d(TAG, "Got product query message");
+        String url = (String) message.obj;
+        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+        activity.startActivity(intent);
+        break;
+    }
+  }
+
+  public void quitSynchronously() {
+    state = State.DONE;
+    CameraManager.get().stopPreview();
+    Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
+    quit.sendToTarget();
+    try {
+      decodeThread.join();
+    } catch (InterruptedException e) {
+      // continue
+    }
+
+    // Be absolutely sure we don't send any queued up messages
+    removeMessages(R.id.decode_succeeded);
+    removeMessages(R.id.decode_failed);
+  }
+
+  private void restartPreviewAndDecode() {
+    if (state == State.SUCCESS) {
+      state = State.PREVIEW;
+      CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
+      CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
+      activity.drawViewfinder();
+    }
+  }
+
+}

+ 106 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeFormatManager.java

@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.content.Intent;
+import android.net.Uri;
+
+
+import com.printer.sdk.zxing.BarcodeFormat;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+import java.util.regex.Pattern;
+
+final class DecodeFormatManager {
+
+  private static final Pattern COMMA_PATTERN = Pattern.compile(",");
+
+  static final Vector<BarcodeFormat> PRODUCT_FORMATS;
+  static final Vector<BarcodeFormat> ONE_D_FORMATS;
+  static final Vector<BarcodeFormat> QR_CODE_FORMATS;
+  static final Vector<BarcodeFormat> DATA_MATRIX_FORMATS;
+  static {
+    PRODUCT_FORMATS = new Vector<BarcodeFormat>(5);
+    PRODUCT_FORMATS.add(BarcodeFormat.UPC_A);
+    PRODUCT_FORMATS.add(BarcodeFormat.UPC_E);
+    PRODUCT_FORMATS.add(BarcodeFormat.EAN_13);
+    PRODUCT_FORMATS.add(BarcodeFormat.EAN_8);
+    PRODUCT_FORMATS.add(BarcodeFormat.RSS_14);
+    ONE_D_FORMATS = new Vector<BarcodeFormat>(PRODUCT_FORMATS.size() + 4);
+    ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
+    ONE_D_FORMATS.add(BarcodeFormat.CODE_39);
+    ONE_D_FORMATS.add(BarcodeFormat.CODE_93);
+    ONE_D_FORMATS.add(BarcodeFormat.CODE_128);
+    ONE_D_FORMATS.add(BarcodeFormat.ITF);
+    QR_CODE_FORMATS = new Vector<BarcodeFormat>(1);
+    QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE);
+    DATA_MATRIX_FORMATS = new Vector<BarcodeFormat>(1);
+    DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX);
+  }
+
+  private DecodeFormatManager() {}
+
+  static Vector<BarcodeFormat> parseDecodeFormats(Intent intent) {
+    List<String> scanFormats = null;
+    String scanFormatsString = intent.getStringExtra(Intents.Scan.SCAN_FORMATS);
+    if (scanFormatsString != null) {
+      scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString));
+    }
+    return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
+  }
+
+  static Vector<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
+    List<String> formats = inputUri.getQueryParameters(Intents.Scan.SCAN_FORMATS);
+    if (formats != null && formats.size() == 1 && formats.get(0) != null){
+      formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
+    }
+    return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
+  }
+
+  private static Vector<BarcodeFormat> parseDecodeFormats(Iterable<String> scanFormats,
+                                                          String decodeMode) {
+    if (scanFormats != null) {
+      Vector<BarcodeFormat> formats = new Vector<BarcodeFormat>();
+      try {
+        for (String format : scanFormats) {
+          formats.add(BarcodeFormat.valueOf(format));
+        }
+        return formats;
+      } catch (IllegalArgumentException iae) {
+        // ignore it then
+      }
+    }
+    if (decodeMode != null) {
+      if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) {
+        return PRODUCT_FORMATS;
+      }
+      if (Intents.Scan.QR_CODE_MODE.equals(decodeMode)) {
+        return QR_CODE_FORMATS;
+      }
+      if (Intents.Scan.DATA_MATRIX_MODE.equals(decodeMode)) {
+        return DATA_MATRIX_FORMATS;
+      }
+      if (Intents.Scan.ONE_D_MODE.equals(decodeMode)) {
+        return ONE_D_FORMATS;
+      }
+    }
+    return null;
+  }
+
+}

+ 112 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeHandler.java

@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+
+
+import com.mining.app.zxing.camera.CameraManager;
+import com.mining.app.zxing.camera.PlanarYUVLuminanceSource;
+import com.printer.demo.MipcaActivityCapture;
+import com.printer.demo.R;
+import com.printer.sdk.zxing.BinaryBitmap;
+import com.printer.sdk.zxing.DecodeHintType;
+import com.printer.sdk.zxing.MultiFormatReader;
+import com.printer.sdk.zxing.ReaderException;
+import com.printer.sdk.zxing.Result;
+import com.printer.sdk.zxing.common.HybridBinarizer;
+
+import java.util.Hashtable;
+
+final class DecodeHandler extends Handler {
+
+  private static final String TAG = DecodeHandler.class.getSimpleName();
+
+  private final MipcaActivityCapture activity;
+  private final MultiFormatReader multiFormatReader;
+
+  DecodeHandler(MipcaActivityCapture activity, Hashtable<DecodeHintType, Object> hints) {
+    multiFormatReader = new MultiFormatReader();
+    multiFormatReader.setHints(hints);
+    this.activity = activity;
+  }
+
+  @Override
+  public void handleMessage(Message message) {
+    switch (message.what) {
+      case R.id.decode:
+        //Log.d(TAG, "Got decode message");
+        decode((byte[]) message.obj, message.arg1, message.arg2);
+        break;
+      case R.id.quit:
+        Looper.myLooper().quit();
+        break;
+    }
+  }
+
+  /**
+   * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency,
+   * reuse the same reader objects from one decode to the next.
+   *
+   * @param data   The YUV preview frame.
+   * @param width  The width of the preview frame.
+   * @param height The height of the preview frame.
+   */
+  private void decode(byte[] data, int width, int height) {
+    long start = System.currentTimeMillis();
+    Result rawResult = null;
+
+    //modify here
+    byte[] rotatedData = new byte[data.length];
+    for (int y = 0; y < height; y++) {
+        for (int x = 0; x < width; x++)
+            rotatedData[x * height + height - y - 1] = data[x + y * width];
+    }
+    int tmp = width; // Here we are swapping, that's the difference to #11
+    width = height;
+    height = tmp;
+
+    PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height);
+    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+    try {
+      rawResult = multiFormatReader.decodeWithState(bitmap);
+    } catch (ReaderException re) {
+      // continue
+    } finally {
+      multiFormatReader.reset();
+    }
+
+    if (rawResult != null) {
+      long end = System.currentTimeMillis();
+      Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
+      Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult);
+      Bundle bundle = new Bundle();
+      bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
+      message.setData(bundle);
+      //Log.d(TAG, "Sending decode succeeded message...");
+      message.sendToTarget();
+    } else {
+      Message message = Message.obtain(activity.getHandler(), R.id.decode_failed);
+      message.sendToTarget();
+    }
+  }
+
+}

+ 87 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/DecodeThread.java

@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.os.Handler;
+import android.os.Looper;
+
+
+import com.printer.demo.MipcaActivityCapture;
+import com.printer.sdk.zxing.BarcodeFormat;
+import com.printer.sdk.zxing.DecodeHintType;
+import com.printer.sdk.zxing.ResultPointCallback;
+
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * This thread does all the heavy lifting of decoding the images.
+ * �����߳�
+ */
+final class DecodeThread extends Thread {
+
+  public static final String BARCODE_BITMAP = "barcode_bitmap";
+  private final MipcaActivityCapture activity;
+  private final Hashtable<DecodeHintType, Object> hints;
+  private Handler handler;
+  private final CountDownLatch handlerInitLatch;
+
+  DecodeThread(MipcaActivityCapture activity,
+               Vector<BarcodeFormat> decodeFormats,
+               String characterSet,
+               ResultPointCallback resultPointCallback) {
+
+    this.activity = activity;
+    handlerInitLatch = new CountDownLatch(1);
+
+    hints = new Hashtable<DecodeHintType, Object>(3);
+
+    if (decodeFormats == null || decodeFormats.isEmpty()) {
+    	 decodeFormats = new Vector<BarcodeFormat>();
+    	 decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
+    	 decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
+    	 decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
+    }
+
+    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
+
+    if (characterSet != null) {
+      hints.put(DecodeHintType.CHARACTER_SET, characterSet);
+    }
+
+    hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
+  }
+
+  Handler getHandler() {
+    try {
+      handlerInitLatch.await();
+    } catch (InterruptedException ie) {
+      // continue?
+    }
+    return handler;
+  }
+
+  @Override
+  public void run() {
+    Looper.prepare();
+    handler = new DecodeHandler(activity, hints);
+    handlerInitLatch.countDown();
+    Looper.loop();
+  }
+
+}

+ 47 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/FinishListener.java

@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.app.Activity;
+import android.content.DialogInterface;
+
+/**
+ * Simple listener used to exit the app in a few cases.
+ *
+ */
+public final class FinishListener
+    implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener, Runnable {
+
+  private final Activity activityToFinish;
+
+  public FinishListener(Activity activityToFinish) {
+    this.activityToFinish = activityToFinish;
+  }
+
+  public void onCancel(DialogInterface dialogInterface) {
+    run();
+  }
+
+  public void onClick(DialogInterface dialogInterface, int i) {
+    run();
+  }
+
+  public void run() {
+    activityToFinish.finish();
+  }
+
+}

+ 71 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/InactivityTimer.java

@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+import android.app.Activity;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Finishes an activity after a period of inactivity.
+ */
+public final class InactivityTimer {
+
+  private static final int INACTIVITY_DELAY_SECONDS = 5 * 60;
+
+  private final ScheduledExecutorService inactivityTimer =
+      Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory());
+  private final Activity activity;
+  private ScheduledFuture<?> inactivityFuture = null;
+
+  public InactivityTimer(Activity activity) {
+    this.activity = activity;
+    onActivity();
+  }
+
+  public void onActivity() {
+    cancel();
+    inactivityFuture = inactivityTimer.schedule(new FinishListener(activity),
+                                                INACTIVITY_DELAY_SECONDS,
+                                                TimeUnit.SECONDS);
+  }
+
+  private void cancel() {
+    if (inactivityFuture != null) {
+      inactivityFuture.cancel(true);
+      inactivityFuture = null;
+    }
+  }
+
+  public void shutdown() {
+    cancel();
+    inactivityTimer.shutdown();
+  }
+
+  private static final class DaemonThreadFactory implements ThreadFactory {
+    public Thread newThread(Runnable runnable) {
+      Thread thread = new Thread(runnable);
+      thread.setDaemon(true);
+      return thread;
+    }
+  }
+
+}

+ 190 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/decoding/Intents.java

@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.decoding;
+
+/**
+ * This class provides the constants to use when sending an Intent to Barcode Scanner.
+ * These strings are effectively API and cannot be changed.
+ */
+public final class Intents {
+  private Intents() {
+  }
+
+  public static final class Scan {
+    /**
+     * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return
+     * the results.
+     */
+    public static final String ACTION = "com.google.zxing.client.android.SCAN";
+
+    /**
+     * By default, sending Scan.ACTION will decode all barcodes that we understand. However it
+     * may be useful to limit scanning to certain formats. Use Intent.putExtra(MODE, value) with
+     * one of the values below ({@link #PRODUCT_MODE}, {@link #ONE_D_MODE}, {@link #QR_CODE_MODE}).
+     * Optional.
+     *
+     * Setting this is effectively shorthnad for setting explicit formats with {@link #SCAN_FORMATS}.
+     * It is overridden by that setting.
+     */
+    public static final String MODE = "SCAN_MODE";
+
+    /**
+     * Comma-separated list of formats to scan for. The values must match the names of
+     * {@link com.google.zxing.BarcodeFormat}s, such as {@link com.google.zxing.BarcodeFormat#EAN_13}.
+     * Example: "EAN_13,EAN_8,QR_CODE"
+     *
+     * This overrides {@link #MODE}.
+     */
+    public static final String SCAN_FORMATS = "SCAN_FORMATS";
+
+    /**
+     * @see com.google.zxing.DecodeHintType#CHARACTER_SET
+     */
+    public static final String CHARACTER_SET = "CHARACTER_SET";
+
+    /**
+     * Decode only UPC and EAN barcodes. This is the right choice for shopping apps which get
+     * prices, reviews, etc. for products.
+     */
+    public static final String PRODUCT_MODE = "PRODUCT_MODE";
+
+    /**
+     * Decode only 1D barcodes (currently UPC, EAN, Code 39, and Code 128).
+     */
+    public static final String ONE_D_MODE = "ONE_D_MODE";
+
+    /**
+     * Decode only QR codes.
+     */
+    public static final String QR_CODE_MODE = "QR_CODE_MODE";
+
+    /**
+     * Decode only Data Matrix codes.
+     */
+    public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE";
+
+    /**
+     * If a barcode is found, Barcodes returns RESULT_OK to onActivityResult() of the app which
+     * requested the scan via startSubActivity(). The barcodes contents can be retrieved with
+     * intent.getStringExtra(RESULT). If the user presses Back, the result code will be
+     * RESULT_CANCELED.
+     */
+    public static final String RESULT = "SCAN_RESULT";
+
+    /**
+     * Call intent.getStringExtra(RESULT_FORMAT) to determine which barcode format was found.
+     * See Contents.Format for possible values.
+     */
+    public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT";
+
+    /**
+     * Setting this to false will not save scanned codes in the history.
+     */
+    public static final String SAVE_HISTORY = "SAVE_HISTORY";
+
+    private Scan() {
+    }
+  }
+
+  public static final class Encode {
+    /**
+     * Send this intent to encode a piece of data as a QR code and display it full screen, so
+     * that another person can scan the barcode from your screen.
+     */
+    public static final String ACTION = "com.google.zxing.client.android.ENCODE";
+
+    /**
+     * The data to encode. Use Intent.putExtra(DATA, data) where data is either a String or a
+     * Bundle, depending on the type and format specified. Non-QR Code formats should
+     * just use a String here. For QR Code, see Contents for details.
+     */
+    public static final String DATA = "ENCODE_DATA";
+
+    /**
+     * The type of data being supplied if the format is QR Code. Use
+     * Intent.putExtra(TYPE, type) with one of Contents.Type.
+     */
+    public static final String TYPE = "ENCODE_TYPE";
+    
+    /**
+     * The barcode format to be displayed. If this isn't specified or is blank, 
+     * it defaults to QR Code. Use Intent.putExtra(FORMAT, format), where
+     * format is one of Contents.Format. 
+     */
+    public static final String FORMAT = "ENCODE_FORMAT";
+
+    private Encode() {
+    }
+  }
+
+  public static final class SearchBookContents {
+    /**
+     * Use Google Book Search to search the contents of the book provided.
+     */
+    public static final String ACTION = "com.google.zxing.client.android.SEARCH_BOOK_CONTENTS";
+
+    /**
+     * The book to search, identified by ISBN number.
+     */
+    public static final String ISBN = "ISBN";
+
+    /**
+     * An optional field which is the text to search for.
+     */
+    public static final String QUERY = "QUERY";
+
+    private SearchBookContents() {
+    }
+  }
+
+  public static final class WifiConnect {
+	    /**
+	     * Internal intent used to trigger connection to a wi-fi network.
+	     */
+	    public static final String ACTION = "com.google.zxing.client.android.WIFI_CONNECT";
+
+	    /**
+	     * The network to connect to, all the configuration provided here.
+	     */
+	    public static final String SSID = "SSID";
+
+	    /**
+	     * The network to connect to, all the configuration provided here.
+	     */
+	    public static final String TYPE = "TYPE";
+
+	    /**
+	     * The network to connect to, all the configuration provided here.
+	     */
+	    public static final String PASSWORD = "PASSWORD";
+
+	    private WifiConnect() {
+	    }
+	  }
+
+
+  public static final class Share {
+    /**
+     * Give the user a choice of items to encode as a barcode, then render it as a QR Code and
+     * display onscreen for a friend to scan with their phone.
+     */
+    public static final String ACTION = "com.google.zxing.client.android.SHARE";
+
+    private Share() {
+    }
+  }
+}

+ 35 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/view/ViewfinderResultPointCallback.java

@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.view;
+
+
+import com.printer.sdk.zxing.ResultPoint;
+import com.printer.sdk.zxing.ResultPointCallback;
+
+public final class ViewfinderResultPointCallback implements ResultPointCallback {
+
+  private final ViewfinderView viewfinderView;
+
+  public ViewfinderResultPointCallback(ViewfinderView viewfinderView) {
+    this.viewfinderView = viewfinderView;
+  }
+
+  public void foundPossibleResultPoint(ResultPoint point) {
+    viewfinderView.addPossibleResultPoint(point);
+  }
+
+}

+ 258 - 0
PrintDemoV5.7.1/src/main/java/com/mining/app/zxing/view/ViewfinderView.java

@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mining.app.zxing.view;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.util.AttributeSet;
+import android.view.View;
+
+import com.mining.app.zxing.camera.CameraManager;
+import com.printer.demo.R;
+import com.printer.sdk.zxing.ResultPoint;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+/**
+ * This view is overlaid on top of the camera preview. It adds the viewfinder
+ * rectangle and partial transparency outside it, as well as the laser scanner
+ * animation and result points.
+ *
+ */
+public final class ViewfinderView extends View {
+	private static final String TAG = "log";
+	/**
+	 * ˢ�½����ʱ��
+	 */
+	private static final long ANIMATION_DELAY = 10L;
+	private static final int OPAQUE = 0xFF;
+
+	/**
+	 * �ĸ���ɫ�߽Ƕ�Ӧ�ij���
+	 */
+	private int ScreenRate;
+
+	/**
+	 * �ĸ���ɫ�߽Ƕ�Ӧ�Ŀ��
+	 */
+	private static final int CORNER_WIDTH = 10;
+	/**
+	 * ɨ����е��м��ߵĿ��
+	 */
+	private static final int MIDDLE_LINE_WIDTH = 6;
+
+	/**
+	 * ɨ����е��м��ߵ���ɨ������ҵļ�϶
+	 */
+	private static final int MIDDLE_LINE_PADDING = 5;
+
+	/**
+	 * �м�������ÿ��ˢ���ƶ��ľ���
+	 */
+	private static final int SPEEN_DISTANCE = 5;
+
+	/**
+	 * �ֻ����Ļ�ܶ�
+	 */
+	private static float density;
+	/**
+	 * �����С
+	 */
+	private static final int TEXT_SIZE = 16;
+	/**
+	 * �������ɨ�������ľ���
+	 */
+	private static final int TEXT_PADDING_TOP = 30;
+
+	/**
+	 * ���ʶ��������
+	 */
+	private Paint paint;
+
+	/**
+	 * �м们���ߵ����λ��
+	 */
+	private int slideTop;
+
+	/**
+	 * �м们���ߵ���׶�λ��
+	 */
+	private int slideBottom;
+
+	/**
+	 * ��ɨ��Ķ�ά��������������û��������ܣ���ʱ������
+	 */
+	private Bitmap resultBitmap;
+	private final int maskColor;
+	private final int resultColor;
+
+	private final int resultPointColor;
+	private Collection<ResultPoint> possibleResultPoints;
+	private Collection<ResultPoint> lastPossibleResultPoints;
+
+	boolean isFirst;
+
+	public ViewfinderView(Context context, AttributeSet attrs) {
+		super(context, attrs);
+
+		density = context.getResources().getDisplayMetrics().density;
+		//������ת����dp
+		ScreenRate = (int)(20 * density);
+
+		paint = new Paint();
+		Resources resources = getResources();
+		maskColor = resources.getColor(R.color.viewfinder_mask);
+		resultColor = resources.getColor(R.color.result_view);
+
+		resultPointColor = resources.getColor(R.color.possible_result_points);
+		possibleResultPoints = new HashSet<ResultPoint>(5);
+	}
+
+	@Override
+	public void onDraw(Canvas canvas) {
+		//�м��ɨ�����Ҫ�޸�ɨ���Ĵ�С��ȥCameraManager�����޸�
+		Rect frame = CameraManager.get().getFramingRect();
+		if (frame == null) {
+			return;
+		}
+
+		//��ʼ���м��߻��������ϱߺ����±�
+		if(!isFirst){
+			isFirst = true;
+			slideTop = frame.top;
+			slideBottom = frame.bottom;
+		}
+
+		//��ȡ��Ļ�Ŀ�͸�
+		int width = canvas.getWidth();
+		int height = canvas.getHeight();
+
+		paint.setColor(resultBitmap != null ? resultColor : maskColor);
+
+		//����ɨ����������Ӱ���֣����ĸ����֣�ɨ�������浽��Ļ���棬ɨ�������浽��Ļ����
+		//ɨ��������浽��Ļ��ߣ�ɨ�����ұߵ���Ļ�ұ�
+		canvas.drawRect(0, 0, width, frame.top, paint);
+		canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
+		canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1,
+				paint);
+		canvas.drawRect(0, frame.bottom + 1, width, height, paint);
+
+
+
+		if (resultBitmap != null) {
+			// Draw the opaque result bitmap over the scanning rectangle
+			paint.setAlpha(OPAQUE);
+			canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
+		} else {
+
+			//��ɨ�����ϵĽǣ��ܹ�8������
+			paint.setColor(Color.GREEN);
+			canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate,
+					frame.top + CORNER_WIDTH, paint);
+			canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top
+					+ ScreenRate, paint);
+			canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right,
+					frame.top + CORNER_WIDTH, paint);
+			canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top
+					+ ScreenRate, paint);
+			canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left
+					+ ScreenRate, frame.bottom, paint);
+			canvas.drawRect(frame.left, frame.bottom - ScreenRate,
+					frame.left + CORNER_WIDTH, frame.bottom, paint);
+			canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH,
+					frame.right, frame.bottom, paint);
+			canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate,
+					frame.right, frame.bottom, paint);
+
+
+			//�����м����,ÿ��ˢ�½��棬�м���������ƶ�SPEEN_DISTANCE
+			slideTop += SPEEN_DISTANCE;
+			if(slideTop >= frame.bottom){
+				slideTop = frame.top;
+			}
+			canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - MIDDLE_LINE_WIDTH/2, frame.right - MIDDLE_LINE_PADDING,slideTop + MIDDLE_LINE_WIDTH/2, paint);
+
+
+			//��ɨ����������
+			paint.setColor(Color.WHITE);
+			paint.setTextSize(TEXT_SIZE * density);
+			paint.setAlpha(0x40);
+			paint.setTypeface(Typeface.create("System", Typeface.BOLD));
+			canvas.drawText(getResources().getString(R.string.scan_text), frame.left, (float) (frame.bottom + (float)TEXT_PADDING_TOP *density), paint);
+
+
+
+			Collection<ResultPoint> currentPossible = possibleResultPoints;
+			Collection<ResultPoint> currentLast = lastPossibleResultPoints;
+			if (currentPossible.isEmpty()) {
+				lastPossibleResultPoints = null;
+			} else {
+				possibleResultPoints = new HashSet<ResultPoint>(5);
+				lastPossibleResultPoints = currentPossible;
+				paint.setAlpha(OPAQUE);
+				paint.setColor(resultPointColor);
+				for (ResultPoint point : currentPossible) {
+					canvas.drawCircle(frame.left + point.getX(), frame.top
+							+ point.getY(), 6.0f, paint);
+				}
+			}
+			if (currentLast != null) {
+				paint.setAlpha(OPAQUE / 2);
+				paint.setColor(resultPointColor);
+				for (ResultPoint point : currentLast) {
+					canvas.drawCircle(frame.left + point.getX(), frame.top
+							+ point.getY(), 3.0f, paint);
+				}
+			}
+
+
+			//ֻˢ��ɨ�������ݣ�����ط���ˢ��
+			postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top,
+					frame.right, frame.bottom);
+
+		}
+	}
+
+	public void drawViewfinder() {
+		resultBitmap = null;
+		invalidate();
+	}
+
+	/**
+	 * Draw a bitmap with the result points highlighted instead of the live
+	 * scanning display.
+	 *
+	 * @param barcode
+	 *            An image of the decoded barcode.
+	 */
+	public void drawResultBitmap(Bitmap barcode) {
+		resultBitmap = barcode;
+		invalidate();
+	}
+
+	public void addPossibleResultPoint(ResultPoint point) {
+		possibleResultPoints.add(point);
+	}
+
+}

+ 392 - 0
PrintDemoV5.7.1/src/main/java/com/printer/MainActivity22.java

@@ -0,0 +1,392 @@
+package com.printer;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.hardware.usb.UsbManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
+
+import com.allenliu.versionchecklib.v2.AllenVersionChecker;
+import com.allenliu.versionchecklib.v2.builder.UIData;
+import com.printer.demo.BarcoePrintActivity;
+import com.printer.demo.BaseActivity;
+import com.printer.demo.CollectPrintActivity;
+import com.printer.demo.LablePrintActivity;
+import com.printer.demo.PdfPrintActivity;
+import com.printer.demo.PicturePrintActivity;
+import com.printer.demo.R;
+import com.printer.demo.SettingActivity;
+import com.printer.demo.TextPrintActivity;
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.UpdateUtils;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.utils.XLog;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class MainActivity22 extends BaseActivity implements View.OnClickListener {
+    private static final String TAG = "MainActivity";
+    // 设置打印机的LinearLayout
+    private LinearLayout llSetPrinter;
+    // 打印标签的LinearLayout
+    private LinearLayout llLablePrint;
+    // 打印文本的LinearLayout
+    private LinearLayout llTextPrint;
+    // 打印PDF文件的LinearLayout
+    private LinearLayout llPDFPrint;
+    // 打印条码的LinearLayout
+    private LinearLayout llBarcodePrint;
+    // 打印图片的LinearLayout
+    private LinearLayout llImagePrint;
+    //采集打印的LinearLayout
+    private LinearLayout llCollectPrint;
+    //在线升级的LinearLayout
+    private LinearLayout llUpdate;
+    private ImageView imgRedpoint;
+    private LinearLayout header;
+    private static Context mContext;
+    private View v1;
+    private ProgressDialog dialog;
+    private UpdateHandler updateHandler = new UpdateHandler();
+    private static String[] PERMISSIONS_STORAGE = {
+            Manifest.permission.READ_EXTERNAL_STORAGE,
+            Manifest.permission.WRITE_EXTERNAL_STORAGE,
+            Manifest.permission.BLUETOOTH,
+            Manifest.permission.BLUETOOTH_ADMIN,
+            Manifest.permission.INTERNET,
+            Manifest.permission.ACCESS_WIFI_STATE,
+            Manifest.permission.ACCESS_NETWORK_STATE,
+            Manifest.permission.CHANGE_WIFI_STATE,
+            Manifest.permission.ACCESS_COARSE_LOCATION,
+            Manifest.permission.CAMERA
+    };
+    private final static int REQUEST_PERMISSION_CODE = 200;
+
+    @SuppressLint("InlinedApi")
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        v1 = getLayoutInflater().inflate(R.layout.activity_main, null);
+        setContentView(v1);
+        init();
+        //判断是否有相应权限
+        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
+            if (!checkPermissionAllGranted(PERMISSIONS_STORAGE)) {
+                ActivityCompat.requestPermissions(
+                        this,
+                        PERMISSIONS_STORAGE,
+                        REQUEST_PERMISSION_CODE
+                );
+            }
+        }
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        mContext.registerReceiver(mUsbAttachReceiver, filter);
+
+        dialog = new ProgressDialog(this);
+        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+        dialog.setCancelable(false);
+        if (!UpdateUtils.hasNet(mContext)) {
+            Message message = new Message();
+            message.what = GlobalContants.NETWORK_ERROR;
+            updateHandler.sendMessage(message);
+            return;
+        }
+        checkUpdate();
+
+    }
+
+    private boolean checkPermissionAllGranted(String[] perssions) {
+        for (String perssion : perssions) {
+            if (ActivityCompat.checkSelfPermission(this, perssion) != PackageManager.PERMISSION_GRANTED) {
+                XLog.d("yxz", "yxz at MainActivity.java checkPermissionAllGranted() perssion:" + "没有权限");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        if (requestCode == REQUEST_PERMISSION_CODE) {
+            boolean isAllGranted = true;
+            // 判断是否所有的权限都已经授予了
+            for (int i = 0; i < grantResults.length; i++) {
+                int grant = grantResults[i];
+                if (grant != PackageManager.PERMISSION_GRANTED) {
+                    XLog.d("yxz", "yxz at MainActivity.java checkPermissionAllGranted() permissions[" + i + "]:" + permissions[i] + "授权未成功");
+                    isAllGranted = false;
+                    break;
+                }
+            }
+            if (!isAllGranted) {
+                // 弹出对话框告诉用户需要权限的原因, 并引导用户去应用权限管理中手动打开权限按钮
+                Toast.makeText(mContext, "权限请求异常可能导致不封功能不可使用", Toast.LENGTH_SHORT).show();
+                return;
+            }
+            return;
+
+        }
+    }
+
+    // 初始化界面
+    private void init() {
+        mContext = getApplicationContext();
+        header = (LinearLayout) findViewById(R.id.ll_header_mainactivity);
+        llSetPrinter = (LinearLayout) findViewById(R.id.ll_setting);
+        llLablePrint = (LinearLayout) findViewById(R.id.ll_lable_print);
+        llTextPrint = (LinearLayout) findViewById(R.id.ll_text_print);
+        llPDFPrint = (LinearLayout) findViewById(R.id.ll_pdf_print);
+        llBarcodePrint = (LinearLayout) findViewById(R.id.ll_barcode_print);
+        llImagePrint = (LinearLayout) findViewById(R.id.ll_image_print);
+        llCollectPrint = (LinearLayout) findViewById(R.id.ll_collect_print);
+        llUpdate = (LinearLayout) findViewById(R.id.ll_update);
+        imgRedpoint = (ImageView) findViewById(R.id.img_redpoint);
+        // 设置点击监听事件
+        llSetPrinter.setOnClickListener(this);
+        llLablePrint.setOnClickListener(this);
+        llTextPrint.setOnClickListener(this);
+        llPDFPrint.setOnClickListener(this);
+        llBarcodePrint.setOnClickListener(this);
+        llImagePrint.setOnClickListener(this);
+        llCollectPrint.setOnClickListener(this);
+        llUpdate.setOnClickListener(this);
+        ChangeUpdateStatus(0);
+        initHeader();
+    }
+
+    /**
+     * 升级状态的显示
+     *
+     * @param flag 0表示没有新版本,1表示有新版本
+     */
+    private void ChangeUpdateStatus(int flag) {
+        if (flag == 1) {
+            imgRedpoint.setVisibility(View.VISIBLE);
+            return;
+        } else {
+            imgRedpoint.setVisibility(View.GONE);
+            return;
+        }
+    }
+
+    // 点击监听事件
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.ll_setting:
+                Intent intent = new Intent(MainActivity22.this, SettingActivity.class);
+                // intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+                startActivity(intent);
+                break;
+            case R.id.ll_lable_print:
+                Intent intent_lable = new Intent(MainActivity22.this, LablePrintActivity.class);
+                startActivity(intent_lable);
+                break;
+            case R.id.ll_text_print:
+                Intent intent_text = new Intent(MainActivity22.this, TextPrintActivity.class);
+                startActivity(intent_text);
+                break;
+            case R.id.ll_pdf_print:
+                Intent intent2 = new Intent(MainActivity22.this, PdfPrintActivity.class);
+                startActivity(intent2);
+                break;
+            case R.id.ll_barcode_print:
+                Intent intent_barcode = new Intent(MainActivity22.this, BarcoePrintActivity.class);
+                startActivity(intent_barcode);
+                break;
+            case R.id.ll_image_print:
+                Intent intent_image = new Intent(MainActivity22.this, PicturePrintActivity.class);
+                startActivity(intent_image);
+                break;
+            case R.id.ll_collect_print:
+                Intent intent_collect_print = new Intent(MainActivity22.this, CollectPrintActivity.class);
+                startActivity(intent_collect_print);
+                break;
+            case R.id.ll_update:
+                //APP在线升级
+                if (GlobalContants.NEED_UPDATE == 1) {
+                    showUpdateDialog();
+                } else {
+                    Toast.makeText(mContext, getString(R.string.current_app_version) + UpdateUtils.getVersionName(mContext), Toast.LENGTH_SHORT).show();
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader() {
+        setHeaderLeftText(header, "", null);
+        headerConnecedState.setText(getTitleState());
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        initHeader();
+    }
+
+    private static BroadcastReceiver mUsbAttachReceiver = new BroadcastReceiver() {
+        @SuppressLint("NewApi")
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            Log.w("fdh", "receiver action: " + action);
+
+            if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
+                Toast.makeText(mContext, "USB设备已接入", 0).show();
+            } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
+                Toast.makeText(mContext, "USB设备已拔出", 0).show();
+                if (PrinterInstance.mPrinter != null && SettingActivity.isConnected) {
+                    PrinterInstance.mPrinter.closeConnection();
+                    PrinterInstance.mPrinter = null;
+                }
+            }
+        }
+    };
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        mContext.unregisterReceiver(mUsbAttachReceiver);
+    }
+
+    // @Override
+    // protected void onStart() {
+    // super.onStart();
+    // initHeader();
+    // }
+
+    /**
+     * 检查是否有新版本,如果有就升级
+     */
+    private void checkUpdate() {
+        new Thread() {
+            public void run() {
+                Message mes = Message.obtain();
+                try {
+                    URL url = new URL(getString(R.string.serverurl));
+                    // 联网
+                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+                    conn.setRequestMethod("GET");
+                    conn.setConnectTimeout(4000);
+                    int code = conn.getResponseCode();
+                    if (code == 200) {
+                        // 请求成功
+                        InputStream is = conn.getInputStream();
+                        // 把流转成String
+                        String result = UpdateUtils.readFromStream(is);
+                        XLog.d(TAG, "联网成功了" + result);
+                        // json解析
+                        JSONObject obj = new JSONObject(result);
+                        // 得到服务器的版本信息
+                        String version = (String) obj.get("version");
+                        if (UpdateUtils.isZh(mContext))
+                            GlobalContants.description = (String) obj.get("description");
+                        else
+                            GlobalContants.description = (String) obj.get("descriptionE");
+                        GlobalContants.apkurl = (String) obj.get("apkurl");
+                        XLog.d("yxz", "apkurl:" + GlobalContants.apkurl);
+                        // 校验是否有新版本
+                        if (UpdateUtils.getVersionName(mContext).equals(version)) {
+                            // 版本一致,没有新版本,设置 GlobalContants.NEED_UPDATE=0;
+                            mes.what = GlobalContants.NO_NEW_VERSION;
+                        } else {
+                            // 有新版本,设置 GlobalContants.NEED_UPDATE=1;
+                            mes.what = GlobalContants.HAS_NEW_VERSION;
+                        }
+                    }
+
+                } catch (MalformedURLException e) {
+                    // TODO Auto-generated catch block
+                    mes.what = GlobalContants.URL_ERROR;
+                    e.printStackTrace();
+                } catch (IOException e) {
+                    mes.what = GlobalContants.NETWORK_ERROR;
+                    e.printStackTrace();
+                } catch (JSONException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                    mes.what = GlobalContants.JSON_ERROR;
+                } finally {
+                    updateHandler.sendMessage(mes);
+                }
+            }
+        }.start();
+
+    }
+
+
+    private class UpdateHandler extends Handler {
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            switch (msg.what) {
+                case GlobalContants.HAS_NEW_VERSION:// 有新版本更新
+                    GlobalContants.NEED_UPDATE = 1;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_has_new_version, Toast.LENGTH_LONG).show();
+                    break;
+                case GlobalContants.NO_NEW_VERSION:// 无新版本更新
+                    GlobalContants.NEED_UPDATE = 0;
+                    break;
+
+                case GlobalContants.URL_ERROR:// URL错误
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_url_error, Toast.LENGTH_LONG).show();
+                    break;
+                case GlobalContants.NETWORK_ERROR:// 网络异常
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_net_error, Toast.LENGTH_LONG).show();
+                    break;
+
+                case GlobalContants.JSON_ERROR:// JSON解析出错
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_json_error, Toast.LENGTH_LONG).show();
+                    break;
+//                D:\webapps\sprtwork
+//                D:\qzfeng_20160325\apache-tomcat-6.0.37-windows-x86\apache-tomcat-6.0.37\bin
+            }
+            ChangeUpdateStatus(GlobalContants.NEED_UPDATE);
+        }
+    }
+
+    /**
+     * 弹出升级对话框
+     */
+    protected void showUpdateDialog() {
+        AllenVersionChecker
+                .getInstance()
+                .downloadOnly(
+                        UIData.create().setTitle(getString(R.string.new_version)).setContent(GlobalContants.description).setDownloadUrl(GlobalContants.apkurl)
+                )
+                .excuteMission(mContext);
+    }
+}

+ 697 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/BarcoePrintActivity.java

@@ -0,0 +1,697 @@
+package com.printer.demo;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.Spinner;
+import android.widget.SpinnerAdapter;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.sdk.Barcode;
+import com.printer.sdk.PrinterConstants.BarcodeType;
+import com.printer.sdk.PrinterConstants.Command;
+import com.printer.sdk.PrinterInstance;
+
+public class BarcoePrintActivity extends BaseActivity implements
+        OnItemSelectedListener,
+		android.widget.CompoundButton.OnCheckedChangeListener, OnClickListener {
+	private RadioButton rbBarCode1;
+	private RadioButton rbBarCode2;
+	private Spinner spBarCodeType;
+	private Spinner spContent;
+	private int barType = 1;
+	private int barNote = 1;
+	private EditText etWidth;
+	private EditText etHeight;
+	private EditText etCodeContent;
+	private TextView tvShowWidth;
+	private TextView tvShowHeight;
+	private TextView tvWidth;
+	private TextView tvHeigh;
+	private TextView tvQRSize;
+
+	private Button btnSend;
+	private Button btnClearContent;
+	private Button btnCode1PrintExample;
+	private Button btnCode2PrintExample;
+	private Button btnScanPrint;
+	private Context mContext;
+
+	private ArrayAdapter<CharSequence> barTypeAdapter;
+	private ArrayAdapter<CharSequence> barNoteAdapter;
+
+	private final static int SCANNIN_GREQUEST_CODE = 2;
+	private String barcodeContent;
+
+	private LinearLayout header;
+	private String TAG = "com.printer.demo.ui";
+
+	protected void onCreate(android.os.Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_print_barcode);
+		init();
+		if (rbBarCode1.isChecked()) {
+			barTypeAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barcode1,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barTypeAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spBarCodeType.setAdapter(barTypeAdapter);
+			barNoteAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barNoteArray,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barNoteAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spContent.setAdapter(barNoteAdapter);
+			rbBarCode2.setChecked(false);
+
+		}
+	};
+
+	@Override
+	protected void onResume() {
+		super.onResume();
+//		if (GlobalContants.ISCONNECTED) {
+//			if ("".equals(GlobalContants.DEVICENAME)
+//					|| GlobalContants.DEVICENAME == null) {
+//				headerConnecedState.setText(R.string.unknown_device);
+//
+//			} else {
+//
+//				headerConnecedState.setText(GlobalContants.DEVICENAME);
+//			}
+//
+//		}
+
+	}
+
+	private void init() {
+		mContext = BarcoePrintActivity.this;
+		header = (LinearLayout) findViewById(R.id.ll_header_barcode);
+		initHeader();
+		// 初始化radioButton并给它设置选择监听事件
+		rbBarCode1 = (RadioButton) findViewById(R.id.rb_58mm);
+		rbBarCode2 = (RadioButton) findViewById(R.id.rb_80mm);
+		rbBarCode1.setOnCheckedChangeListener(this);
+		rbBarCode2.setOnCheckedChangeListener(this);
+		// 初始化spinner并给他设置子项选择监听事件
+		spBarCodeType = (Spinner) findViewById(R.id.spinner_barcode_type);
+		spContent = (Spinner) findViewById(R.id.spinner_interface_type);
+		spBarCodeType.setOnItemSelectedListener(this);
+		spContent.setOnItemSelectedListener(this);
+		// 初始化设置条码宽度和高度以及输入条码内容的Edittext,
+		etHeight = (EditText) findViewById(R.id.et_input_height);
+		etWidth = (EditText) findViewById(R.id.et_input_width);
+		etCodeContent = (EditText) findViewById(R.id.et_barcode_content);
+		// 初始化显示条码宽度和高度的范围的textview
+		tvShowWidth = (TextView) findViewById(R.id.tv_input_width);
+		tvShowHeight = (TextView) findViewById(R.id.tv_input_height);
+		tvWidth = (TextView) findViewById(R.id.tv_barcode_width);
+		tvHeigh = (TextView) findViewById(R.id.tv_barcode_height);
+		tvQRSize = (TextView) findViewById(R.id.tv_barcode_setting);
+
+		// 初始化Button按钮并给他们设置点击监听事件
+		btnSend = (Button) findViewById(R.id.btn_barcodedata_send);
+		btnClearContent = (Button) findViewById(R.id.btn_data_default);
+		btnCode1PrintExample = (Button) findViewById(R.id.btn_barcode_example);
+		btnCode2PrintExample = (Button) findViewById(R.id.btn_qrcode_example);
+		btnScanPrint = (Button) findViewById(R.id.btn_scan_print);
+		btnSend.setOnClickListener(this);
+		btnClearContent.setOnClickListener(this);
+		btnCode1PrintExample.setOnClickListener(this);
+		btnCode2PrintExample.setOnClickListener(this);
+		btnScanPrint.setOnClickListener(this);
+
+	}
+
+	/**
+	 * 初始化标题上的信息
+	 */
+	private void initHeader() {
+		setHeaderLeftText(header, getString(R.string.back),
+				new OnClickListener() {
+
+					@Override
+					public void onClick(View v) {
+						finish();
+
+					}
+				});
+		headerConnecedState.setText(getTitleState());
+		setHeaderLeftImage(header, new OnClickListener() {
+
+			@Override
+			public void onClick(View v) {
+				finish();
+			}
+		});
+		setHeaderCenterText(header, getString(R.string.headview_BarcodePrint));
+	}
+
+	@Override
+	public void onItemSelected(AdapterView<?> parent, View view, int position,
+                               long id) {
+		if (parent == spBarCodeType) {
+			barType = position;
+		} else if (parent == spContent) {
+
+			if(rbBarCode1.isChecked()){
+				barNote = position;
+			}else{
+				barNote = position + 5;
+				if (barNote > 5) {
+					barNote = barNote - position * 2;
+				}
+			}
+		}
+
+		initUI();
+	}
+
+	/**
+	 * 选择不同的条码,取值范围不同
+	 */
+	private void initUI() {
+		boolean isDimOneChecked = rbBarCode1.isChecked();
+		if (isDimOneChecked) {
+			tvWidth.setText(R.string.barcode_width);
+			tvShowWidth.setText(R.string.width_data_range);
+			etWidth.setText(R.string.barcode_width_default_value);
+			tvHeigh.setText(R.string.barcode_height);
+			tvShowHeight.setText(R.string.height_data_range);
+			etHeight.setText(R.string.barcode_height_default_value);
+			tvQRSize.setText(R.string.content_position);
+			if (barType == 6) {
+				// UPC_E编码
+				etCodeContent.setText(R.string.upc_e_default_value);
+			} else if (barType == 7) {
+				// EAN13编码
+				etCodeContent.setText(R.string.ean_13_default_value);
+
+			} else if (barType == 8) {
+				// EAN8编码
+				etCodeContent.setText(R.string.ean_8_default_value);
+
+			} else if (barType == 9) {
+				// 全部格式的编码 适配 UPC_E,EAN13,EAN8等所有对内容格式有要求的编码
+				etCodeContent.setText(R.string.upc_e_default_value);
+			} else {
+			}
+
+		} else {
+			if (barType == 0) {
+				tvWidth.setText(R.string.version);
+				tvShowWidth.setText(R.string.verion_range);
+				etWidth.setText(R.string.characters_default_value);
+				tvShowHeight.setText(R.string.level_range);
+				tvHeigh.setText(R.string.level);
+				etHeight.setText(R.string.level_default_value);
+				tvQRSize.setText(R.string.multiple);
+
+			} else if (barType == 1) {
+				tvWidth.setText(R.string.characters_in_line);
+				tvShowWidth.setText(R.string.characters_range);
+				etWidth.setText(R.string.version_default_value);
+				tvHeigh.setText(R.string.level);
+				tvShowHeight.setText(R.string.level_range_qrcode);
+				etHeight.setText(R.string.level_range_default_value_qrcode);
+				tvQRSize.setText(R.string.multiple);
+			} else if (barType == 2) {
+				tvWidth.setText(R.string.barcode_width);
+				tvShowWidth
+						.setText(R.string.barcode_width_data_range_datamatrix);
+				etWidth.setText(R.string.level_range_default_value_qrcode);
+				tvHeigh.setText(R.string.barcode_height);
+				tvShowHeight
+						.setText(R.string.barcode_height_data_range_datamatrix);
+				etHeight.setText(R.string.barcode_height_default_value_datamatrix);
+				tvQRSize.setText(R.string.multiple);
+
+			}
+		}
+	}
+
+	@Override
+	public void onNothingSelected(AdapterView<?> parent) {
+	}
+
+	/**
+	 * 选择一维码或者二维码,条码列表不同
+	 */
+
+	@Override
+	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+		// 一维码
+		if (buttonView == rbBarCode1 && isChecked) {
+			barTypeAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barcode1,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barTypeAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spBarCodeType.setAdapter(barTypeAdapter);
+
+			barNoteAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barNoteArray,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barNoteAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spContent.setAdapter(barNoteAdapter);
+			rbBarCode2.setChecked(false);
+			// 二维码
+		} else if (buttonView == rbBarCode2 && isChecked) {
+			barTypeAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barcode2,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barTypeAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spBarCodeType.setAdapter(barTypeAdapter);
+
+			barNoteAdapter = ArrayAdapter.createFromResource(
+					BarcoePrintActivity.this, R.array.barEnlargeArray,
+					android.R.layout.simple_spinner_item);
+			// 设置样式
+			barNoteAdapter
+					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			spContent.setAdapter(barNoteAdapter);
+			rbBarCode1.setChecked(false);
+		}
+		initUI();
+	}
+
+	@Override
+	public void onClick(View v) {
+
+		switch (v.getId()) {
+		// 发送数据并打印
+		case R.id.btn_barcodedata_send:
+			if (PrinterInstance.mPrinter == null) {
+				Toast.makeText(BarcoePrintActivity.this,
+						R.string.no_connected, Toast.LENGTH_SHORT)
+						.show();
+
+			} else {
+				String content = etCodeContent.getText().toString();
+				int width = Integer.parseInt(etWidth.getText().toString());
+				int height = Integer.parseInt(etHeight.getText().toString());
+				if (rbBarCode1.isChecked()) {
+					if (width < 2 || width > 6) {
+						width = 2;
+					}
+					if (height < 1 || width > 255) {
+						height = 162;
+					}
+				} else {
+
+					switch (barType) {
+					case 0:
+						if(width>40 || width < 0)
+							width = 0;
+						if(height != 72 || height != 76 || height != 77 || height != 81){
+							height = 76;
+						}
+						break;
+					case 1:
+						if(width>30 || width < 1)
+							width = 1;
+						if(height>8 || height < 0){
+							height = 0;
+						}
+						break;
+					case 2:
+						if(width>144 || width < 8)
+							width = 8;
+						if(height>144 || height < 0){
+							height = 0;
+						}
+						break;
+					default:
+						break;
+					}
+
+				}
+				Barcode barcode = null;
+				String codeType = null;
+				switch (barType) {
+				case 0:
+					barcode = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.CODE128
+									: BarcodeType.QRCODE, width, height,
+							barNote, content);
+					if (rbBarCode1.isChecked()) {
+						codeType = "CODE128";
+					} else {
+						codeType = "QRCODE";
+					}
+					break;
+
+				case 1:
+					barcode = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.CODE39
+									: BarcodeType.PDF417, width, height,
+							barNote, content);
+					if (rbBarCode1.isChecked()) {
+						codeType = "CODE39";
+					} else {
+						codeType = "PDF417";
+					}
+					break;
+				case 2:
+					barcode = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.CODABAR
+									: BarcodeType.DATAMATRIX, width, height,
+							barNote, content);
+					if (rbBarCode1.isChecked()) {
+						codeType = "CODEBAR";
+					} else {
+						codeType = "DATAMATRIX";
+					}
+					break;
+				case 3:
+					barcode = new Barcode(BarcodeType.ITF, width, height,
+							barNote, content);
+					codeType = "ITF";
+					break;
+				case 4:
+					barcode = new Barcode(BarcodeType.CODE93, width, height,
+							barNote, content);
+					codeType = "CODE93";
+					break;
+				case 5:
+					barcode = new Barcode(BarcodeType.UPC_A, width, height,
+							barNote, content);
+					codeType = "UPC_A";
+					break;
+				case 6:
+					barcode = new Barcode(BarcodeType.UPC_E, width, height,
+							barNote, content);
+					codeType = "UPC_E";
+					break;
+				case 7:
+					barcode = new Barcode(BarcodeType.JAN13, width, height,
+							barNote, content);
+					codeType = "JAN13";
+					break;
+				case 8:
+					barcode = new Barcode(BarcodeType.JAN8, width, height,
+							barNote, content);
+					codeType = "JAN8";
+					break;
+				case 9:
+					Barcode barcode1 = new Barcode(BarcodeType.CODE128, width,
+							height, barNote, content);
+					Barcode barcode2 = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.CODE39
+									: BarcodeType.PDF417, width, height,
+							barNote, content);
+					Barcode barcode3 = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.CODABAR
+									: BarcodeType.QRCODE, width, height,
+							barNote, content);
+					Barcode barcode4 = new Barcode(
+							rbBarCode1.isChecked() ? BarcodeType.ITF
+									: BarcodeType.DATAMATRIX, width, height,
+							barNote, content);
+					Barcode barcode5 = new Barcode(BarcodeType.CODE93, width,
+							height, barNote, content);
+					Barcode barcode6 = new Barcode(BarcodeType.UPC_A, width,
+							height, barNote, content);
+					Barcode barcode7 = new Barcode(BarcodeType.UPC_E, width,
+							height, barNote, content);
+					Barcode barcode8 = new Barcode(BarcodeType.JAN13, width,
+							height, barNote, content);
+					barcode = new Barcode(BarcodeType.JAN8, width, height,
+							barNote, content);
+					PrinterInstance.mPrinter.printText("打印 CODE128 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode1);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 CODE39 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode2);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 CODEBAR 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode3);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 ITF 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode4);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 CODE93 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode5);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 UPC_A 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode6);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 UPC_E 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode7);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					PrinterInstance.mPrinter.printText("打印 JAN13 码效果演示:");
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+					PrinterInstance.mPrinter.printBarCode(barcode8);
+					PrinterInstance.mPrinter.setPrinter(
+							Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+					codeType = "JAN8";
+				}
+				PrinterInstance.mPrinter
+						.printText("打印 " + codeType + " 码效果展示:");
+				PrinterInstance.mPrinter.setPrinter(
+						Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+				PrinterInstance.mPrinter.printBarCode(barcode);
+				PrinterInstance.mPrinter.setPrinter(
+						Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+			}
+			break;
+		// 打印一维码示例
+		case R.id.btn_barcode_example:
+			if (PrinterInstance.mPrinter == null) {
+				Toast.makeText(BarcoePrintActivity.this,
+						R.string.no_connected, Toast.LENGTH_SHORT)
+						.show();
+
+			} else {
+				PrinterInstance.mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
+				Barcode barcode1 = new Barcode(BarcodeType.CODE128, 2, 150, 2,
+						"123456");
+				PrinterInstance.mPrinter.printBarCode(barcode1);
+			}
+
+			break;
+		// 打印二维码示例
+		case R.id.btn_qrcode_example:
+			if (PrinterInstance.mPrinter == null) {
+				Toast.makeText(BarcoePrintActivity.this,
+						R.string.no_connected, Toast.LENGTH_SHORT)
+						.show();
+
+			} else {
+				PrinterInstance.mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
+				Barcode barcode2 = new Barcode(BarcodeType.QRCODE, 2, 3, 6,
+						"123456");
+				PrinterInstance.mPrinter.printBarCode(barcode2);
+			}
+
+			break;
+		// 清空数据到默认
+		case R.id.btn_data_default:
+			etCodeContent.setText(R.string.default_code_content);
+			if (rbBarCode1.isChecked()) {
+				etWidth.setText("2");
+				etHeight.setText("162");
+				setSpinnerItemSelectedByValue(spContent,
+						getString(R.string.default_content_position));
+				setSpinnerItemSelectedByValue(spBarCodeType,
+						getString(R.string.default_barcode_type));
+
+			} else {
+				// if (barType == 0) {
+				// tvWidth.setText(R.string.version);
+				// etWidth.setText(R.string.level_default_value_qrcode);
+				// tvHeigh.setText(R.string.level);
+				// tvShowHeight.setText(R.string.level_range);
+				// etHeight.setText(R.string.level_default_value);
+				// tvQRSize.setText(R.string.multiple);
+				// } else if (barType == 1) {
+				tvWidth.setText(R.string.characters_in_line);
+				tvShowWidth.setText(R.string.characters_range);
+				etWidth.setText(R.string.characters_default_value);
+				tvHeigh.setText(R.string.level);
+				tvShowHeight.setText(R.string.level_range_qrcode);
+				etHeight.setText(R.string.level_range_default_value_qrcode);
+				tvQRSize.setText(R.string.multiple);
+				// } else if (barType == 2) {
+				// tvWidth.setText(R.string.barcode_width);
+				// tvShowWidth.setText(R.string.barcode_width_data_range_datamatrix);
+				// etWidth.setText(R.string.level_default_value_qrcode);
+				// tvHeigh.setText(R.string.barcode_height);
+				// tvShowHeight.setText(R.string.barcode_height_data_range_datamatrix);
+				// etHeight.setText(R.string.barcode_height_default_value_datamatrix);
+				// tvQRSize.setText("放大倍数:");
+				//
+				// }
+				// 恢复spinner打印位置为默认
+				// spContent.setAdapter(barNoteAdapter);
+				// spContent.setSelection(0,true);
+				// spContent.setSelected(false);
+				setSpinnerItemSelectedByValue(spContent,
+						getString(R.string.characters_default_value));
+				setSpinnerItemSelectedByValue(spBarCodeType,
+						getString(R.string.default_qrcode_type));
+
+			}
+			break;
+		// 扫一扫打印
+		case R.id.btn_scan_print:
+			if (PrinterInstance.mPrinter == null && !SettingActivity.isConnected) {
+				Toast.makeText(BarcoePrintActivity.this,
+						R.string.no_connected, Toast.LENGTH_SHORT)
+						.show();
+
+			} else {
+				Intent intent = new Intent();
+				intent.setClass(mContext, MipcaActivityCapture.class);
+				startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
+			}
+			break;
+
+		}
+	}
+
+	/**
+	 * 根据值, 设置spinner默认选中:
+	 *
+	 * @param spinner
+	 * @param value
+	 */
+	public static void setSpinnerItemSelectedByValue(Spinner spinner,
+			String value) {
+		SpinnerAdapter apsAdapter = spinner.getAdapter(); // 得到SpinnerAdapter对象
+		int k = apsAdapter.getCount();
+		for (int i = 0; i < k; i++) {
+			if (value.equals(apsAdapter.getItem(i).toString())) {
+				spinner.setSelection(i, true);// 默认选中项
+				break;
+			}
+		}
+	}
+
+	@SuppressLint("ShowToast")
+	@Override
+	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+		super.onActivityResult(requestCode, resultCode, data);
+		if (resultCode != Activity.RESULT_OK)
+			return;
+		if (requestCode == SCANNIN_GREQUEST_CODE) {
+			Log.e(TAG, "执行onActivityResult方法");
+			// 得到扫描后的条码的类型
+			int barcodeType = data.getExtras().getInt("codetype");
+			Log.e(TAG, "条码类型" + barcodeType);
+
+			// 得到扫描后的内容再生成条码并打印
+			barcodeContent = data.getExtras().getString(
+					BluetoothDeviceList.EXTRA_DEVICE_ADDRESS);
+			Log.e(TAG, "--条码内容" + barcodeContent);
+			if(barcodeType == 1){
+
+				Toast.makeText(mContext,
+						"一维码:" + barcodeContent, 0)
+						.show();
+			}else{
+				Toast.makeText(mContext,
+						"二维码:" + barcodeContent + " " + barcodeContent, 0)
+						.show();
+			}
+
+			// 判端条码类型
+			switch (barcodeType) {
+			case 1:
+				if (PrinterInstance.mPrinter == null) {
+					Toast.makeText(BarcoePrintActivity.this,
+							R.string.tips_for_not_connect, Toast.LENGTH_SHORT)
+							.show();
+				} else {
+					// 生成CODE128类型的一维码
+					Barcode barcode1 = new Barcode(BarcodeType.CODE128, 2, 150,
+							2, barcodeContent);
+					PrinterInstance.mPrinter.printBarCode(barcode1);
+
+				}
+				break;
+			case 2:
+				if (PrinterInstance.mPrinter == null) {
+					Toast.makeText(BarcoePrintActivity.this,
+							R.string.tips_for_not_connect, Toast.LENGTH_SHORT)
+							.show();
+				} else {
+					// 生成QRCODE类型的二维码
+					Barcode barcode2 = new Barcode(BarcodeType.QRCODE, 2, 3, 6,
+							barcodeContent);
+					PrinterInstance.mPrinter.printBarCode(barcode2);
+				}
+
+				break;
+			case 3:
+				if (PrinterInstance.mPrinter == null) {
+					Toast.makeText(BarcoePrintActivity.this,
+							R.string.tips_for_not_connect, Toast.LENGTH_SHORT)
+							.show();
+
+				} else {
+					// 其他条码类型 //TODO 按CODE128类型的一维码处理
+					Barcode barcode3 = new Barcode(BarcodeType.CODE128, 2, 150,
+							2, barcodeContent);
+					PrinterInstance.mPrinter.printBarCode(barcode3);
+				}
+
+				break;
+
+			}
+		}
+	}
+
+}

+ 93 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/BaseActivity.java

@@ -0,0 +1,93 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class BaseActivity extends Activity {
+	private static boolean isFirst = true;
+	protected static String titleConnectState = "";
+	/**
+	 * ��������textview
+	 */
+	protected static TextView headerConnecedState;
+
+	public static String getTitleState() {
+		return titleConnectState;
+	}
+
+	public static void setTitleState(String titleState) {
+		BaseActivity.titleConnectState = titleState;
+	}
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		if (isFirst) {
+			setTitleState(getResources().getString(R.string.off_line));
+			isFirst = false;
+		}
+	}
+
+	/**
+	 * ����2������������headerview��
+	 */
+	public void setHeaderLeftImage(LinearLayout header, View.OnClickListener listener) {
+		ImageView ivback = (ImageView) header.findViewById(R.id.iv_hearderview_left_image);
+		ivback.setVisibility(View.VISIBLE);
+		if (listener != null) {
+			ivback.setOnClickListener(listener);
+		}
+		ivback.setImageResource(R.drawable.icon_back);
+	}
+
+	public void setHeaderLeftText(LinearLayout header, String title, View.OnClickListener listener) {
+		TextView tvText = (TextView) header.findViewById(R.id.tv_headerview_left_text);
+		headerConnecedState = (TextView) header.findViewById(R.id.tv_headerview_connected);
+		if (TextUtils.isEmpty(title)) {
+			tvText.setText("");
+		} else {
+			tvText.setText(title);
+		}
+		if (listener != null) {
+			tvText.setOnClickListener(listener);
+		}
+
+	}
+
+	public void setHeaderCenterText(LinearLayout header, String title) {
+		TextView tvText = (TextView) header.findViewById(R.id.tv_headerview_center_text);
+		headerConnecedState = (TextView) header.findViewById(R.id.tv_headerview_connected);
+		if (TextUtils.isEmpty(title)) {
+			tvText.setText("");
+		} else {
+			tvText.setText(title);
+		}
+
+	}
+
+	// 判断当前是否使用的是 WIFI网络
+	public static boolean isWifiActive(Context icontext) {
+		Context context = icontext.getApplicationContext();
+		ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo[] info;
+		if (connectivity != null) {
+			info = connectivity.getAllNetworkInfo();
+			if (info != null) {
+				for (int i = 0; i < info.length; i++) {
+					if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) {
+						return true;
+					}
+				}
+			}
+		}
+		return false;
+	}
+}

+ 211 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/BluetoothDeviceList.java

@@ -0,0 +1,211 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.RequiresApi;
+
+import com.printer.sdk.utils.XLog;
+
+import java.lang.reflect.Method;
+import java.util.Set;
+
+public class BluetoothDeviceList extends Activity {
+    private static final String TAG = "DeviceListActivity";
+    public static String EXTRA_DEVICE_ADDRESS = "device_address";
+    public static String EXTRA_RE_PAIR = "re_pair";
+    public static String EXTRA_DEVICE_NAME = "device_name";
+
+    // Member fields
+    private BluetoothAdapter mBtAdapter;
+    private ArrayAdapter<String> mPairedDevicesArrayAdapter;
+    private ListView pairedListView;
+    private Button scanButton;
+    private Button backButton;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+        setContentView(R.layout.device_list);
+        setTitle(R.string.select_device);
+        setResult(Activity.RESULT_CANCELED);
+        initView();
+    }
+
+    private void initView() {
+        mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_item);
+        pairedListView = (ListView) findViewById(R.id.paired_devices);
+        pairedListView.setAdapter(mPairedDevicesArrayAdapter);
+        pairedListView.setOnItemClickListener(mDeviceClickListener);
+        mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+        Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
+        if (pairedDevices.size() > 0) {
+            for (BluetoothDevice device : pairedDevices) {
+                mPairedDevicesArrayAdapter.add(device.getName() + " ( " + getResources().getText(R.string.has_paired)
+                        + " )" + "\n" + device.getAddress());
+            }
+        }
+
+        scanButton = (Button) findViewById(R.id.button_scan);
+        scanButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+				doDiscovery();
+				v.setEnabled(false);
+            }
+        });
+
+        backButton = (Button) findViewById(R.id.button_bace);
+        backButton.setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+
+        });
+
+    }
+
+    @Override
+    protected void onStop() {
+        if (mBtAdapter != null && mBtAdapter.isDiscovering()) {
+            mBtAdapter.cancelDiscovery();
+        }
+        this.unregisterReceiver(mReceiver);
+        super.onStop();
+    }
+
+    @Override
+    protected void onResume() {
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
+        filter.addAction(BluetoothDevice.ACTION_FOUND);
+        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
+        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+        registerReceiver(mReceiver, filter);
+        super.onResume();
+    }
+
+    /**
+     * Start device discover with the BluetoothAdapter
+     */
+    private void doDiscovery() {
+        Log.d(TAG, "doDiscovery()");
+
+        // Indicate scanning in the title
+        setProgressBarIndeterminateVisibility(true);
+        setTitle(R.string.scanning);
+
+        // If we're already discovering, stop it
+        // if (mBtAdapter.isDiscovering()) {
+        // mBtAdapter.cancelDiscovery();
+        // }
+
+        mPairedDevicesArrayAdapter.clear();
+        // Request discover from BluetoothAdapter
+        mBtAdapter.startDiscovery();
+    }
+
+    private void returnToPreviousActivity(String address, boolean re_pair, String name) {
+        if (mBtAdapter.isDiscovering()) {
+            mBtAdapter.cancelDiscovery();
+        }
+
+        Intent intent = new Intent();
+        intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
+        intent.putExtra(EXTRA_RE_PAIR, re_pair);
+        intent.putExtra(EXTRA_DEVICE_NAME, name);
+        setResult(Activity.RESULT_OK, intent);
+        finish();
+    }
+
+    private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
+        public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
+
+            String info = ((TextView) v).getText().toString();
+            String address = info.substring(info.length() - 17);
+            String name = info.substring(0, info.length() - 17);
+            returnToPreviousActivity(address, false, name);
+        }
+    };
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+
+            if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
+            }
+            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
+                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+                int deviceType = device.getBluetoothClass().getMajorDeviceClass();
+                if(((deviceType==1536)||(deviceType==7936))&&(device.getType()!=2)){
+                    String itemName = device.getName() + " ( "
+                            + getResources().getText(device.getBondState() == BluetoothDevice.BOND_BONDED
+                            ? R.string.has_paired : R.string.not_paired)
+                            + " )" + "\n" + device.getAddress();
+
+                    mPairedDevicesArrayAdapter.remove(itemName);
+                    mPairedDevicesArrayAdapter.add(itemName);
+                    pairedListView.setEnabled(true);
+                }
+            }
+
+            if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
+                setProgressBarIndeterminateVisibility(false);
+                setTitle(R.string.select_device);
+                if (mPairedDevicesArrayAdapter.getCount() == 0) {
+                    String noDevices = getResources().getText(R.string.none_found).toString();
+                    mPairedDevicesArrayAdapter.add(noDevices);
+                    pairedListView.setEnabled(false);
+                }
+                scanButton.setEnabled(true);
+
+            }
+            if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
+                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+                switch (device.getBondState()) {
+                    case BluetoothDevice.BOND_BONDING:
+                        XLog.d(TAG, "----------bounding......,mac" + device.getAddress() + "----------");
+                        break;
+                    case BluetoothDevice.BOND_BONDED:
+                        XLog.d(TAG, "----------bound success, mac:" + device.getAddress() + "----------");
+                        break;
+                    case BluetoothDevice.BOND_NONE:
+                        XLog.e(TAG, "----------bound cancel, mac:" + device.getAddress() + "----------");
+                        Toast.makeText(BluetoothDeviceList.this,"设备:"+device.getAddress()+"已解除配对",Toast.LENGTH_SHORT).show();;
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+    };
+
+    //与设备解除配对
+    static public boolean removeBond(Class btClass, BluetoothDevice btDevice) throws Exception {
+        Method removeBondMethod = btClass.getMethod("removeBond");
+        Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);
+        return returnValue.booleanValue();
+    }
+
+}

+ 370 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/CollectPrintActivity.java

@@ -0,0 +1,370 @@
+package com.printer.demo;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.RadioGroup.OnCheckedChangeListener;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.sdk.Barcode;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.listener.OnPrintListener;
+import com.printer.sdk.utils.IOUtils;
+import com.printer.sdk.utils.Utils;
+import com.printer.sdk.utils.XLog;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+/**
+ * @Description 处理图片打印相关
+ */
+public class CollectPrintActivity extends BaseActivity implements OnCheckedChangeListener {
+    protected static final String TAG = "yxz";
+    private static Context mContext;
+    private LinearLayout header;
+    private RadioGroup rg_is_notifacation, rg_is_service_setable;
+    private RadioButton rbYes, reNo, rbAllow, rbNotAllow;
+    private PrinterInstance myPrinter;
+    private TextView tvCollectData;
+    private boolean isOpen;
+    private TextView testPrint, testNotPrint;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mContext = this;
+        setContentView(R.layout.activity_collect_print);
+        init();
+        XLog.d("yxz", "oncreate");
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        XLog.d("yxz", "onresume");
+        if (!isOpen)
+            return;
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                if (myPrinter.getSetable()) {
+                    runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            rbAllow.setChecked(true);
+                            // rg_is_service_setable.check(R.id.rb_allow);
+                        }
+                    });
+                } else {
+                    runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            rbNotAllow.setChecked(true);
+                            // rg_is_service_setable.check(R.id.rb_not_allow);
+                        }
+                    });
+                }
+            }
+        }).start();
+
+    }
+
+    private void init() {
+
+        header = (LinearLayout) findViewById(R.id.ll_header_picture);
+        rg_is_notifacation = (RadioGroup) findViewById(R.id.rg_is_notifacation);
+        rbYes = (RadioButton) findViewById(R.id.yes);
+        reNo = (RadioButton) findViewById(R.id.no);
+        rg_is_notifacation.setOnCheckedChangeListener(this);
+        rg_is_service_setable = (RadioGroup) findViewById(R.id.rg_is_service_setable);
+        rbAllow = (RadioButton) findViewById(R.id.rb_allow);
+        rbNotAllow = (RadioButton) findViewById(R.id.rb_not_allow);
+        rg_is_service_setable.setOnCheckedChangeListener(this);
+        tvCollectData = (TextView) findViewById(R.id.et_collect_data);
+        // 设置文本可以滚动
+        tvCollectData.setMovementMethod(ScrollingMovementMethod.getInstance());
+        testPrint = (TextView) findViewById(R.id.tv_show_msg);
+        testNotPrint = (TextView) findViewById(R.id.tv_show_is_notifacation);
+        testPrint.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                // myPrinter.setPrintable(true);
+                // myPrinter.setCutCommand("1d5555");
+                myPrinter.setAppendAble(false);
+                XLog.d("yxz","setAppendAble :"+false);
+
+            }
+        });
+        testNotPrint.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+//                myPrinter.setPrintable(false);
+//                XLog.d("yxz", "setPrintable str:" + false);
+                //String str= myPrinter.getCutCommand();
+                //XLog.d("yxz","cutcommand str:"+str);
+//                boolean isNewApk = myPrinter.isNewApk();
+//                XLog.d("yxz", "isNewApk str:" + isNewApk);
+//                boolean isAppendAble=myPrinter.getAppendAble();
+//                XLog.d("yxz", "isAppendAble str:" + isAppendAble);
+                myPrinter.setAppendAble(true);
+                XLog.d("yxz","setAppendAble :"+true);
+//                boolean isAppendAble2=myPrinter.getAppendAble();
+//                XLog.d("yxz", "isAppendAble str2:" + isAppendAble2);
+
+            }
+        });
+        initHeader(header);
+        // 打开服务远程端口
+        open();
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader(LinearLayout header) {
+        setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                finish();
+
+            }
+        });
+        headerConnecedState.setText(getTitleState());
+        setHeaderLeftImage(header, new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        setHeaderCenterText(header, getString(R.string.headview_CollectPrint));
+        setTitleState("");
+    }
+
+    @Override
+    public void onCheckedChanged(RadioGroup group, int checkedId) {
+        if (group == rg_is_notifacation) {
+            switch (checkedId) {
+                case R.id.yes:
+                    collect(true);
+                    Toast.makeText(mContext, "等待数据上传后执行追加动作", Toast.LENGTH_SHORT).show();
+                    break;
+                case R.id.no:
+                    collect(false);
+                    Toast.makeText(mContext, "追加并采集功能关闭", Toast.LENGTH_SHORT).show();
+                    break;
+            }
+        }
+//		if (group == rg_is_service_setable) {
+//			switch (checkedId) {
+//			case R.id.rb_allow:
+//				isServiceSetable(true);
+//				Toast.makeText(mContext, "打开服务端配置", Toast.LENGTH_SHORT).show();
+//				break;
+//			case R.id.rb_not_allow:
+//				isServiceSetable(false);
+//				Toast.makeText(mContext, "关闭服务端配置", Toast.LENGTH_SHORT).show();
+//				break;
+//			}
+//		}
+    }
+
+    private boolean open() {
+        if (isOpen)
+            return true;
+        myPrinter = PrinterInstance.getPrinterInstance();
+        return isOpen = myPrinter.openConnection();
+
+    }
+
+    public void isServiceSetable(boolean isSetable) {
+        if (!isOpen) {
+            if (isSetable)
+                Toast.makeText(mContext, "开口失败,无法设置服务端为可配置", Toast.LENGTH_SHORT).show();
+            else
+                Toast.makeText(mContext, "开口失败,无法设置服务端为不可配置", Toast.LENGTH_SHORT).show();
+            return;
+        }
+        myPrinter.isSetAble(isSetable);
+    }
+
+    public void collect(boolean isCollect) {
+        if (!isOpen) {
+            Toast.makeText(mContext, "开口失败,无法追加或采集", Toast.LENGTH_SHORT).show();
+            return;
+        }
+        if (!isCollect) {
+            myPrinter.setOnPrintListener(null);
+            return;
+        }
+        myPrinter.setOnPrintListener(new OnPrintListener() {
+            @Override
+            public int doBeforePrint() {
+                XLog.i(TAG, "客户端 打印开始前打印开头,发送广播给Service端。");
+//                try {
+//                    int writeLen = myPrinter.sendBytesData("*************一单数据开始**************\r\n".getBytes("gbk"));
+//                    XLog.i(TAG, "客户端 打印前发送的数据长度writeLen:" + writeLen);
+//                } catch (UnsupportedEncodingException e) {
+//                    e.printStackTrace();
+//                }
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        tvCollectData.setText("采集数据开始\r\n");
+
+                    }
+                });
+                return 1;
+            }
+
+            @Override
+            public int doAfterPrint() {
+                XLog.i(TAG, "客户端 打印结束后追加数据尾,发送广播给Service端。");
+//				try {
+
+//					myPrinter.drawQrCode(0,"http://i.baiwang.com/f?d=100232916965&c=100232916965346972876963840", PrinterConstants.PRotate.Rotate_0,3,6);
+//					myPrinter.drawQrCode(1,"http://i.baiwang.com/f?d=100232916965&c=100232916965346972876963840", PrinterConstants.PRotate.Rotate_0,3,6);
+//					myPrinter.drawQrCode(2,"http://i.baiwang.com/f?d=100232916965&c=100232916965346972876963840", PrinterConstants.PRotate.Rotate_0,3,6);
+//					int writeLen = myPrinter.sendBytesData("*************一单数据结束**************\r\n".getBytes("gbk"));
+//					byte[]data=getBytes();
+//					int writeLen =myPrinter.sendBytesData(getBytes());
+//					IOUtils.writeStrToSD(mContext,"异常数据:" );
+//					IOUtils.writeStrToSD(mContext,Utils.bytesToHexString(data,data.length) );
+//					myPrinter.sendBytesData("\r\n".getBytes("gbk"));
+//					XLog.i(TAG, "客户端 打印后发送的数据长度writeLen:" + writeLen);
+//				} catch (UnsupportedEncodingException e) {
+//					e.printStackTrace();
+//				}
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        tvCollectData.append("\r\n采集数据结束");
+                    }
+                });
+                return 1;
+            }
+
+            @Override
+            public int onReceiveParserData(int type, final byte[] data) {
+                if (data == null || data.length == 0) {
+                    XLog.i(TAG, "客户端 上传的采集数据为空");
+                    return 1;
+                }
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        XLog.i(TAG, "客户端 上传的采集数据大小小于1M");
+                        tvCollectData.append(Utils.bytesToHexString(data, data.length));
+                    }
+                });
+                return 1;
+            }
+
+            @Override
+            public int onReceiveParserData(int i, final byte[] bytes, final int i1) {
+                if (bytes == null || bytes.length == 0) {
+                    XLog.i(TAG, "客户端 上传的采集数据为空");
+                    return 1;
+                }
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        XLog.i(TAG, "客户端 上传的采集数据大小大于1M,分包传送。解析数据总长度:" + i1);
+                        tvCollectData.append(Utils.bytesToHexString(bytes, bytes.length));
+                        tempLength += bytes.length;
+                        if (tempLength == i1) {
+                            PrinterInstance.getPrinterInstance().endAidl();
+                            XLog.i(TAG, "客户端 上传的采集数据大小大于1M,采集完成,服务端" );
+                        }
+                    }
+                });
+                return 1;
+            }
+
+            @Override
+            public int onReceiveParserData(int i, final List<byte[]> list) {
+
+                if (list == null || list.size() == 0) {
+                    XLog.i(TAG, "客户端 上传的采集数据为空");
+                    return 1;
+                }
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        XLog.i(TAG, "客户端 上传的采集数据大小大于1M");
+                        tvCollectData.append(Utils.bytesToHexString(list.get(0), list.get(0).length));
+                        tvCollectData.append("list.size:" + list.size());
+                    }
+                });
+                return 1;
+            }
+        });
+
+    }
+
+    public int tempLength = 0;
+
+    private void close() {
+        if (!isOpen)
+            return;
+        myPrinter.closeConnection();
+        isOpen = false;
+    }
+
+    private void closeAndRelease() {
+        close();
+        myPrinter.setOnPrintListener(null);
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        closeAndRelease();
+    }
+
+    public static byte[] getBytes() {
+        ByteArrayOutputStream out = null;
+        try {
+            AssetManager manager = mContext.getAssets();
+            InputStream is = manager.open("test.txt");
+
+            out = new ByteArrayOutputStream();
+            byte[] b = new byte[1024];
+            int i = 0;
+            while ((i = is.read(b)) != -1) {
+                out.write(b, 0, i);
+            }
+            out.close();
+            is.close();
+        } catch (FileNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        byte[] s = out.toByteArray();
+        return s;
+    }
+
+}

+ 77 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/DemoApplication.java

@@ -0,0 +1,77 @@
+package com.printer.demo;
+
+import android.util.Log;
+
+import com.android.print.demo.loghelper.LogcatHelper;
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.sdk.application.MyApplication;
+
+/**
+ * 
+ * @author vector
+ * @Description: 锟斤拷锟斤拷锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷痛锟斤拷锟角帮拷锟接︼拷贸锟斤拷锟�,
+ *               锟斤拷锟斤拷要锟斤拷锟藉单锟侥硷拷application锟斤拷锟斤拷锟斤拷
+ * @date 2015-3-29 锟斤拷锟斤拷4:14:17
+ */
+public class DemoApplication extends MyApplication {
+
+	private static final String TAG = "DemoApplication";
+	private static boolean isConnected;
+
+	// TSPL指令添加的全局变量
+	// 设置界面是否选中TSPL指令框
+	public static boolean isSettingTSPL;
+	// 设置界面打印内容的左边距
+	public static int MARGINLEFT = 0;
+	// 设置界面打印内容的上边距
+	public static int MARGINTOP = 0;
+	// 打印的标签份数
+	public static int PRINT_NUMBER = 1;
+
+	// oncreate锟斤拷锟轿猴拷activity锟斤拷service,receiver之前使锟矫o拷锟斤拷锟斤拷content providers
+	@Override
+	public void onCreate() {
+		// TODO Auto-generated method stub
+		super.onCreate();
+		// Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
+		Log.i(TAG, "DemoApplication>>>>>>>>>>>>>>>");
+		LogcatHelper.getInstance(this).start();
+		PrefUtils.setBoolean(getApplicationContext(), GlobalContants.CONNECTSTATE, false);
+	}
+	// //锟斤拷锟斤拷未锟斤拷锟斤拷锟斤拷斐�
+	// private class MyExceptionHandler implements UncaughtExceptionHandler{
+	//
+	//
+	// @Override
+	// public void uncaughtException(Thread thread, Throwable ex) {
+	// //锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷状态锟斤拷未锟斤拷锟斤拷
+	// PrefUtils.setBoolean(getApplicationContext(),
+	// GlobalContants.CONNECTSTATE, false);
+	// // TODO Auto-generated method stub
+	// // Logger.i(TAG, "锟斤拷锟斤拷锟斤拷锟届常锟斤拷锟斤拷锟斤拷锟界捕锟斤拷锟斤拷");
+	// System.out.println("锟斤拷锟斤拷锟届常锟斤拷锟金不诧拷锟斤拷锟斤拷");
+	// // StringWriter wr = new StringWriter();
+	// // PrintWriter err = new PrintWriter(wr);
+	// // ex.printStackTrace(err);
+	// //// System.out.println("??/"+wr.toString());
+	// // File file = new
+	// File(Environment.getExternalStorageDirectory(),"err.log");
+	// // try {
+	// // FileOutputStream fos = new FileOutputStream(file);
+	// // fos.write(wr.toString().getBytes());
+	// // fos.close();
+	// // } catch (Exception e) {
+	// // // TODO Auto-generated catch block
+	// // e.printStackTrace();
+	// // }
+	// //锟斤拷杀----系统锟斤拷为锟角凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷迅锟斤拷锟斤拷锟斤拷
+	// // android.os.Process.killProcess(android.os.Process.myPid());
+	// //一同锟斤拷锟斤拷锟届常锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷状态锟斤拷未锟斤拷锟斤拷
+	// PrefUtils.setBoolean(getApplicationContext(),
+	// GlobalContants.CONNECTSTATE, false);
+	// }
+	//
+	// }
+
+}

+ 36 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/ExitApplication.java

@@ -0,0 +1,36 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.app.Application;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class ExitApplication extends Application {
+	private List<Activity> activityList = new LinkedList();
+	private static ExitApplication instance;
+
+	private ExitApplication() {
+	}
+
+	public static ExitApplication getInstance() {
+		if (null == instance) {
+			instance = new ExitApplication();
+		}
+		return instance;
+	}
+
+	public void addActivity(Activity activity) {
+		activityList.add(activity);
+	}
+//	public void remveActivity(Activity activity) {
+//		activityList.remove(activity);
+//	}
+
+	public void exit() {
+		for (Activity activity : activityList) {
+			activity.finish();
+		}
+		System.exit(0);
+	}
+}

+ 174 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/IpEditActivity.java

@@ -0,0 +1,174 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.demo.global.GlobalContants;
+
+public class IpEditActivity extends Activity {
+	// private MyDialog dialog;
+	private LinearLayout layout;
+	private int[] mIDs = { R.id.ip_edit_1, R.id.ip_edit_2, R.id.ip_edit_3, R.id.ip_edit_4 };
+	private EditText ipEdit1, ipEdit2, ipEdit3, ipEdit4;
+	private TextView tv_wifi_name;
+	private EditText[] ipEdits = { ipEdit1, ipEdit2, ipEdit3, ipEdit4 };
+	private String wifiName = null;
+	private static String ipAddress = "192.168.0.100";
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_ip_edit);
+		IntentFilter filter = new IntentFilter();
+		filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+		registerReceiver(mReceiver, filter);
+
+		MyTextWatcher[] mTextWatcher = new MyTextWatcher[4];
+		for (int i = 0; i < 4; i++) {
+			ipEdits[i] = (EditText) findViewById(mIDs[i]);
+			mTextWatcher[i] = new MyTextWatcher(ipEdits[i]);
+			ipEdits[i].addTextChangedListener(mTextWatcher[i]);
+		}
+
+		String[] split = ipAddress.split("\\.");
+
+		Log.i("ip", "split:" + split.length);
+		for (int i = 0; i < split.length; i++) {
+			ipEdits[i].setText(split[i]);
+		}
+		// dialog=new MyDialog(this);
+		layout = (LinearLayout) findViewById(R.id.exit_layout);
+		tv_wifi_name = (TextView) findViewById(R.id.tv_wifi_name);
+		// 得到上个activity传回的当前所处wifi的名称
+		Intent intent = getIntent();
+		wifiName = "current wifi:" + intent.getStringExtra(GlobalContants.WIFINAME);
+		tv_wifi_name.setText(wifiName);
+		ipEdits[3].requestFocus();
+
+	}
+
+	class MyTextWatcher implements TextWatcher {
+		public EditText mEditText;
+
+		public MyTextWatcher(EditText mEditText) {
+			super();
+			this.mEditText = mEditText;
+		}
+
+		@Override
+		public void afterTextChanged(Editable s) {
+			// TODO Auto-generated method stub
+			if (s.length() == 3) {
+				if (Integer.parseInt(mEditText.getEditableText().toString()) > 255) {
+					mEditText.setText("255");
+				}
+				if (this.mEditText == ipEdits[0]) {
+					ipEdits[1].requestFocus();
+
+				} else if (this.mEditText == ipEdits[1]) {
+					ipEdits[2].requestFocus();
+
+				} else if (this.mEditText == ipEdits[2]) {
+					ipEdits[3].requestFocus();
+				}
+				if (this.mEditText == ipEdits[3]) {
+					ipEdits[3].setSelection(3);
+				}
+
+			}
+			// else if (s.length() == 0) {
+			// if (this.mEditText == ipEdits[3]) {
+			// ipEdits[2].requestFocus();
+			// ipEdits[2].setSelection(ipEdits[2].length());
+			// } else if (this.mEditText == ipEdits[2]) {
+			// ipEdits[1].requestFocus();
+			// ipEdits[1].setSelection(ipEdits[1].length());
+			// } else if (this.mEditText == ipEdits[1]) {
+			// ipEdits[0].requestFocus();
+			// ipEdits[0].setSelection(ipEdits[0].length());
+			// }
+			// }
+		}
+
+		@Override
+		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+		}
+
+		@Override
+		public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+		}
+
+	}
+
+	// 确认wifi热点和打印机IP正确后去连接打印机
+	public void connect(View v) {
+		StringBuffer sb = new StringBuffer();
+		for (int i = 0; i < 4; i++) {
+			sb.append(ipEdits[i].getEditableText());
+			if (i != 3) {
+				sb.append(".");
+			}
+		}
+		Toast.makeText(this, sb.toString(), Toast.LENGTH_SHORT).show();
+
+		Intent intent = new Intent();
+		intent.putExtra("ip_address", sb.toString());
+		ipAddress = sb.toString();
+		Log.i("ip", "ip:" + ipAddress);
+		// Set result and finish this Activity
+		setResult(Activity.RESULT_OK, intent);
+		this.finish();
+	}
+
+	// 切换wifi热点
+	public void switchWiFi(View v) {
+		startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
+	}
+
+	private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+
+		@Override
+		public void onReceive(Context context, Intent intent) {
+
+			if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {// wifi连接上与否
+				Log.i("yxz", "网络状态改变");
+				NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
+				if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
+					Log.i("yxz", "wifi网络连接断开");
+				} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
+
+					WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+					WifiInfo wifiInfo = wifiManager.getConnectionInfo();
+					// 获取当前wifi名称
+					System.out.println("连接到网络 " + wifiInfo.getSSID());
+					wifiName = "current wifi:" + wifiInfo.getSSID();
+					tv_wifi_name.setText(wifiName);
+
+				}
+
+			}
+
+		}
+	};
+
+	protected void onDestroy() {
+		super.onDestroy();
+		unregisterReceiver(mReceiver);
+	};
+}

+ 124 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/ItemPdfPdfactivity.java

@@ -0,0 +1,124 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ItemPdfPdfactivity extends Activity implements OnItemClickListener {
+	private ListView listView;
+	private String TAG = "com.print.demo";
+	private Context mContext;
+	private ArrayAdapter<String> fileAdapter;
+	ArrayList<String> list = null;
+	private List<File> fileList = new ArrayList<File>();
+	String pdf_text = null;
+	String str = null;
+	private ProgressDialog daDialog;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		// TODO Auto-generated method stub
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_itempdf);
+		mContext = this;
+		init();
+		daDialog = ProgressDialog.show(ItemPdfPdfactivity.this, "Handing the PDF file....", "Please Wait", true, false,
+				null);
+		// new Thread(){
+		// public void run(){
+		Log.i("pdfActivity", "zl at onclick-------->begain");
+		fileAdapter = new ArrayAdapter<String>(ItemPdfPdfactivity.this, R.layout.device_item);
+		Log.i("pdfActivity", "zl at onclick-------->fileAdapter");
+		// onSearch();
+		Log.i("pdfActivity", "zl at onclick-------->onsearch");
+		// 设置listview中的内容
+		listView.setAdapter(fileAdapter);
+		Log.i("pdfActivity", "zl at onclick-------->listView.setAdapter");
+		// }
+		// }.start();
+		listView.setOnItemClickListener(this);
+		new Thread() {
+			public void run() {
+				onSearch();
+			};
+		}.start();
+
+	}
+
+	// new Thread(){
+	// public void run(){
+	//
+	// }
+	// }.start();
+	public void onSearch() {
+
+		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+			final File sdFile = Environment.getExternalStorageDirectory();
+			getAllFiles(sdFile);
+			daDialog.dismiss();
+			Log.i("mainactivity", "zl --onSearch()----list.size:" + list.size());
+		} else {
+			Toast.makeText(ItemPdfPdfactivity.this, "SD卡不存在", 0).show();
+		}
+	}
+
+	/* 遍历接收一个文件路径,然后把文件子目录中的所有文件遍历并输出来 */
+	private void getAllFiles(final File root) {
+		// new Thread() {
+		// public void run() {
+		File files[] = root.listFiles();
+		list = new ArrayList<String>();
+		if (files != null) {
+			for (final File f : files) {
+				if (f.isDirectory()) {
+					getAllFiles(f);
+				} else {
+					if (f.getAbsolutePath().endsWith(".pdf")) {
+						runOnUiThread(new Runnable() {
+							@Override
+							public void run() {
+								fileList.add(f);
+								fileAdapter.add(f.getName());
+								Log.i("mainactivity", "zl --getAllFiles()----fileAdapter.add(f.getAbsolutePath()):"
+										+ f.getAbsolutePath());
+							}
+						});
+
+					}
+				}
+			}
+		}
+		// }
+		// }.run();
+	}
+
+	private void init() {
+		listView = (ListView) super.findViewById(R.id.listView);
+		listView.setOnItemClickListener(this);
+	}
+
+	@Override
+	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+		pdf_text = fileList.get(position).getAbsolutePath();
+		Intent intent_item_pdfActivity = new Intent();
+		intent_item_pdfActivity.putExtra("data_return", pdf_text);
+		setResult(RESULT_OK, intent_item_pdfActivity);
+
+		finish();
+	}
+
+}

+ 736 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/LablePrintActivity.java

@@ -0,0 +1,736 @@
+package com.printer.demo;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.RadioGroup.OnCheckedChangeListener;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.demo.utils.PrintLabel100;
+import com.printer.demo.utils.PrintLabel58;
+import com.printer.demo.utils.PrintLabel80;
+import com.printer.demo.utils.PrintLabelDrink;
+import com.printer.demo.utils.PrintLabelExpress;
+import com.printer.demo.utils.PrintLabelFruit;
+import com.printer.demo.utils.PrintLabelMaterial;
+import com.printer.demo.utils.PrintLabelStorage;
+import com.printer.demo.utils.PrintLablel;
+import com.printer.sdk.PrinterConstants.CommandTSPL;
+import com.printer.sdk.PrinterConstants.Connect;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+import com.printer.sdk.utils.XLog;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+public class LablePrintActivity extends BaseActivity
+        implements OnClickListener, OnItemSelectedListener, OnCheckedChangeListener {
+    private String TAG = "LablePrintActivity";
+    private Button btnPrintLable100mm;
+    private Button btnPrintLable80mm;
+    private Button btnPrintLable50mm;
+    private Button btnPrintLable;
+    private LinearLayout header;
+    public static final int PRINT_START = 0x1557; // 15:57
+    public static final int PRINT_DONE = 0x1558;
+    protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);
+
+    protected Handler printerHandler = new Handler(new Handler.Callback() {
+        @Override
+        public boolean handleMessage(android.os.Message msg) {
+            return false;
+        }
+    });
+
+    PrinterInstance mPritner;
+    public static PrinterInstance myPrinter;
+    private boolean isConnected = false;
+    private int interfaceType = 0;
+    // 与TSPL指令有关的控件
+    private Button btnFruitLabel;
+    private Button btnDrinkLabel;
+    private Button btnMaterialLabel;
+    private Button btnExpressLabel;
+    private Button btnStorageLabel;
+
+    private Context mContext;
+    /**
+     * 与TSPL指令相关的控件
+     */
+    private RadioGroup rgOrderSet;
+    private RadioButton rb_order_cpcl;
+    private RadioButton rb_order_tspl;
+    private LinearLayout llTSPL;
+    /**
+     * 与TSPL指令相关的控件
+     */
+
+    // TODO 因为暂时不能自定义标签的宽高,所以暂时不设置这俩个属性
+    // private EditText etLabelWidth;
+    // private EditText etLabelHeight;
+    private EditText etGapWidth;
+    private EditText etGapOffset;
+    private EditText etPrintSpeed;
+    private EditText etPrintLevel;
+    private EditText etLabelOffset;
+    private EditText etPrintNumbers;
+    private EditText etPrintLeftMargin;
+    private EditText etPrintTopMargin;
+    private Spinner spTear;
+    private Spinner spOpenCashBox;
+    private Spinner spIsBeep;
+    private ArrayAdapter<CharSequence> tearData_Adapter;
+    private ArrayAdapter<CharSequence> OpenCashBoxAdapter;
+    private ArrayAdapter<CharSequence> IsBeepAdapter;
+    private String tearSet = "撕纸";
+    private String OpenCashSet = "禁止开钱箱";
+    private String IsBeepSet = "禁止蜂鸣器";
+
+    /**
+     * @param mPrinter调用PrinterInstance中的方法设置TSPL相关参数
+     * @param mPrinter
+     * @return true:设置成功 false:设置失败
+     * @describe 判断设置TSPL指令是否成功
+     */
+    private boolean setPrinterTSPL(PrinterInstance mPrinter) {
+        boolean isSettingSuccess = false;
+        String gapWidth = etGapWidth.getText().toString();
+        String gapOffset = etGapOffset.getText().toString();
+        String printSpeed = etPrintSpeed.getText().toString();
+        String printLevel = etPrintLevel.getText().toString();
+        String printLabelOffset = etLabelOffset.getText().toString();
+        String printNumbers = etPrintNumbers.getText().toString();
+        String printLeftMargin = etPrintLeftMargin.getText().toString();
+        String printTopMargin = etPrintTopMargin.getText().toString();
+        for (int i = 0; i < 1; i++) {
+            try {
+                // 处于TSPL指令模式下
+                if (llTSPL.getVisibility() == View.VISIBLE) {
+                    // 设置标签间的缝隙大小
+                    if (gapWidth == null || gapWidth.equals("") || gapOffset == null || gapOffset.equals("")) {
+                        Toast.makeText(mContext, "间隙宽度和间隙偏移量不能为空", 0).show();
+                        break;
+                    } else {
+                        int gapWidthTSPL = Integer.parseInt(gapWidth);
+                        int gapOffsetTSPL = Integer.parseInt(gapOffset);
+                        mPrinter.setGAPTSPL(gapWidthTSPL, gapOffsetTSPL);
+                        PrefUtils.setInt(mContext, "gapwidthtspl", gapWidthTSPL);
+                        PrefUtils.setInt(mContext, "gapoffsettspl", gapOffsetTSPL);
+                    }
+                    // 设置打印机打印速度
+                    if (printSpeed == null || printSpeed.equals("")) {
+                        Toast.makeText(mContext, "打印机打印速度不能设置为空", 0).show();
+                        break;
+                    } else {
+                        int printSpeedTSPL = Integer.parseInt(printSpeed);
+                        mPrinter.setPrinterTSPL(CommandTSPL.SPEED, printSpeedTSPL);
+                        PrefUtils.setInt(mContext, "printspeed", printSpeedTSPL);
+                    }
+                    // 设置打印机打印浓度
+                    if (printLevel == null || printLevel.equals("")) {
+                        Toast.makeText(mContext, "打印机打印浓度不能设置为空", 0).show();
+                        break;
+                    } else {
+                        int printLevelSpeedTSPL = Integer.parseInt(printLevel);
+                        mPrinter.setPrinterTSPL(CommandTSPL.DENSITY, printLevelSpeedTSPL);
+                        PrefUtils.setInt(mContext, "printlevel", printLevelSpeedTSPL);
+                    }
+                    // 设置标签偏移量
+                    if (printLabelOffset == null || printLabelOffset.equals("")) {
+                        Toast.makeText(mContext, "标签偏移量不能设置为空", 0).show();
+                        break;
+                    } else {
+                        // 标签偏移量(点数)
+                        int labelOffsetTSPL = Integer.parseInt(printLabelOffset) * 8;
+                        mPrinter.setPrinterTSPL(CommandTSPL.SHIFT, labelOffsetTSPL);
+                        PrefUtils.setInt(mContext, "labeloffsettspl", labelOffsetTSPL / 8);
+
+                    }
+                    // 设置打印机打印份数
+                    if (printNumbers == null || printNumbers.equals("")) {
+                        Toast.makeText(mContext, "打印机打印数量不能设置为空或者为负数", 0).show();
+                        break;
+                    } else {
+                        int printNumbersTSPL = Integer.parseInt(printNumbers);
+                        PrefUtils.setInt(mContext, "printnumbers", printNumbersTSPL);
+                    }
+
+                    // 设置打印内容初始位置
+                    if (printLeftMargin == null || printLeftMargin.equals("") || printTopMargin == null
+                            || printLeftMargin.equals("")) {
+                        Toast.makeText(mContext, "标签偏移量不能为空或者为负数", 0).show();
+                        break;
+                    } else {
+                        int marginLeft = Integer.parseInt(printLeftMargin);
+                        PrefUtils.setInt(mContext, "leftmargin", marginLeft);
+                        int marginTop = Integer.parseInt(printTopMargin);
+                        PrefUtils.setInt(mContext, "topmargin", marginTop);
+
+                    }
+
+                    // // 撕纸设置
+                    // if (tearSet == null || tearSet.equals("")) {
+                    // break;
+                    // } else if (tearSet.equals("撕纸")) {
+                    // mPrinter.setPrinterTSPL(CommandTSPL.TEAR, 1);
+                    // mPrinter.setPrinterTSPL(CommandTSPL.PEEL, 0);
+                    // PrefUtils.setInt(mContext, "tearAndpeel", 0);
+                    // } else if (tearSet.equals("剥纸")) {
+                    // mPrinter.setPrinterTSPL(CommandTSPL.PEEL, 1);
+                    // PrefUtils.setInt(mContext, "tearAndpeel", 1);
+                    // } else if (tearSet.equals("关")) {
+                    // mPrinter.setPrinterTSPL(CommandTSPL.TEAR, 0);
+                    // mPrinter.setPrinterTSPL(CommandTSPL.PEEL, 0);
+                    // PrefUtils.setInt(mContext, "tearAndpeel", 2);
+                    //
+                    // }
+                    // 开关钱箱设置
+                    if (OpenCashSet == null || OpenCashSet.equals("")) {
+                        break;
+                    } else if (OpenCashSet.equals(R.string.String_judge1)) {
+                        PrefUtils.setInt(mContext, "isOpenCash", 0);
+                    } else if (OpenCashSet.equals(R.string.String_judge2)) {
+                        PrefUtils.setInt(mContext, "isOpenCash", 1);
+                    } else if (OpenCashSet.equals(R.string.String_judge3)) {
+                        PrefUtils.setInt(mContext, "isOpenCash", 2);
+                    }
+                    // 开关蜂鸣器设置
+                    if (IsBeepSet == null || IsBeepSet.equals("")) {
+                        break;
+                    } else if (IsBeepSet.equals(R.string.String_judge4)) {
+                        PrefUtils.setInt(mContext, "isBeep", 2);
+                    } else if (IsBeepSet.equals(R.string.String_judge5)) {
+                        PrefUtils.setInt(mContext, "isBeep", 1);
+                    } else if (IsBeepSet.equals(R.string.String_judge6)) {
+                        PrefUtils.setInt(mContext, "isBeep", 0);
+
+                    }
+
+                    isSettingSuccess = true;
+                }
+            } catch (NumberFormatException e) {
+                e.printStackTrace();
+            } catch (WriteException e) {
+                Toast.makeText(mContext, "向打印机写入数据异常", 0).show();
+                e.printStackTrace();
+            } catch (PrinterPortNullException e) {
+                Toast.makeText(mContext, "打印机为空异常", 0).show();
+                e.printStackTrace();
+            } catch (ParameterErrorException e) {
+                Toast.makeText(mContext, "传入参数异常", 0).show();
+                e.printStackTrace();
+            } catch (Exception e) {
+                Toast.makeText(mContext, "其他未知异常", 0).show();
+                e.printStackTrace();
+            }
+        }
+
+        return isSettingSuccess;
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_lable_print);
+        header = (LinearLayout) findViewById(R.id.ll_headerview_LablePrintactivity);
+        btnPrintLable100mm = (Button) findViewById(R.id.btn_100mm);
+        btnPrintLable80mm = (Button) findViewById(R.id.btn_80mm);
+        btnPrintLable50mm = (Button) findViewById(R.id.btn_58mm);
+        btnPrintLable = (Button) findViewById(R.id.btn_lable);
+        btnPrintLable100mm.setOnClickListener(this);
+        btnPrintLable80mm.setOnClickListener(this);
+        btnPrintLable50mm.setOnClickListener(this);
+        btnPrintLable.setOnClickListener(this);
+        // TSPL指令相关的控件初始化
+        btnFruitLabel = (Button) findViewById(R.id.btn_fruit_tspl);
+        btnDrinkLabel = (Button) findViewById(R.id.btn_drink_tspl);
+        btnMaterialLabel = (Button) findViewById(R.id.btn_material_tspl);
+        btnExpressLabel = (Button) findViewById(R.id.btn_express_tspl);
+        btnStorageLabel = (Button) findViewById(R.id.btn_storage_tspl);
+
+        btnFruitLabel.setOnClickListener(this);
+        btnDrinkLabel.setOnClickListener(this);
+        btnMaterialLabel.setOnClickListener(this);
+        btnExpressLabel.setOnClickListener(this);
+        btnStorageLabel.setOnClickListener(this);
+        mPritner = PrinterInstance.mPrinter;
+        init();
+        initHeader();
+        // 判断设置界面是不是选中TSPL指令集的选择框,从而选择界面上需要显示的标签
+        Log.i(TAG, "zl at LablePrintActivity.java  onCreate()----> before if ");
+        rb_order_cpcl.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Log.i(TAG, "zl at LablePrintActivity.java  onCreate()----> rb_order_tspl__cpcl"
+                        + rb_order_cpcl.isChecked());
+                btnPrintLable100mm.setVisibility(View.VISIBLE);
+                btnPrintLable80mm.setVisibility(View.VISIBLE);
+                btnPrintLable50mm.setVisibility(View.VISIBLE);
+                btnPrintLable.setVisibility(View.VISIBLE);
+
+                btnFruitLabel.setVisibility(View.GONE);
+                btnDrinkLabel.setVisibility(View.GONE);
+                btnMaterialLabel.setVisibility(View.GONE);
+                btnExpressLabel.setVisibility(View.GONE);
+                btnStorageLabel.setVisibility(View.GONE);
+            }
+        });
+        rb_order_tspl.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                btnPrintLable100mm.setVisibility(View.GONE);
+                btnPrintLable80mm.setVisibility(View.GONE);
+                btnPrintLable50mm.setVisibility(View.GONE);
+                btnPrintLable.setVisibility(View.GONE);
+
+                btnFruitLabel.setVisibility(View.VISIBLE);
+                btnDrinkLabel.setVisibility(View.VISIBLE);
+                btnMaterialLabel.setVisibility(View.VISIBLE);
+                btnExpressLabel.setVisibility(View.VISIBLE);
+                btnStorageLabel.setVisibility(View.VISIBLE);
+
+            }
+        });
+        // if (rb_order_tspl.isChecked()) {
+        // Log.i(TAG,
+        // "zl at LablePrintActivity.java onCreate()---->
+        // rb_order_tspl__1"+rb_order_tspl.isChecked());
+        // btnPrintLable100mm.setVisibility(View.GONE);
+        // btnPrintLable80mm.setVisibility(View.GONE);
+        // btnPrintLable50mm.setVisibility(View.GONE);
+        // btnPrintLable.setVisibility(View.GONE);
+        //
+        // btnFruitLabel.setVisibility(View.VISIBLE);
+        // btnDrinkLabel.setVisibility(View.VISIBLE);
+        // btnMaterialLabel.setVisibility(View.VISIBLE);
+        // btnExpressLabel.setVisibility(View.VISIBLE);
+        // btnStorageLabel.setVisibility(View.VISIBLE);
+        // }else if (rb_order_cpcl.isChecked()) {
+        // Log.i(TAG,
+        // "zl at LablePrintActivity.java onCreate()---->
+        // rb_order_tspl__cpcl"+rb_order_cpcl.isChecked());
+        // btnPrintLable100mm.setVisibility(View.VISIBLE);
+        // btnPrintLable80mm.setVisibility(View.VISIBLE);
+        // btnPrintLable50mm.setVisibility(View.VISIBLE);
+        // btnPrintLable.setVisibility(View.VISIBLE);
+        //
+        // btnFruitLabel.setVisibility(View.GONE);
+        // btnDrinkLabel.setVisibility(View.GONE);
+        // btnMaterialLabel.setVisibility(View.GONE);
+        // btnExpressLabel.setVisibility(View.GONE);
+        // btnStorageLabel.setVisibility(View.GONE);
+        // }
+        //
+
+    }
+
+    private void init() {
+        /**
+         * 与TSPL指令相关的设置
+         */
+        mContext = LablePrintActivity.this;
+        rgOrderSet = (RadioGroup) findViewById(R.id.rg_orderset);
+        rb_order_tspl = (RadioButton) findViewById(R.id.rb_order_tspl);
+        rb_order_cpcl = (RadioButton) findViewById(R.id.rb_order_cpcl);
+        llTSPL = (LinearLayout) findViewById(R.id.ll_tspls);
+        rgOrderSet.setOnCheckedChangeListener(this);
+        // TODO 暂时不设置标签的宽和高
+        // etLabelWidth = (EditText) findViewById(R.id.et_label_width);
+        // etLabelHeight = (EditText) findViewById(R.id.et_label_height);
+        etGapWidth = (EditText) findViewById(R.id.et_gap_width);
+        etGapOffset = (EditText) findViewById(R.id.et_gap_offset);
+        etPrintSpeed = (EditText) findViewById(R.id.et_print_speed);
+        etPrintLevel = (EditText) findViewById(R.id.et_print_level);
+        etLabelOffset = (EditText) findViewById(R.id.et_print_label_offset);
+        etPrintNumbers = (EditText) findViewById(R.id.et_print_numbers);
+        etPrintLeftMargin = (EditText) findViewById(R.id.et_left_margin);
+        etPrintTopMargin = (EditText) findViewById(R.id.et_top_margin);
+        spTear = (Spinner) findViewById(R.id.spinner_tear);
+        tearData_Adapter = ArrayAdapter.createFromResource(LablePrintActivity.this, R.array.tear_data,
+                android.R.layout.simple_spinner_item);
+        tearData_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        spTear.setAdapter(tearData_Adapter);
+        spTear.setOnItemSelectedListener(this);
+        spOpenCashBox = (Spinner) findViewById(R.id.spinner_cash);
+        OpenCashBoxAdapter = ArrayAdapter.createFromResource(LablePrintActivity.this, R.array.cash_data,
+                android.R.layout.simple_spinner_item);
+        OpenCashBoxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
+        spOpenCashBox.setAdapter(OpenCashBoxAdapter);
+        spOpenCashBox.setOnItemSelectedListener(this);
+        spIsBeep = (Spinner) findViewById(R.id.spinner_beep);
+        IsBeepAdapter = ArrayAdapter.createFromResource(LablePrintActivity.this, R.array.beep_data,
+                android.R.layout.simple_spinner_item);
+        IsBeepAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
+        spIsBeep.setAdapter(IsBeepAdapter);
+        spIsBeep.setOnItemSelectedListener(this);
+        // 根据是不是选中了TSPL指令来选择是不是显示TSPL指令标签
+        if (DemoApplication.isSettingTSPL) {
+            rgOrderSet.check(R.id.rb_order_tspl);
+            btnPrintLable100mm.setVisibility(View.GONE);
+            btnPrintLable80mm.setVisibility(View.GONE);
+            btnPrintLable50mm.setVisibility(View.GONE);
+            btnPrintLable.setVisibility(View.GONE);
+
+            btnFruitLabel.setVisibility(View.VISIBLE);
+            btnDrinkLabel.setVisibility(View.VISIBLE);
+            btnMaterialLabel.setVisibility(View.VISIBLE);
+            btnExpressLabel.setVisibility(View.VISIBLE);
+            btnStorageLabel.setVisibility(View.VISIBLE);
+        } else {
+            rgOrderSet.check(R.id.rb_order_cpcl);
+            btnPrintLable100mm.setVisibility(View.VISIBLE);
+            btnPrintLable80mm.setVisibility(View.VISIBLE);
+            btnPrintLable50mm.setVisibility(View.VISIBLE);
+            btnPrintLable.setVisibility(View.VISIBLE);
+
+            btnFruitLabel.setVisibility(View.GONE);
+            btnDrinkLabel.setVisibility(View.GONE);
+            btnMaterialLabel.setVisibility(View.GONE);
+            btnExpressLabel.setVisibility(View.GONE);
+            btnStorageLabel.setVisibility(View.GONE);
+        }
+        interfaceType = PrefUtils.getInt(mContext, GlobalContants.INTERFACETYPE, 0);
+        // 初始化TSPL设置界面
+        getSavedTSPL();
+
+    }
+
+    // 用于接受连接状态消息的 Handler
+    private Handler mHandler = new Handler() {
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case Connect.SUCCESS:
+                    isConnected = true;
+
+                    // TOTO 暂时将TSPL指令设置参数的设置放在这
+                    if (setPrinterTSPL(myPrinter)) {
+                        if (interfaceType == 0) {
+                            Toast.makeText(mContext, R.string.settingactivitty_toast_bluetooth_set_tspl_successful, 0)
+                                    .show();
+                        } else if (interfaceType == 1) {
+                            Toast.makeText(mContext, R.string.settingactivity_toast_usb_set_tspl_succefful, 0).show();
+                        }
+                    }
+                    break;
+            }
+        }
+    };
+
+    /**
+     * 获取TSPL指令下各个指令的内容
+     */
+    private void getSavedTSPL() {
+        XLog.i(TAG, "ZL at LablePrintActivity.java getSavedTSPL()------>begain");
+        etPrintNumbers.setText(PrefUtils.getInt(mContext, "printnumbers", 1) + "");
+        etPrintLeftMargin.setText(PrefUtils.getInt(mContext, "leftmargin", 0) + "");
+        etPrintTopMargin.setText(PrefUtils.getInt(mContext, "topmargin", 0) + "");
+        etPrintLevel.setText(PrefUtils.getInt(mContext, "printlevel", 7) + "");
+        etPrintSpeed.setText(PrefUtils.getInt(mContext, "printspeed", 12) + "");
+        etGapWidth.setText(PrefUtils.getInt(mContext, "gapwidthtspl", 0) + "");
+        etGapOffset.setText(PrefUtils.getInt(mContext, "gapoffsettspl", 0) + "");
+        etLabelOffset.setText(PrefUtils.getInt(mContext, "labeloffsettspl", 0) + "");
+        spTear.setSelection(PrefUtils.getInt(mContext, "tearAndpeel", 0), true);
+        spIsBeep.setSelection(PrefUtils.getInt(mContext, "isBeep", 0), true);
+        spOpenCashBox.setSelection(PrefUtils.getInt(mContext, "isOpenCash", 0), true);
+        XLog.i(TAG, "ZL at LablePrintActivity.java getSavedTSPL()------>end");
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        // if (GlobalContants.ISCONNECTED) {
+        // if ("".equals(GlobalContants.DEVICENAME)
+        // || GlobalContants.DEVICENAME == null) {
+        // headerConnecedState.setText(R.string.unknown_device);
+        //
+        // } else {
+        //
+        // headerConnecedState.setText(GlobalContants.DEVICENAME);
+        // }
+        //
+        // }
+
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader() {
+        setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+
+            }
+        });
+        setHeaderLeftImage(header, new OnClickListener() {// 初始化了
+            // headerConnecedState
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        headerConnecedState.setText(getTitleState());
+        setHeaderCenterText(header, getString(R.string.headview_LablePrint));
+    }
+
+    @Override
+    public void onClick(View v) {
+        if (mPritner == null && !SettingActivity.isConnected) {
+            Toast.makeText(LablePrintActivity.this, getString(R.string.no_connected), 0).show();
+            return;
+        }
+        switch (v.getId()) {
+            case R.id.btn_100mm:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        new PrintLabel100().doPrint(mPritner);
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_80mm:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        new PrintLabel80().doPrint(mPritner);
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_58mm:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        new PrintLabel58().doPrint(mPritner, getResources());
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_lable:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        new PrintLablel().doPrint(mPritner);
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_fruit_tspl:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        // TODO 开发蔬菜水果标签打印模版
+                        new PrintLabelFruit().doPrintTSPL(mPritner, getApplicationContext());
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_drink_tspl:
+                new Thread(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        // TODO 开发奶茶标签打印模版
+                        new PrintLabelDrink().doPrintTSPL(mPritner, getApplicationContext());
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_material_tspl:
+                new Thread(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        new PrintLabelMaterial().doPrintTSPL(mPritner, getApplicationContext());
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_express_tspl:
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        new PrintLabelExpress().doPrintTSPL(mPritner, getApplicationContext());
+                    }
+                }).start();
+
+                break;
+            case R.id.btn_storage_tspl:
+                new Thread(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        new PrintLabelStorage().doPrintTSPL(mPritner, getApplicationContext());
+                    }
+                }).start();
+
+                break;
+        }
+
+    }
+
+    private String getFilePath() {
+
+        String PATH_LOGCAT = null;
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// 优先保存到SD卡中
+            PATH_LOGCAT = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "MyPicture";
+            XLog.i(TAG, "ZL at LablePrintActivity.java getFilePath() sdka ");
+        } else {// 如果SD卡不存在,就保存到本应用的目录下
+            PATH_LOGCAT = this.getFilesDir().getAbsolutePath() + File.separator + "MyPicture";
+            XLog.i(TAG, "ZL at LablePrintActivity.java getFilePath() neicun ");
+        }
+        File dir = new File(PATH_LOGCAT);
+        if (!dir.exists()) {
+            dir.mkdir(); // 创建文件夹
+        }
+        String remp_dir = PATH_LOGCAT + File.separator + "tmpPhoto.jpg";
+        XLog.i(TAG, "ZL at LablePrintActivity.java getFilePath() remp_dir: " + remp_dir);
+        return remp_dir;
+    }
+
+    private void print() {
+        if (PrinterInstance.mPrinter == null) {
+            Toast.makeText(LablePrintActivity.this, "请连接打印机", Toast.LENGTH_SHORT).show();
+        } else {
+            new PrintThread().start();
+        }
+    }
+
+    private class PrintThread extends Thread {
+        String codeStr, destinationStr, countStr, weightStr, volumeStr, dispatchModeStr, businessModeStr, packModeStr,
+                receiverAddress;
+
+        public PrintThread() {
+            codeStr = "DF1234567890";
+            destinationStr = "西安长线";
+            countStr = "1";
+            weightStr = "2";
+            volumeStr = "1";
+            dispatchModeStr = "派送";
+            businessModeStr = "定时达";
+            packModeStr = "袋装";
+            receiverAddress = "陕西省西安市临潼区秦始皇陵兵马俑一号坑五排三列俑";
+        }
+
+        @Override
+        public void run() {
+            Looper.prepare();
+            try {
+                printerHandler.obtainMessage(PRINT_START).sendToTarget();
+                printing(codeStr, destinationStr, countStr, weightStr, volumeStr, dispatchModeStr, businessModeStr,
+                        packModeStr, receiverAddress);
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                printerHandler.obtainMessage(PRINT_DONE).sendToTarget();
+            }
+            Looper.loop();
+        }
+    }
+
+    public void printing(String codeStr, String destinationStr, String countStr, String weightStr, String volumeStr,
+                         String dispatchModeStr, String businessModeStr, String packModeStr, String receiverAddress)
+            throws Exception {
+        String centerName = "西安分拔中心"; // 目的地分拨
+        String centerCode = "0292001"; // 目的地分拨编号
+
+        String userSite = "测试二级网点" + "(" + dateFormat.format(new Date()) + ")"; // 出发网点
+
+        int count = Integer.parseInt(countStr);
+        for (int c = 1; c <= count; c++) {
+            // 子单号
+            String serialNum = String.format("%03d", c);
+            String subCodeStr = codeStr + serialNum + centerCode;
+            String serialStr = "第" + c + "件";
+            //
+            // LablePrintUtils.doPrint(this, mPritner, codeStr,
+            // businessModeStr, centerName, destinationStr, userSite,
+            // receiverAddress, countStr, serialStr, dispatchModeStr,
+            // packModeStr, subCodeStr);
+        }
+
+        // onPrintSucceed();
+    }
+
+    /**
+     * @describe 判断点击的是TSPL按钮还是cpcl按钮
+     */
+    @Override
+    public void onCheckedChanged(RadioGroup group, int checkedId) {
+        // TODO Auto-generated method stub
+        if (group == rgOrderSet) {
+            if (checkedId == R.id.rb_order_cpcl) {
+                llTSPL.setVisibility(View.GONE);
+                DemoApplication.isSettingTSPL = false;
+            } else if (checkedId == R.id.rb_order_tspl) {
+                llTSPL.setVisibility(View.VISIBLE);
+                DemoApplication.isSettingTSPL = true;
+            }
+        }
+
+    }
+
+    @Override
+    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+
+        // if (parent == spinner_printer_type) {
+        // PrefUtils.setInt(mContext, GlobalContants.PRINTERID, position);
+        // String printerName = getResources().getStringArray(
+        // R.array.printertype)[position];
+        // if (printerName.contains("T10") || printerName.contains("POS58")
+        // || printerName.contains("T7")) {
+        // rg__select_paper_size.check(R.id.rb_58mm);
+        // } else if (printerName.contains("L31")
+        // || printerName.contains("T9")
+        // || printerName.contains("POS885")
+        // || printerName.contains("EU80")) {
+        // rg__select_paper_size.check(R.id.rb_80mm);
+        // } else if (printerName.contains("L51")) {
+        // rg__select_paper_size.check(R.id.rb_100mm);
+        // }
+        // } else if (parent == spinner_interface_type) {
+        // }
+
+        if (parent == spTear) {
+            tearSet = spTear.getSelectedItem().toString();
+        }
+        if (parent == spOpenCashBox) {
+            OpenCashSet = spOpenCashBox.getSelectedItem().toString();
+        }
+        if (parent == spIsBeep) {
+            IsBeepSet = spIsBeep.getSelectedItem().toString();
+        }
+
+    }
+
+    @Override
+    public void onNothingSelected(AdapterView<?> parent) {
+        // TODO Auto-generated method stub
+
+    }
+}

+ 401 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/MainActivity.java

@@ -0,0 +1,401 @@
+package com.printer.demo;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.hardware.usb.UsbManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
+
+import com.allenliu.versionchecklib.v2.AllenVersionChecker;
+import com.allenliu.versionchecklib.v2.builder.UIData;
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.UpdateUtils;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.utils.XLog;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class MainActivity extends BaseActivity implements View.OnClickListener {
+    private static final String TAG = "MainActivity";
+    // 设置打印机的LinearLayout
+    private LinearLayout llSetPrinter;
+    // 打印标签的LinearLayout
+    private LinearLayout llLablePrint;
+    // 打印文本的LinearLayout
+    private LinearLayout llTextPrint;
+    // 打印PDF文件的LinearLayout
+    private LinearLayout llPDFPrint;
+    // 打印条码的LinearLayout
+    private LinearLayout llBarcodePrint;
+    // 打印图片的LinearLayout
+    private LinearLayout llImagePrint;
+    //采集打印的LinearLayout
+    private LinearLayout llCollectPrint;
+    //在线升级的LinearLayout
+    private LinearLayout llUpdate;
+    private ImageView imgRedpoint;
+    private LinearLayout header;
+    private static Context mContext;
+    private View v1;
+    private ProgressDialog dialog;
+    private UpdateHandler updateHandler = new UpdateHandler();
+    private static String[] PERMISSIONS_STORAGE = {
+            Manifest.permission.READ_EXTERNAL_STORAGE,
+            Manifest.permission.WRITE_EXTERNAL_STORAGE,
+            Manifest.permission.BLUETOOTH,
+            Manifest.permission.BLUETOOTH_ADMIN,
+            Manifest.permission.INTERNET,
+            Manifest.permission.ACCESS_WIFI_STATE,
+            Manifest.permission.ACCESS_NETWORK_STATE,
+            Manifest.permission.CHANGE_WIFI_STATE,
+            Manifest.permission.ACCESS_COARSE_LOCATION,
+            Manifest.permission.CAMERA
+    };
+    private final static int REQUEST_PERMISSION_CODE = 200;
+
+    @SuppressLint("InlinedApi")
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        v1 = getLayoutInflater().inflate(R.layout.activity_main, null);
+        setContentView(v1);
+        init();
+        //判断是否有相应权限
+        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
+            if (!checkPermissionAllGranted(PERMISSIONS_STORAGE)) {
+                ActivityCompat.requestPermissions(
+                        this,
+                        PERMISSIONS_STORAGE,
+                        REQUEST_PERMISSION_CODE
+                );
+            }
+        }
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        mContext.registerReceiver(mUsbAttachReceiver, filter);
+
+        dialog = new ProgressDialog(this);
+        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+        dialog.setCancelable(false);
+        if (!UpdateUtils.hasNet(mContext)) {
+            Message message = new Message();
+            message.what = GlobalContants.NETWORK_ERROR;
+            updateHandler.sendMessage(message);
+            return;
+        }
+        checkUpdate();
+
+    }
+
+    private boolean checkPermissionAllGranted(String[] perssions) {
+        for (String perssion : perssions) {
+            if (ActivityCompat.checkSelfPermission(this, perssion) != PackageManager.PERMISSION_GRANTED) {
+                XLog.d("yxz", "yxz at MainActivity.java checkPermissionAllGranted() perssion:" + "没有权限");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        if (requestCode == REQUEST_PERMISSION_CODE) {
+            boolean isAllGranted = true;
+            // 判断是否所有的权限都已经授予了
+            for (int i = 0; i < grantResults.length; i++) {
+                int grant = grantResults[i];
+                if (grant != PackageManager.PERMISSION_GRANTED) {
+                    XLog.d("yxz", "yxz at MainActivity.java checkPermissionAllGranted() permissions[" + i + "]:" + permissions[i] + "授权未成功");
+                    isAllGranted = false;
+                    break;
+                }
+            }
+            if (!isAllGranted) {
+                // 弹出对话框告诉用户需要权限的原因, 并引导用户去应用权限管理中手动打开权限按钮
+                Toast.makeText(mContext, "权限请求异常可能导致不封功能不可使用", Toast.LENGTH_SHORT).show();
+                return;
+            }
+            return;
+
+        }
+    }
+
+    // 初始化界面
+    private void init() {
+        mContext = getApplicationContext();
+        header = (LinearLayout) findViewById(R.id.ll_header_mainactivity);
+        llSetPrinter = (LinearLayout) findViewById(R.id.ll_setting);
+        llLablePrint = (LinearLayout) findViewById(R.id.ll_lable_print);
+        llTextPrint = (LinearLayout) findViewById(R.id.ll_text_print);
+        llPDFPrint = (LinearLayout) findViewById(R.id.ll_pdf_print);
+        llBarcodePrint = (LinearLayout) findViewById(R.id.ll_barcode_print);
+        llImagePrint = (LinearLayout) findViewById(R.id.ll_image_print);
+        llCollectPrint = (LinearLayout) findViewById(R.id.ll_collect_print);
+        llUpdate = (LinearLayout) findViewById(R.id.ll_update);
+        imgRedpoint = (ImageView) findViewById(R.id.img_redpoint);
+        // 设置点击监听事件
+        llSetPrinter.setOnClickListener(this);
+        llLablePrint.setOnClickListener(this);
+        llTextPrint.setOnClickListener(this);
+        llPDFPrint.setOnClickListener(this);
+        llBarcodePrint.setOnClickListener(this);
+        llImagePrint.setOnClickListener(this);
+        llCollectPrint.setOnClickListener(this);
+        llUpdate.setOnClickListener(this);
+        ChangeUpdateStatus(0);
+        initHeader();
+    }
+
+    /**
+     * 升级状态的显示
+     *
+     * @param flag 0表示没有新版本,1表示有新版本
+     */
+    private void ChangeUpdateStatus(int flag) {
+        if (flag == 1) {
+            imgRedpoint.setVisibility(View.VISIBLE);
+            return;
+        } else {
+            imgRedpoint.setVisibility(View.GONE);
+            return;
+        }
+    }
+
+    // 点击监听事件
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.ll_setting:
+                Intent intent = new Intent(MainActivity.this, SettingActivity.class);
+                // intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+                startActivity(intent);
+//                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+//                List<InputMethodInfo> mInputMethodProperties = imm.getInputMethodList();
+//                for (int i = 0; i < mInputMethodProperties.size(); i++) {
+//                   XLog.e("yxz",i + "、"
+//                            + mInputMethodProperties.get(i).getServiceName() + " , id:"
+//                            + mInputMethodProperties.get(i).getId());
+//                }
+
+//                PackageManager pckMan = mContext.getPackageManager();
+//                List<PackageInfo> packageInfo = pckMan.getInstalledPackages(0);
+//                for (PackageInfo pInfo : packageInfo) {
+//                    if("打印工具V1.07".equals(pInfo.applicationInfo.loadLabel(pckMan).toString())){
+//                        Log.e(TAG,"\n\nappName:"+pInfo.applicationInfo.loadLabel(pckMan).toString());
+//                        Log.e(TAG,"packageName:"+pInfo.packageName);
+//                        Log.e(TAG,"versionCode:"+pInfo.versionCode);
+//                        Log.e(TAG,"versionName:"+pInfo.versionName);
+//                    }
+//                }
+
+                break;
+            case R.id.ll_lable_print:
+                Intent intent_lable = new Intent(MainActivity.this, LablePrintActivity.class);
+                startActivity(intent_lable);
+                break;
+            case R.id.ll_text_print:
+                Intent intent_text = new Intent(MainActivity.this, TextPrintActivity.class);
+                startActivity(intent_text);
+                break;
+            case R.id.ll_pdf_print:
+                Intent intent2 = new Intent(MainActivity.this, PdfPrintActivity.class);
+                startActivity(intent2);
+                break;
+            case R.id.ll_barcode_print:
+                Intent intent_barcode = new Intent(MainActivity.this, BarcoePrintActivity.class);
+                startActivity(intent_barcode);
+                break;
+            case R.id.ll_image_print:
+                Intent intent_image = new Intent(MainActivity.this, PicturePrintActivity.class);
+                startActivity(intent_image);
+                break;
+            case R.id.ll_collect_print:
+                Intent intent_collect_print = new Intent(MainActivity.this, CollectPrintActivity.class);
+                startActivity(intent_collect_print);
+                break;
+            case R.id.ll_update:
+                //APP在线升级
+                if (GlobalContants.NEED_UPDATE == 1) {
+                    showUpdateDialog();
+                } else {
+                    Toast.makeText(mContext, getString(R.string.current_app_version) + UpdateUtils.getVersionName(mContext), Toast.LENGTH_SHORT).show();
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader() {
+        setHeaderLeftText(header, "", null);
+        headerConnecedState.setText(getTitleState());
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        initHeader();
+    }
+
+    private static BroadcastReceiver mUsbAttachReceiver = new BroadcastReceiver() {
+        @SuppressLint("NewApi")
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            Log.w("fdh", "receiver action: " + action);
+
+            if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
+                Toast.makeText(mContext, "USB设备已接入", Toast.LENGTH_LONG).show();
+            } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
+                Toast.makeText(mContext, "USB设备已拔出", Toast.LENGTH_LONG).show();
+                if (PrinterInstance.mPrinter != null && SettingActivity.isConnected) {
+                    PrinterInstance.mPrinter.closeConnection();
+                    PrinterInstance.mPrinter = null;
+                }
+            }
+        }
+    };
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        mContext.unregisterReceiver(mUsbAttachReceiver);
+    }
+
+    // @Override
+    // protected void onStart() {
+    // super.onStart();
+    // initHeader();
+    // }
+
+    /**
+     * 检查是否有新版本,如果有就升级
+     */
+    private void checkUpdate() {
+        new Thread() {
+            public void run() {
+                Message mes = Message.obtain();
+                try {
+                    URL url = new URL(getString(R.string.serverurl));
+                    // 联网
+                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+                    conn.setRequestMethod("GET");
+                    conn.setConnectTimeout(4000);
+                    int code = conn.getResponseCode();
+                    if (code == 200) {
+                        // 请求成功
+                        InputStream is = conn.getInputStream();
+                        // 把流转成String
+                        String result = UpdateUtils.readFromStream(is);
+                        XLog.d(TAG, "联网成功了" + result);
+                        // json解析
+                        JSONObject obj = new JSONObject(result);
+                        // 得到服务器的版本信息
+                        String version = (String) obj.get("version");
+                        if (UpdateUtils.isZh(mContext))
+                            GlobalContants.description = (String) obj.get("description");
+                        else
+                            GlobalContants.description = (String) obj.get("descriptionE");
+                        GlobalContants.apkurl = (String) obj.get("apkurl");
+                        XLog.d("yxz", "apkurl:" + GlobalContants.apkurl);
+                        // 校验是否有新版本
+                        if (UpdateUtils.getVersionName(mContext).equals(version)) {
+                            // 版本一致,没有新版本,设置 GlobalContants.NEED_UPDATE=0;
+                            mes.what = GlobalContants.NO_NEW_VERSION;
+                        } else {
+                            // 有新版本,设置 GlobalContants.NEED_UPDATE=1;
+                            mes.what = GlobalContants.HAS_NEW_VERSION;
+                        }
+                    }
+
+                } catch (MalformedURLException e) {
+                    // TODO Auto-generated catch block
+                    mes.what = GlobalContants.URL_ERROR;
+                    e.printStackTrace();
+                } catch (IOException e) {
+                    mes.what = GlobalContants.NETWORK_ERROR;
+                    e.printStackTrace();
+                } catch (JSONException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                    mes.what = GlobalContants.JSON_ERROR;
+                } finally {
+                    updateHandler.sendMessage(mes);
+                }
+            }
+        }.start();
+
+    }
+
+
+    private class UpdateHandler extends Handler {
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            switch (msg.what) {
+                case GlobalContants.HAS_NEW_VERSION:// 有新版本更新
+                    GlobalContants.NEED_UPDATE = 1;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_has_new_version, Toast.LENGTH_LONG).show();
+                    break;
+                case GlobalContants.NO_NEW_VERSION:// 无新版本更新
+                    GlobalContants.NEED_UPDATE = 0;
+                    break;
+                case GlobalContants.URL_ERROR:// URL错误
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_url_error, Toast.LENGTH_LONG).show();
+                    break;
+                case GlobalContants.NETWORK_ERROR:// 网络异常
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_net_error, Toast.LENGTH_LONG).show();
+                    break;
+
+                case GlobalContants.JSON_ERROR:// JSON解析出错
+                    GlobalContants.NEED_UPDATE = 0;
+                    Toast.makeText(getApplicationContext(), R.string.start_checkupdate_json_error, Toast.LENGTH_LONG).show();
+                    break;
+//                D:\webapps\sprtwork
+//                D:\qzfeng_20160325\apache-tomcat-6.0.37-windows-x86\apache-tomcat-6.0.37\bin
+            }
+            ChangeUpdateStatus(GlobalContants.NEED_UPDATE);
+        }
+    }
+
+    /**
+     * 弹出升级对话框
+     */
+    protected void showUpdateDialog() {
+        AllenVersionChecker
+                .getInstance()
+                .downloadOnly(
+                        UIData.create().setTitle(getString(R.string.current_app_version) + UpdateUtils.getVersionName(mContext)).setContent(GlobalContants.description).setDownloadUrl(GlobalContants.apkurl)
+                )
+                .excuteMission(mContext);
+    }
+}

+ 339 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/MaterialTransportActivity.java

@@ -0,0 +1,339 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.demo.utils.PrefUtils;
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+
+public class MaterialTransportActivity extends Activity implements
+        OnClickListener {
+
+	private static int MULTIPLE = 11;
+	private static final int line_width_border = 1;
+	private static final int page_width = 75 * MULTIPLE;
+	private static final int page_height = 80 * MULTIPLE;
+	private static final int margin_horizontal = (int) (1.5 * MULTIPLE);
+	private static final int top_left_x = margin_horizontal;
+	private static final int margin_vertical = 3 * MULTIPLE;
+	private static final int top_left_y = margin_vertical;// 32
+	private static final int border_width = page_width - 2 * margin_horizontal;
+	private static final int border_height = (int) (page_height - 8
+			* margin_vertical - 8);
+	private static final int top_right_x = top_left_x + border_width;
+	private static final int bottom_left_y = top_left_y + border_height;
+	private static final int bottom_right_y = bottom_left_y;
+	private static final int bottom_right_x = top_right_x;
+	private static final int row36_column1_width = 10 * MULTIPLE;
+	private static final int row37_column3_width = 20 * MULTIPLE;
+	private static final int row36_sep1_x = top_left_x + row36_column1_width;
+	private static final int row37_sep2_x = top_right_x - row37_column3_width;
+	private static final int[] row_height = { 6 * MULTIPLE, 6 * MULTIPLE,
+			6 * MULTIPLE, 6 * MULTIPLE, 6 * MULTIPLE, 6 * MULTIPLE,
+			6 * MULTIPLE, 6 * MULTIPLE };
+	private int startX;
+	private int startX1;
+
+	private EditText etType;
+	private EditText etFilaments;
+	private EditText etLotNo;
+	private EditText etCaseNo;
+	private EditText etDate;
+	private EditText etNetWt;
+	private EditText etLength;
+	private Button btnPrint;
+	private Button btnSave;
+	private TextView tvTitleCenter;
+	private TextView tvTitleRightTop;
+	private TextView tvTitleRightBottom;
+	private EditText etBarcode;
+	PrinterInstance mPritner;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_material_transport);
+		mPritner = PrinterInstance.mPrinter;
+		init();
+	}
+
+	private void init() {
+		etType = (EditText) findViewById(R.id.et_type);
+		etFilaments = (EditText) findViewById(R.id.et_filaments);
+		etLotNo = (EditText) findViewById(R.id.et_lot_no);
+		etCaseNo = (EditText) findViewById(R.id.et_case_no);
+		etDate = (EditText) findViewById(R.id.et_date);
+		etNetWt = (EditText) findViewById(R.id.et_wt);
+		etLength = (EditText) findViewById(R.id.et_length);
+		etBarcode = (EditText) findViewById(R.id.et_barcode);
+		btnPrint = (Button) findViewById(R.id.btn_print);
+		btnSave = (Button) findViewById(R.id.btn_save_data);
+		tvTitleCenter = (TextView) findViewById(R.id.tv_center_title);
+		tvTitleRightTop = (TextView) findViewById(R.id.tv_title_right_top);
+		tvTitleRightBottom = (TextView) findViewById(R.id.tv_title_right_bottom);
+		btnPrint.setOnClickListener(this);
+		btnSave.setOnClickListener(this);
+
+	}
+
+	@Override
+	public void onClick(View v) {
+		switch (v.getId()) {
+		case R.id.btn_print:
+			if (mPritner == null && !SettingActivity.isConnected) {
+				Toast.makeText(MaterialTransportActivity.this, "未连接打印机!", 0)
+						.show();
+				return;
+			}
+			doPrint(mPritner);
+			break;
+		case R.id.btn_save_data:
+
+			break;
+		}
+
+	}
+
+	@Override
+	protected void onStop() {
+		super.onStop();
+		PrefUtils.setString(getApplicationContext(), "type", etType.getText()
+				.toString());
+		PrefUtils.setString(getApplicationContext(), "filaments", etFilaments
+				.getText().toString());
+		PrefUtils.setString(getApplicationContext(), "lotno", etLotNo.getText()
+				.toString());
+		PrefUtils.setString(getApplicationContext(), "caseno", etCaseNo
+				.getText().toString());
+		PrefUtils.setString(getApplicationContext(), "date", etDate.getText()
+				.toString());
+//		PrefUtils.setString(getApplicationContext(), "netwt", etNetWt.getText()
+//				.toString());
+		PrefUtils.setString(getApplicationContext(), "length", etLength
+				.getText().toString());
+		PrefUtils.setString(getApplicationContext(), "barcode", etBarcode
+				.getText().toString());
+
+	}
+
+	@Override
+	protected void onStart() {
+		super.onStart();
+		etType.setText(PrefUtils.getString(getApplicationContext(), "type",
+				"T700XX"));
+		etFilaments.setText(PrefUtils.getString(getApplicationContext(),
+				"filaments", "12K——XXX"));
+		etLotNo.setText(PrefUtils.getString(getApplicationContext(), "lotno",
+				"XXXXXXXXX"));
+		etCaseNo.setText(PrefUtils.getString(getApplicationContext(), "caseno",
+				"XXXXXXXXX"));
+//		etDate.setText(PrefUtils.getString(getApplicationContext(), "date",
+//				PrefUtils.getSystemTime()));
+		etDate.setText(PrefUtils.getSystemTime());
+		etNetWt.setText(PrefUtils.getString(getApplicationContext(), "netwt",
+				"4.00kg"));
+		etLength.setText(PrefUtils.getString(getApplicationContext(), "length",
+				"5000m"));
+		etBarcode.setText(PrefUtils.getString(getApplicationContext(),
+				"barcode", ""));
+
+	}
+
+	public void doPrint(PrinterInstance iPrinter) {
+
+		iPrinter.pageSetup(LablePaperType.Size_58mm,page_width, page_height);
+		drawBigBox(iPrinter);
+		drawHorizontalSeparator(iPrinter);
+		drawVerticalSeparator(iPrinter);
+		drawRowContent(iPrinter);
+		iPrinter.print(PRotate.Rotate_0, 1);
+
+	}
+
+	private void drawBigBox(PrinterInstance iPrinter) {
+		int border_top_left_y = top_left_y;
+		// int border_top_left_y = top_left_y + row_height[0];
+		iPrinter.drawBorder(3, top_left_x, top_left_y, bottom_right_x,
+				bottom_right_y);
+
+	}
+
+	private void drawHorizontalSeparator(PrinterInstance iPrinter) {
+
+		int temp = top_left_y; //
+		// int temp = top_left_y+row_height[0]; //
+		for (int i = 0; i < row_height.length; i++) {
+			temp += row_height[i];
+			int start_x = top_left_x + 10;
+			int end_x = (int) (top_left_x + ((top_right_x - top_left_x) / 10) * 6.9);
+			Log.i("temp", "第" + (i + 1) + "次");
+			iPrinter.drawLine(line_width_border, start_x, temp, end_x, temp,
+					false);
+			/*
+			 * if(i!= 3){ iPrinter.drawLine(line_width_border, start_x, temp,
+			 * end_x, temp); }else{ iPrinter.drawLine(line_width_border,
+			 * row37_sep2_x, temp, end_x, temp); }
+			 */
+
+		}
+	}
+
+	private void drawVerticalSeparator(PrinterInstance iPrinter) {
+
+		startX = top_left_x + ((top_right_x - top_left_x) / 10) * 2;
+		startX1 = (int) (top_left_x + ((top_right_x - top_left_x) / 10) * 6.9);
+		int startY = top_left_y + row_height[0];
+		int endY = top_left_y + row_height[0] * 8;
+		iPrinter.drawLine(line_width_border, startX, startY, startX, endY,
+				false);
+		iPrinter.drawLine(line_width_border * 2, top_left_x + 10, startY,
+				top_left_x + 10, endY, false);
+		iPrinter.drawLine(line_width_border * 2, startX1, startY, startX1,
+				endY, false);
+
+		// iPrinter.drawLine(line_width_border, startX1, endY, startX1,
+		// bottom_right_y, false);
+
+	}
+
+	private void drawRowContent(PrinterInstance iPrinter) {
+
+		// 第一行内容
+		iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+				+ row_height[0], PAlign.CENTER, PAlign.END, tvTitleCenter
+				.getText().toString(), LableFontSize.Size_64, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+				+ row_height[0], PAlign.END, PAlign.CENTER, tvTitleRightTop
+				.getText().toString(), LableFontSize.Size_24, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+				+ row_height[0], PAlign.END, PAlign.END, tvTitleRightBottom
+				.getText().toString(), LableFontSize.Size_16, 0, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第二行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0], startX,
+				top_left_y + row_height[0] + row_height[0] / 2, PAlign.CENTER,
+				PAlign.END, "规格:", LableFontSize.Size_24, 0, 0, 0, 0,
+				PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0]
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 2, PAlign.CENTER, PAlign.START,
+				"TYPE:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+		// Log.i("sp", "startX:"+startX+"top_right_x:"+top_right_x);
+		// 第二行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0], bottom_right_x,
+				top_left_y + row_height[0] * 2, PAlign.CENTER, PAlign.CENTER,
+				etType.getText().toString(), LableFontSize.Size_32, 0, 0, 0, 0,
+				PRotate.Rotate_0);
+
+		// 第三行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 2, startX,
+				top_left_y + row_height[0] * 2 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "型号:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 2
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 3, PAlign.CENTER, PAlign.START,
+				"FILAMENTS:", LableFontSize.Size_24, 0, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第三行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 2, top_right_x,
+				top_left_y + row_height[0] * 3, PAlign.CENTER, PAlign.CENTER,
+				etFilaments.getText().toString(), LableFontSize.Size_32, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		// 第四行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 3, startX,
+				top_left_y + row_height[0] * 3 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "批次:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 3
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 4, PAlign.CENTER, PAlign.START,
+				"LOT NO.", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+		// 第四行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 3, top_right_x,
+				top_left_y + row_height[0] * 4, PAlign.CENTER, PAlign.CENTER,
+				etLotNo.getText().toString(), LableFontSize.Size_32, 0, 0, 0,
+				0, PRotate.Rotate_0);
+		// 第五行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 4, startX,
+				top_left_y + row_height[0] * 4 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "序列号:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 4
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 5, PAlign.CENTER, PAlign.START,
+				"CASE NO.", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+		// 第五行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 4, top_right_x,
+				top_left_y + row_height[0] * 5, PAlign.CENTER, PAlign.CENTER,
+				etCaseNo.getText().toString(), LableFontSize.Size_32, 0, 0, 0,
+				0, PRotate.Rotate_0);
+		// 第六行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 5, startX,
+				top_left_y + row_height[0] * 5 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "时间:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 5
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 6, PAlign.CENTER, PAlign.START,
+				"DATE:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+		// 第六行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 5, top_right_x,
+				top_left_y + row_height[0] * 6, PAlign.CENTER, PAlign.CENTER,
+				// TODO
+				PrefUtils.getSystemTime(), LableFontSize.Size_32, 0, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第七行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 6, startX,
+				top_left_y + row_height[0] * 6 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "重量:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 6
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 7, PAlign.CENTER, PAlign.START,
+				"NET wt:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+		// 第七行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 6, top_right_x,
+				top_left_y + row_height[0] * 7, PAlign.CENTER, PAlign.CENTER,
+				etNetWt.getText().toString(), LableFontSize.Size_32, 0, 0, 0,
+				0, PRotate.Rotate_0);
+		// 第八行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 7, startX,
+				top_left_y + row_height[0] * 7 + row_height[0] / 2,
+				PAlign.CENTER, PAlign.END, "长度:", LableFontSize.Size_24, 0, 0,
+				0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 7
+				+ row_height[0] / 2 + 4, startX,
+				top_left_y + row_height[0] * 8, PAlign.CENTER, PAlign.START,
+				"LENGTH:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+		// 第八行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y + row_height[0] * 7, top_right_x,
+				top_left_y + row_height[0] * 8, PAlign.CENTER, PAlign.CENTER,
+				etLength.getText().toString(), LableFontSize.Size_32, 0, 0, 0,
+				0, PRotate.Rotate_0);
+		// 打印第九行条码
+
+		iPrinter.drawBarCode(top_left_x, top_left_y + row_height[0] * 8,
+				bottom_right_x + 120, bottom_right_y, PAlign.CENTER,
+				PAlign.CENTER, 0, 0, etBarcode.getText().toString(),
+				PBarcodeType.CODE128, 1, 70, PRotate.Rotate_0);
+
+	}
+
+}

+ 328 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/MipcaActivityCapture.java

@@ -0,0 +1,328 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.res.AssetFileDescriptor;
+import android.graphics.Bitmap;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.media.MediaPlayer.OnCompletionListener;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Vibrator;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.Toast;
+
+
+import com.mining.app.zxing.camera.CameraManager;
+import com.mining.app.zxing.decoding.CaptureActivityHandler;
+import com.mining.app.zxing.decoding.InactivityTimer;
+import com.mining.app.zxing.view.ViewfinderView;
+import com.printer.sdk.zxing.BarcodeFormat;
+import com.printer.sdk.zxing.Result;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Initial the camera
+ * 
+ * @author Ryan.Tang
+ */
+public class MipcaActivityCapture extends Activity implements Callback {
+	private static final String codetype = "codetype";
+	private CaptureActivityHandler handler;
+	private ViewfinderView viewfinderView;
+	private boolean hasSurface;
+	private Vector<BarcodeFormat> decodeFormats;
+	private String characterSet;
+	private InactivityTimer inactivityTimer;
+	private MediaPlayer mediaPlayer;
+	private boolean playBeep;
+	private static final float BEEP_VOLUME = 0.10f;
+	private boolean vibrate;
+	private String TAG = "com.example.qr_codescan";
+
+	/** Called when the activity is first created. */
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		requestWindowFeature(Window.FEATURE_NO_TITLE);
+		setContentView(R.layout.activity_capture);
+		// ViewUtil.addTopView(getApplicationContext(), this,
+		// R.string.scan_card);
+		CameraManager.init(getApplication());
+		viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
+
+		Button mButtonBack = (Button) findViewById(R.id.button_back);
+		mButtonBack.setOnClickListener(new OnClickListener() {
+
+			@Override
+			public void onClick(View v) {
+				MipcaActivityCapture.this.finish();
+
+			}
+		});
+		hasSurface = false;
+		inactivityTimer = new InactivityTimer(this);
+	}
+
+	@Override
+	protected void onResume() {
+		super.onResume();
+		SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
+		SurfaceHolder surfaceHolder = surfaceView.getHolder();
+		if (hasSurface) {
+			initCamera(surfaceHolder);
+		} else {
+			surfaceHolder.addCallback(this);
+			surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+		}
+		decodeFormats = null;
+		characterSet = null;
+
+		playBeep = true;
+		AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
+		if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
+			playBeep = false;
+		}
+		initBeepSound();
+		vibrate = true;
+
+	}
+
+	@Override
+	protected void onPause() {
+		super.onPause();
+		if (handler != null) {
+			handler.quitSynchronously();
+			handler = null;
+		}
+		CameraManager.get().closeDriver();
+	}
+
+	@Override
+	protected void onDestroy() {
+		inactivityTimer.shutdown();
+		super.onDestroy();
+	}
+
+	/**
+	 * 处理扫描结果
+	 * 
+	 * @param result
+	 * @param barcode
+	 */
+	/**
+	 * 处理扫描结果
+	 * 
+	 * @param result
+	 * @param barcode
+	 */
+	public void handleDecode(Result result, Bitmap barcode) {
+		inactivityTimer.onActivity();
+		playBeepSoundAndVibrate();
+
+		String resultString = result.getText();
+		try {
+			resultString = new String(resultString.getBytes("gbk"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		if (resultString.equals("")) {
+			Toast.makeText(MipcaActivityCapture.this, "Scan failed!",
+					Toast.LENGTH_SHORT).show();
+		} else {
+			// 用默认浏览器打开扫描得到的地址
+			Log.i("yxz", "扫描得到的文本内容" + resultString);
+			int CODE_TYPE = -1; // 标示 (1一维码、 2、二维码 3、其他码)
+			final String QR_CODE = "QR_CODE"; // 二维码
+			final String DATA_MATRIX = "DATA_MATRIX"; // 其他码
+
+			// 扫描获取的 编码 不为空
+			if (!TextUtils.isEmpty(result.getBarcodeFormat().toString())) {
+
+				String mBarcodeFormat = result.getBarcodeFormat().toString(); // 拍码后返回的编码格式
+
+				if (mBarcodeFormat.equals(DATA_MATRIX)) {
+					CODE_TYPE = 3;
+				} else if (mBarcodeFormat.equals(QR_CODE)) {
+					CODE_TYPE = 2;
+				} else {
+					CODE_TYPE = 1;
+				}
+				Log.e("---> (1一维码、  2、二维码    3、其他码) ", "" + CODE_TYPE);
+
+				// Intent intent = new Intent();
+				// intent.setAction("android.intent.action.VIEW");
+				//
+				// if(isHomepage(result.getText())){
+				// Uri content_url = Uri.parse(result.getText());
+				// Log.i(TAG, "根据文本内容生成的url"+content_url);
+				// if(content_url!=null){
+				// intent.setData(content_url);
+				// startActivity(intent);
+				// }else{
+				// Toast.makeText(MipcaActivityCapture.this, "url为空",
+				// Toast.LENGTH_LONG).show();
+				//
+				// // Intent resultIntent = new Intent();
+				// // Bundle bundle = new Bundle();
+				// // bundle.putString("result", resultString);
+				// // bundle.putParcelable("bitmap", barcode);
+				// // resultIntent.putExtras(bundle);
+				// // this.setResult(RESULT_OK, resultIntent);
+				// }
+				//
+				// }else{
+				// // Intent intent1 = new
+				// Intent(MipcaActivityCapture.this,ShowResult.class);
+				// // intent1.putExtra("context", result.getText());
+				// // startActivity(intent1);
+				// }
+			}
+			Intent intent = new Intent();
+			intent.putExtra(BluetoothDeviceList.EXTRA_DEVICE_ADDRESS,
+					resultString);
+			intent.putExtra(codetype, CODE_TYPE);
+			setResult(Activity.RESULT_OK, intent);
+			MipcaActivityCapture.this.finish();
+		}
+	}
+
+	/**
+	 * @param 待验证的字符串
+	 * @return 如果是符合邮箱格式的字符串,返回<b>true</b>,否则为<b>false</b>
+	 */
+	public static boolean isEmail(String str) {
+		String regex = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
+		return match(regex, str);
+	}
+
+	/**
+	 * @param 待验证的字符串
+	 * @return 如果是符合网址格式的字符串,返回<b>true</b>,否则为<b>false</b>
+	 */
+	public static boolean isHomepage(String str) {
+		String regex = "http://(([a-zA-z0-9]|-){1,}\\.){1,}[a-zA-z0-9]{1,}-*";
+		return match(regex, str);
+	}
+
+	/**
+	 * @param regex
+	 *            正则表达式字符串
+	 * @param str
+	 *            要匹配的字符串
+	 * @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
+	 */
+	private static boolean match(String regex, String str) {
+		Pattern pattern = Pattern.compile(regex);
+		Matcher matcher = pattern.matcher(str);
+		return matcher.matches();
+	}
+
+	private void initCamera(SurfaceHolder surfaceHolder) {
+		try {
+			CameraManager.get().openDriver(surfaceHolder);
+		} catch (IOException ioe) {
+			return;
+		} catch (RuntimeException e) {
+			return;
+		}
+		if (handler == null) {
+			handler = new CaptureActivityHandler(this, decodeFormats,
+					characterSet);
+		}
+	}
+
+	@Override
+	public void surfaceChanged(SurfaceHolder holder, int format, int width,
+                               int height) {
+
+	}
+
+	@Override
+	public void surfaceCreated(SurfaceHolder holder) {
+		if (!hasSurface) {
+			hasSurface = true;
+			initCamera(holder);
+		}
+
+	}
+
+	@Override
+	public void surfaceDestroyed(SurfaceHolder holder) {
+		hasSurface = false;
+
+	}
+
+	public ViewfinderView getViewfinderView() {
+		return viewfinderView;
+	}
+
+	public Handler getHandler() {
+		return handler;
+	}
+
+	public void drawViewfinder() {
+		viewfinderView.drawViewfinder();
+
+	}
+
+	private void initBeepSound() {
+		if (playBeep && mediaPlayer == null) {
+			// The volume on STREAM_SYSTEM is not adjustable, and users found it
+			// too loud,
+			// so we now play on the music stream.
+			setVolumeControlStream(AudioManager.STREAM_MUSIC);
+			mediaPlayer = new MediaPlayer();
+			mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+			mediaPlayer.setOnCompletionListener(beepListener);
+
+			AssetFileDescriptor file = getResources().openRawResourceFd(
+					R.raw.beep);
+			try {
+				mediaPlayer.setDataSource(file.getFileDescriptor(),
+						file.getStartOffset(), file.getLength());
+				file.close();
+				mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
+				mediaPlayer.prepare();
+			} catch (IOException e) {
+				mediaPlayer = null;
+			}
+		}
+	}
+
+	private static final long VIBRATE_DURATION = 200L;
+
+	private void playBeepSoundAndVibrate() {
+		if (playBeep && mediaPlayer != null) {
+			mediaPlayer.start();
+		}
+		if (vibrate) {
+			Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+			vibrator.vibrate(VIBRATE_DURATION);
+		}
+	}
+
+	/**
+	 * When the beep has finished playing, rewind to queue up another one.
+	 */
+	private final OnCompletionListener beepListener = new OnCompletionListener() {
+		public void onCompletion(MediaPlayer mediaPlayer) {
+			mediaPlayer.seekTo(0);
+		}
+	};
+
+}

+ 273 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/PdfPrintActivity.java

@@ -0,0 +1,273 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.PointF;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.mupdf.MuPDFCore;
+import com.printer.sdk.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PdfPrintActivity extends BaseActivity implements OnClickListener {
+    private Button btnPrintPdf;
+    private Button btnPrintthis;
+    private Button btnPrevious;
+    private Button btnNext;
+    private Button btnChosePdf;
+    private ImageView ivShowPdf;
+    private TextView tvShowPage;
+    private LinearLayout header;
+    private int currentCount = -1;
+    private int pageCount = -1;
+    private Bitmap bitmap;
+    private String TAG = "com.printer.demo.ui";
+    private String path = null;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_pdf_print);
+        btnPrintPdf = (Button) findViewById(R.id.btn_printpdf);
+        btnPrevious = (Button) findViewById(R.id.btn_pre);
+        btnNext = (Button) findViewById(R.id.btn_next);
+        btnPrintthis = (Button) findViewById(R.id.btn_printthis);
+        btnChosePdf = (Button) findViewById(R.id.btn_choose_pdf_file);
+        btnChosePdf.setOnClickListener(this);
+        btnPrintPdf.setOnClickListener(this);
+        btnPrevious.setOnClickListener(this);
+        btnNext.setOnClickListener(this);
+        btnPrintthis.setOnClickListener(this);
+        ivShowPdf = (ImageView) findViewById(R.id.iv_showpdf);
+        tvShowPage = (TextView) findViewById(R.id.tv_showpage);
+        header = (LinearLayout) findViewById(R.id.ll_headerview_Pdf_Printactivity);
+        DisplayMetrics dm = new DisplayMetrics();
+        getWindowManager().getDefaultDisplay().getMetrics(dm);
+        initHeader();
+
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader() {
+        setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+
+            }
+        });
+        setHeaderLeftImage(header, new OnClickListener() {// 初始化了
+            // headerConnecedState
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        headerConnecedState.setText(getTitleState());
+        setHeaderCenterText(header, getString(R.string.headview_PdfPrint));
+    }
+
+    int count = 0;
+
+    @Override
+    public void onClick(View v) {
+        if (PrinterInstance.mPrinter == null && !SettingActivity.isConnected) {
+            Toast.makeText(PdfPrintActivity.this, getString(R.string.no_connected), 0).show();
+            return;
+        }
+        switch (v.getId()) {
+            case R.id.btn_printpdf:
+                if (path == null) {
+                    Toast.makeText(PdfPrintActivity.this, "请先选择pdf文件", Toast.LENGTH_SHORT).show();
+                    return;
+                }
+                Toast.makeText(PdfPrintActivity.this, "准备打印整份pdf,请稍候...", Toast.LENGTH_SHORT).show();
+                // 打印整份pdf
+                preloadPDF();
+
+                // 打印整份pdf
+                Log.i(TAG, "yxz at PdfPrintActivity.java onClick() case R.id.btn_printpdf: pdf文件共有 " + pageCount + "页");
+                int countIndex = 0;
+                while (countIndex < pageCount) {
+                    if (pageData.size() > 0) {
+                        PrinterInstance.mPrinter.sendBytesData(pageData.get(0));
+                        pageData.remove(0);
+                        countIndex++;
+                    }
+                }
+
+                break;
+            case R.id.btn_printthis:
+                if (path == null) {
+                    Toast.makeText(PdfPrintActivity.this, "请先选择pdf文件", Toast.LENGTH_SHORT).show();
+                    return;
+                }
+                Toast.makeText(PdfPrintActivity.this, "准备打印,请稍候...", Toast.LENGTH_SHORT).show();
+
+                // 打印当前页码的pdf
+                if (currentCount >= pageCount) {
+                    currentCount = pageCount - 1;
+                }
+                if (currentCount <= 0) {
+                    currentCount = 0;
+                }
+                PointF pageSize = core.getPageSize(currentCount);
+                float pageW = pageSize.x;
+                float pageH = pageSize.y;
+                Log.i(TAG, "yxz at PdfPrintActivity.java onclick() case R.id.btn_printthis pageW:" + pageW + "  pageH:"
+                        + pageH);
+                bitmap = Bitmap.createBitmap((int) pageW, (int) pageH, Bitmap.Config.ARGB_8888);
+                core.drawPage(currentCount, bitmap, (int) pageW, (int) pageH, 0, 0, (int) pageW, (int) pageH);
+                new InnerAsyncTask().execute();
+                break;
+            case R.id.btn_pre:
+                if (path == null) {
+                    Toast.makeText(PdfPrintActivity.this, "请先选择pdf文件", Toast.LENGTH_SHORT).show();
+                    return;
+                }
+                // 显示上一页pdf
+                currentCount--;
+                if (currentCount <= 0) {
+                    currentCount = 0;
+                    showImage(currentCount);
+                    tvShowPage.setText("1/" + pageCount);
+                } else {
+                    showImage(currentCount);
+                    tvShowPage.setText(currentCount + 1 + "/" + pageCount);
+                }
+                break;
+            case R.id.btn_next:
+                if (path == null) {
+                    Toast.makeText(PdfPrintActivity.this, "请先选择pdf文件", Toast.LENGTH_SHORT).show();
+                    return;
+                }
+                // 显示下页pdf
+                currentCount++;
+                if (currentCount >= pageCount) {
+                    currentCount = pageCount;
+                    showImage(currentCount);
+                    tvShowPage.setText(core.countPages() + "/" + pageCount);
+                } else {
+                    showImage(currentCount);
+                    tvShowPage.setText(currentCount + 1 + "/" + pageCount);
+
+                }
+                break;
+            case R.id.btn_choose_pdf_file:
+                Intent intent_item_pdf = new Intent(PdfPrintActivity.this, ItemPdfPdfactivity.class);
+                startActivityForResult(intent_item_pdf, 1);
+                break;
+        }
+
+    }
+
+    List<byte[]> pageData = null;
+
+    private void preloadPDF() { // 预加载PDF
+        count = 0;
+        pageData = new ArrayList<>();
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                synchronized (this) {
+                    while (count < pageCount) {
+                        PointF pageSize = core.getPageSize(count);
+                        float pageW = pageSize.x;
+                        float pageH = pageSize.y;
+                        bitmap = Bitmap.createBitmap((int) pageW, (int) pageH, Bitmap.Config.ARGB_8888);
+                        core.drawPage(count, bitmap, (int) pageW, (int) pageH, 0, 0, (int) pageW, (int) pageH);
+                        bitmap = Utils.zoomImage(bitmap, PrinterConstants.paperWidth, PrefUtils.getInt(PdfPrintActivity.this, GlobalContants.PRINTERTYPE, 0));
+                        pageData.add(Utils.originalBmpToPrintByte(bitmap, PAlign.NONE, 0, 128));
+                        count++;
+                    }
+                }
+            }
+        }).start();
+
+    }
+
+    private void showImage(int count) {
+        Log.d(TAG, "yxz at PdfPrintActivity.java showImage() count:" + count);
+        PointF pageSize = core.getPageSize(count);
+        float pageW = pageSize.x;
+        float pageH = pageSize.y;
+        Log.d(TAG, "yxz at PdfPrintActivity.java showImage() pageW:" + pageW + "  pageH:" + pageH);
+        Bitmap bitmap = Bitmap.createBitmap((int) pageW, (int) pageH, Bitmap.Config.ARGB_8888);
+        core.drawPage(count, bitmap, (int) pageW, (int) pageH, 0, 0, (int) pageW, (int) pageH);
+        ivShowPdf.setImageBitmap(bitmap);
+    }
+
+    private class InnerAsyncTask extends AsyncTask<Void, Void, Void> {
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            Log.i(TAG, "yxz at PdfPrintActivity.java InnerAsyncTask 图片原始宽:" + bitmap.getWidth() + " 图片原始高:"
+                    + bitmap.getHeight());
+            if (bitmap.getWidth() > PrinterConstants.paperWidth) {
+                bitmap = Utils.zoomImage(bitmap, PrinterConstants.paperWidth,PrefUtils.getInt(PdfPrintActivity.this, GlobalContants.PRINTERTYPE, 0));
+            }
+            Log.i(TAG, "yxz at PdfPrintActivity.java InnerAsyncTask 缩放后宽:" + bitmap.getWidth() + " 缩放后高:"
+                    + bitmap.getHeight());
+            PrinterInstance.mPrinter.printImage(bitmap, PAlign.NONE, 0, 128);
+
+
+            return null;
+        }
+
+
+    }
+
+    private MuPDFCore core = null;
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (resultCode == Activity.RESULT_OK) {
+            path = data.getStringExtra("data_return");
+            if (path == null) {
+                Toast.makeText(PdfPrintActivity.this, ".pdf文件路径为空", Toast.LENGTH_SHORT).show();
+                ivShowPdf.setImageResource(R.drawable.ic_launcher);
+            } else {
+                try {
+                    core = new MuPDFCore(this, path);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                /********** 以下处理转成图片 ***********/
+                pageCount = core.countPages();
+                Log.i(TAG, "yxz at PdfPrintActivity.java onActivityResult() pageCount:" + pageCount);
+                currentCount = 0;
+                Log.i(TAG, "yxz at PdfPrintActivity.java onActivityResult() currentCount:" + currentCount);
+                showImage(currentCount);
+                tvShowPage.setText(1 + "/" + pageCount);
+            }
+            super.onActivityResult(requestCode, resultCode, data);
+        }
+    }
+
+}

+ 422 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/PicturePrintActivity.java

@@ -0,0 +1,422 @@
+package com.printer.demo;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.provider.MediaStore;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.WindowManager;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+
+import androidx.core.content.FileProvider;
+
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.CanvasUtils;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.sdk.CanvasDrawPrint;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.Command;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.monochrome.BitmapConvertor;
+import com.printer.sdk.utils.Utils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * 
+ * @Description 处理图片打印相关
+ */
+public class PicturePrintActivity extends BaseActivity implements OnClickListener, OnItemSelectedListener {
+	private Context mContext;
+	private boolean is58mm = false;
+	private boolean isStylus = false;
+	private Button btn_photo_print, btn_select_photo, btn_canvas_print, btn_monochrome_print,btn_page_mode_printingt;
+	private ImageView iv_Original_picture, iv_monochrome_picture;
+	private LinearLayout header;
+	private final static int IMAGE_CAPTURE_FROM_CAMERA = 1;
+	private final static int IMAGE_CAPTURE_FROM_GALLERY = 2;
+	private static final String TAG = "PicturePrintActivity";
+	private BitmapConvertor convertor;
+	private WindowManager wm;
+	private ProgressDialog mPd;
+	private String remp_dir = null;
+	private static PrinterInstance mPrinter;
+	private CanvasDrawPrint mCanvasDrawPrint;
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		mContext = this;
+		setContentView(R.layout.activity_print_picture);
+		init();
+		Log.e(TAG, "onCreate");
+		// if (savedInstanceState != null) {
+		// remp_dir = savedInstanceState.getString("remp_dir");
+		// // System.out.println("onCreate: temp = " + remp_dir);
+		// Log.e(TAG, "remp_dir:"+remp_dir);
+		// }
+		mPrinter = PrinterInstance.mPrinter;
+		remp_dir = getFilePath();
+	}
+
+	@Override
+	protected void onResume() {
+		super.onResume();
+		Log.e(TAG, "onResume");
+		// if (GlobalContants.ISCONNECTED) {
+		// if ("".equals(GlobalContants.DEVICENAME)
+		// || GlobalContants.DEVICENAME == null) {
+		// headerConnecedState.setText(R.string.unknown_device);
+		//
+		// } else {
+		//
+		// headerConnecedState.setText(GlobalContants.DEVICENAME);
+		// }
+		//
+		// }
+
+	}
+
+	private void init() {
+
+		header = (LinearLayout) findViewById(R.id.ll_header_picture);
+		btn_photo_print = (Button) findViewById(R.id.btn_photo_print);
+		btn_photo_print.setOnClickListener(this);
+		btn_monochrome_print = (Button) findViewById(R.id.btn_monochrome_print);
+		btn_monochrome_print.setOnClickListener(this);
+		btn_page_mode_printingt = (Button) findViewById(R.id.btn_page_mode_printingt);
+		btn_page_mode_printingt.setOnClickListener(this);
+		btn_select_photo = (Button) findViewById(R.id.btn_select_photo);
+		btn_select_photo.setOnClickListener(this);
+		btn_canvas_print = (Button) findViewById(R.id.btn_canvas_print);
+		btn_canvas_print.setOnClickListener(this);
+		// iv_Original_picture = (ImageView)
+		// findViewById(R.id.iv_Original_picture);
+		iv_monochrome_picture = (ImageView) findViewById(R.id.iv_monochrome_picture);
+		initHeader(header);
+		convertor = new BitmapConvertor(this);
+		wm = this.getWindowManager();
+	}
+
+	/**
+	 * 初始化标题上的信息
+	 */
+	private void initHeader(LinearLayout header) {
+		setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+
+			@Override
+			public void onClick(View v) {
+				finish();
+
+			}
+		});
+		headerConnecedState.setText(getTitleState());
+		setHeaderLeftImage(header, new OnClickListener() {
+
+			@Override
+			public void onClick(View v) {
+				finish();
+			}
+		});
+		setHeaderCenterText(header, getString(R.string.headview_PicturePrint));
+
+	}
+
+	@Override
+	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void onNothingSelected(AdapterView<?> arg0) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void onClick(View view) {
+
+		if (mPrinter == null || !SettingActivity.isConnected) {
+			Toast.makeText(mContext, getString(R.string.no_connected), 0).show();
+			return;
+		}
+		if (view == btn_monochrome_print) {
+			new Thread(new Runnable() {
+				public void run() {
+
+					mPrinter.printText("打印单色位图演示:");
+					mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);
+					Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.my_monochrome_image);
+					if (bitmap1.getWidth() > PrinterConstants.paperWidth) {
+						bitmap1 = Utils.zoomImage(bitmap1, PrinterConstants.paperWidth,PrefUtils.getInt(mContext, GlobalContants.PRINTERTYPE, 0));
+					}
+					mPrinter.printImage(bitmap1, PAlign.NONE, 0, 128);
+				}
+			}).start();
+
+		} else if (view == btn_photo_print) {
+			remp_dir = getFilePath();
+			// 拍照我们用Action为MediaStroe.ACTION_IMAGE_CAPTURE,
+			// 有些人使用其他的Action但我发现在有些机子中会出问题,所以优先选择这个
+			Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+			intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
+			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+				//设置7.0中共享文件,分享路径定义在xml/provider_pathsaths.xml
+				intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+				Uri contentUri = FileProvider.getUriForFile(this,
+						BuildConfig.APPLICATION_ID + ".fileProvider", new File(remp_dir));
+				intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
+			} else {
+				intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(remp_dir)));
+			}
+
+			startActivityForResult(intent, IMAGE_CAPTURE_FROM_CAMERA);
+
+		} else if (view == btn_select_photo) {
+			// 拍照我们用Action为Intent.ACTION_GET_CONTENT,
+			// 有些人使用其他的Action但我发现在有些机子中会出问题,所以优先选择这个
+			Intent intent2 = new Intent();
+			intent2.setType("image/*");
+			intent2.setAction(Intent.ACTION_GET_CONTENT);
+			startActivityForResult(intent2, IMAGE_CAPTURE_FROM_GALLERY);
+
+		} else if (view == btn_canvas_print) {
+			if (mPrinter == null) {
+				Log.i(TAG, "mPrinter为空");
+			} else {
+				new Thread(new Runnable() {
+					@Override
+					public void run() {
+						new CanvasUtils().printCustomImage2(mContext.getResources(), PrinterInstance.mPrinter);
+					}
+				}).start();
+
+			}
+		}else if (view == btn_page_mode_printingt){
+			if (mPrinter == null) {
+				Log.i(TAG, "mPrinter为空");
+			} else {
+				// 创建画布
+
+		        if(mCanvasDrawPrint == null){
+		        	mCanvasDrawPrint = new CanvasDrawPrint();
+		        };
+		        mCanvasDrawPrint.setCanvasDrawBack(mCanvasDrawBack);
+				new Thread(new Runnable() {
+					@Override
+					public void run() {
+						new CanvasUtils().pageModePrinting(mCanvasDrawPrint,PrinterInstance.mPrinter, mContext);
+					}
+				}).start();
+
+			}
+		}
+
+	}
+	String str = "";
+	CanvasDrawPrint.CanvasDrawBack mCanvasDrawBack = new CanvasDrawPrint.CanvasDrawBack() {
+		@Override
+		public void resultsBack(int i) {
+
+			if (i == CanvasDrawPrint.LINE) {
+				str = ("绘制直线出错请查看相关log");
+			} else if (i == CanvasDrawPrint.BOX) {
+				str = ("绘制矩形出错请查看相关log");
+			} else if (i == CanvasDrawPrint.TEXT) {
+				str = ("绘制文字出错请查看相关log");
+			} else if (i == CanvasDrawPrint.PDF417_PROFESSIONAL) {
+				str = ("绘制专业PDF417出错请查看相关log");
+			} else if (i == CanvasDrawPrint.PDF417_ORDINARY) {
+				str = ("绘制普通PDF417出错请查看相关log");
+			} else if (i == CanvasDrawPrint.QRCODE_PROFESSIONAL) {
+				str = ("绘制专业二维码出错请查看相关log");
+			} else if (i == CanvasDrawPrint.QRCODE_ORDINARY) {
+				str = ("绘制二维码普通出错请查看相关log");
+			} else if (i == CanvasDrawPrint.ONE_DIMENSION_CODE) {
+				str = ("绘制一维码出错请查看相关log");
+			} else if (i == CanvasDrawPrint.IMG) {
+				str = ("绘制bitmap出错请查看相关log");
+			}
+			runOnUiThread(new Runnable() {
+
+				@Override
+				public void run() {
+					// TODO Auto-generated method stub
+					Toast.makeText(mContext, str, 0).show();
+				}
+			});
+		}
+	};
+
+	private String getFilePath() {
+		String PATH_LOGCAT = null;
+		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// 优先保存到SD卡中
+			PATH_LOGCAT = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "MyPicture";
+			Log.i(TAG, "sdka ");
+		} else {// 如果SD卡不存在,就保存到本应用的目录下
+			PATH_LOGCAT = PicturePrintActivity.this.getFilesDir().getAbsolutePath() + File.separator + "MyPicture";
+			Log.i(TAG, "neicun");
+		}
+		File dir = new File(PATH_LOGCAT);
+		if (!dir.exists()) {
+			dir.mkdir(); // 创建文件夹
+		}
+		remp_dir = PATH_LOGCAT + File.separator + "tmpPhoto.jpg";
+		Log.i(TAG, "remp_dir:" + remp_dir);
+		return remp_dir;
+	}
+
+	Bitmap monoChromeBitmap = null;
+
+	@Override
+	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+
+		if (resultCode != RESULT_OK) {
+			return;
+		}
+		int width = wm.getDefaultDisplay().getWidth();
+		int height = wm.getDefaultDisplay().getHeight();
+		Log.i(TAG, "windows height:" + height + "----" + "windows width:" + width);
+
+		switch (requestCode) {
+		case IMAGE_CAPTURE_FROM_CAMERA:
+			if (remp_dir == null)
+				Log.e(TAG, "remp_dir为空!");
+			else
+				Log.i(TAG, "remp_dir" + remp_dir);
+			File f = new File(remp_dir);
+			Uri capturedImage = null;
+			Bitmap photoBitmap = null;
+			try {
+				capturedImage = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),
+						f.getAbsolutePath(), null, null));
+				Log.i(TAG, capturedImage.toString());
+				photoBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), capturedImage);
+			} catch (FileNotFoundException e1) {
+				e1.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			Log.i("camera", "Selected image: " + capturedImage.toString());
+			f.delete();
+			Log.i(TAG, "height1:" + photoBitmap.getHeight() + "----" + "width1:" + photoBitmap.getWidth());
+			new ConvertInBackground().execute(photoBitmap);
+			// mPrinter.printImage(bitmap, alignType, left, isCompressed);
+			break;
+		case IMAGE_CAPTURE_FROM_GALLERY:
+			Uri mImageCaptureUri = data.getData();
+			// 这个方法是根据Uri获取Bitmap图片的静态方法
+			try {
+				// 选择相册
+				Bitmap photoBitmap2 = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageCaptureUri);
+				new ConvertInBackground().execute(photoBitmap2);
+			} catch (FileNotFoundException e) {
+				e.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		default:
+			break;
+		}
+	}
+
+	@Override
+	public void onConfigurationChanged(Configuration newConfig) {
+		// 其实这里什么都不要做
+		super.onConfigurationChanged(newConfig);
+	}
+
+	@Override
+	protected void onStop() {
+		super.onStop();
+		Log.e(TAG, "onStop");
+	}
+
+	@Override
+	protected void onDestroy() {
+		// TODO Auto-generated method stub
+		super.onDestroy();
+		Log.e(TAG, "onDestroy");
+	}
+
+	@Override
+	protected void onStart() {
+		// TODO Auto-generated method stub
+		super.onStart();
+		Log.e(TAG, "onStart");
+	}
+
+	@Override
+	protected void onPause() {
+		super.onPause();
+		Log.e(TAG, "onPause");
+	}
+
+	@Override
+	protected void onSaveInstanceState(Bundle outState) {
+		super.onSaveInstanceState(outState);
+
+		outState.putString("remp_dir", remp_dir);
+		Log.e(TAG, "onSaveInstanceState");
+
+	}
+
+	class ConvertInBackground extends AsyncTask<Bitmap, String, Void> {
+		@Override
+		protected Void doInBackground(Bitmap... params) {
+			monoChromeBitmap = params[0];
+			if (monoChromeBitmap == null || mPrinter == null) {
+				Log.i(TAG, "monoChromeBitmap为空!");
+				return null;
+			}
+			Log.i(TAG, "heightD:" + monoChromeBitmap.getHeight() + "----" + "widthD:" + monoChromeBitmap.getWidth());
+			if (monoChromeBitmap.getWidth() > PrinterConstants.paperWidth) {
+				monoChromeBitmap = Utils.zoomImage(monoChromeBitmap, PrinterConstants.paperWidth, PrefUtils.getInt(mContext, GlobalContants.PRINTERTYPE, 0));
+			}
+			 mPrinter.printImage(monoChromeBitmap, PAlign.NONE, 0, 128);
+			// mPrinter.printColorImg2Gray(PicturePrintActivity.this,monoChromeBitmap, PAlign.NONE, 0, false);
+			return null;
+		}
+
+		@Override
+		protected void onPostExecute(Void result) {
+			// TODO Auto-generated method stub
+			iv_monochrome_picture.setImageBitmap(monoChromeBitmap);
+			mPd.dismiss();
+		}
+
+		@Override
+		protected void onPreExecute() {
+			mPd = ProgressDialog.show(PicturePrintActivity.this, "Converting Image", "Please Wait", true, false, null);
+		}
+	}
+
+
+
+
+
+
+
+
+}

+ 155 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/SerialsDeviceList.java

@@ -0,0 +1,155 @@
+package com.printer.demo;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.RadioGroup;
+import android.widget.Spinner;
+
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.serial.SerialPortFinder;
+
+public class SerialsDeviceList extends Activity implements RadioGroup.OnCheckedChangeListener {
+
+    private Button scanButton;
+    private Button backButton;
+    private ArrayAdapter<String> deviceArrayAdapter;
+    private ListView mFoundDevicesListView;
+    //	private EditText baudrateEt;
+    private String baudrateStr;
+    private String path;
+    private String[] entries;
+    private String[] entryValues;
+    private Spinner baudrateSpin;
+    private RadioGroup rgLiuKong;
+    private int liuKong = 0;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+        setContentView(R.layout.device_list_serial);
+        setTitle("请选择设备");
+
+        setResult(Activity.RESULT_CANCELED);
+
+//		baudrateEt = (EditText) findViewById(R.id.editBaudrateText);
+        baudrateSpin = (Spinner) findViewById(R.id.BaudrateSpin);
+
+//		baudrateSpin.setOnItemClickListener(new OnItemClickListener() {
+//
+//			@Override
+//			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+//				
+//				
+//			}
+//		});
+        scanButton = (Button) findViewById(R.id.button_scan);
+        scanButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                doDiscovery();
+            }
+        });
+
+        backButton = (Button) findViewById(R.id.button_bace);
+        backButton.setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+
+        });
+
+        deviceArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_item);
+
+        mFoundDevicesListView = (ListView) findViewById(R.id.paired_devices);
+        mFoundDevicesListView.setAdapter(deviceArrayAdapter);
+        mFoundDevicesListView.setOnItemClickListener(mDeviceClickListener);
+        rgLiuKong = (RadioGroup) findViewById(R.id.rg_liukong);
+        rgLiuKong.setOnCheckedChangeListener(this);
+        switch (PrefUtils.getInt(SerialsDeviceList.this, GlobalContants.LiuKongType, 1)) {
+            case 0:
+                rgLiuKong.check(R.id.rb_xon_xoff);
+                break;
+            case 1:
+                rgLiuKong.check(R.id.rb_rts_cts);
+                break;
+            case 2:
+                rgLiuKong.check(R.id.rb_none);
+                break;
+            default:
+                rgLiuKong.check(R.id.rb_rts_cts);
+                break;
+        }
+        doDiscovery();
+    }
+
+    public void doDiscovery() {
+        if (!deviceArrayAdapter.isEmpty()) {
+            deviceArrayAdapter.clear();
+        }
+        SerialPortFinder mSerialPortFinder = new SerialPortFinder();
+        entries = mSerialPortFinder.getAllDevices();
+        if (entries == null || entries.length == 0) {
+            deviceArrayAdapter.add(getString(R.string.notroot));
+            Log.i("sprt", "entries.length为空!");
+        }
+        entryValues = mSerialPortFinder.getAllDevicesPath();
+        for (int i = 0; i < entries.length; i++) {
+            deviceArrayAdapter.add(entries[i] + "/npath:" + entryValues[i]);
+        }
+    }
+
+    private void returnToPreviousActivity(String path, String baudrate) {
+        Intent intent = new Intent();
+        intent.putExtra("path", path);
+        intent.putExtra("baudrate", baudrate);
+
+        System.out.println("0path:" + path);
+        System.out.println("0baudrate:" + baudrate);
+
+        setResult(Activity.RESULT_OK, intent);
+        finish();
+    }
+
+    private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
+        public void onItemClick(AdapterView<?> av, View v, int position, long id) {
+            baudrateStr = baudrateSpin.getSelectedItem().toString();
+            path = entryValues[position];
+            returnToPreviousActivity(path, baudrateStr);
+        }
+    };
+
+    @Override
+    public void onCheckedChanged(RadioGroup group, int checkedId) {
+        if (group == rgLiuKong) {
+            switch (checkedId) {
+                case R.id.rb_rts_cts:
+                    liuKong = 1;
+                    break;
+                case R.id.rb_xon_xoff:
+                    liuKong = 0;
+                    break;
+                case R.id.rb_none:
+                    liuKong = 2;
+                    break;
+                default:
+                    liuKong = 1;
+                    break;
+            }
+            PrefUtils.setInt(SerialsDeviceList.this, GlobalContants.LiuKongType, liuKong);
+        }
+    }
+}

+ 1101 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/SettingActivity.java

@@ -0,0 +1,1101 @@
+package com.printer.demo;
+
+import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.app.ProgressDialog;
+import android.app.Service;
+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.content.res.AssetManager;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbManager;
+import android.media.MediaPlayer;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Vibrator;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.RadioGroup;
+import android.widget.RadioGroup.OnCheckedChangeListener;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.printer.demo.global.GlobalContants;
+import com.printer.demo.utils.PrefUtils;
+import com.printer.demo.utils.PrintBean;
+import com.printer.demo.utils.PrintLabel80_test;
+import com.printer.demo.utils.XTUtils;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.Connect;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.usb.USBPort;
+import com.printer.sdk.utils.XLog;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+@SuppressLint("HandlerLeak")
+public class SettingActivity extends BaseActivity
+        implements OnClickListener, OnItemSelectedListener, OnCheckedChangeListener {
+    private LinearLayout header;
+    private TextView tvShowPrinterType;
+    private TextView tvShowPrinterPortType;
+    private Spinner spinner_printer_type;
+    private Spinner spinner_interface_type;
+    private List<String> data_list;
+    private ArrayAdapter<CharSequence> arr_adapter;
+    private ArrayAdapter<CharSequence> printType_adapter;
+    private final static int SCANNIN_GREQUEST_CODE = 2;
+    public static final int CONNECT_DEVICE = 1;
+    public static final int ENABLE_BT = 3;
+    // 不同蓝牙链接方式的判断依据 “确认连接”
+    public static int connectMains = 0;
+    protected static final String TAG = "SettingActivity";
+    private static Button btn_search_devices, btn_scan_and_connect, btn_selfprint_test, btn_status_test, btn_selfCheckingPage_print;
+    public static boolean isConnected = false;// 蓝牙连接状态
+    public static String devicesName = "未知设备";
+    private static String devicesAddress;
+    private ProgressDialog dialog;
+    public static PrinterInstance myPrinter;
+    private static BluetoothDevice mDevice;
+    private static UsbDevice mUSBDevice;
+    private static Context mContext;
+    private int printerId = 0;
+    private int interfaceType = 0;
+    private List<UsbDevice> deviceList;
+    private static final String ACTION_USB_PERMISSION = "com.android.usb.USB_PERMISSION";
+    private RadioGroup rg__select_paper_size;
+    boolean isError;
+    private BluetoothAdapter mBtAdapter;
+    private TextView tv_device_name, tv_printer_address;
+    private IntentFilter bluDisconnectFilter;
+    private static boolean hasRegDisconnectReceiver = false;
+    private ProgressDialog dialogH;
+    private static final String ACTION_UPDATE_CHARACTERS_CANCLE = "canclUpdateCharacters";
+    private IntentFilter cancleUpdateCharactersFilter;
+    private String strStatus = null;
+    private RadioGroup rgPrinterType;
+    /**
+     * 设置TSPL指令打印机
+     *
+     * @param mPrinter
+     * @return 是否设置成功
+     */
+
+    /**
+     * 显示扫描结果
+     */
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_setting);
+        init();
+        XLog.i(TAG, "yxz at SetteingActivity.java onCreate() SettingActivity.this:" + SettingActivity.this);
+        mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+        Log.e(TAG, "yxz at SetteingActivity.java onCreate()");
+
+    }
+
+    // 用于接受连接状态消息的 Handler
+    private Handler mHandler = new Handler() {
+        @SuppressLint("ShowToast")
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case Connect.SUCCESS:
+                    isConnected = true;
+                    GlobalContants.ISCONNECTED = isConnected;
+                    GlobalContants.DEVICENAME = devicesName;
+                    if (interfaceType == 0) {
+                        PrefUtils.setString(mContext, GlobalContants.DEVICEADDRESS, devicesAddress);
+                        bluDisconnectFilter = new IntentFilter();
+                        bluDisconnectFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
+                        mContext.registerReceiver(myReceiver, bluDisconnectFilter);
+                        hasRegDisconnectReceiver = true;
+                    }
+
+                    // TOTO 暂时将TSPL指令设置参数的设置放在这
+                    // if (setPrinterTSPL(myPrinter)) {
+                    // if (interfaceType == 0) {
+                    // Toast.makeText(mContext,
+                    // R.string.settingactivitty_toast_bluetooth_set_tspl_successful,
+                    // 0)
+                    // .show();
+                    // } else if (interfaceType == 1) {
+                    // Toast.makeText(mContext,
+                    // R.string.settingactivity_toast_usb_set_tspl_succefful,
+                    // 0).show();
+                    // }
+                    // }
+                    break;
+                case Connect.FAILED:
+                    isConnected = false;
+                    Toast.makeText(mContext, R.string.conn_failed, Toast.LENGTH_SHORT).show();
+                    XLog.i(TAG, "ZL at SettingActivity Handler() 连接失败!");
+                    break;
+                case Connect.CLOSED:
+                    isConnected = false;
+                    GlobalContants.ISCONNECTED = isConnected;
+                    GlobalContants.DEVICENAME = devicesName;
+                    Toast.makeText(mContext, R.string.conn_closed, Toast.LENGTH_SHORT).show();
+                    XLog.i(TAG, "ZL at SettingActivity Handler() 连接关闭!");
+                    break;
+                case Connect.NODEVICE:
+                    isConnected = false;
+                    Toast.makeText(mContext, R.string.conn_no, Toast.LENGTH_SHORT).show();
+                    break;
+                // case 10:
+                // if (setPrinterTSPL(myPrinter)) {
+                // Toast.makeText(mContext, "蓝牙连接设置TSPL指令成功", 0).show();
+                // }
+                default:
+                    break;
+            }
+
+            updateButtonState(isConnected);
+
+            if (dialog != null && dialog.isShowing()) {
+                dialog.dismiss();
+            }
+        }
+
+    };
+    int count = 0;
+
+    @SuppressWarnings("static-access")
+    public void vibrator() {
+        count++;
+        PrefUtils.setInt(mContext, "count3", count);
+        Log.e(TAG, "" + count);
+        // Vibrator vib = (Vibrator) SettingActivity.this
+        // .getSystemService(Service.VIBRATOR_SERVICE);
+        // vib.vibrate(1000);
+        // try {
+        // Thread.sleep(500);
+        // } catch (InterruptedException e) {
+        // e.printStackTrace();
+        // }
+        MediaPlayer player = new MediaPlayer().create(mContext, R.raw.test);
+        // MediaPlayer player2 = new MediaPlayer().create(mContext, R.raw.beep);
+
+        player.start();
+        // player2.start();
+    }
+
+    /**
+     * 初始化界面
+     */
+    private void init() {
+        mContext = SettingActivity.this;
+        header = (LinearLayout) findViewById(R.id.ll_headerview_settingactivity);
+        // 初始化标题
+        initHeader(header);
+        // 初始化下拉列表框
+        // spinner_printer_type = (Spinner)
+        // findViewById(R.id.spinner_printer_type);
+        spinner_interface_type = (Spinner) findViewById(R.id.spinner_interface_type);
+        // 初始化按钮的点击事件
+        btn_search_devices = (Button) findViewById(R.id.btn_search_devices);
+        btn_scan_and_connect = (Button) findViewById(R.id.btn_scan_and_connect);
+        btn_selfprint_test = (Button) findViewById(R.id.btn_selfprint_test);
+        btn_status_test = (Button) findViewById(R.id.btn_status_test);
+        btn_selfCheckingPage_print = (Button) findViewById(R.id.btn_selfchekingpage_print);
+        // 设置按钮的监听事件
+        btn_search_devices.setOnClickListener(this);
+        btn_scan_and_connect.setOnClickListener(this);
+        btn_selfprint_test.setOnClickListener(this);
+        btn_status_test.setOnClickListener(this);
+        btn_selfCheckingPage_print.setOnClickListener(this);
+
+        // 展示设备名和设备地址
+        tv_device_name = (TextView) findViewById(R.id.tv_device_name);
+        tv_printer_address = (TextView) findViewById(R.id.tv_printer_address);
+        // // 适配器
+        // arr_adapter = ArrayAdapter.createFromResource(this,
+        // R.array.printertype, android.R.layout.simple_spinner_item);
+        printType_adapter = ArrayAdapter.createFromResource(this, R.array.interface_type,
+                android.R.layout.simple_spinner_item);
+
+        // // 设置样式
+        // arr_adapter
+        // .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        printType_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        // 加载适配器
+        // spinner_printer_type.setAdapter(arr_adapter);
+        spinner_interface_type.setAdapter(printType_adapter);
+        // 下拉列表框的监听事件
+        // spinner_printer_type.setOnItemSelectedListener(this);
+        spinner_interface_type.setOnItemSelectedListener(this);
+
+        rg__select_paper_size = (RadioGroup) findViewById(R.id.rg__select_paper_size);
+        rg__select_paper_size.setOnCheckedChangeListener(this);
+
+        rgPrinterType = (RadioGroup) findViewById(R.id.rg_printer_type);
+        rgPrinterType.setOnCheckedChangeListener(this);
+        // 初始化对话框
+        dialog = new ProgressDialog(mContext);
+        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+        dialog.setTitle(getString(R.string.connecting));
+        dialog.setMessage(getString(R.string.please_wait));
+        dialog.setIndeterminate(true);
+        dialog.setCancelable(false);
+
+        getSaveState();
+        updateButtonState(isConnected);
+        // 初始化进度条对话框
+        dialogH = new ProgressDialog(this);
+        dialogH.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+        dialogH.setCancelable(false);
+        dialogH.setCanceledOnTouchOutside(false);
+
+        PrinterConstants.paperWidth = PrefUtils.getInt(mContext, GlobalContants.PAPERWIDTH, 576);
+        switch (PrinterConstants.paperWidth) {
+            case 384:
+                rg__select_paper_size.check(R.id.rb_58mm);
+                break;
+            case 576:
+                rg__select_paper_size.check(R.id.rb_80mm);
+                break;
+            case 724:
+                rg__select_paper_size.check(R.id.rb_100mm);
+                break;
+            default:
+                rg__select_paper_size.check(R.id.rb_80mm);
+                break;
+        }
+        switch (PrefUtils.getInt(mContext, GlobalContants.PRINTERTYPE, 0)) {
+            case 0:
+                rgPrinterType.check(R.id.rb_normal);
+                break;
+            case 1:
+                rgPrinterType.check(R.id.rb_t7);
+                break;
+            default:
+                rgPrinterType.check(R.id.rb_normal);
+                break;
+        }
+    }
+
+    private void getSaveState() {
+        XLog.d(TAG, "yxz at SettingActivity.java getSaveState() ---begin");
+        isConnected = PrefUtils.getBoolean(SettingActivity.this, GlobalContants.CONNECTSTATE, false);
+        printerId = PrefUtils.getInt(mContext, GlobalContants.PRINTERID, 0);
+        interfaceType = PrefUtils.getInt(mContext, GlobalContants.INTERFACETYPE, 0);
+        // spinner_printer_type.setSelection(printerId);
+        spinner_interface_type.setSelection(interfaceType);
+        XLog.i(TAG, "zl at MainActivity.java isConnected:" + isConnected);
+        XLog.d(TAG, "yxz at SettingActivity.java getSaveState() ---end");
+
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader(LinearLayout header) {
+        setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+
+            }
+        });
+        headerConnecedState.setText(getTitleState());
+        setHeaderLeftImage(header, new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        setHeaderCenterText(header, getString(R.string.headview_setting));
+
+    }
+
+    @Override
+    protected void onStart() {
+        XLog.e(TAG, "yxz at SettingActivity.java onStart()   progressdialog");
+        super.onStart();
+
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        XLog.e(TAG, "yxz at SettingActivity.java onResume()   progressdialog");
+        XLog.e(TAG, "yxz at SettingActivity.java onResume()   liukong:" + PrefUtils.getInt(mContext, GlobalContants.LiuKongType, 1));
+
+    }
+
+    @Override
+    protected void onRestart() {
+        super.onRestart();
+        XLog.e(TAG, "yxz at SettingActivity.java onRestart()   progressdialog");
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        XLog.e(TAG, "yxz at SettingActivity.java onPause()   progressdialog");
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        XLog.e(TAG, "yxz at SettingActivity.java onStop()   progressdialog");
+
+    }
+
+    @Override
+    protected void onDestroy() {
+        XLog.e(TAG, "yxz at SettingActivity.java onDestroy()   progressdialog");
+        super.onDestroy();
+        if (interfaceType == 0 && hasRegDisconnectReceiver) {
+            mContext.unregisterReceiver(myReceiver);
+            hasRegDisconnectReceiver = false;
+            // Log.i(TAG, "关闭了广播!");
+        }
+
+    }
+
+    @SuppressLint("ShowToast")
+    @Override
+    public void onClick(View v) {
+
+        if (v == btn_search_devices) {
+            XLog.i(TAG, "YXZ at SettingActivity onClick() isConnected:" + isConnected);
+            if (!isConnected) {
+                switch (interfaceType) {
+                    case 0:// kuetooth
+                        new AlertDialog.Builder(this).setTitle(R.string.str_message).setMessage(R.string.str_connlast)
+                                .setPositiveButton(R.string.yesconn, new DialogInterface.OnClickListener() {
+                                    @Override
+                                    public void onClick(DialogInterface arg0, int arg1) {
+                                        connectMains = 0;
+                                        // 重新连接
+                                        if (!(mBtAdapter == null)) {
+                                            // 判断设备蓝牙功能是否打开
+                                            if (!mBtAdapter.isEnabled()) {
+                                                // 打开蓝牙功能
+                                                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+                                                startActivityForResult(enableIntent, ENABLE_BT);
+                                            } else {
+                                                // mDevice
+                                                devicesAddress = PrefUtils.getString(mContext, GlobalContants.DEVICEADDRESS,
+                                                        "");
+
+                                                if (devicesAddress == null || devicesAddress.length() <= 0) {
+                                                    Toast.makeText(SettingActivity.this, "您是第一次启动程序,请选择重新搜索连接!",
+                                                            Toast.LENGTH_SHORT).show();
+                                                } else {
+                                                    connect2BlueToothdevice();
+
+                                                }
+                                            }
+                                        }
+
+                                    }
+                                }).setNegativeButton(R.string.str_resel, new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                connectMains = 1;
+                                if (!(mBtAdapter == null)) {
+                                    // 判断设备蓝牙功能是否打开
+                                    if (!mBtAdapter.isEnabled()) {
+                                        // 打开蓝牙功能
+                                        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+                                        startActivityForResult(enableIntent, SettingActivity.ENABLE_BT);
+                                    } else {
+                                        Intent intent = new Intent(mContext, BluetoothDeviceList.class);
+                                        startActivityForResult(intent, CONNECT_DEVICE);
+
+                                    }
+
+                                }
+
+                            }
+
+                        }).show();
+
+                        break;
+                    case 1:// USB
+
+                        new AlertDialog.Builder(this).setTitle(R.string.str_message).setMessage(R.string.str_connlast)
+                                .setPositiveButton(R.string.yesconn, new DialogInterface.OnClickListener() {
+                                    @SuppressLint("InlinedApi")
+                                    @Override
+                                    public void onClick(DialogInterface arg0, int arg1) {
+
+                                        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
+                                        usbAutoConn(manager);
+                                    }
+                                }).setNegativeButton(R.string.str_resel, new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                XLog.i(TAG, "yxz at SettingActivity.java "
+                                        + "DialogInterface.OnClickListener() isConnected:" + isConnected);
+
+                                Intent intent = new Intent(mContext, UsbDeviceList.class);
+                                startActivityForResult(intent, CONNECT_DEVICE);
+
+                            }
+
+                        }).show();
+                        break;
+                    case 2:// wifi
+                        Intent intent = new Intent(mContext, IpEditActivity.class);
+                        intent.putExtra(GlobalContants.WIFINAME, getWiFiName());
+                        startActivityForResult(intent, CONNECT_DEVICE);
+                        break;
+                    case 3:// serial port
+                        Intent intentSerial = new Intent(mContext, SerialsDeviceList.class);
+                        startActivityForResult(intentSerial, CONNECT_DEVICE);
+                        break;
+                    default:
+                        break;
+                }
+            } else {
+                if (myPrinter != null) {
+                    myPrinter.closeConnection();
+                    myPrinter = null;
+                    XLog.i(TAG, "yxz at SettingActivity.java  onClick()  mPrinter:" + myPrinter);
+                    if (interfaceType == 0 && hasRegDisconnectReceiver) {
+                        mContext.unregisterReceiver(myReceiver);
+                        hasRegDisconnectReceiver = false;
+                        // Log.i(TAG, "关闭了广播!");
+                    }
+                }
+                tv_device_name.setText(getString(R.string.printerName));
+                tv_printer_address.setText(getString(R.string.printerAddress));
+            }
+
+        }
+
+        if (v == btn_scan_and_connect) {
+            connectMains = 2;
+            if (interfaceType != 0) {
+                Toast.makeText(mContext, "此功能只适用于部分蓝牙打印机", 0).show();
+                return;
+            }
+            if (isConnected) {
+                Toast.makeText(mContext, "当前已经连接到" + devicesName, 0).show();
+                return;
+            }
+            // 判断设备蓝牙功能是否打开
+            if (!mBtAdapter.isEnabled()) {
+                // 打开蓝牙功能
+                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+                startActivityForResult(enableIntent, ENABLE_BT);
+            } else {
+                Intent intent = new Intent();
+                intent.setClass(mContext, MipcaActivityCapture.class);
+                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
+            }
+
+        }
+
+        if (v == btn_selfprint_test) {
+            // WIFI 由于是网络操作,需要放到线程中,其他通信方式可以放在线程中也可以不必如此
+            if (isConnected) {
+                new Thread(new Runnable() {
+                    public void run() {
+                        XTUtils.printTest(getResources(), myPrinter);
+                    }
+
+                }).start();
+            } else {
+                Toast.makeText(mContext, getString(R.string.no_connected), 0).show();
+            }
+        }
+        if (v == btn_selfCheckingPage_print) {
+            if (isConnected) {
+                new Thread(new Runnable() {
+                    public void run() {
+                        synchronized (this) {
+                            myPrinter.printSelfCheckingPage();
+                            myPrinter.cutPaper(66, 50);
+                            myPrinter.closeConnection();
+                        }
+                        runOnUiThread(new Runnable() {
+                            @Override
+                            public void run() {
+                                Toast.makeText(mContext, getString(R.string.reconnect), 0).show();
+                            }
+                        });
+                    }
+
+                }).start();
+            } else {
+                Toast.makeText(mContext, getString(R.string.no_connected), 0).show();
+            }
+        }
+        if (v == btn_status_test) {
+            if (isConnected) {
+                new Thread(new Runnable() {
+                    public void run() {
+                        int i = myPrinter.getCurrentStatus();
+                        if (i == 0) {
+                            strStatus = "打印机状态正常";
+                        } else if (i == -1) {
+                            strStatus = "接收数据失败";
+                        } else if (i == -2) {
+                            strStatus = "打印机缺纸";
+                        } else if (i == -3) {
+                            strStatus = "打印机纸将尽";
+                        } else if (i == -4) {
+                            strStatus = "打印机开盖";
+                        } else if (i == -5) {
+                            strStatus = "发送数据失败";
+                        }
+                        runOnUiThread(new Runnable() {
+                            public void run() {
+                                Toast.makeText(mContext, strStatus, Toast.LENGTH_LONG).show();
+                                XLog.i(TAG, "zl at SettingActivity.java onClick()------> btn_status_test");
+                            }
+                        });
+
+                    }
+
+                }).start();
+            } else {
+                Toast.makeText(mContext, getString(R.string.no_connected), 0).show();
+            }
+        }
+    }
+
+    /**
+     * 使设备震动
+     */
+    public void vibrators() {
+
+        Vibrator vib = (Vibrator) SettingActivity.this.getSystemService(Service.VIBRATOR_SERVICE);
+        vib.vibrate(1000);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public static String jsonToStringFromAssetFolder(String fileName, Context context) throws IOException {
+        AssetManager manager = context.getAssets();
+        InputStream file = manager.open(fileName);
+        byte[] data = new byte[file.available()];
+        file.read(data);
+        file.close();
+        return new String(data, "gbk");
+
+    }
+
+    // 安卓3.1以后才有权限操作USB
+    @SuppressLint("ShowToast")
+    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (resultCode != Activity.RESULT_OK)
+            return;
+        if (requestCode == CONNECT_DEVICE) {// 连接设备
+            if (interfaceType == 0) {
+                devicesAddress = data.getExtras().getString(BluetoothDeviceList.EXTRA_DEVICE_ADDRESS);
+                devicesName = data.getExtras().getString(BluetoothDeviceList.EXTRA_DEVICE_NAME);
+                connect2BlueToothdevice();
+
+            } else if (interfaceType == 1)// usb
+            {
+                mUSBDevice = data.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                myPrinter = PrinterInstance.getPrinterInstance(mContext, mUSBDevice, mHandler);
+                devicesName = mUSBDevice.getDeviceName();
+                devicesAddress = "vid: " + mUSBDevice.getVendorId() + "  pid: " + mUSBDevice.getProductId();
+                UsbManager mUsbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
+                if (mUsbManager.hasPermission(mUSBDevice)) {
+                    myPrinter.openConnection();
+                } else {
+                    // 没有权限询问用户是否授予权限
+                    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
+                            new Intent(ACTION_USB_PERMISSION), 0);
+                    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
+                    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+                    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+                    mContext.registerReceiver(mUsbReceiver, filter);
+                    mUsbManager.requestPermission(mUSBDevice, pendingIntent); // 该代码执行后,系统弹出一个对话框
+                }
+
+            } else if (interfaceType == 2)// wifi
+            {
+                devicesName = "Net device";
+                devicesAddress = data.getStringExtra("ip_address");
+                myPrinter = PrinterInstance.getPrinterInstance(devicesAddress, 9100, mHandler);
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        myPrinter.openConnection();
+                    }
+                }).start();
+            } else if (interfaceType == 3) {// 串口
+
+                int baudrate = 9600;
+                int liukong = PrefUtils.getInt(mContext, GlobalContants.LiuKongType, 1);
+                String path = data.getStringExtra("path");
+                devicesName = "Serial device";
+                devicesAddress = path;
+                String com_baudrate = data.getExtras().getString("baudrate");
+                if (com_baudrate == null || com_baudrate.length() == 0) {
+                    baudrate = 9600;
+                }
+                baudrate = Integer.parseInt(com_baudrate);
+                XLog.i(TAG, "baudrate:" + baudrate);
+                myPrinter = PrinterInstance.getPrinterInstance(new File(path), baudrate, 0, liukong, mHandler);
+                myPrinter.openConnection();
+                // myPrinter
+                // .printText("测试串口连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭测试蓝牙连续连接--打印--关闭/n");
+                // myPrinter.closeConnection();
+                Log.i(TAG, "波特率:" + baudrate + "路径:" + path);
+            }
+
+        }
+        if (requestCode == SCANNIN_GREQUEST_CODE) {
+
+            // 校验扫描到的mac是否合法
+            devicesAddress = data.getExtras().getString(BluetoothDeviceList.EXTRA_DEVICE_ADDRESS);
+            Log.i(TAG, "devicesAddress:" + devicesAddress);
+            devicesAddress = XTUtils.formatTheString(devicesAddress);
+            if (BluetoothAdapter.checkBluetoothAddress(devicesAddress)) {
+                connect2BlueToothdevice();
+            } else {
+                Log.e("yxz", devicesAddress);
+                Toast.makeText(mContext, "蓝牙mac:" + devicesAddress + "不合法", 0).show();
+            }
+        }
+        if (requestCode == ENABLE_BT) {
+            if (resultCode == Activity.RESULT_OK) {
+                if (!mBtAdapter.isEnabled()) {
+                    // 打开蓝牙功能
+                    Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+                    startActivityForResult(enableIntent, SettingActivity.ENABLE_BT);
+                } else {
+                    switch (connectMains) {
+                        case 0:
+                            // mDevice
+                            devicesAddress = PrefUtils.getString(mContext, GlobalContants.DEVICEADDRESS, "");
+                            if (devicesAddress == null || devicesAddress.length() <= 0) {
+                                Toast.makeText(SettingActivity.this, "您是第一次启动程序,请选择重新搜索连接!", Toast.LENGTH_SHORT).show();
+                            } else {
+                                connect2BlueToothdevice();
+                            }
+                            break;
+                        case 1:
+                            Intent intent = new Intent(mContext, BluetoothDeviceList.class);
+                            startActivityForResult(intent, CONNECT_DEVICE);
+                            break;
+                        case 2:
+                            Intent scanIntent = new Intent();
+                            scanIntent.setClass(mContext, MipcaActivityCapture.class);
+                            scanIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                            startActivityForResult(scanIntent, SCANNIN_GREQUEST_CODE);
+                            break;
+                    }
+                }
+            } else {
+                Toast.makeText(SettingActivity.this, R.string.bt_not_enabled, 0).show();
+            }
+        }
+    }
+
+    private void connect2BlueToothdevice() {
+        dialog.show();
+        mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(devicesAddress);
+        devicesName = mDevice.getName();
+        myPrinter = PrinterInstance.getPrinterInstance(mDevice, mHandler);
+        if (mDevice.getBondState() == BluetoothDevice.BOND_NONE) {// 未绑定
+            // IntentFilter boundFilter = new IntentFilter();
+            // boundFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+            // mContext.registerReceiver(boundDeviceReceiver, boundFilter);
+            PairOrConnect(true);
+        } else {
+            PairOrConnect(false);
+        }
+    }
+
+    private void PairOrConnect(boolean pair) {
+        if (pair) {
+            IntentFilter boundFilter = new IntentFilter();
+            boundFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+            mContext.registerReceiver(boundDeviceReceiver, boundFilter);
+            boolean success = false;
+            try {
+                // // 自动设置pin值
+                // Method autoBondMethod =
+                // BluetoothDevice.class.getMethod("setPin", new Class[] {
+                // byte[].class });
+                // boolean result = (Boolean) autoBondMethod.invoke(mDevice, new
+                // Object[] { "1234".getBytes() });
+                // Log.i(TAG, "setPin is success? : " + result);
+
+                // 开始配对 这段代码打开输入配对密码的对话框
+                Method createBondMethod = BluetoothDevice.class.getMethod("createBond");
+                success = (Boolean) createBondMethod.invoke(mDevice);
+                // // 取消用户输入
+                // Method cancelInputMethod =
+                // BluetoothDevice.class.getMethod("cancelPairingUserInput");
+                // boolean cancleResult = (Boolean)
+                // cancelInputMethod.invoke(mDevice);
+                // Log.i(TAG, "cancle is success? : " + cancleResult);
+
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+                Log.e(TAG, "IllegalAccessException: " + e.getMessage());
+            } catch (IllegalArgumentException e) {
+                e.printStackTrace();
+                Log.e(TAG, "IllegalArgumentException: " + e.getMessage());
+            } catch (InvocationTargetException e) {
+                e.printStackTrace();
+                Log.e(TAG, "InvocationTargetException: " + e.getMessage());
+            } catch (NoSuchMethodException e) {
+                e.printStackTrace();
+                Log.e(TAG, "NoSuchMethodException: " + e.getMessage());
+            }
+            Log.i(TAG, "createBond is success? : " + success);
+        } else {
+            new connectThread().start();
+
+        }
+    }
+
+    private void updateButtonState(boolean isConnected) {
+        XLog.d(TAG, "yxz at SettingActivity.java updateButtonState() ---begin");
+        XLog.d(TAG, "yxz at SettingActivity.java updateButtonState() ---isConnected" + isConnected);
+        if (isConnected) {
+            headerConnecedState.setText(R.string.on_line);
+            btn_search_devices.setText(R.string.disconnect);
+            setTitleState(mContext.getResources().getString(R.string.on_line));
+            Log.i("fdh", getString(R.string.printerName).split(":")[0]);
+            Log.i("fdh", getString(R.string.printerAddress).split(":")[0]);
+            tv_device_name.setText(getString(R.string.printerName).split(":")[0] + ": " + devicesName);
+            tv_printer_address.setText(getString(R.string.printerAddress).split(":")[0] + ": " + devicesAddress);
+        } else {
+            tv_device_name.setText(getString(R.string.printerName));
+            tv_printer_address.setText(getString(R.string.printerAddress));
+            btn_search_devices.setText(R.string.connect);
+            headerConnecedState.setText(R.string.off_line);
+            setTitleState(mContext.getResources().getString(R.string.off_line));
+            // mHandler.removeCallbacks(runnable);
+            // if (isFirst) {
+            //
+            // } else {
+            // timer.cancel();
+            // }
+            // Log.i(TAG, "定时器取消了");
+            XLog.d(TAG, "yxz at SettingActivity.java updateButtonState() ---end");
+
+        }
+
+        PrefUtils.setBoolean(SettingActivity.this, GlobalContants.CONNECTSTATE, isConnected);
+
+    }
+
+    private BroadcastReceiver boundDeviceReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+
+            if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
+                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+                if (!mDevice.equals(device)) {
+                    return;
+                }
+                switch (device.getBondState()) {
+                    case BluetoothDevice.BOND_BONDING:
+                        Log.i(TAG, "bounding......");
+                        break;
+                    case BluetoothDevice.BOND_BONDED:
+                        Log.i(TAG, "bound success");
+                        // if bound success, auto init BluetoothPrinter. open
+                        // connect.
+                        mContext.unregisterReceiver(boundDeviceReceiver);
+                        dialog.show();
+                        // 配对完成开始连接
+                        if (myPrinter != null) {
+                            new connectThread().start();
+                        }
+                        break;
+                    case BluetoothDevice.BOND_NONE:
+                        Log.i(TAG, "执行顺序----4");
+                        mContext.unregisterReceiver(boundDeviceReceiver);
+                        Log.i(TAG, "bound cancel");
+                        if (dialog != null && dialog.isShowing()) {
+                            dialog.dismiss();
+                            Toast.makeText(mContext, "配对失败", Toast.LENGTH_LONG).show();
+                        }
+                        break;
+                    default:
+                        break;
+                }
+
+            }
+        }
+    };
+
+    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
+        @SuppressLint("NewApi")
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            Log.w(TAG, "receiver action: " + action);
+
+            if (ACTION_USB_PERMISSION.equals(action)) {
+                synchronized (this) {
+                    mContext.unregisterReceiver(mUsbReceiver);
+                    UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
+                            && mUSBDevice.equals(device)) {
+                        myPrinter.openConnection();
+                    } else {
+                        mHandler.obtainMessage(Connect.FAILED).sendToTarget();
+                        Log.e(TAG, "permission denied for device " + device);
+                    }
+                }
+            }
+        }
+    };
+
+
+    private class connectThread extends Thread {
+        @Override
+        public void run() {
+            if (myPrinter != null) {
+                isConnected = myPrinter.openConnection();
+            }
+        }
+    }
+
+    @Override
+    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+
+        // if (parent == spinner_printer_type) {
+        // PrefUtils.setInt(mContext, GlobalContants.PRINTERID, position);
+        // String printerName = getResources().getStringArray(
+        // R.array.printertype)[position];
+        // if (printerName.contains("T10") || printerName.contains("POS58")
+        // || printerName.contains("T7")) {
+        // rg__select_paper_size.check(R.id.rb_58mm);
+        // } else if (printerName.contains("L31")
+        // || printerName.contains("T9")
+        // || printerName.contains("POS885")
+        // || printerName.contains("EU80")) {
+        // rg__select_paper_size.check(R.id.rb_80mm);
+        // } else if (printerName.contains("L51")) {
+        // rg__select_paper_size.check(R.id.rb_100mm);
+        // }
+        // } else if (parent == spinner_interface_type) {
+        // }
+
+        if (parent == spinner_interface_type) {
+            PrefUtils.setInt(mContext, GlobalContants.INTERFACETYPE, position);
+            interfaceType = position;
+            Log.i(TAG, "position:" + position);
+        }
+
+    }
+
+    @Override
+    public void onNothingSelected(AdapterView<?> arg0) {
+
+    }
+
+    @Override
+    public void onCheckedChanged(RadioGroup group, int checkedId) {
+        if (group == rg__select_paper_size) {
+            switch (checkedId) {
+                case R.id.rb_58mm:
+                    PrinterConstants.paperWidth = 384;
+                    break;
+                case R.id.rb_80mm:
+                    PrinterConstants.paperWidth = 576;
+                    break;
+                case R.id.rb_100mm:
+                    PrinterConstants.paperWidth = 812;
+                    break;
+                default:
+                    PrinterConstants.paperWidth = 576;
+                    break;
+            }
+            PrefUtils.setInt(mContext, GlobalContants.PAPERWIDTH, PrinterConstants.paperWidth);
+        }
+        if (group == rgPrinterType) {
+            switch (checkedId) {
+                case R.id.rb_normal:
+                    PrefUtils.setInt(mContext, GlobalContants.PRINTERTYPE, 0);
+                    break;
+                case R.id.rb_t7:
+                    PrefUtils.setInt(mContext, GlobalContants.PRINTERTYPE, 1);
+                    break;
+                default:
+                    PrefUtils.setInt(mContext, GlobalContants.PRINTERTYPE, 0);
+                    break;
+            }
+        }
+
+    }
+
+	/*
+     * @Override public void onConfigurationChanged(Configuration newConfig) {
+	 * super.onConfigurationChanged(newConfig); if
+	 * (this.getResources().getConfiguration().orientation ==
+	 * Configuration.ORIENTATION_LANDSCAPE) { // land } else if
+	 * (this.getResources().getConfiguration().orientation ==
+	 * Configuration.ORIENTATION_PORTRAIT) { // port } }
+	 */
+
+    @SuppressLint({"InlinedApi", "NewApi"})
+    public void usbAutoConn(UsbManager manager) {
+
+        doDiscovery(manager);
+        if (deviceList.isEmpty()) {
+            Toast.makeText(mContext, R.string.no_connected, 0).show();
+            return;
+        }
+        mUSBDevice = deviceList.get(0);
+        if (mUSBDevice == null) {
+            mHandler.obtainMessage(Connect.FAILED).sendToTarget();
+            return;
+        }
+        myPrinter = PrinterInstance.getPrinterInstance(mContext, mUSBDevice, mHandler);
+        devicesName = mUSBDevice.getDeviceName();
+        devicesAddress = "vid: " + mUSBDevice.getVendorId() + "  pid: " + mUSBDevice.getProductId();
+        UsbManager mUsbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
+        if (mUsbManager.hasPermission(mUSBDevice)) {
+            myPrinter.openConnection();
+        } else {
+            // 没有权限询问用户是否授予权限
+            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
+            IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
+            filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+            filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+            mContext.registerReceiver(mUsbReceiver, filter);
+            mUsbManager.requestPermission(mUSBDevice, pendingIntent); // 该代码执行后,系统弹出一个对话框
+        }
+
+    }
+
+    @SuppressLint("NewApi")
+    private void doDiscovery(UsbManager manager) {
+        HashMap<String, UsbDevice> devices = manager.getDeviceList();
+        deviceList = new ArrayList<UsbDevice>();
+        for (UsbDevice device : devices.values()) {
+            if (USBPort.isUsbPrinter(device)) {
+                deviceList.add(device);
+            }
+        }
+
+    }
+
+    private String getWiFiName() {
+        String wifiName = null;
+        WifiManager mWifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+        if (!mWifi.isWifiEnabled()) {
+            mWifi.setWifiEnabled(true);
+        }
+        WifiInfo wifiInfo = mWifi.getConnectionInfo();
+        wifiName = wifiInfo.getSSID();
+        Log.i("yxz", "wifiName" + wifiName);
+        wifiName = wifiName.replaceAll("\"", "");
+        return wifiName;
+
+    }
+
+    public BroadcastReceiver myReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+            if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
+
+                if (device != null && myPrinter != null && isConnected && device.equals(mDevice)) {
+                    myPrinter.closeConnection();
+                    mHandler.obtainMessage(Connect.CLOSED).sendToTarget();
+                }
+            }
+
+        }
+    };
+
+    public synchronized static void allCut(View v) {
+        if (isConnected) {
+            new Thread(new Runnable() {
+                public void run() {
+                    XTUtils.printNote(mContext.getResources(), myPrinter);
+                    myPrinter.cutPaper(65, 50);
+                }
+            }).start();
+
+            // num=0;
+
+        } else {
+            Toast.makeText(mContext, mContext.getString(R.string.no_connected), 0).show();
+        }
+    }
+
+    static int num = 0;
+
+    public synchronized static void halfCut(View v) {
+        if (isConnected) {
+            new Thread(new Runnable() {
+                public void run() {
+                    XTUtils.printNote(mContext.getResources(), myPrinter);
+                    synchronized (this) {
+                        myPrinter.cutPaper(66, 50);
+                    }
+                }
+            }).start();
+//            new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+//                    List<PrintBean> list =new ArrayList();
+//                    PrintBean pb =new PrintBean("transferWaybillNo","goodQty","flowDirectionCore","serviceProduct","goodsNum");
+//                    list.add(pb);
+//                    num=100;
+//                    for(int i=0;i<num;i++){
+//                        new PrintLabel80_test().doPrint(myPrinter,getResources(), (ArrayList<PrintBean>) list);
+//                        try {
+//                            Thread.sleep(500);
+//                        } catch (InterruptedException e) {
+//                            e.printStackTrace();
+//                        }
+//                    }
+//                }
+//            }).start();
+        } else {
+            Toast.makeText(mContext, mContext.getString(R.string.no_connected), 0).show();
+        }
+    }
+
+
+}

+ 185 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/TextPrintActivity.java

@@ -0,0 +1,185 @@
+package com.printer.demo;
+
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+import android.widget.ToggleButton;
+
+import com.printer.demo.utils.CodePageUtils;
+import com.printer.demo.utils.XTUtils;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.utils.XLog;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Locale;
+
+public class TextPrintActivity extends BaseActivity implements OnClickListener, OnCheckedChangeListener {
+
+    private static final String TAG = "TextPrintActivity";
+    private LinearLayout header;
+    private Button btn_send, btn_print_note, btn_print_codepaper;
+    private ToggleButton tb_isHexData;
+    private EditText et_input;
+    private boolean isHexData = false;
+    private static PrinterInstance mPrinter;
+    private String input;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        XLog.d(TAG, "yxz at TextPrintActivity.java onCreate()");
+        setContentView(R.layout.activity_print_text);
+        init();
+        mPrinter = PrinterInstance.mPrinter;
+        input = et_input.getText().toString();
+        et_input.addTextChangedListener(new TextWatcher() {
+
+            @Override
+            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
+
+            }
+
+            @Override
+            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
+
+            }
+
+            @Override
+            public void afterTextChanged(Editable arg0) {
+                input = et_input.getText().toString();
+            }
+        });
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    private void init() {
+
+        et_input = (EditText) findViewById(R.id.et_input);
+        et_input.setText(R.string.textprintactivty_input_content);
+        header = (LinearLayout) findViewById(R.id.ll_headerview_textPrint);
+        btn_send = (Button) findViewById(R.id.btn_send);
+        btn_send.setOnClickListener(this);
+        btn_print_note = (Button) findViewById(R.id.btn_print_note);
+        btn_print_note.setOnClickListener(this);
+        btn_print_codepaper = (Button) findViewById(R.id.btn_print_codepaper);
+        btn_print_codepaper.setOnClickListener(this);
+        btn_send.setOnClickListener(this);
+        tb_isHexData = (ToggleButton) findViewById(R.id.tb_hex_on);
+        tb_isHexData.setOnCheckedChangeListener(this);
+        isHexData = tb_isHexData.isChecked();
+        initHeader();
+    }
+
+    /**
+     * 初始化标题上的信息
+     */
+    private void initHeader() {
+        setHeaderLeftText(header, getString(R.string.back), new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+
+            }
+        });
+        headerConnecedState.setText(getTitleState());
+        setHeaderCenterText(header, getString(R.string.headview_TextPrint));
+        setHeaderLeftImage(header, new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+
+    }
+
+    @Override
+    public void onClick(View view) {
+        if (PrinterInstance.mPrinter != null && SettingActivity.isConnected) {
+            if (view == btn_send) {
+
+                final String content = et_input.getText().toString();
+                Log.i(TAG, content);
+                if (content != null || content.length() != 0) {
+
+                    if (isHexData && SettingActivity.isConnected) {
+                        byte[] srcData = XTUtils.string2bytes2(content);
+                        mPrinter.sendBytesData(srcData);
+                    } else if (!isHexData && SettingActivity.isConnected) {
+                        // // PrinterInstance.mPrinter.printText(content +
+                        // "\r\n");
+                        new Thread(new Runnable() {
+                            @Override
+                            public void run() {
+                                synchronized (this){
+                                    mPrinter.printText(content + "\r\n");
+                                    try {
+                                        XLog.d("yxz", "str:" + new String(content.getBytes("gbk")
+                                                , "gbk"));
+                                    } catch (UnsupportedEncodingException e) {
+                                        e.printStackTrace();
+                                    }
+                                }
+                            }
+                        }).start();
+//						Locale locale = Locale.getDefault();
+//						String language = locale.getLanguage();
+//						String country = locale.getCountry();
+                    }
+                }
+
+            } else if (view == btn_print_note) {
+                new Thread(new Runnable() {
+                    public void run() {
+                        XTUtils.printNote(TextPrintActivity.this.getResources(), mPrinter);
+                    }
+                }).start();
+            } else if (view == btn_print_codepaper) {
+                new CodePageUtils().selectCodePage(this, PrinterInstance.mPrinter);
+            }
+        } else {
+            Toast.makeText(TextPrintActivity.this, getString(R.string.no_connected), 0).show();
+        }
+
+    }
+
+    @Override
+    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+
+        if (isChecked) {// 16进制开
+            isHexData = true;
+            byte[] datas;
+            try {
+                datas = input.getBytes("GBK");
+                et_input.setText(XTUtils.bytesToHexString2(datas, datas.length));
+                input = et_input.getText().toString();
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+        } else {
+            isHexData = false;
+            if (input == null || input.length() == 0) {
+                et_input.setText(R.string.textprintactivty_input_content);
+            } else {
+                et_input.setText(XTUtils.hexStringToString2(input));
+                input = et_input.getText().toString();
+            }
+        }
+
+    }
+
+}

+ 112 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/UsbDeviceList.java

@@ -0,0 +1,112 @@
+package com.printer.demo;
+
+import android.annotation.TargetApi;
+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.Build;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+
+import androidx.annotation.RequiresApi;
+
+import com.printer.sdk.usb.USBPort;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * This Activity appears as a dialog. It lists any paired devices and devices
+ * detected in the area after discovery. When a device is chosen by the user,
+ * the MAC address of the device is sent back to the parent Activity in the
+ * result Intent.
+ *
+ * @param <V>
+ */
+@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
+public class UsbDeviceList<V> extends Activity {
+	private ArrayAdapter<String> deviceArrayAdapter;
+	private ListView mFoundDevicesListView;
+	private Button scanButton;
+	private Button backButton;
+	private List<UsbDevice> deviceList;
+
+	@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+		setContentView(R.layout.device_list);
+		setTitle(R.string.select_device);
+
+		setResult(Activity.RESULT_CANCELED);
+
+		scanButton = (Button) findViewById(R.id.button_scan);
+		scanButton.setOnClickListener(new OnClickListener() {
+			public void onClick(View v) {
+				doDiscovery();
+			}
+		});
+
+		backButton= (Button) findViewById(R.id.button_bace);
+		backButton.setOnClickListener(new OnClickListener()
+		{
+			@Override
+			public void onClick(View v)
+			{
+                 finish();
+			}
+		});
+
+		deviceArrayAdapter = new ArrayAdapter<String>(this,
+				R.layout.device_item);
+
+		mFoundDevicesListView = (ListView) findViewById(R.id.paired_devices);
+		mFoundDevicesListView.setAdapter(deviceArrayAdapter);
+		mFoundDevicesListView.setOnItemClickListener(mDeviceClickListener);
+		doDiscovery();
+	}
+
+
+	@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+	private void doDiscovery() {
+		deviceArrayAdapter.clear();
+		UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
+		HashMap<String, UsbDevice> devices = manager.getDeviceList();
+		deviceList = new ArrayList<UsbDevice>();
+		for (UsbDevice device : devices.values()) {
+				if (USBPort.isUsbPrinter(device)) {
+				deviceArrayAdapter.add(device.getDeviceName() + "\nvid: "
+						+ device.getVendorId() + " pid: "
+						+ device.getProductId() + "\n" + device.getProductName());
+				deviceList.add(device);
+			}
+		}
+	}
+
+	private void returnToPreviousActivity(UsbDevice device) {
+		Intent intent = new Intent();
+		Bundle bundle = new Bundle();
+		bundle.putParcelable(UsbManager.EXTRA_DEVICE, device);
+		intent.putExtras(bundle);
+		setResult(Activity.RESULT_OK, intent);
+		finish();
+	}
+
+
+	private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
+		public void onItemClick(AdapterView<?> av, View v, int position, long id) {
+			returnToPreviousActivity(deviceList.get(position));
+		}
+	};
+}

+ 37 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/global/GlobalContants.java

@@ -0,0 +1,37 @@
+package com.printer.demo.global;
+
+/**
+ * 定义全局参数
+ * 
+ * @author Kevin
+ * 
+ */
+public class GlobalContants {
+
+	public static final String CONNECTSTATE = "connectState";
+	public static final String PRINTERID = "printerID";
+	public static final String INTERFACETYPE = "interfacetype";
+	public static final String DEVICEADDRESS = "deviceAddress";
+	public static String DEVICENAME = "deviceName";
+	public static final String WIFINAME = "wifiname";
+	public static final String PAPERWIDTH = "paperwidth";
+	public static final String LiuKongType = "liukong";
+	public static final String PRINTERTYPE = "printertype";
+
+	public static boolean ISCONNECTED;
+
+	public static final int NO_NEW_VERSION = 0;
+	public static final int HAS_NEW_VERSION = 1;
+	public static final int URL_ERROR = 2;
+	public static final int NETWORK_ERROR = 3;
+	public static final int JSON_ERROR = 4;
+	public static final int PROGRESS_UPDATE = 5;
+	public static final int START_UPDATE = 6;
+	public static final int FINISH_UPDATE = 7;
+	public static int NEED_UPDATE=0;
+	public static String description="";
+	public static String apkurl="";
+
+
+
+}

+ 327 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/CanvasUtils.java

@@ -0,0 +1,327 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.util.Log;
+
+
+import com.printer.demo.R;
+import com.printer.sdk.BarcodeCreater;
+import com.printer.sdk.CanvasDrawPrint;
+import com.printer.sdk.CanvasPrint;
+import com.printer.sdk.FontProperty;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.Command;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PrinterType;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.zxing.BarcodeFormat;
+import com.printer.sdk.zxing.EncodeHintType;
+import com.printer.sdk.zxing.MultiFormatWriter;
+import com.printer.sdk.zxing.WriterException;
+import com.printer.sdk.zxing.common.BitMatrix;
+import com.printer.sdk.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+import java.util.Hashtable;
+
+public class CanvasUtils {
+	private static String TAG = "com.printer.demo.utils";
+
+	/**
+	 * 画布模版一 普通画布,画布的用法
+	 * 
+	 * @param resources
+	 * @param mPrinter
+	 * @param isStylus
+	 * @param is58mm
+	 */
+	public void printCustomImage(Resources resources, PrinterInstance mPrinter, boolean isStylus, boolean is58mm) {
+		mPrinter.initPrinter();
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
+		mPrinter.printText(resources.getString(R.string.str_canvas));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+		CanvasPrint cp = new CanvasPrint();
+		/**
+		 * 初始化画布,画布的宽度为变量,一般有两个选择:1.58mm型号打印机实际可用是48mm,48*8=384px 2.
+		 * 80mm型号打印机实际可用是72mm,72*8=576px,因为画布的高度是无限制的,但从内存分配方面考虑要小于4M比较合适。
+		 * 所有预置为宽度的5倍。初始化画笔,默认属性有:1.消除锯齿 2.设置画笔颜色为黑色。
+		 *
+		 * init 方法包含cp.initCanvas(550)和cp.initPaint(),T9打印宽度为72mm,其他为47mm
+		 */
+		if (isStylus) {
+			cp.init(PrinterType.TIII);
+		} else {
+			if (is58mm) {
+				cp.init(PrinterType.TIII);
+			} else {
+				cp.init(PrinterType.T9);
+			}
+		}
+		// 非中文使用空格分隔单词
+		cp.setUseSplit(true);
+		// 阿拉伯文靠右显示
+		cp.setTextAlignRight(true);
+		/*
+		 * 插入图片函数:drawImage(float x,float y, String path) 其中(x,y)是指插入图片的左上顶点坐标。
+		 */
+		FontProperty fp = new FontProperty();
+		fp.setFont(false, false, false, false, 25, null);
+		// 通过初始化的字体属性设置画笔
+		cp.setFontProperty(fp);
+		cp.drawText("Show example of context contains English language is showed in right of parent:");
+		fp.setFont(false, false, false, false, 30, null);
+		cp.setFontProperty(fp);
+		cp.setTextAlignRight(false);
+		cp.drawText("打印汉字测试,测试打满一行内容后,是否自动换行,且向左对齐展示。");
+		cp.drawText("\n\b\n\n");
+		cp.drawImage(BitmapFactory.decodeResource(resources, R.drawable.my_picture));
+		if (isStylus) {
+			// 针打图形,第二个参数为0倍高倍宽,为1只倍高
+			mPrinter.printImageStylus(cp.getCanvasImage(), 1);
+
+		} else {
+			mPrinter.printImage(cp.getCanvasImage(), PAlign.NONE, 0, false);
+		}
+	}
+
+	/**
+	 * 画布模版二 图片跟文字并行
+	 * 
+	 * @param resources
+	 * @param mPrinter
+	 * @param isStylus
+	 * @param is58mm
+	 */
+	public void printCustomImage2(Resources resources, PrinterInstance mPrinter) {
+		// 创建画布
+		CanvasPrint cp = new CanvasPrint();
+		if (PrinterConstants.paperWidth == 576) {
+			// 初始化画布,POS88系列用T9参数即可
+			cp.init(PrinterType.T9);
+			// 调用下面的方法生成二维码
+			Bitmap bitmapCODE39 = createBitmapQR_CODE("123456789", 270, 270);
+			// 将二维码画到画布上(0,0)处坐标
+			cp.drawImage(0, 0, bitmapCODE39);
+			/**
+			 * 默认字体
+			 */
+			// 创建字体
+			FontProperty fp = new FontProperty();
+			// 字体属性赋值 此处参数个数根据SDK版本不同,有略微差别,酌情增减。
+			fp.setFont(true, false, false, false, 40, null);
+			// 设置字体
+			cp.setFontProperty(fp);
+			// 将文字画到画布上指定坐标处
+			cp.drawText(250, 80, "默认字体");
+			cp.drawLine(0, 240, 576, 240);
+
+		} else if (PrinterConstants.paperWidth == 724) {
+			// 100mm纸宽
+			cp.init(PrinterType.T7);
+			// 调用下面的方法生成二维码
+			Bitmap bitmapCODE39 = createBitmapQR_CODE("123456789", 300, 300);
+			// 将二维码画到画布上(0,0)处坐标
+			cp.drawImage(0, 0, bitmapCODE39);
+			/**
+			 * 默认字体
+			 */
+			// 创建字体
+			FontProperty fp = new FontProperty();
+			// 字体属性赋值 此处参数个数根据SDK版本不同,有略微差别,酌情增减。
+			fp.setFont(true, false, false, false, 50, null);
+			// 设置字体
+			cp.setFontProperty(fp);
+			// 将文字画到画布上指定坐标处
+			cp.drawText(320, 80, "默认字体");
+			/**
+			 * 楷体
+			 */
+			Typeface kaiti = Typeface.createFromAsset(resources.getAssets(), "kaiti.ttf");
+			fp.setFont(true, false, false, false, 50, kaiti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(320, 140, "楷体展示");
+			/**
+			 * 宋体
+			 */
+			Typeface songti = Typeface.createFromAsset(resources.getAssets(), "songti.ttf");
+			fp.setFont(true, false, false, false, 50, songti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(320, 200, "宋体展示");
+			/**
+			 * 黑体
+			 */
+			Typeface heiti = Typeface.createFromAsset(resources.getAssets(), "heiti.ttf");
+			fp.setFont(true, false, false, false, 50, heiti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(320, 260, "黑体展示");
+			cp.drawLine(0, 265, 724, 265);
+
+		} else if (PrinterConstants.paperWidth == 384) {
+			// 58mm
+			cp.init(PrinterType.TIII);
+			// 调用下面的方法生成二维码
+			Bitmap bitmapCODE39 = createBitmapQR_CODE("123456789", 150, 150);
+			// 将二维码画到画布上(0,0)处坐标
+			cp.drawImage(0, 0, bitmapCODE39);
+			// 创建字体
+			FontProperty fp = new FontProperty();
+			/**
+			 * 楷体
+			 */
+			Typeface kaiti = Typeface.createFromAsset(resources.getAssets(), "kaiti.ttf");
+			fp.setFont(true, false, false, false, 30, kaiti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(160, 40, "楷体展示");
+			/**
+			 * 宋体
+			 */
+			Typeface songti = Typeface.createFromAsset(resources.getAssets(), "songti.ttf");
+			fp.setFont(true, false, false, false, 30, songti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(160, 80, "宋体展示");
+			/**
+			 * 黑体
+			 */
+			Typeface heiti = Typeface.createFromAsset(resources.getAssets(), "heiti.ttf");
+			fp.setFont(true, false, false, false, 30, heiti);
+			// 设置字体
+			cp.setFontProperty(fp);
+			cp.drawText(160, 120, "黑体展示");
+			cp.drawLine(0, 160, 384, 160);
+		}
+
+		// 将画布保存成图片并进行打印
+		mPrinter.printImage(cp.getCanvasImage(), PAlign.NONE, 0, false);
+
+	}
+	
+	public static void pageModePrinting(CanvasDrawPrint mCanvasDrawPrint,PrinterInstance mPrinter,Context mContext){
+		
+        // 初始化画布宽高
+        mCanvasDrawPrint.SPRTSetPageMode(500, 800);
+        mCanvasDrawPrint.setTextAlignRight(true);//设置对其方式
+        mCanvasDrawPrint.setUseSplit(true); // 页面上文本超出后换行是否使用分隔字符串
+        // 绘制字体
+        mCanvasDrawPrint.SPRTPrintText(0, 0, null, 60, true, true, 0.5f, "测试字体多文字测试文本换行问题", mContext);
+        mCanvasDrawPrint.SPRTPrintText(0, mCanvasDrawPrint.getLength(), "kaiti.ttf", 60, false, false, 0, "楷体文字", mContext);
+        //绘制直线
+        mCanvasDrawPrint.SPRTPrintLine(0, mCanvasDrawPrint.getLength(), 450, mCanvasDrawPrint.getLength(), 10);
+        //设置画笔样式
+        mCanvasDrawPrint.setPaintStyle(Paint.Style.STROKE);
+	   //绘制专业PDF417
+        mCanvasDrawPrint.SPRTPrintPDFCode(0, mCanvasDrawPrint.getLength(), 500, 500, 23, 8, 3, "123456789");
+        //绘制专业QRCode
+        mCanvasDrawPrint.SPRTPrintQRCode(0, mCanvasDrawPrint.getLength(), 200, 200, 10, 10, 4, "123456");
+		
+	   // 绘制一维码
+        mCanvasDrawPrint.SPRTPrintCode(BarcodeCreater.CODE_128, 0, mCanvasDrawPrint.getLength(),300,200, true, "123456");
+
+        //将画布保存成图片并进行打印
+        mPrinter.printImage(mCanvasDrawPrint.getCanvasImage(), PAlign.NONE, 0,false);
+
+	}
+
+	/**
+	 * 生成二维码图片
+	 * 
+	 * @param str
+	 *            内容
+	 * @param param1
+	 *            宽度
+	 * @param param2
+	 *            高度
+	 * @return
+	 */
+	public static Bitmap createBitmap(String str, int param1, int param2, int type) {
+		try {
+			// BitMatrix matrix = new
+			// MultiFormatWriter().encode(str,BarcodeFormat.PDF417, param1,
+			// param2);
+			// BitMatrix matrix = new
+			// MultiFormatWriter().encode(str,BarcodeFormat.QR_CODE, param1,
+			// param2);
+			// new MultiFormatWriter().en
+			Hashtable<EncodeHintType, Object> hint = new Hashtable<EncodeHintType, Object>();
+			if (type == 0) {
+				hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
+			} else if (type == 1) {
+				hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
+			} else if (type == 2) {
+				hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
+			} else {
+				hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
+			}
+			BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, param1, param1, hint);
+			int width = param1;
+			// int width = matrix.width;
+			int height = param2;
+			// int height = matrix.height;
+			int[] pixels = new int[width * height];
+			for (int y = 0; y < width; ++y) {
+				for (int x = 0; x < height; ++x) {
+					if (matrix.get(x, y)) {
+						pixels[y * width + x] = 0xff000000; // black pixel
+					} else {
+						pixels[y * width + x] = 0xffffffff; // white pixel
+					}
+				}
+			}
+			Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+			bmp.setPixels(pixels, 0, width, 0, 0, width, height);
+			Log.i(TAG, "createBitmap-width:" + bmp.getWidth());
+			Log.i(TAG, "createBitmap-height:" + bmp.getHeight());
+			return bmp;
+		} catch (WriterException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 生成QR_CODE类型二维码图片
+	 * 
+	 * @param str
+	 *            内容
+	 * @param param1
+	 *            宽度
+	 * @param param2
+	 *            高度
+	 * @return
+	 */
+	public static Bitmap createBitmapQR_CODE(String str, int param1, int param2) {
+		try {
+			BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, param1, param2);
+			int width = matrix.getWidth();
+			int height = matrix.getWidth();
+			int[] pixels = new int[width * height];
+			for (int y = 0; y < height; ++y) {
+				for (int x = 0; x < width; ++x) {
+					if (matrix.get(x, y)) {
+						pixels[y * width + x] = 0xff000000; // black pixel
+					} else {
+						pixels[y * width + x] = 0xffffffff; // white pixel
+					}
+				}
+			}
+			Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+			bmp.setPixels(pixels, 0, width, 0, 0, width, height);
+			Log.i(TAG, "createBitmapCODE39-width:" + bmp.getWidth());
+			Log.i(TAG, "createBitmapCODE39-height:" + bmp.getHeight());
+			return bmp;
+		} catch (WriterException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+}

+ 194 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/CodePageUtils.java

@@ -0,0 +1,194 @@
+package com.printer.demo.utils;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
+
+import com.printer.demo.R;
+import com.printer.sdk.PrinterConstants.Command;
+import com.printer.sdk.PrinterInstance;
+
+import java.lang.reflect.Field;
+
+public class CodePageUtils
+{
+
+	private int cTypeid=0;
+
+	 public void selectCodePage(final Context context, final PrinterInstance mPrinter)
+     {
+   	  LayoutInflater inflater = LayoutInflater.from(context);
+         View BarcodeView = inflater.inflate(R.layout.codepage, null);
+         final Spinner page_types = (Spinner)BarcodeView.findViewById(R.id.page_types);
+
+
+         final ArrayAdapter<CharSequence> pagetypes = ArrayAdapter.createFromResource(context, R.array.codepages, android.R.layout.simple_spinner_item);
+         page_types.setAdapter(pagetypes);
+
+         page_types.setPromptId(R.string.codepageTest);
+
+         page_types.setOnItemSelectedListener(new OnItemSelectedListener()
+         {
+
+			@Override
+			public void onItemSelected(AdapterView<?> arg0, View arg1,
+                                       int arg2, long arg3)
+			{
+				cTypeid=arg2;
+			}
+
+			@Override
+			public void onNothingSelected(AdapterView<?> arg0)
+			{
+				// TODO Auto-generated method stub
+			}});
+
+         AlertDialog.Builder builder = new AlertDialog.Builder(context);
+         builder.setCancelable(false);
+         builder.setTitle(R.string.codepageTest);
+         builder.setView(BarcodeView);
+
+         builder.setPositiveButton(R.string.print, new DialogInterface.OnClickListener()
+         {
+ 			@Override
+ 			public void onClick(DialogInterface dialog, int which)
+ 			{
+
+                 System.out.println("cTypeid="+cTypeid);
+                 try
+                 {
+										byte [] realData = new byte[]{
+							(byte)0x80,(byte)0x81,(byte)0x82,(byte)0x83,
+							(byte)0x84,(byte)0x85,(byte)0x86,(byte)0x87,
+							(byte)0x88,(byte)0x89,(byte)0x8A,(byte)0x8B,
+							(byte)0x8C,(byte)0x8D,(byte)0x8E,(byte)0x8F,
+
+							(byte)0x90,(byte)0x91,(byte)0x92,(byte)0x93,
+							(byte)0x94,(byte)0x95,(byte)0x96,(byte)0x97,
+							(byte)0x98,(byte)0x99,(byte)0x9A,(byte)0x9B,
+							(byte)0x9C,(byte)0x9D,(byte)0x9E,(byte)0x9F,
+
+							(byte)0xA0,(byte)0xA1,(byte)0xA2,(byte)0xA3,
+							(byte)0xA4,(byte)0xA5,(byte)0xA6,(byte)0xA7,
+							(byte)0xA8,(byte)0xA9,(byte)0xAA,(byte)0xAB,
+							(byte)0xAC,(byte)0xAD,(byte)0xAE,(byte)0xAF,
+
+							(byte)0xB0,(byte)0xB1,(byte)0xB2,(byte)0xB3,
+							(byte)0xB4,(byte)0xB5,(byte)0xB6,(byte)0xB7,
+							(byte)0xB8,(byte)0xB9,(byte)0xBA,(byte)0xBB,
+							(byte)0xBC,(byte)0xBD,(byte)0xBE,(byte)0xBF,
+
+							(byte)0xC0,(byte)0xC1,(byte)0xC2,(byte)0xC3,
+							(byte)0xC4,(byte)0xC5,(byte)0xC6,(byte)0xC7,
+							(byte)0xC8,(byte)0xC9,(byte)0xCA,(byte)0xCB,
+							(byte)0xCC,(byte)0xCD,(byte)0xCE,(byte)0xCF,
+
+							(byte)0xD0,(byte)0xD1,(byte)0xD2,(byte)0xD3,
+							(byte)0xD4,(byte)0xD5,(byte)0xD6,(byte)0xD7,
+							(byte)0xD8,(byte)0xD9,(byte)0xDA,(byte)0xDB,
+							(byte)0xDC,(byte)0xDD,(byte)0xDE,(byte)0xDF,
+
+							(byte)0xE0,(byte)0xE1,(byte)0xE2,(byte)0xE3,
+							(byte)0xE4,(byte)0xE5,(byte)0xE6,(byte)0xE7,
+							(byte)0xE8,(byte)0xE9,(byte)0xEA,(byte)0xEB,
+							(byte)0xEC,(byte)0xED,(byte)0xEE,(byte)0xEF,
+
+							(byte)0xF0,(byte)0xF1,(byte)0xF2,(byte)0xF3,
+							(byte)0xF4,(byte)0xF5,(byte)0xF6,(byte)0xF7,
+							(byte)0xF8,(byte)0xF9,(byte)0xFA,(byte)0xFB,
+							(byte)0xFC,(byte)0xFD,(byte)0xFE,(byte)0xFF,
+					        };
+
+			              if(cTypeid!=47)
+				          {
+
+		                      mPrinter.printText(context.getResources().getString(R.string.print)+pagetypes.getItem(cTypeid).toString()+context.getResources().getString(R.string.str_show));
+		                      mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+		                      mPrinter.sendBytesData(new byte[]{(byte)0x1c,(byte)0x2E});
+
+		                      mPrinter.sendBytesData(new byte[]{(byte)0x1B,(byte)0x74,(byte)cTypeid});
+		                      mPrinter.sendBytesData(realData);
+		                      mPrinter.sendBytesData(new byte[]{(byte)0x0A});
+
+		                      mPrinter.sendBytesData(new byte[]{(byte)0x1c,(byte)0x26});
+		                      mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+       				    }else
+       				    {
+       					    for(cTypeid=0;cTypeid<46;cTypeid++)
+       					    {
+       						     if(cTypeid>14 || cTypeid<11)
+       						     {
+
+	        						  mPrinter.printText(context.getResources().getString(R.string.print)+pagetypes.getItem(cTypeid).toString()+""+context.getResources().getString(R.string.str_show));
+	    		                      mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+	    		                      mPrinter.sendBytesData(new byte[]{(byte)0x1c,(byte)0x2E});
+
+	    		                      mPrinter.sendBytesData(new byte[]{(byte)0x1B,(byte)0x74,(byte)cTypeid});
+	    		                      mPrinter.sendBytesData(realData);
+	    		                      mPrinter.sendBytesData(new byte[]{(byte)0x0A});
+
+	    		                      mPrinter.sendBytesData(new byte[]{(byte)0x1c,(byte)0x26});
+	    		                      mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+       						 }
+       					}
+       				}
+
+                     Field field = dialog.getClass()
+  				            .getSuperclass().getDeclaredField(
+  				                     "mShowing" );
+  				    field.setAccessible( true );
+  				     //   将mShowing变量设为false,表示对话框已关�?
+  				    field.set(dialog, false );
+
+           }catch(Exception e)
+           {
+
+           }
+
+		}});
+
+         builder.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener()
+         {
+ 			@Override
+ 			public void onClick(DialogInterface dialog, int which)
+ 			{
+ 				 Field field;
+				try {
+					field = dialog.getClass()
+					            .getSuperclass().getDeclaredField(
+					                     "mShowing" );
+
+					field.setAccessible( true );
+				     //   将mShowing变量设为false,表示对话框已关�?
+				    field.set(dialog, true );
+				    dialog.dismiss();
+				} catch (NoSuchFieldException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				} catch (IllegalAccessException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				} catch (IllegalArgumentException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+
+ 			}
+
+ 		});
+
+         builder.create();
+         final AlertDialog dialog=builder.show();
+
+     }
+
+}

+ 69 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PictureUtils.java

@@ -0,0 +1,69 @@
+package com.printer.demo.utils;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Log;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+public class PictureUtils {
+
+
+	public static Bitmap compress(Bitmap image) {
+
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
+	    if( baos.toByteArray().length / 1024>1024) {//�ж����ͼƬ����1M,����ѹ������������ͼƬ��BitmapFactory.decodeStream��ʱ���
+	        baos.reset();//����baos�����baos
+	        image.compress(Bitmap.CompressFormat.JPEG, 50, baos);//����ѹ��50%����ѹ��������ݴ�ŵ�baos��
+	    }
+	    ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
+	    BitmapFactory.Options newOpts = new BitmapFactory.Options();
+	    //��ʼ����ͼƬ����ʱ��options.inJustDecodeBounds ���true��
+	    newOpts.inJustDecodeBounds = true;
+	    Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
+	    newOpts.inJustDecodeBounds = false;
+	    int w = newOpts.outWidth;
+	    int h = newOpts.outHeight;
+	    //���������ֻ��Ƚ϶���800*480�ֱ��ʣ����ԸߺͿ���������Ϊ
+	    float hh = 800f;//�������ø߶�Ϊ800f
+	    float ww = 480f;//�������ÿ��Ϊ480f
+	    //���űȡ������ǹ̶��������ţ�ֻ�ø߻��߿�����һ�����ݽ��м��㼴��
+	    int be = 1;//be=1��ʾ������
+//	    if (w > h && w > ww) {//�����ȴ�Ļ����ݿ�ȹ̶���С����
+//	    }
+	    be = (int) (newOpts.outWidth / ww);
+	    Log.i("fdh", "w:"+w+"h:"+h+"   newOpts.outWidth:"+newOpts.outWidth+"ww:"+ww+"be:"+be);
+
+//	    if (w > h && w > ww) {//�����ȴ�Ļ����ݿ�ȹ̶���С����
+//	        be = (int) (newOpts.outWidth / ww);
+//	    } else if (w < h && h > hh) {//����߶ȸߵĻ����ݿ�ȹ̶���С����
+//	        be = (int) (newOpts.outHeight / hh);
+//	    }
+	    if (be <= 0)
+	        be = 1;
+	    newOpts.inSampleSize = 8;//�������ű���
+//	    ���¶���ͼƬ��ע���ʱ�Ѿ���options.inJustDecodeBounds ���false��
+	    isBm = new ByteArrayInputStream(baos.toByteArray());
+	    bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
+	    Log.i("fdh", "inSampleSize:"+ newOpts.inSampleSize );
+	    Log.i("fdh", "heightUtils:"+bitmap.getHeight()+"----"+"widthUtils:"+bitmap.getWidth());
+
+	    return compressImage(bitmap);//ѹ���ñ�����С���ٽ�������ѹ��
+	}
+	public static Bitmap compressImage(Bitmap image) {
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//����ѹ������������100��ʾ��ѹ������ѹ��������ݴ�ŵ�baos��
+        int options = 100;
+        while ( baos.toByteArray().length / 1024>100) {  //ѭ���ж����ѹ����ͼƬ�Ƿ����100kb,���ڼ���ѹ��
+            baos.reset();//����baos�����baos
+            image.compress(Bitmap.CompressFormat.JPEG, options, baos);//����ѹ��options%����ѹ��������ݴ�ŵ�baos��
+            options -= 10;//ÿ�ζ�����10
+        }
+        ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//��ѹ���������baos��ŵ�ByteArrayInputStream��
+        Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//��ByteArrayInputStream��������ͼƬ
+        return bitmap;
+    }
+}

+ 130 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrefUtils.java

@@ -0,0 +1,130 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.text.format.Time;
+
+/**
+ * SharePreference封装
+ * 
+ * @author Kevin
+ * 
+ */
+public class PrefUtils {
+
+	public static final String PREF_NAME = "config";
+
+	public static boolean getBoolean(Context ctx, String key, boolean defaultValue) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		return sp.getBoolean(key, defaultValue);
+	}
+
+	public static void setBoolean(Context ctx, String key, boolean value) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		sp.edit().putBoolean(key, value).commit();
+	}
+
+	public static String getString(Context ctx, String key, String defaultValue) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		return sp.getString(key, defaultValue);
+	}
+
+	public static void setString(Context ctx, String key, String value) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		sp.edit().putString(key, value).commit();
+	}
+
+	public static int getInt(Context ctx, String key, int defaultValue) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		return sp.getInt(key, defaultValue);
+	}
+
+	public static void setInt(Context ctx, String key, int value) {
+		SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+		sp.edit().putInt(key, value).commit();
+	}
+
+	public static String getSystemTime() {
+		Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
+		t.setToNow(); // 取得系统时间。
+		int year = t.year;
+		int month = t.month + 1;
+		int date = t.monthDay;
+		int hour = t.hour; // 0-23
+		int minute = t.minute;
+		int seconds = t.second;
+		String tag = "AM";
+		if (hour >= 12) {
+			tag = "PM";
+		}
+		String time = date + "/" + month + "/" + year + " " + hour + ":" + minute + " " + tag;
+		return time;
+
+	}
+
+	public static String getSystemTime2() {
+		Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
+		t.setToNow(); // 取得系统时间。
+		int year = t.year;
+		int month = t.month + 1;
+		int date = t.monthDay;
+		int hour = t.hour; // 0-23
+		int minute = t.minute;
+		int seconds = t.second;
+		String tag = "AM";
+		if (hour >= 12) {
+			tag = "PM";
+		}
+		String time;
+		if (month < 10) {
+			if (seconds >= 10) {
+				time = year + "-0" + month + "-" + date + "     " + hour + ":" + minute + ":" + seconds;
+			} else {
+				time = year + "-0" + month + "-" + date + "     " + hour + ":" + minute + ":0" + seconds;
+			}
+
+		} else {
+			if (seconds >= 10) {
+				time = year + "-" + month + "-" + date + "     " + hour + ":" + minute + ":" + seconds;
+			} else {
+				time = year + "-" + month + "-" + date + "     " + hour + ":" + minute + ":0" + seconds;
+			}
+
+		}
+		return time;
+
+	}
+
+	public static String getSystemTime3() {
+		Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
+		t.setToNow(); // 取得系统时间。
+		int year = t.year;
+		int month = t.month + 1;
+		int date = t.monthDay;
+		int hour = t.hour; // 0-23
+		int minute = t.minute;
+		int seconds = t.second;
+		String tag = "AM";
+		if (hour >= 12) {
+			tag = "PM";
+		}
+		String time;
+		if (month < 10) {
+			if (seconds >= 10) {
+				time = year + "-0" + month + "-" + date;
+			} else {
+				time = year + "-0" + month + "-" + date;
+			}
+
+		} else {
+			if (seconds >= 10) {
+				time = year + "-" + month + "-" + date;
+			} else {
+				time = year + "-" + month + "-" + date;
+			}
+
+		}
+		return time;
+
+	}
+}

+ 22 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintBean.java

@@ -0,0 +1,22 @@
+package com.printer.demo.utils;
+
+
+public class PrintBean {
+    public String transferWaybillNo;
+    public String goodsQty;
+    public String flowDirectionCode;
+    public String serviceProduct;
+    public String goodsNum;
+
+    public PrintBean(String transferWaybillNo,
+                     String goodsQty,
+                     String flowDirectionCode,
+                     String serviceProduct,
+                     String goodsNum) {
+        this.transferWaybillNo = transferWaybillNo;
+        this.goodsQty = goodsQty;
+        this.flowDirectionCode = flowDirectionCode;
+        this.serviceProduct = serviceProduct;
+        this.goodsNum = goodsNum;
+    }
+}

+ 138 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel100.java

@@ -0,0 +1,138 @@
+package com.printer.demo.utils;
+
+import android.util.Log;
+
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+
+public class PrintLabel100 {
+
+
+	private static  int MULTIPLE = 11;
+	private static final int line_width_border = 1;
+	private static final int page_width = 75 * MULTIPLE;
+	private static final int page_height = 80 * MULTIPLE;
+	private static final int margin_horizontal = (int) (1.5 * MULTIPLE);
+	private static final int top_left_x = margin_horizontal;
+	private static final int margin_vertical = 3 * MULTIPLE;
+	private static final int top_left_y = margin_vertical;//32
+	private static final int border_width = page_width - 2 * margin_horizontal;
+	private static final int border_height = (int) (page_height - 5 * margin_vertical);
+	private static final int top_right_x = top_left_x + border_width;
+	private static final int bottom_left_y = top_left_y + border_height;
+	private static final int bottom_right_y = bottom_left_y;
+	private static final int bottom_right_x = top_right_x;
+	private static final int row36_column1_width = 10 * MULTIPLE;
+	private static final int row37_column3_width = 20 * MULTIPLE;
+	private static final int row36_sep1_x = top_left_x + row36_column1_width;
+	private static final int row37_sep2_x = top_right_x - row37_column3_width;
+	private static final int[] row_height = { 9 * MULTIPLE, 9 * MULTIPLE, 9 * MULTIPLE,9 * MULTIPLE,9 * MULTIPLE };
+	private static int startX;
+	private static int startX1;
+
+	public  synchronized static void doPrint(PrinterInstance iPrinter){
+		iPrinter.pageSetup(LablePaperType.Size_100mm,page_width, page_height);
+		drawBox(iPrinter);
+		drawVerticalSeparator(iPrinter);
+		drawRowContent(iPrinter);
+		iPrinter.print(PRotate.Rotate_0, 1);
+
+	}
+
+	private static void drawBox(PrinterInstance iPrinter) {
+		int border_top_left_y = top_left_y;
+//		int border_top_left_y = top_left_y + row_height[0];
+		iPrinter.drawBorder(3, top_left_x, top_left_y, bottom_right_x, bottom_right_y);
+		drawHorizontalSeparator(iPrinter);
+
+	}
+	private static void drawHorizontalSeparator(PrinterInstance iPrinter) {
+
+		int temp = top_left_y; //
+//		int temp = top_left_y+row_height[0]; //
+		for (int i = 0; i < row_height.length; i++)
+		{
+			temp += row_height[i];
+			int start_x = top_left_x;
+			int end_x = top_right_x;
+			Log.i("temp", "第"+(i+1)+"次");
+			iPrinter.drawLine(line_width_border, start_x, temp, end_x, temp, false);
+			/*if(i!= 3){
+				iPrinter.drawLine(line_width_border, start_x, temp, end_x, temp);
+			}else{
+				iPrinter.drawLine(line_width_border, row37_sep2_x, temp, end_x, temp);
+			}*/
+
+		}
+	}
+
+	private static void drawVerticalSeparator(PrinterInstance iPrinter) {
+
+		startX = top_left_x + ((top_right_x - top_left_x) / 10)*3;
+		startX1 = top_left_x + ((top_right_x - top_left_x) / 10)*5;
+		int startY = top_left_y+row_height[0];
+		int endY =  top_left_y+row_height[0]*5;
+		iPrinter.drawLine(line_width_border, startX, startY,startX, endY, false);
+
+		iPrinter.drawLine(line_width_border, startX1, endY,startX1, bottom_right_y, false);
+
+	}
+
+	private static void drawRowContent(PrinterInstance iPrinter) {
+
+		//第一行内容
+		iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y+row_height[0], PAlign.CENTER, PAlign.CENTER,
+				"XX物流",LableFontSize.Size_64, 1, 0, 0, 0, PRotate.Rotate_0);
+		//第二行内容 左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y+row_height[0], startX, top_left_y+row_height[0]*2, PAlign.CENTER, PAlign.CENTER,
+				"寄件人", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+//		Log.i("sp", "startX:"+startX+"top_right_x:"+top_right_x);
+		//第二行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y+row_height[0], bottom_right_x, top_left_y+row_height[0]*2, PAlign.CENTER, PAlign.CENTER,
+				"王西 010-1234567",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+
+		//第三行内容  左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y+row_height[0]*2, startX, top_left_y+row_height[0]*3, PAlign.CENTER, PAlign.CENTER,
+				"收件人",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+		//第三行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y+row_height[0]*2, top_right_x, top_left_y+row_height[0]*3, PAlign.CENTER, PAlign.CENTER,
+				"业务经理 杨凯 156 1212 9516",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+		//第四行内容  左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y+row_height[0]*3, startX, top_left_y+row_height[0]*4, PAlign.CENTER, PAlign.CENTER,
+								"收件人地址",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+
+		//第四行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y+row_height[0]*3, top_right_x, top_left_y+row_height[0]*4, PAlign.START, PAlign.CENTER,
+								"  XX市XX区XX号院XX号楼XX层",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+		//第五行内容  左边栏内容
+		iPrinter.drawText(top_left_x, top_left_y+row_height[0]*4, startX, top_left_y+row_height[0]*5, PAlign.CENTER, PAlign.CENTER,
+						"收件人签名",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+
+		//第六行内容 右边栏内容
+		iPrinter.drawText(startX, top_left_y+row_height[0]*4, top_right_x, top_left_y+row_height[0]*5, PAlign.CENTER, PAlign.CENTER,
+						"业务经理 杨凯 156 1212 9516",  LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+		//第6行左侧条码
+		iPrinter.drawBarCode(top_left_x+35, top_left_y+row_height[0]*5, startX1+35, bottom_right_y-40, PAlign.CENTER, PAlign.CENTER, 0, 0,
+				"010-1234567",  PBarcodeType.CODE128, 1, 80, PRotate.Rotate_0);
+		//第6行左侧条码下面的内容
+		iPrinter.drawText(top_left_x, top_left_y+row_height[0]*5+90, startX1, bottom_right_y, PAlign.CENTER, PAlign.CENTER,
+								"010-12345678", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+//		iPrinter.drawQrCode(startX1+10, top_left_y+row_height[0]*5+30,
+//				"https://www.baidu.com/",
+//				PRotate.Rotate_0, startX, startX);
+
+		//第6行左侧条码下面的内容
+		iPrinter.drawText(startX1+180, top_left_y+row_height[0]*5, bottom_right_x, bottom_right_y, PAlign.CENTER, PAlign.CENTER,
+										"扫一扫     关注我", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+
+	}
+
+
+
+
+}

+ 69 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel58.java

@@ -0,0 +1,69 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import com.printer.demo.R;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.ReadException;
+import com.printer.sdk.exception.WriteException;
+import com.printer.sdk.utils.Utils;
+
+public class PrintLabel58 {
+
+    private static int MULTIPLE = 5;
+    private static final int line_width_border = 2;
+    private static final int page_width = 75 * MULTIPLE;// 384����
+    private static final int page_height = 90 * MULTIPLE;
+    private static final int margin_horizontal = 2 * MULTIPLE;
+    private static final int top_left_x = margin_horizontal;
+    private static final int margin_vertical = 2 * MULTIPLE;
+    private static final int top_left_y = margin_vertical;// 32
+    private static final int border_width = page_width - 2 * margin_horizontal;
+    private static final int border_height = page_height - 2 * margin_vertical;
+    private static final int top_right_x = top_left_x + border_width;
+    private static final int bottom_left_y = top_left_y + border_height;
+    private static final int bottom_right_y = bottom_left_y;
+    private static final int bottom_right_x = top_right_x;
+    private static final int row36_column1_width = 10 * MULTIPLE;
+    private static final int row37_column3_width = 20 * MULTIPLE;
+    private static final int row36_sep1_x = top_left_x + row36_column1_width;
+    private static final int row37_sep2_x = top_right_x - row37_column3_width;
+    private static final int[] row_height = {8 * MULTIPLE * 2, 10 * MULTIPLE, 10 * MULTIPLE, 10 * MULTIPLE,
+            10 * MULTIPLE, 10 * MULTIPLE};
+    private static final String TAG = "PrintLabel";
+
+    public  synchronized  static void doPrint(final PrinterInstance iPrinter, final Resources resources) {
+        iPrinter.pageSetup(LablePaperType.Size_58mm, 384, 540);
+        iPrinter.drawText(0, 0, 200, 200, PAlign.START, PAlign.START, "扫一扫二维码连接打印机", LableFontSize.Size_48, 0,
+                0, 0, 0, PRotate.Rotate_0);
+       // iPrinter.drawQrCode(230, 0, "12345678", PRotate.Rotate_0, 6, 1);
+        iPrinter.drawBarCode(1, 150, "12345678", PBarcodeType.CODE128, 2, 75, PRotate.Rotate_0);
+        Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.ztl);
+        iPrinter.drawGraphic(0, 240, Utils.zoomImage(bitmap, 384,0));
+        iPrinter.print(PRotate.Rotate_0, 0);
+
+    }
+
+    public void doPrintTSPL(PrinterInstance iPrinter, Resources resources, Context mContext)
+            throws WriteException, PrinterPortNullException, ReadException, ParameterErrorException, Exception {
+        iPrinter.pageSetupTSPL(PrinterConstants.SIZE_58mm, 56 * 8, 45 * 8);
+        iPrinter.printText("CLS\r\n");
+        iPrinter.drawTextTSPL(30, 30, true, 1, 1, null, "区域内打印图片效果演示:");
+        Bitmap bmp = BitmapFactory.decodeResource(resources, R.drawable.goodwork);
+        iPrinter.drawBorderTSPL(3, 50, 50, 400, 350);
+        iPrinter.drawBitmapTSPL(50, 50, 400, 350, PAlign.CENTER, PAlign.CENTER, 0, bmp);
+        iPrinter.printTSPL(1, 1);
+    }
+
+}

+ 179 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80.java

@@ -0,0 +1,179 @@
+package com.printer.demo.utils;
+
+import android.util.Log;
+
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+
+public class PrintLabel80 {
+
+    private static int MULTIPLE = 8;
+    private static final int line_width_border = 2;
+    private static final int page_width = 75 * MULTIPLE;
+    private static final int page_height = 90 * MULTIPLE;
+    private static final int margin_horizontal = 2 * MULTIPLE;
+    private static final int top_left_x = margin_horizontal;
+    private static final int margin_vertical = 2 * MULTIPLE;
+    private static final int top_left_y = margin_vertical;// 32
+    private static final int border_width = page_width - 2 * margin_horizontal;
+    private static final int border_height = page_height - 2 * margin_vertical;
+    private static final int top_right_x = top_left_x + border_width;
+    private static final int bottom_left_y = top_left_y + border_height;
+    private static final int bottom_right_y = bottom_left_y;
+    private static final int bottom_right_x = top_right_x;
+    private static final int row36_column1_width = 10 * MULTIPLE;
+    private static final int row37_column3_width = 20 * MULTIPLE;
+    private static final int row36_sep1_x = top_left_x + row36_column1_width;
+    private static final int row37_sep2_x = top_right_x - row37_column3_width;
+    private static final int[] row_height = {8 * MULTIPLE * 2, 10 * MULTIPLE, 10 * MULTIPLE, 10 * MULTIPLE,
+            10 * MULTIPLE, 10 * MULTIPLE};
+    private static final String TAG = "PrintLabel";
+
+    public synchronized static void doPrint(final PrinterInstance iPrinter) {
+        iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
+        drawBox(iPrinter);
+        drawVerticalSeparator(iPrinter);
+        drawRowContent(iPrinter);
+        iPrinter.print(PRotate.Rotate_0, 1);
+
+    }
+
+    private static void drawRowContent(PrinterInstance iPrinter) {
+
+        int area_start_x = top_left_x + (top_right_x - top_left_x) / 2;
+        int area_start_y = top_left_y;
+        // 第一行内容
+        iPrinter.drawText(area_start_x, area_start_y, bottom_right_x, top_left_y + row_height[0] - line_width_border,
+                PAlign.CENTER, PAlign.CENTER, "定时达1", LableFontSize.Size_64, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第二行内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0], bottom_right_x,
+                top_left_y + row_height[0] + row_height[1], PAlign.CENTER, PAlign.CENTER, "DF1234567890",
+                LableFontSize.Size_64, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第三行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 6, top_left_y + row_height[0] + row_height[1], top_left_x + row_height[1],
+                top_left_y// +3弥补边框线宽误差
+                        + row_height[0] + row_height[1] * 2,
+                PAlign.CENTER, PAlign.CENTER, "目的 分拨 ", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第三行内容 中间栏内容
+        iPrinter.drawText(top_left_x + row_height[1], top_left_y + row_height[0] + row_height[1],
+                top_left_x + 3 * (top_right_x - top_left_x) / 4, top_left_y + row_height[0] + row_height[1] * 2,
+                PAlign.CENTER, PAlign.CENTER, "西安分拨中心", LableFontSize.Size_32, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第三行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 3 * (top_right_x - top_left_x) / 4, top_left_y + row_height[0] + row_height[1],
+                bottom_right_x, top_left_y + row_height[0] + row_height[1] * 2, PAlign.CENTER, PAlign.CENTER, "第1件",
+                LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第四行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 6, top_left_y + row_height[0] + row_height[1] * 2,
+                top_left_x + row_height[1] + 3, top_left_y + row_height[0] + row_height[1] * 3, PAlign.CENTER,
+                PAlign.CENTER, "到达 网点 ", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第四行内容 中间栏内容
+        iPrinter.drawText(top_left_x + row_height[1], top_left_y + row_height[0] + row_height[1] * 2,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4, top_left_y + row_height[0] + row_height[1] * 3,
+                PAlign.CENTER, PAlign.CENTER, "西安长线", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第四行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] * 2, bottom_right_x,
+                top_left_y + row_height[0] + row_height[1] * 3, PAlign.CENTER, PAlign.CENTER, "1",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第五行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 6, top_left_y + row_height[0] + row_height[1] * 3,
+                top_left_x + row_height[1] + 3, top_left_y + row_height[0] + row_height[1] * 4, PAlign.CENTER,
+                PAlign.CENTER, "出发 网点 ", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第五行内容 中间栏内容
+        iPrinter.drawText(top_left_x + row_height[1], top_left_y + row_height[0] + row_height[1] * 3 + 6,
+                top_left_x + 3 // +6弥补线宽的误差
+                        * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] * 4, PAlign.CENTER, PAlign.CENTER,
+                "测试二级网点         (2016-05-31 19:02)", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第五行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] * 3, bottom_right_x,
+                top_left_y + row_height[0] + row_height[1] * 5, PAlign.CENTER, PAlign.CENTER, "袋装",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第六行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 6, top_left_y + row_height[0] + row_height[1] * 4,
+                top_left_x + row_height[1] + 3, top_left_y + row_height[0] + row_height[1] * 5, PAlign.CENTER,
+                PAlign.CENTER, "详细 地址 ", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        // 第六行内容 中间栏内容
+        iPrinter.drawText(top_left_x + row_height[1], top_left_y + row_height[0] + row_height[1] * 4,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4, top_left_y + row_height[0] + row_height[1] * 5,
+                PAlign.CENTER, PAlign.CENTER, "陕西省西安市临潼区秦始皇陵兵马俑一号坑五排三列俑", LableFontSize.Size_24, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+
+        // 打印第七行条码
+
+        iPrinter.drawBarCode(top_left_x, top_left_y + row_height[0] + row_height[1] * 5,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4, bottom_right_y, PAlign.CENTER, PAlign.CENTER, 0, 0,
+                "DF12345678900010292001", PBarcodeType.CODE128, 1, 70, PRotate.Rotate_0);
+
+        // 打印第七行条码下方的文字
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] + row_height[1] * 5 + 110,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4, bottom_right_y, PAlign.CENTER, PAlign.CENTER,
+                "DF12345678900010292001", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] * 5, bottom_right_x, bottom_right_y, PAlign.CENTER,
+                PAlign.CENTER, "派送", LableFontSize.Size_48, 1, 0, 0, 0, PRotate.Rotate_0);
+    }
+
+    private static void drawHorizontalSeparator(PrinterInstance iPrinter, int start_x, int end_x) {
+
+        int temp = top_left_y; //
+        for (int i = 0; i < row_height.length; i++) {
+            temp += row_height[i];
+            // int start_x = top_left_x;
+            // int end_x = top_right_x;
+            // Log.i("temp", "第"+(i+1)+"次");
+            if (i == 4)
+                end_x = top_left_x + 3 * (top_right_x - top_left_x) / 4;
+            else
+                end_x = bottom_right_x;
+            iPrinter.drawLine(2, start_x, temp, end_x, temp, true);
+            /*
+             * if(i!= 3){ iPrinter.drawLine(line_width_border, start_x, temp,
+			 * end_x, temp); }else{ iPrinter.drawLine(line_width_border,
+			 * row37_sep2_x, temp, end_x, temp); }
+			 */
+        }
+    }
+
+    //
+    private static void drawVerticalSeparator(PrinterInstance iPrinter) {
+
+        int start_x = top_left_x + row_height[1];
+        int start_y = top_left_y + row_height[0] + row_height[1];
+        int end_x = start_x;
+        int end_y = top_left_y + row_height[0] + row_height[1] * 5;
+        // 从左边数起第一条分割线
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+        // 从左边数起第二条分割线
+        start_x = top_left_x + (top_right_x - top_left_x) / 2;
+        start_y = top_left_y;
+        end_x = start_x;
+        end_y = start_y + row_height[0];
+        Log.i(TAG, "start_x;" + start_x + "end_x:" + end_x);
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+        // 从左边数起第三条分割线
+        start_x = top_left_x + 3 * (top_right_x - top_left_x) / 4;
+        start_y = top_left_y + row_height[0] + row_height[1];
+        end_x = start_x;
+        end_y = bottom_right_y;
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+
+    }
+
+    private static void drawBox(PrinterInstance iPrinter) {
+        int border_top_left_y = top_left_y;
+        iPrinter.drawBorder(3, top_left_x, border_top_left_y, bottom_right_x, bottom_right_y);
+        drawHorizontalSeparator(iPrinter, top_left_x, bottom_right_x);
+
+    }
+
+}

+ 179 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80_1.java

@@ -0,0 +1,179 @@
+package com.printer.demo.utils;
+
+import android.util.Log;
+
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+
+public class PrintLabel80_1 {
+	// 材料80mm
+
+	private static int MULTIPLE = 2;
+	private static final int line_width_border = 2; // 边框
+	private static final int page_width = 260 * MULTIPLE; // 内容宽
+	private static final int page_height = 165 * MULTIPLE; // 内容高
+	private static final int margin_horizontal = 2 * MULTIPLE; // 水平边距
+	private static final int top_left_x = margin_horizontal; // 左上角x坐标,左上角为原点
+	private static final int margin_vertical = 2 * MULTIPLE; // 垂直边距
+	private static final int top_left_y = margin_vertical; // 左上角y坐标
+	private static final int border_width = page_width - 2 * margin_horizontal; // 边框宽度
+	private static final int border_height = page_height - 2 * margin_vertical; // 边框高度
+	private static final int top_right_x = top_left_x + border_width; // 右上角x坐标
+	private static final int bottom_left_y = top_left_y + border_height; // 左下角y坐标
+	private static final int bottom_right_y = bottom_left_y; // 右下角y坐标
+	private static final int bottom_right_x = top_right_x; // 右下角x坐标
+	private static final int row36_column1_width = 10 * MULTIPLE;
+	private static final int row37_column3_width = 20 * MULTIPLE;
+	private static final int row36_sep1_x = top_left_x + row36_column1_width;
+	private static final int row37_sep2_x = top_right_x - row37_column3_width;
+	private static final int[] row_height = { 10 * MULTIPLE * 2, 27 * MULTIPLE, 27 * MULTIPLE, 27 * MULTIPLE,
+			27 * MULTIPLE };
+	private static final String TAG = "PrintLabel";
+
+	public void doPrint(PrinterInstance iPrinter) {
+
+		iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
+		drawBox(iPrinter);
+		// drawVerticalSeparator(iPrinter);
+		drawRowContent(iPrinter);
+		iPrinter.print(PRotate.Rotate_0, 1);
+
+	}
+
+	private void drawRowContent(PrinterInstance iPrinter) {
+
+		// int area_start_x = top_left_x + (top_right_x - top_left_x) / 2;
+		// int area_start_y = top_left_y;
+		// 第一行左一内容
+		// iPrinter.drawText(top_left_x, top_left_y, top_left_x + 2 *
+		// (border_width) / 3 + 20, top_left_y + row_height[1],
+		// PAlign.START, PAlign.END, "全程路运 12-02 04:22浙江",
+		// LableFontSize.Size_32, 1, 0, 0, 0, PRotate.Rotate_0);
+		iPrinter.drawText(top_left_x, top_left_y, "全程路运 12-02 04:22浙江", LableFontSize.Size_32, PRotate.Rotate_0, 1, 0,
+				0);
+		// 第一行左二内容
+		/*
+		 * iPrinter.drawText(top_left_x + 5 * (border_width) / 9, top_left_y ,
+		 * top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] ,
+		 * PAlign.CENTER, PAlign.CENTER, "浙江", LableFontSize.Size_32, 1, 0, 0,
+		 * 0, PRotate.Rotate_0);
+		 */
+		// 第一行右二内容
+		iPrinter.drawText(top_left_x + 2 * (border_width) / 3 + 20, top_left_y,
+				top_left_x + 7 * (border_width) / 9 + 50, top_left_y + row_height[1], PAlign.END, PAlign.END, "邮特",
+				LableFontSize.Size_32, 1, 0, 0, 0, PRotate.Rotate_0);
+		// 第一行右一内容
+		iPrinter.drawText(top_left_x + 7 * (border_width) / 9 + 30, top_left_y, top_right_x, top_left_y + row_height[1],
+				PAlign.END, PAlign.END, "2014", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+		// 第二行内容
+		iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1], top_right_x,
+				top_left_y + row_height[1] * 2, PAlign.CENTER, PAlign.END, "特快", LableFontSize.Size_32, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第三行左一内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[1] * 2, top_left_x + 5 * (border_width) / 9,
+				top_left_y + row_height[1] * 3, PAlign.START, PAlign.END, "义乌市 ", LableFontSize.Size_48, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第三行左二内容
+		iPrinter.drawText(top_left_x + 5 * (border_width) / 9, top_left_y + row_height[1] * 2 + 26,
+				top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 3, PAlign.START, PAlign.START, "局收",
+				LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+		// 第三行右二内容
+		iPrinter.drawText(top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 2 + 26,
+				top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 3, PAlign.END, PAlign.START, "号码",
+				LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+		// 第三行右一内容
+		iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 2, top_right_x,
+				top_left_y + row_height[1] * 3, PAlign.CENTER, PAlign.END, "58280" + " ", LableFontSize.Size_24, 1, 0,
+				2, 0, PRotate.Rotate_0);
+		// 第四行左一内容
+		iPrinter.drawText(top_left_x, top_left_y + row_height[1] * 3, top_left_x + 5 * (border_width) / 9,
+				top_left_y + row_height[1] * 4, PAlign.START, PAlign.END, "江西集散  7件", LableFontSize.Size_32, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+		// 第四行左二内容
+		iPrinter.drawText(top_left_x + 5 * (border_width) / 9, top_left_y + row_height[1] * 3 + 26,
+				top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 4, PAlign.START, PAlign.START, "局发",
+				LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+		// 第四行右二内容
+		iPrinter.drawText(top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 3 + 26,
+				top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 4, PAlign.END, PAlign.START, "重量",
+				LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+		// 第四行右一内容
+		iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 3, top_right_x,
+				top_left_y + row_height[1] * 4, PAlign.CENTER, PAlign.END, " " + "10" + "  ", LableFontSize.Size_24, 1,
+				0, 2, 0, PRotate.Rotate_0);
+		// 打印第五行条码
+
+		// iPrinter.drawBarCode(top_left_x, top_left_y + row_height[1] * 4,
+		// bottom_right_x, bottom_right_y - 30,
+		// PAlign.START, PAlign.END, 0, 0,
+		// "33000166-32206100-1-131-5828-0060-3-0", PBarcodeType.CODE128, 1, 60,
+		// PRotate.Rotate_0);
+		iPrinter.drawBarCode(0, top_left_y + row_height[1] * 4, "33000166322061001131582800603",
+				PBarcodeType.CODE128, 1, 60, PRotate.Rotate_0);
+
+		// 打印第五行条码下方的文字
+		iPrinter.drawText(top_left_x, top_left_y + bottom_right_y - 30, bottom_right_x, bottom_right_y, PAlign.START,
+				PAlign.START, "33000166-32206100-1-131-5828-0060-3", LableFontSize.Size_24, 1, 0, 0, 0,
+				PRotate.Rotate_0);
+
+	}
+
+	private void drawHorizontalSeparator(PrinterInstance iPrinter, int start_x, int end_x) {
+
+		int temp = top_left_y; //
+		for (int i = 1; i < row_height.length; i++) {
+			temp += row_height[i];
+			int start_x1 = top_left_x + 7 * (border_width) / 9;
+			int end_x1 = top_left_x + 5 * (border_width) / 9;
+			// Log.i("temp", "第"+(i+1)+"次");
+			iPrinter.drawLine(2, start_x, temp, end_x1, temp, true);
+			/*
+			 * if(i > 2 ){ iPrinter.drawLine(1, start_x1, temp,
+			 * end_x,temp,true); }
+			 */
+			/*
+			 * if(i!= 3){ iPrinter.drawLine(line_width_border, start_x, temp,
+			 * end_x, temp); }else{ iPrinter.drawLine(line_width_border,
+			 * row37_sep2_x, temp, end_x, temp); }
+			 */
+		}
+	}
+
+	private void drawVerticalSeparator(PrinterInstance iPrinter) {
+
+		int start_x = top_left_x + row_height[1];
+		int start_y = top_left_y + row_height[0] + row_height[1];
+		int end_x = start_x;
+		int end_y = top_left_y + row_height[0] + row_height[1] * 5;
+		// 从左边数起第一条分割线
+		iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+		// 从左边数起第二条分割线
+		start_x = top_left_x + (top_right_x - top_left_x) / 2;
+		start_y = top_left_y;
+		end_x = start_x;
+		end_y = start_y + row_height[0];
+		Log.i(TAG, "start_x;" + start_x + "end_x:" + end_x);
+		iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+		// 从左边数起第三条分割线
+		start_x = top_left_x + 3 * (top_right_x - top_left_x) / 4;
+		start_y = top_left_y + row_height[0] + row_height[1];
+		end_x = start_x;
+		end_y = bottom_right_y;
+		iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+
+	}
+
+	private void drawBox(PrinterInstance iPrinter) {
+		int border_top_left_y = top_left_y;
+		// iPrinter.drawBorder(3, top_left_x, border_top_left_y, bottom_right_x,
+		// bottom_right_y);
+		drawHorizontalSeparator(iPrinter, top_left_x, bottom_right_x);
+
+	}
+
+}

+ 400 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabel80_test.java

@@ -0,0 +1,400 @@
+package com.printer.demo.utils;
+
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+
+import com.printer.demo.R;
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.utils.XLog;
+
+import java.util.ArrayList;
+
+public class PrintLabel80_test {
+
+    private static int MULTIPLE = 8;
+    private static final int line_width_border = 2;
+    private static final int page_width = 77 * MULTIPLE;
+    private static final int page_height = 50 * MULTIPLE;
+    private static final int margin_horizontal = 2 * MULTIPLE;
+    private static final int top_left_x = margin_horizontal;
+    private static final int margin_vertical = 2 * MULTIPLE;
+    private static final int top_left_y = margin_vertical;// 32
+    private static final int border_width = page_width - 2 * margin_horizontal;
+    private static final int border_height = page_height - 2 * margin_vertical;
+    private static final int top_right_x = top_left_x + border_width;
+    private static final int bottom_left_y = top_left_y + border_height;
+    private static final int bottom_right_y = bottom_left_y;
+    private static final int bottom_right_x = top_right_x;
+    private static final int row36_column1_width = 10 * MULTIPLE;
+    private static final int row37_column3_width = 20 * MULTIPLE;
+    private static final int row36_sep1_x = top_left_x + row36_column1_width;
+    private static final int row37_sep2_x = top_right_x - row37_column3_width;
+    private static final int[] row_height = {6 * MULTIPLE, 14 * MULTIPLE, 7 * MULTIPLE, 4 * MULTIPLE, 14 * MULTIPLE};
+    private static final String TAG = "PrintLabel";
+
+    public void doPrint(final PrinterInstance iPrinter) {
+        print(iPrinter, null);
+
+    }
+
+    ArrayList<String> mList;
+    String mCode;
+
+    public void doPrint(final PrinterInstance iPrinter, String code, final Resources resources, int begain, int end) {
+        mCode = code;
+        if (end - begain >= 20) {
+          //  ComToastUtils.showShortToast("单次打印不能超过20个货单");
+            return;//避免打印机损坏
+        }
+        int num = (end - begain) == 0 ? 1 : end - begain;
+        for (int i = 0; i < num; i++) {
+            print(iPrinter, resources);
+        }
+    }
+
+    public void doPrint(final PrinterInstance iPrinter, final Resources resources, ArrayList<PrintBean> list) {
+        for (int i = 0; i < list.size(); i++) {
+            print(iPrinter, resources, list.get(i));
+        }
+    }
+
+    private void print(PrinterInstance iPrinter, Resources resources, PrintBean data) {
+        if (resources == null) return;
+        iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
+        drawBox(iPrinter);
+        drawVerticalSeparator(iPrinter);
+        drawRowContent(iPrinter, resources, data);
+        iPrinter.print(PRotate.Rotate_0, 1);
+    }
+
+    private void print(PrinterInstance iPrinter, Resources resources) {
+        if (resources == null) return;
+        iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
+        drawBox(iPrinter);
+        drawVerticalSeparator(iPrinter);
+        drawRowContent(iPrinter, resources);
+        iPrinter.print(PRotate.Rotate_0, 1);
+    }
+
+    private void drawRowContent(PrinterInstance iPrinter, final Resources resources, PrintBean data) {
+        int area_start_x = top_left_x;
+        int area_start_y = top_left_y;
+
+        // 第一左边图标
+        Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.label_icon7);
+        iPrinter.drawGraphic(
+                top_left_x + 3,
+                top_left_y + 3,
+                top_left_x + 136,
+                top_left_y + row_height[0] - 5,
+                PAlign.START,
+                PAlign.START,
+                136,
+                row_height[0] - 10,
+                bitmap);
+
+
+        // 第一行内容
+        iPrinter.drawText(
+                area_start_x,
+                area_start_y,
+                bottom_right_x,
+                top_left_y + row_height[0] - line_width_border,
+                PAlign.CENTER, PAlign.CENTER, "安迅卡航电子标签", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第二行内容 条形码
+        iPrinter.drawBarCode(
+                top_left_x,
+                top_left_y + row_height[0] + 3,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] - 30,
+                PAlign.CENTER, PAlign.CENTER, 0, 0,
+                data.transferWaybillNo,
+                PBarcodeType.CODE128, 1, 75, PRotate.Rotate_0);
+
+        // 第二行内容 条形码下文字
+        iPrinter.drawText(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] - 30,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1],
+                PAlign.CENTER, PAlign.CENTER,
+                data.transferWaybillNo,
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第二行内容 右边文字
+        iPrinter.drawText(
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0],
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1],
+                PAlign.CENTER, PAlign.CENTER,
+                "好到家",
+                LableFontSize.Size_16, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第三行内容
+        iPrinter.drawText(top_left_x + 6,
+                top_left_y + row_height[0] + row_height[1],
+                bottom_right_x - 6,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],// +3弥补边框线宽误差
+                PAlign.CENTER, PAlign.CENTER,
+                data.flowDirectionCode,
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第四行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 10,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],
+                top_left_x + 14 * MULTIPLE,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3],
+                PAlign.START,
+                PAlign.CENTER,
+                "货物编号",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第四行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 14 * MULTIPLE,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3],
+                PAlign.CENTER,
+                PAlign.CENTER,
+                data.goodsNum.replace(data.transferWaybillNo + "-", ""),
+                LableFontSize.Size_24,
+                1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 条形码上方文字
+        iPrinter.drawText(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 5,
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 30,
+                PAlign.CENTER, PAlign.CENTER,
+                data.goodsNum,
+                LableFontSize.Size_24,
+                1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 条形码
+        drawBarCode(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 30,
+                top_right_x - 20,
+                bottom_left_y - 5,
+                PAlign.CENTER, PAlign.CENTER, 0, 0,
+                data.goodsNum,
+                PBarcodeType.CODE128, 1, 80, PRotate.Rotate_0);
+    }
+
+    private void drawRowContent(PrinterInstance iPrinter, final Resources resources) {
+        int area_start_x = top_left_x;
+        int area_start_y = top_left_y;
+
+        // 第一左边图标
+        Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.label_icon7);
+        iPrinter.drawGraphic(
+                top_left_x + 3,
+                top_left_y + 3,
+                top_left_x + 136,
+                top_left_y + row_height[0] - 5,
+                PAlign.START,
+                PAlign.START,
+                136,
+                row_height[0] - 10,
+                bitmap);
+
+
+        // 第一行内容
+        iPrinter.drawText(
+                area_start_x,
+                area_start_y,
+                bottom_right_x,
+                top_left_y + row_height[0] - line_width_border,
+                PAlign.CENTER, PAlign.CENTER, "安迅卡航电子标签", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第二行内容 条形码
+        iPrinter.drawBarCode(
+                top_left_x,
+                top_left_y + row_height[0] + 3,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1] - 30,
+                PAlign.CENTER, PAlign.CENTER, 0, 0,
+                mCode, PBarcodeType.CODE128, 1, 75, PRotate.Rotate_0);
+
+        // 第二行内容 条形码下文字
+        iPrinter.drawText(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] - 30,
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0] + row_height[1],
+                PAlign.CENTER, PAlign.CENTER, mCode, LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第二行内容 右边文字
+        iPrinter.drawText(
+                top_left_x + 3 * (top_right_x - top_left_x) / 4,
+                top_left_y + row_height[0],
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1],
+                PAlign.CENTER, PAlign.CENTER, "好到家", LableFontSize.Size_16, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第三行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 6,
+                top_left_y + row_height[0] + row_height[1],
+                bottom_right_x - 6,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],// +3弥补边框线宽误差
+                PAlign.CENTER, PAlign.CENTER, "YZ0100A1-010001-TC010001-TC021002-021003-BJ0210B1",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+
+        // 第四行内容 左边栏内容
+        iPrinter.drawText(top_left_x + 10,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],
+                top_left_x + 14 * MULTIPLE,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3],
+                PAlign.START,
+                PAlign.CENTER, "货物编号",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第四行内容 右边栏内容
+        iPrinter.drawText(top_left_x + 14 * MULTIPLE,
+                top_left_y + row_height[0] + row_height[1] + row_height[2],
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3],
+                PAlign.CENTER,
+                PAlign.CENTER, "9999-9999", LableFontSize.Size_24,
+                1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 条形码下文字
+        iPrinter.drawText(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 5,
+                top_right_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 30,
+                PAlign.CENTER, PAlign.CENTER, "KY202104160000002-9999-1111", LableFontSize.Size_24,
+                1, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 条形码
+        drawBarCode(
+                top_left_x,
+                top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3] + 30,
+                top_right_x - 20,
+                bottom_left_y - 5,
+                PAlign.CENTER, PAlign.CENTER, 0, 0,
+                "KY202104160000002-9999-1111", PBarcodeType.CODE128, 1, 80, PRotate.Rotate_0);
+    }
+
+    public void drawBarCode(int area_start_x, int area_start_y, int area_end_x, int area_end_y, PAlign xAlign, PAlign yAlign, int start_x, int start_y, String text, PBarcodeType type, int linewidth, int height, PRotate rotate) {
+        // int xa = false;
+        byte xa;
+        if (xAlign == PAlign.CENTER) {
+            xa = 1;
+        } else if (xAlign == PAlign.END) {
+            xa = 2;
+        } else {
+            xa = 0;
+        }
+
+        if (yAlign == PAlign.CENTER) {
+            start_y = area_start_y + (area_end_y - area_start_y - height) / 2;
+        } else if (yAlign == PAlign.END) {
+            start_y = area_end_y - height;
+        } else {
+            start_y = area_start_y;
+        }
+
+        String barcodeType = "128";
+        if (type == PBarcodeType.CODABAR) {
+            barcodeType = "CODABAR";
+        } else if (type == PBarcodeType.CODE128) {
+            barcodeType = "128";
+        } else if (type == PBarcodeType.CODE39) {
+            barcodeType = "39";
+        } else if (type == PBarcodeType.CODE93) {
+            barcodeType = "93";
+        } else if (type == PBarcodeType.JAN8_EAN8) {
+            barcodeType = "EAN8";
+        } else if (type == PBarcodeType.JAN3_EAN13) {
+            barcodeType = "EAN13";
+        } else if (type == PBarcodeType.UPC_A) {
+            barcodeType = "UPCA";
+        } else if (type == PBarcodeType.UPC_E) {
+            barcodeType = "UPCE";
+        }
+
+        String str = "BA " + area_start_x + " " + area_start_y + " " + area_end_x + " " + area_end_y + " " + xa + "\r\n";
+        XLog.d("PrinterInstance", "yxz at PrinterInstance.java drawBarCode() 区域内打印条码:str:" + str);
+        PrinterInstance.mPrinter.printText(str);
+        String st1 = "B";
+        if (rotate != PRotate.Rotate_0) {
+            st1 = "VB";
+        }
+
+        String str2 = st1 + " " + barcodeType + " " + linewidth + " 2 " + height + " " + area_start_x + " " + start_y + " " + text + "\r\n";
+        PrinterInstance.mPrinter.printText(str2);
+        XLog.d("PrinterInstance", "yxz at PrinterInstance.java drawBarCode() 区域内打印条码:str2:" + str2);
+        String str3 = "BA 0 0 0 0 3\r\n";
+        PrinterInstance.mPrinter.printText(str3);
+        XLog.d("PrinterInstance", "yxz at PrinterInstance.java drawBarCode() 区域内打印条码:str3:" + str3);
+    }
+
+    private void drawHorizontalSeparator(PrinterInstance iPrinter, int start_x, int end_x) {
+
+        int temp = top_left_y; //
+        for (int i = 0; i < row_height.length; i++) {
+            temp += row_height[i];
+            // int start_x = top_left_x;
+            // int end_x = top_right_x;
+            // Log.i("temp", "第"+(i+1)+"次");
+            if (i == 4) {
+                end_x = bottom_right_x;
+                return;
+            }
+
+            iPrinter.drawLine(2, start_x, temp, end_x, temp, true);
+            /*
+             * if(i!= 3){ iPrinter.drawLine(line_width_border, start_x, temp,
+             * end_x, temp); }else{ iPrinter.drawLine(line_width_border,
+             * row37_sep2_x, temp, end_x, temp); }
+             */
+        }
+    }
+
+    //
+    private void drawVerticalSeparator(PrinterInstance iPrinter) {
+        int start_x = top_left_x + 14 * MULTIPLE;
+        int start_y = top_left_y + row_height[0] + row_height[1] + row_height[2];
+        int end_x = start_x;
+        int end_y = top_left_y + row_height[0] + row_height[1] + row_height[2] + row_height[3];
+        // 从左边数起第一条分割线
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+      /*  // 从左边数起第二条分割线
+        start_x = start_x + 15 * MULTIPLE;
+        // start_y = top_left_y;
+        end_x = start_x;
+        //end_y = start_y + row_height[0];
+        Log.i(TAG, "start_x;" + start_x + "end_x:" + end_x);
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);*/
+        // 从左边数起第三条分割线
+        start_x = top_left_x + 3 * (top_right_x - top_left_x) / 4 + 4;
+        start_y = top_left_y + row_height[0];
+        end_x = start_x;
+        end_y = top_left_y + row_height[0] + row_height[1];
+        iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
+    }
+
+    private void drawBox(PrinterInstance iPrinter) {
+        int border_top_left_y = top_left_y;
+        iPrinter.drawBorder(3, top_left_x, border_top_left_y, bottom_right_x, bottom_right_y);
+        drawHorizontalSeparator(iPrinter, top_left_x, bottom_right_x);
+    }
+}

+ 92 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelDrink.java

@@ -0,0 +1,92 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.CommandTSPL;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+
+public class PrintLabelDrink {
+    public synchronized static void doPrintTSPL(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_58mm, 56 * 8, 45 * 8);
+            // 清除缓存区内容
+            iPrinter.sendStrToPrinterTSPL("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 打印第一行的内容
+            iPrinter.setPrinterTSPL(CommandTSPL.DENSITY, 10);
+            iPrinter.drawTextTSPL(0, 0, 56 * 8, 8 * 8, PAlign.CENTER, PAlign.CENTER, true, 2, 2, null,
+                    "蜜果蜜制鲜饮");
+            // 打印第二行内容
+            iPrinter.setPrinterTSPL(CommandTSPL.DENSITY, 1);
+            iPrinter.drawTextTSPL(0, 8 * 8, 56 * 8, 8 * 8 * 2, PAlign.END, PAlign.CENTER, true, 2, 2, null,
+                    "蜜果奶茶(中)");
+            // 打印第三行内容
+            iPrinter.drawTextTSPL(20, 8 * 8 * 2, true, 2, 2, null, "价格减二");
+            // 打印第四行内容
+            iPrinter.drawTextTSPL(0, 8 * 8 * 3, 56 * 8, 8 * 8 * 4, PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+                    null, "¥6.00");
+            // 打印第五行内容
+            iPrinter.drawTextTSPL(0, 8 * 8 * 4, 56 * 8, 8 * 8 * 5, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    null, PrefUtils.getSystemTime2());
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 258 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelExpress.java

@@ -0,0 +1,258 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import com.printer.demo.R;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+
+public class PrintLabelExpress {
+
+    public synchronized static void doPrintTSPL(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_108mm, 800, 1500);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 打印内容
+            // 画所有的线条
+            // 上框的上边框横线
+            iPrinter.drawLineTSPL(40, 40, 720, 1);
+            // 上框的左边框的竖线
+            iPrinter.drawLineTSPL(40, 40, 1, 840);
+            // 上框的右框线竖线
+            iPrinter.drawLineTSPL(760, 40, 1, 840);
+            // 上框的下边框横线
+            iPrinter.drawLineTSPL(40, 880, 720, 1);
+            // 下框的上边框横线
+            iPrinter.drawLineTSPL(40, 889, 720, 1);
+            // 下框的左边框竖线
+            iPrinter.drawLineTSPL(40, 889, 1, 511);
+            // 下框的右边框竖线
+            iPrinter.drawLineTSPL(760, 889, 1, 511);
+            // 下框的下边框横线
+            iPrinter.drawLineTSPL(40, 1400, 720, 1);
+            // 上框里的第一条横线
+            iPrinter.drawLineTSPL(40, 136, 720, 1);
+            // 上框里的第二条横线(三号便利箱那条短线)
+            iPrinter.drawLineTSPL(472, 192, 288, 1);
+            // 上框里的第二条横线
+            iPrinter.drawLineTSPL(40, 296, 720, 1);
+            // 上框里的第三条横线
+            iPrinter.drawLineTSPL(40, 400, 720, 1);
+            // 上框里的第四条横线
+            iPrinter.drawLineTSPL(40, 504, 720, 1);
+            // 上框里的第五条横线
+            iPrinter.drawLineTSPL(40, 608, 720, 1);
+            // 上框里的第六条横线
+            iPrinter.drawLineTSPL(40, 792, 720, 1);
+            // 上框里的第一条竖线(目的地,收件人。。。。)
+            iPrinter.drawLineTSPL(88, 296, 1, 312);
+            // 上框里的竖线(托寄物)
+            iPrinter.drawLineTSPL(88, 792, 1, 88);
+            // 上框里的竖线(收件员)
+            iPrinter.drawLineTSPL(336, 792, 1, 88);
+            // 上框里的竖线(签名)
+            iPrinter.drawLineTSPL(512, 792, 1, 88);
+            // 上框里的竖线(三号便利箱)
+            iPrinter.drawLineTSPL(472, 136, 1, 160);
+            // 下框里的第一条横线
+            iPrinter.drawLineTSPL(40, 1016, 720, 1);
+            // 下框里的第二条横线
+            iPrinter.drawLineTSPL(40, 1104, 720, 1);
+            // 下框里的第三条横线
+            iPrinter.drawLineTSPL(40, 1192, 720, 1);
+            // 下框里的第四条横线
+            iPrinter.drawLineTSPL(40, 1232, 720, 1);
+            // 下框里的第五条横线
+            iPrinter.drawLineTSPL(40, 1272, 720, 1);
+            // 下框里的竖线(收件人)
+            iPrinter.drawLineTSPL(88, 1016, 1, 176);
+            // 下框里的竖线(衣物)
+            iPrinter.drawLineTSPL(216, 1192, 1, 80);
+            // 下框里的竖线(顺丰快递)
+            iPrinter.drawLineTSPL(304, 889, 1, 127);
+            // 下框里的竖线(付款方式)
+            iPrinter.drawLineTSPL(400, 1192, 1, 80);
+            // 下框里的竖线(寄付)
+            iPrinter.drawLineTSPL(576, 1192, 1, 80);
+            // // 上框 一维条码
+            iPrinter.drawBarCodeTSPL(12, 160, PBarcodeType.CODE128, 100, true, PRotate.Rotate_0, 1, 1,
+                    "001 160 68");
+            // 上框 图片
+            Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.goodwork);
+            iPrinter.drawBitmapTSPL(472, 192, 760, 296, PAlign.CENTER, PAlign.CENTER, 0, bmp);
+            // 三号便利箱
+            iPrinter.drawTextTSPL(480, 156, true, 1, 1, PRotate.Rotate_0, "三号便利箱/袋");
+            // 上框 目的地
+            iPrinter.drawTextTSPL(40, 297, 88, 331, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "目");
+            iPrinter.drawTextTSPL(40, 331, 88, 365, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "的");
+            iPrinter.drawTextTSPL(40, 365, 88, 399, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "地");
+            // 上框 7312
+            iPrinter.drawTextTSPL(108, 296, 760, 400, PAlign.START, PAlign.CENTER, true, 3, 3, PRotate.Rotate_0,
+                    "7312");
+            // 上框 收件人
+            iPrinter.drawTextTSPL(40, 401, 88, 435, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "收");
+            iPrinter.drawTextTSPL(40, 435, 88, 469, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "件");
+            iPrinter.drawTextTSPL(40, 469, 88, 503, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "人");
+            iPrinter.drawTextTSPL(108, 410, true, 1, 1, PRotate.Rotate_0, "熊二 13913913913");
+            iPrinter.drawTextTSPL(108, 440, true, 1, 1, PRotate.Rotate_0, "湖南省湘潭市雨湖区学府路与建设路口交汇口666号南山科");
+            iPrinter.drawTextTSPL(108, 470, true, 1, 1, PRotate.Rotate_0, "技产业基地B栋88楼湖南省湘潭市雨湖区学府路与建设路口");
+            // 上框 寄件人
+            iPrinter.drawTextTSPL(40, 505, 88, 539, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "寄");
+            iPrinter.drawTextTSPL(40, 539, 88, 573, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "件");
+            iPrinter.drawTextTSPL(40, 573, 88, 607, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "人");
+            iPrinter.drawTextTSPL(108, 514, true, 1, 1, PRotate.Rotate_0, "熊大  13913913913");
+            iPrinter.drawTextTSPL(108, 544, true, 1, 1, PRotate.Rotate_0, "深圳市雨湖区学府路与建设路口交汇口666号南山科技产业");
+            iPrinter.drawTextTSPL(108, 574, true, 1, 1, PRotate.Rotate_0, "基地B栋16楼");
+            // 上框 付款方式
+            iPrinter.drawTextTSPL(44, 608, true, 1, 1, PRotate.Rotate_0, "付款方式:  寄付");
+            iPrinter.drawTextTSPL(44, 638, true, 1, 1, PRotate.Rotate_0, "月结帐号:");
+            iPrinter.drawTextTSPL(44, 668, true, 1, 1, PRotate.Rotate_0, "第三方地区:");
+            iPrinter.drawTextTSPL(44, 698, true, 1, 1, PRotate.Rotate_0, "计费重量: 5kg");
+            iPrinter.drawTextTSPL(44, 728, true, 1, 1, PRotate.Rotate_0, "费用合计:42元");
+            iPrinter.drawTextTSPL(44, 758, true, 1, 1, PRotate.Rotate_0, "定时派送日期:");
+            iPrinter.drawTextTSPL(440, 608, true, 1, 1, PRotate.Rotate_0, "声明价值:2000元");
+            iPrinter.drawTextTSPL(440, 638, true, 1, 1, PRotate.Rotate_0, "报价费用:10元");
+            iPrinter.drawTextTSPL(440, 668, true, 1, 1, PRotate.Rotate_0, "包装费用:");
+            iPrinter.drawTextTSPL(440, 698, true, 1, 1, PRotate.Rotate_0, "运费:22元");
+            iPrinter.drawTextTSPL(440, 728, true, 1, 1, PRotate.Rotate_0, "长*宽*高");
+            // 上框 托寄物
+            iPrinter.drawTextTSPL(40, 792, 88, 821, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "托");
+            iPrinter.drawTextTSPL(40, 821, 88, 850, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "寄");
+            iPrinter.drawTextTSPL(40, 850, 88, 880, PAlign.CENTER, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+                    "物");
+            // 上框 衣物
+            iPrinter.drawTextTSPL(108, 792, 760, 880, PAlign.START, PAlign.CENTER, true, 2, 2, PRotate.Rotate_0,
+                    "衣物");
+            // 上框 收件员,寄件日期,派件员
+            // iPrinter.drawTextTSPL(338, 792, 512, 821, PAlign.START,
+            // PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+            // "收件员:42625");
+            // iPrinter.drawTextTSPL(338, 821, 512, 850, PAlign.START,
+            // PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+            // "寄件日期:03月");
+            // iPrinter.drawTextTSPL(338, 850, 512, 880, PAlign.START,
+            // PAlign.CENTER, true, 1, 1, PRotate.Rotate_0,
+            // "派件员:");
+            iPrinter.drawTextTSPL(338, 795, true, 1, 1, PRotate.Rotate_0, "收件员:42625");
+            iPrinter.drawTextTSPL(338, 825, true, 1, 1, PRotate.Rotate_0, "寄件日期:03月");
+            iPrinter.drawTextTSPL(338, 855, true, 1, 1, PRotate.Rotate_0, "派件员:");
+            // 上框 签名:
+            iPrinter.drawTextTSPL(515, 795, true, 1, 1, PRotate.Rotate_0, "签名:");
+            iPrinter.drawTextTSPL(512, 860, true, 1, 1, PRotate.Rotate_0, "       年   月   日");
+            // 下框 图片
+            iPrinter.drawBitmapTSPL(40, 889, 304, 1016, PAlign.CENTER, PAlign.CENTER, 0, bmp);
+            // 下框 一维条码
+            iPrinter.drawBarCodeTSPL(288, 900, PBarcodeType.CODE128, 80, true, PRotate.Rotate_0, 1, 1,
+                    "001 160 68");
+            // 下框 收件人
+            iPrinter.drawTextTSPL(40, 1016, 88, 1045, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "收");
+            iPrinter.drawTextTSPL(40, 1045, 88, 1074, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "件");
+            iPrinter.drawTextTSPL(40, 1074, 88, 1104, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "人");
+            iPrinter.drawTextTSPL(108, 1016, true, 1, 1, PRotate.Rotate_0, "熊大  13913913913");
+            iPrinter.drawTextTSPL(108, 1045, true, 1, 1, PRotate.Rotate_0, "湖南省湘潭市雨湖区学府路与建设路口交汇口666号南山科");
+            iPrinter.drawTextTSPL(108, 1074, true, 1, 1, PRotate.Rotate_0, "技产业基地B栋88楼湖南省湘潭市雨湖区学府路与建设路口");
+            // 下框 寄件人
+            iPrinter.drawTextTSPL(40, 1104, 88, 1133, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "寄");
+            iPrinter.drawTextTSPL(40, 1133, 88, 1162, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "件");
+            iPrinter.drawTextTSPL(40, 1162, 88, 1192, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "人");
+            iPrinter.drawTextTSPL(108, 1104, true, 1, 1, PRotate.Rotate_0, "熊大  13913913913");
+            iPrinter.drawTextTSPL(108, 1148, true, 1, 1, PRotate.Rotate_0, "深圳市雨湖区学府路与建设路口交汇口666号南山科技产业");
+            // 下框 表格
+            iPrinter.drawTextTSPL(40, 1192, 216, 1232, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "托寄物");
+            iPrinter.drawTextTSPL(40, 1232, 216, 1272, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "数量");
+            iPrinter.drawTextTSPL(216, 1192, 400, 1232, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "衣物");
+            iPrinter.drawTextTSPL(216, 1232, 400, 1272, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "1");
+            iPrinter.drawTextTSPL(400, 1192, 576, 1232, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "付款方式");
+            iPrinter.drawTextTSPL(400, 1232, 576, 1272, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "费用合计");
+            iPrinter.drawTextTSPL(650, 1200, true, 1, 1, PRotate.Rotate_0, "寄付");
+            iPrinter.drawTextTSPL(650, 1240, true, 1, 1, PRotate.Rotate_0, "42元");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 159 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelFruit.java

@@ -0,0 +1,159 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.util.Log;
+
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.TwoDarCodeType;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+
+public class PrintLabelFruit {
+
+    public synchronized static void doPrintTSPL(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        Log.i("yxz", "左边距------------" + left);
+        Log.i("yxz", "上边距------------" + top);
+        Log.i("yxz", "打印份数------------" + numbers);
+
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_58mm, 56 * 8, 45 * 8);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 横线上方区域
+            // 横线上方区域左上方的文字((0,0)(40*8,7*8))
+            iPrinter.drawTextTSPL(0, 0, 35 * 8, 7 * 8, PAlign.START, PAlign.START, true, 1, 1, null, "HanBu");
+            // 横线上方区域左下方的文字 ((0,0)(40*8,7*8))
+            iPrinter.drawTextTSPL(0, 0, 35 * 8, 7 * 8, PAlign.START, PAlign.END, true, 1, 1, null, "汉步");
+            // 横线上方区域右侧的文字 ((100,0)(40*8,7*8))
+            iPrinter.drawTextTSPL(100, 0, 35 * 8, 7 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 2, null,
+                    "热敏不干胶纸");
+
+            // 横线 (0,7*8+2);
+            iPrinter.drawLineTSPL(0, 7 * 8 + 2, 35 * 8, 5);
+            // 横线下方区域
+            // 左侧的二维码
+            iPrinter.draw2DBarCodeTSPL(0, 7 * 8 + 15, TwoDarCodeType.QR, 1, 4, null, "热敏不干胶纸");
+            // 右侧第一行汉字
+            iPrinter.drawTextTSPL(12 * 8, 7 * 8 + 10, true, 2, 2, null, "SIZE:");
+            // 右侧第二行汉字
+            iPrinter.drawTextTSPL(12 * 8, 7 * 8 + 55, true, 2, 2, null, "40MM*30MM");
+            // 二维码下方的一维条码
+            iPrinter.drawBarCodeTSPL(0, 20 * 8 + 4, PBarcodeType.CODE128, 5 * 8, false, null, 1, 2,
+                    "123456789012");
+            iPrinter.drawTextTSPL(0, 25 * 8, 40 * 8, 30 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 1, null,
+                    "123456789012");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+            // 备份
+
+            // // 设置标签纸大小
+            // iPrinter.pageSetupTSPL(PrinterConstants.SIZE_58mm, 40 *
+            // 8, 30 *
+            // 8);
+            // // 清楚缓存区内容
+            // iPrinter.printText("CLS\r\n");
+            // // 横线上方区域
+            // // 横线上方区域左上方的文字((0,0)(40*8,7*8))
+            // iPrinter.drawTextTSPL(0 + left, 0 + top, 40 * 8 + left, 7
+            // * 8 +
+            // top, PAlign.START, PAlign.START, true, 1, 1,
+            // null, "汉 步");
+            // // 横线上方区域左下方的文字 ((0,0)(40*8,7*8))
+            // iPrinter.drawTextTSPL(0 + left, 0 + top, 40 * 8 + left, 7
+            // * 8 +
+            // top, PAlign.START, PAlign.END, true, 1, 1,
+            // null, "HanBu");
+            // // 横线上方区域右侧的文字 ((100,0)(40*8,7*8))
+            // iPrinter.drawTextTSPL(100 + left, 0 + top, 40 * 8 + left,
+            // 7 * 8 +
+            // top, PAlign.CENTER, PAlign.CENTER, true,
+            // 1, 2, null, "热敏不干胶纸");
+            //
+            // // 横线 (0,7*8+2);
+            // iPrinter.drawLineTSPL(0 + left, 7 * 8 + 2 + top, 40 * 8,
+            // 5);
+            // // 横线下方区域
+            // // 左侧的二维码
+            // iPrinter.draw2DBarCodeTSPL(0 + left, 7 * 8 + 15 + top,
+            // TwoDarCodeType.QR, 1, 4, null, "热敏不干胶纸");
+            // // 右侧第一行汉字
+            // iPrinter.drawTextTSPL(14 * 8 + left, 7 * 8 + 10 + top,
+            // true, 2,
+            // 2, null, "SIZE:");
+            // // 右侧第二行汉字
+            // iPrinter.drawTextTSPL(14 * 8 + left, 7 * 8 + 55 + top,
+            // true, 2,
+            // 2, null, "40MM*30MM");
+            // // 二维码下方的一维条码
+            // iPrinter.drawBarCodeTSPL(0 + left, 20 * 8 + 4 + top,
+            // PBarcodeType.CODE128, 5 * 8, false, null, 1, 2,
+            // "123456789012");
+            // iPrinter.drawTextTSPL(0 + left, 25 * 8 + top, 40 * 8 +
+            // left, 30 *
+            // 8 + top, PAlign.CENTER, PAlign.CENTER,
+            // true, 1, 1, null, "123456789012");
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+}

+ 811 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelMaterial.java

@@ -0,0 +1,811 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+
+public class PrintLabelMaterial {
+    public void doPrintTSPL270mm(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_80mm, 80 * 8, 270 * 8);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 最外面的方框(0,0)--(72*8,90*8)
+            iPrinter.drawBorderTSPL(3, 0, 0, 72 * 8, 90 * 8);
+            // 大框和小框之间的标题内容
+            // 标题中间内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.CENTER, PAlign.END, true, 3, 3, null, "ZAX");
+            // 标题右上方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.CENTER, true, 1, 1, null,
+                    "中安信科技有限公司");
+            // 标调右下方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.END, true, 1, 1, null,
+                    "Zhong An Xin Technology");
+            // 里面的小框(10,10*8)(72*8-10,80*8)
+            iPrinter.drawBorderTSPL(2, 10, 10 * 8, 72 * 8 - 10, 80 * 8);
+            // 小框里的第一条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 2, 72 * 8 - 20, 2);
+            // 打印第一行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 + 5, 180, 10 * 8 * 2, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "规格:");
+            iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2 - 5, PAlign.CENTER, PAlign.END, true, 1, 1, null,
+                    "TYPE:");
+            // 打印第一行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8, 72 * 8 - 10, 10 * 8 * 2, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "T700XX");
+            // 小框里的第二条行横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 3, 72 * 8 - 20, 2);
+            // 打印第二行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2 + 5, 180, 10 * 8 * 3, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "型号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "FILAMNTS:");
+            // 打印第二行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 2, 72 * 8 - 10, 10 * 8 * 3, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "12K-XXX");
+            // 小框里的第三条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 4, 72 * 8 - 20, 2);
+            // 打印第三行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3 + 5, 180, 10 * 8 * 4, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "批次:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LOT NO.");
+            // 打印第三行右边内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 3, 72 * 8 - 10, 10 * 8 * 4, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+            // 小框里的第四条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 5, 72 * 8 - 20, 2);
+            // 打印第四行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4 + 5, 180, 10 * 8 * 5, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "序列号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "CASE No.");
+            // 打印第四行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 4, 72 * 8 - 10, 10 * 8 * 5, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+
+            // 小框里的第五条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 6, 72 * 8 - 20, 2);
+            // 打印第五行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5 + 5, 180, 10 * 8 * 6, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "时间:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "Date:");
+            // 打印第五行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 5, 72 * 8 - 10, 10 * 8 * 6, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, PrefUtils.getSystemTime());
+            // 小框里的第六条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 7, 72 * 8 - 20, 2);
+            // 打印第六行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6 + 5, 180, 10 * 8 * 7, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "重量:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "NET wt.");
+            // 打印第六行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 6, 72 * 8 - 10, 10 * 8 * 7, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "4.00 kg");
+            // 打印第七行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7 + 5, 180, 10 * 8 * 8, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "长度:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LENGTH:");
+            // 打印第七行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 7, 72 * 8 - 10, 10 * 8 * 8, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "5000 m");
+            // 小框里的竖线
+            iPrinter.drawLineTSPL(180, 10 * 8, 2, 10 * 8 * 7);
+            // 打印条码
+            iPrinter.drawBarCodeTSPL(30, 80 * 8 + 2, PBarcodeType.CODE128, 9 * 8, false, PRotate.Rotate_0, 1, 1,
+                    "123456BC");
+            // 打印第一行右边的内容
+            iPrinter.drawTextTSPL(10, 240 * 8, 72 * 8 - 10, 260 * 8, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "This is 270mm height Label");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+    public void doPrintTSPL240mm(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_80mm, 80 * 8, 240 * 8);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 最外面的方框(0,0)--(72*8,90*8)
+            iPrinter.drawBorderTSPL(3, 0, 0, 72 * 8, 90 * 8);
+            // 大框和小框之间的标题内容
+            // 标题中间内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.CENTER, PAlign.END, true, 3, 3, null, "ZAX");
+            // 标题右上方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.CENTER, true, 1, 1, null,
+                    "中安信科技有限公司");
+            // 标调右下方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.END, true, 1, 1, null,
+                    "Zhong An Xin Technology");
+            // 里面的小框(10,10*8)(72*8-10,80*8)
+            iPrinter.drawBorderTSPL(2, 10, 10 * 8, 72 * 8 - 10, 80 * 8);
+            // 小框里的第一条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 2, 72 * 8 - 20, 2);
+            // 打印第一行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 + 5, 180, 10 * 8 * 2, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "规格:");
+            iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2 - 5, PAlign.CENTER, PAlign.END, true, 1, 1, null,
+                    "TYPE:");
+            // 打印第一行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8, 72 * 8 - 10, 10 * 8 * 2, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "T700XX");
+            // 小框里的第二条行横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 3, 72 * 8 - 20, 2);
+            // 打印第二行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2 + 5, 180, 10 * 8 * 3, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "型号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "FILAMNTS:");
+            // 打印第二行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 2, 72 * 8 - 10, 10 * 8 * 3, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "12K-XXX");
+            // 小框里的第三条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 4, 72 * 8 - 20, 2);
+            // 打印第三行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3 + 5, 180, 10 * 8 * 4, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "批次:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LOT NO.");
+            // 打印第三行右边内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 3, 72 * 8 - 10, 10 * 8 * 4, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+            // 小框里的第四条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 5, 72 * 8 - 20, 2);
+            // 打印第四行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4 + 5, 180, 10 * 8 * 5, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "序列号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "CASE No.");
+            // 打印第四行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 4, 72 * 8 - 10, 10 * 8 * 5, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+
+            // 小框里的第五条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 6, 72 * 8 - 20, 2);
+            // 打印第五行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5 + 5, 180, 10 * 8 * 6, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "时间:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "Date:");
+            // 打印第五行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 5, 72 * 8 - 10, 10 * 8 * 6, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, PrefUtils.getSystemTime());
+            // 小框里的第六条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 7, 72 * 8 - 20, 2);
+            // 打印第六行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6 + 5, 180, 10 * 8 * 7, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "重量:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "NET wt.");
+            // 打印第六行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 6, 72 * 8 - 10, 10 * 8 * 7, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "4.00 kg");
+            // 打印第七行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7 + 5, 180, 10 * 8 * 8, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "长度:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LENGTH:");
+            // 打印第七行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 7, 72 * 8 - 10, 10 * 8 * 8, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "5000 m");
+            // 小框里的竖线
+            iPrinter.drawLineTSPL(180, 10 * 8, 2, 10 * 8 * 7);
+            // 打印条码
+            iPrinter.drawBarCodeTSPL(30, 80 * 8 + 2, PBarcodeType.CODE128, 9 * 8, false, PRotate.Rotate_0, 1, 1,
+                    "123456BC");
+            iPrinter.drawTextTSPL(10, 200 * 8, 72 * 8 - 10, 220 * 8, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "This is 240mm height Label");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void doPrintTSPL200mm(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_80mm, 80 * 8, 200 * 8);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 最外面的方框(0,0)--(72*8,90*8)
+            iPrinter.drawBorderTSPL(3, 0, 0, 72 * 8, 90 * 8);
+            // 大框和小框之间的标题内容
+            // 标题中间内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.CENTER, PAlign.END, true, 3, 3, null, "ZAX");
+            // 标题右上方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.CENTER, true, 1, 1, null,
+                    "中安信科技有限公司");
+            // 标调右下方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.END, true, 1, 1, null,
+                    "Zhong An Xin Technology");
+            // 里面的小框(10,10*8)(72*8-10,80*8)
+            iPrinter.drawBorderTSPL(2, 10, 10 * 8, 72 * 8 - 10, 80 * 8);
+            // 小框里的第一条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 2, 72 * 8 - 20, 2);
+            // 打印第一行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 + 5, 180, 10 * 8 * 2, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "规格:");
+            iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2 - 5, PAlign.CENTER, PAlign.END, true, 1, 1, null,
+                    "TYPE:");
+            // 打印第一行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8, 72 * 8 - 10, 10 * 8 * 2, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "T700XX");
+            // 小框里的第二条行横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 3, 72 * 8 - 20, 2);
+            // 打印第二行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2 + 5, 180, 10 * 8 * 3, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "型号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "FILAMNTS:");
+            // 打印第二行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 2, 72 * 8 - 10, 10 * 8 * 3, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "12K-XXX");
+            // 小框里的第三条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 4, 72 * 8 - 20, 2);
+            // 打印第三行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3 + 5, 180, 10 * 8 * 4, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "批次:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LOT NO.");
+            // 打印第三行右边内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 3, 72 * 8 - 10, 10 * 8 * 4, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+            // 小框里的第四条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 5, 72 * 8 - 20, 2);
+            // 打印第四行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4 + 5, 180, 10 * 8 * 5, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "序列号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "CASE No.");
+            // 打印第四行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 4, 72 * 8 - 10, 10 * 8 * 5, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+
+            // 小框里的第五条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 6, 72 * 8 - 20, 2);
+            // 打印第五行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5 + 5, 180, 10 * 8 * 6, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "时间:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "Date:");
+            // 打印第五行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 5, 72 * 8 - 10, 10 * 8 * 6, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, PrefUtils.getSystemTime());
+            // 小框里的第六条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 7, 72 * 8 - 20, 2);
+            // 打印第六行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6 + 5, 180, 10 * 8 * 7, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "重量:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "NET wt.");
+            // 打印第六行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 6, 72 * 8 - 10, 10 * 8 * 7, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "4.00 kg");
+            // 打印第七行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7 + 5, 180, 10 * 8 * 8, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "长度:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LENGTH:");
+            // 打印第七行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 7, 72 * 8 - 10, 10 * 8 * 8, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "5000 m");
+            // 小框里的竖线
+            iPrinter.drawLineTSPL(180, 10 * 8, 2, 10 * 8 * 7);
+            // 打印条码
+            iPrinter.drawBarCodeTSPL(30, 80 * 8 + 2, PBarcodeType.CODE128, 9 * 8, false, PRotate.Rotate_0, 1, 1,
+                    "123456BC");
+            iPrinter.drawTextTSPL(10, 160 * 8, 72 * 8 - 10, 180 * 8, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "This is 200mm height Label");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public synchronized static void doPrintTSPL(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // 设置标签纸大小
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_80mm, 80 * 8, 90 * 8);
+            // 清除缓存区内容
+            iPrinter.printText("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 最外面的方框(0,0)--(72*8,90*8)
+            iPrinter.drawBorderTSPL(3, 0, 0, 72 * 8, 90 * 8);
+            // 大框和小框之间的标题内容
+            // 标题中间内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.CENTER, PAlign.END, true, 3, 3, null, "ZAX");
+            // 标题右上方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.CENTER, true, 1, 1, null,
+                    "中安信科技有限公司");
+            // 标调右下方内容
+            iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END, PAlign.END, true, 1, 1, null,
+                    "Zhong An Xin Technology");
+            // 里面的小框(10,10*8)(72*8-10,80*8)
+            iPrinter.drawBorderTSPL(2, 10, 10 * 8, 72 * 8 - 10, 80 * 8);
+            // 小框里的第一条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 2, 72 * 8 - 20, 2);
+            // 打印第一行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 + 5, 180, 10 * 8 * 2, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "规格:");
+            iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2 - 5, PAlign.CENTER, PAlign.END, true, 1, 1, null,
+                    "TYPE:");
+            // 打印第一行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8, 72 * 8 - 10, 10 * 8 * 2, PAlign.CENTER, PAlign.CENTER, true, 1,
+                    1, null, "T700XX");
+            // 小框里的第二条行横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 3, 72 * 8 - 20, 2);
+            // 打印第二行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2 + 5, 180, 10 * 8 * 3, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "型号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "FILAMNTS:");
+            // 打印第二行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 2, 72 * 8 - 10, 10 * 8 * 3, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "12K-XXX");
+            // 小框里的第三条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 4, 72 * 8 - 20, 2);
+            // 打印第三行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3 + 5, 180, 10 * 8 * 4, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "批次:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LOT NO.");
+            // 打印第三行右边内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 3, 72 * 8 - 10, 10 * 8 * 4, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+            // 小框里的第四条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 5, 72 * 8 - 20, 2);
+            // 打印第四行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4 + 5, 180, 10 * 8 * 5, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "序列号:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "CASE No.");
+            // 打印第四行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 4, 72 * 8 - 10, 10 * 8 * 5, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "XXXXXXXXX");
+
+            // 小框里的第五条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 6, 72 * 8 - 20, 2);
+            // 打印第五行左边内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5 + 5, 180, 10 * 8 * 6, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "时间:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "Date:");
+            // 打印第五行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 5, 72 * 8 - 10, 10 * 8 * 6, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, PrefUtils.getSystemTime());
+            // 小框里的第六条横线
+            iPrinter.drawLineTSPL(10, 10 * 8 * 7, 72 * 8 - 20, 2);
+            // 打印第六行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6 + 5, 180, 10 * 8 * 7, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "重量:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "NET wt.");
+            // 打印第六行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 6, 72 * 8 - 10, 10 * 8 * 7, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "4.00 kg");
+            // 打印第七行左边的内容
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7 + 5, 180, 10 * 8 * 8, PAlign.CENTER, PAlign.START, true, 1, 1,
+                    null, "长度:");
+            iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8 - 5, PAlign.CENTER, PAlign.END, true, 1, 1,
+                    null, "LENGTH:");
+            // 打印第七行右边的内容
+            iPrinter.drawTextTSPL(180, 10 * 8 * 7, 72 * 8 - 10, 10 * 8 * 8, PAlign.CENTER, PAlign.CENTER, true,
+                    1, 1, null, "5000 m");
+            // 小框里的竖线
+            iPrinter.drawLineTSPL(180, 10 * 8, 2, 10 * 8 * 7);
+            // 打印条码
+            iPrinter.drawBarCodeTSPL(30, 80 * 8 + 2, PBarcodeType.CODE128, 9 * 8, false, PRotate.Rotate_0, 1, 1,
+                    "123456BC");
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        // 备份
+        // new Thread() {
+        // public void run() {
+        // int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        // int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        // int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        // int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        // int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        // try {
+        // // 设置标签纸大小
+        // iPrinter.pageSetupTSPL(PrinterConstants.SIZE_80mm, 80 * 8, 100 * 8);
+        // // 清除缓存区内容
+        // iPrinter.printText("CLS\r\n");
+        // // 设置标签的参考坐标原点
+        // if (left == 0 || top == 0) {
+        // // 不做设置,默认
+        // } else {
+        // iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8
+        // + "\r\n");
+        // }
+        // // 最外面的方框(0,0)--(72*8,90*8)
+        // iPrinter.drawBorderTSPL(3, 0, 0, 72 * 8, 90 * 8);
+        // // 大框和小框之间的标题内容
+        // // // 标题中间内容
+        // // iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8,
+        // // PAlign.CENTER,
+        // // PAlign.END, true, 2, 2, null, "ZAX");
+        // // // 标题右上方内容
+        // // iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END,
+        // // PAlign.CENTER, true, 1, 1, null, "中安信科技有限公司");
+        // // // 标调右下方内容
+        // // iPrinter.drawTextTSPL(0, 0, 72 * 8, 10 * 8, PAlign.END,
+        // // PAlign.END, true, 1, 1, null,
+        // // "Zhong An Xin Technology Co.Lsd");
+        // // 里面的小框(10,10*8)(72*8-10,80*8)
+        // iPrinter.drawBorderTSPL(2, 10, 10 * 8, 72 * 8 - 10, 80 * 8);
+        // // 小框里的第一条横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 2, 72 * 8 - 20, 2);
+        // // 打印第一行左边的内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2,
+        // // PAlign.CENTER,
+        // // PAlign.START, true, 1, 1, null, "规格:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8, 180, 10 * 8 * 2,
+        // // PAlign.CENTER,
+        // // PAlign.END, true, 1, 1, null, "TYPE:");
+        // // 打印第一行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8, 72 * 8 - 10, 10 * 8 *
+        // // 2,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2, null,
+        // // "T700XX");
+        // // 小框里的第二条行横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 3, 72 * 8 - 20, 2);
+        // // 打印第二行左边的内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "型号:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 2, 180, 10 * 8 * 3,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "FILAMNTS:");
+        // // 打印第二行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 2, 72 * 8 - 10, 10 *
+        // // 8 * 3,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, "12K-XXX");
+        // // 小框里的第三条横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 4, 72 * 8 - 20, 2);
+        // // 打印第三行左边内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "批次:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 3, 180, 10 * 8 * 4,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "LOT NO.");
+        // // 打印第三行右边内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 3, 72 * 8 - 10, 10 *
+        // // 8 * 4,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, "XXXXXXXXX");
+        // // 小框里的第四条横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 5, 72 * 8 - 20, 2);
+        // // 打印第四行左边的内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "序列号:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 4, 180, 10 * 8 * 5,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "CASE No.");
+        // // 打印第四行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 4, 72 * 8 - 10, 10 *
+        // // 8 * 5,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, "XXXXXXXXX");
+        //
+        // // 小框里的第五条横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 6, 72 * 8 - 20, 2);
+        // // 打印第五行左边内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "时间:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 5, 180, 10 * 8 * 6,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "Date:");
+        // // 打印第五行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 5, 72 * 8 - 10, 10 *
+        // // 8 * 6,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, PrefUtils.getSystemTime());
+        // // 小框里的第六条横线
+        // iPrinter.drawLineTSPL(10, 10 * 8 * 7, 72 * 8 - 20, 2);
+        // // 打印第六行左边的内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "重量:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 6, 180, 10 * 8 * 7,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "NET wt.");
+        // // 打印第六行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 6, 72 * 8 - 10, 10 *
+        // // 8 * 7,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, "4.00 kg");
+        // // 打印第七行左边的内容
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8,
+        // // PAlign.CENTER, PAlign.START, true, 1, 1, null,
+        // // "长度:");
+        // // iPrinter.drawTextTSPL(10, 10 * 8 * 7, 180, 10 * 8 * 8,
+        // // PAlign.CENTER, PAlign.END, true, 1, 1, null,
+        // // "LENGTH:");
+        // // 打印第七行右边的内容
+        // // iPrinter.drawTextTSPL(180, 10 * 8 * 7, 75 * 8 - 10, 10 *
+        // // 8 * 8,
+        // // PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+        // // null, "5000 m");
+        // // 小框里的竖线
+        // iPrinter.drawLineTSPL(180, 10 * 8, 2, 10 * 8 * 7);
+        // // 打印条码
+        // // iPrinter.drawBarCodeTSPL(20, 80 * 8,
+        // // PBarcodeType.CODE128, 9 * 8,
+        // // true, PRotate.Rotate_0, 1, 1, "123456BC");
+        // // // 判断是否响应钱箱
+        // // if (isOpenCash == 1) {
+        // // // 打印前打开钱箱
+        // // iPrinter.openCashBoxTSPL(1, 2);
+        // // Thread.sleep(3000);
+        // // // 打印
+        // // iPrinter.printTSPL(numbers, 1);
+        // // } else if (isBeep == 2) {
+        // // // 打印
+        // // iPrinter.printTSPL(numbers, 1);
+        // // // 打印后后打开钱箱
+        // // iPrinter.openCashBoxTSPL(1, 2);
+        // // } else {
+        // // // 打印
+        // // iPrinter.printTSPL(numbers, 1);
+        // // }
+        //
+        // // 判断是否响应蜂鸣器
+        // if (isBeep == 1) {
+        // // 打印前响
+        // iPrinter.beepTSPL(1, 1000);
+        // Thread.sleep(3000);
+        // // 打印
+        // iPrinter.printTSPL(numbers, 1);
+        // } else if (isBeep == 2) {
+        // // 打印
+        // iPrinter.printTSPL(numbers, 1);
+        // // 打印后响
+        // // Thread.sleep(3000);
+        // iPrinter.beepTSPL(1, 1000);
+        // } else {
+        // // 打印
+        // iPrinter.printTSPL(numbers, 1);
+        // }
+        //
+        // } catch (WriteException e) {
+        // e.printStackTrace();
+        // } catch (PrinterPortNullException e) {
+        // e.printStackTrace();
+        // } catch (ParameterErrorException e) {
+        // e.printStackTrace();
+        // } catch (Exception e) {
+        // e.printStackTrace();
+        // }
+        // };
+        // }.start();
+    }
+
+}

+ 123 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLabelStorage.java

@@ -0,0 +1,123 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.exception.ParameterErrorException;
+import com.printer.sdk.exception.PrinterPortNullException;
+import com.printer.sdk.exception.WriteException;
+
+public class PrintLabelStorage {
+
+    public synchronized static void doPrintTSPL(final PrinterInstance iPrinter, final Context mContext) {
+        int left = PrefUtils.getInt(mContext, "leftmargin", 0);
+        int top = PrefUtils.getInt(mContext, "topmargin", 0);
+        int numbers = PrefUtils.getInt(mContext, "printnumbers", 1);
+        int isBeep = PrefUtils.getInt(mContext, "isBeep", 0);
+        int isOpenCash = PrefUtils.getInt(mContext, "isOpenCash", 0);
+        try {
+            // TODO 设置标签纸大小 测试时修改一下PrinterInstance里面的代码
+            iPrinter.pageSetupTSPL(PrinterConstants.SIZE_58mm, 55 * 8, 70 * 8);
+            // 清除缓存区内容
+            iPrinter.sendStrToPrinterTSPL("CLS\r\n");
+            // 设置标签的参考坐标原点
+            if (left == 0 || top == 0) {
+                // 不做设置,默认
+            } else {
+                iPrinter.sendStrToPrinterTSPL("REFERENCE " + left * 8 + "," + top * 8 + "\r\n");
+            }
+            // 画框
+            iPrinter.drawBorderTSPL(2, 5 * 8, 5 * 8, 50 * 8, 65 * 8);
+            // 将框分成三块 画俩条行线
+            // 画第一条行线
+            iPrinter.drawLineTSPL(5 * 8, 25 * 8, 45 * 8, 2);
+            // 画第二条行线
+            iPrinter.drawLineTSPL(5 * 8, 45 * 8, 45 * 8, 2);
+            // 画第一块中的内容
+            // 标题 反白打印
+
+            iPrinter.drawTextTSPL(5 * 8, 5 * 8, 50 * 8, 5 * 8 + 8 * 8, PAlign.CENTER, PAlign.CENTER, true, 2, 2,
+                    PRotate.Rotate_0, "仓储行业");
+            iPrinter.reverseAreaTSPL(15 * 8, 6 * 8 - 4, 25 * 8, 7 * 8);
+            // 第一行
+            iPrinter.drawTextTSPL(5 * 8 + 3 * 8, 5 * 8 + 8 * 8, 50 * 8, 5 * 8 + 8 * 8 + 4 * 8, PAlign.START,
+                    PAlign.CENTER, true, 1, 1, PRotate.Rotate_0, "PO:345-896779-0");
+            // 第二行
+            iPrinter.drawTextTSPL(5 * 8 + 3 * 8, 5 * 8 + 8 * 8 + 4 * 8, 50 * 8, 5 * 8 + 8 * 8 + 4 * 8 + 4 * 8,
+                    PAlign.START, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0, "Zone:4");
+            // 第三行
+            iPrinter.drawTextTSPL(5 * 8 + 3 * 8, 5 * 8 + 8 * 8 + 4 * 8 * 2, 50 * 8, 5 * 8 + 8 * 8 + 4 * 8 * 3,
+                    PAlign.START, PAlign.CENTER, true, 1, 1, PRotate.Rotate_0, "DWCP:968484-23   STORE#49");
+
+            // 画第二块中的内容
+            // 第一行的文字
+            iPrinter.drawTextTSPL(5 * 8, 25 * 8, 50 * 8, 30 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "SHIP TO LOC 0614141000531");
+            // 第二行的条码
+            iPrinter.drawBarCodeTSPL(5 * 8 + 5 * 8, 30 * 8, PBarcodeType.CODE128, 10 * 8, false,
+                    PRotate.Rotate_0, 1, 1, "0614141");
+            // 第三行的文字
+            iPrinter.drawTextTSPL(5 * 8, 40 * 8, 50 * 8, 45 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "(410)0614141000531");
+
+            // 画第三块中的内容
+            // 第一行的文字
+            iPrinter.drawTextTSPL(5 * 8, 45 * 8, 50 * 8, 50 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "SSCC 0 0614141 1234567 0");
+            // 第二行的条码
+            iPrinter.drawBarCodeTSPL(5 * 8 + 5 * 8, 50 * 8, PBarcodeType.CODE128, 10 * 8, false,
+                    PRotate.Rotate_0, 1, 1, "0614141");
+            // 第三行的文字
+            iPrinter.drawTextTSPL(5 * 8, 60 * 8, 50 * 8, 65 * 8, PAlign.CENTER, PAlign.CENTER, true, 1, 1,
+                    PRotate.Rotate_0, "(00)006141411234567890");
+
+            // // 判断是否响应钱箱
+            // if (isOpenCash == 1) {
+            // // 打印前打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // Thread.sleep(3000);
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // } else if (isBeep == 2) {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // // 打印后后打开钱箱
+            // iPrinter.openCashBoxTSPL(1, 2);
+            // } else {
+            // // 打印
+            // iPrinter.printTSPL(numbers, 1);
+            // }
+
+            // 判断是否响应蜂鸣器
+            if (isBeep == 1) {
+                // 打印前响
+                iPrinter.beepTSPL(1, 1000);
+                Thread.sleep(3000);
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            } else if (isBeep == 2) {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+                // 打印后响
+                // Thread.sleep(3000);
+                iPrinter.beepTSPL(1, 1000);
+            } else {
+                // 打印
+                iPrinter.printTSPL(numbers, 1);
+            }
+        } catch (WriteException e) {
+            e.printStackTrace();
+        } catch (PrinterPortNullException e) {
+            e.printStackTrace();
+        } catch (ParameterErrorException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+}

+ 215 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/PrintLablel.java

@@ -0,0 +1,215 @@
+package com.printer.demo.utils;
+
+import android.util.Log;
+
+import com.printer.sdk.PrinterConstants.LableFontSize;
+import com.printer.sdk.PrinterConstants.LablePaperType;
+import com.printer.sdk.PrinterConstants.PAlign;
+import com.printer.sdk.PrinterConstants.PBarcodeType;
+import com.printer.sdk.PrinterConstants.PRotate;
+import com.printer.sdk.PrinterInstance;
+
+public class PrintLablel {
+
+    private static int MULTIPLE = 11;
+    private static final int line_width_border = 1;
+    private static final int page_width = 75 * MULTIPLE;
+    private static final int page_height = 80 * MULTIPLE;
+    private static final int margin_horizontal = (int) (1.5 * MULTIPLE);
+    private static final int top_left_x = margin_horizontal;
+    private static final int margin_vertical = 3 * MULTIPLE;
+    private static final int top_left_y = margin_vertical;// 32
+    private static final int border_width = page_width - 2 * margin_horizontal;
+    private static final int border_height = (int) (page_height - 8
+            * margin_vertical - 8);
+    private static final int top_right_x = top_left_x + border_width;
+    private static final int bottom_left_y = top_left_y + border_height;
+    private static final int bottom_right_y = bottom_left_y;
+    private static final int bottom_right_x = top_right_x;
+    private static final int row36_column1_width = 10 * MULTIPLE;
+    private static final int row37_column3_width = 20 * MULTIPLE;
+    private static final int row36_sep1_x = top_left_x + row36_column1_width;
+    private static final int row37_sep2_x = top_right_x - row37_column3_width;
+    private static final int[] row_height = {6 * MULTIPLE, 6 * MULTIPLE,
+            6 * MULTIPLE, 6 * MULTIPLE, 6 * MULTIPLE, 6 * MULTIPLE,
+            6 * MULTIPLE, 6 * MULTIPLE};
+    private static int startX;
+    private static int startX1;
+
+    public synchronized static void doPrint(PrinterInstance iPrinter) {
+        iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
+        drawBigBox(iPrinter);
+        drawHorizontalSeparator(iPrinter);
+        drawVerticalSeparator(iPrinter);
+        drawRowContent(iPrinter);
+        iPrinter.print(PRotate.Rotate_0, 0);
+
+    }
+
+    private static void drawBigBox(PrinterInstance iPrinter) {
+        int border_top_left_y = top_left_y;
+        // int border_top_left_y = top_left_y + row_height[0];
+        iPrinter.drawBorder(3, top_left_x, top_left_y, bottom_right_x,
+                bottom_right_y);
+        Log.i("fdh", "bottom_right_x0:" + bottom_right_x);
+
+    }
+
+    private static void drawHorizontalSeparator(PrinterInstance iPrinter) {
+
+        int temp = top_left_y; //
+        // int temp = top_left_y+row_height[0]; //
+        for (int i = 0; i < row_height.length; i++) {
+            temp += row_height[i];
+            int start_x = top_left_x + 10;
+            int end_x = (int) (top_left_x + ((top_right_x - top_left_x) / 10) * 6.9);
+            Log.i("temp", "第" + (i + 1) + "次");
+            iPrinter.drawLine(line_width_border, start_x, temp, end_x, temp,
+                    false);
+            /*
+			 * if(i!= 3){ iPrinter.drawLine(line_width_border, start_x, temp,
+			 * end_x, temp); }else{ iPrinter.drawLine(line_width_border,
+			 * row37_sep2_x, temp, end_x, temp); }
+			 */
+
+        }
+    }
+
+    private static void drawVerticalSeparator(PrinterInstance iPrinter) {
+
+        startX = top_left_x + ((top_right_x - top_left_x) / 10) * 2;
+        startX1 = (int) (top_left_x + ((top_right_x - top_left_x) / 10) * 6.9);
+        int startY = top_left_y + row_height[0];
+        int endY = top_left_y + row_height[0] * 8;
+        iPrinter.drawLine(line_width_border, startX, startY, startX, endY,
+                false);
+        iPrinter.drawLine(line_width_border * 2, top_left_x + 10, startY,
+                top_left_x + 10, endY, false);
+        iPrinter.drawLine(line_width_border * 2, startX1, startY,
+                startX1, endY, false);
+
+        // iPrinter.drawLine(line_width_border, startX1, endY, startX1,
+        // bottom_right_y, false);
+
+    }
+
+    private static void drawRowContent(PrinterInstance iPrinter) {
+
+        // 第一行内容
+        iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+                        + row_height[0], PAlign.CENTER, PAlign.END, "ZAX",
+                LableFontSize.Size_64, 1, 0, 0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+                        + row_height[0], PAlign.END, PAlign.CENTER, "中安信科技有限公司",
+                LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y, top_right_x, top_left_y
+                        + row_height[0], PAlign.END, PAlign.END, "Zhong An Xin Technology Co.Lsg",
+                LableFontSize.Size_16, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第二行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0], startX,
+                top_left_y + row_height[0] + row_height[0] / 2, PAlign.CENTER,
+                PAlign.END, "规格:", LableFontSize.Size_24, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0]
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 2, PAlign.CENTER, PAlign.START,
+                "TYPE:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+        // Log.i("sp", "startX:"+startX+"top_right_x:"+top_right_x);
+        // 第二行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0], bottom_right_x,
+                top_left_y + row_height[0] * 2, PAlign.CENTER, PAlign.CENTER,
+                "T700XX", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第三行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 2, startX,
+                top_left_y + row_height[0] * 2 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "型号:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 2
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 3, PAlign.CENTER, PAlign.START,
+                "FILAMENTS:", LableFontSize.Size_24, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+        // 第三行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 2, top_right_x,
+                top_left_y + row_height[0] * 3, PAlign.CENTER, PAlign.CENTER,
+                "12K—XXX", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第四行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 3, startX,
+                top_left_y + row_height[0] * 3 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "批次:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 3
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 4, PAlign.CENTER, PAlign.START,
+                "LOT NO.", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第四行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 3, top_right_x,
+                top_left_y + row_height[0] * 4, PAlign.CENTER, PAlign.CENTER,
+                "XXXXXXXXX", LableFontSize.Size_32, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+        // 第五行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 4, startX,
+                top_left_y + row_height[0] * 4 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "序列号:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 4
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 5, PAlign.CENTER, PAlign.START,
+                "CASE NO.", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+
+        // 第五行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 4, top_right_x,
+                top_left_y + row_height[0] * 5, PAlign.CENTER, PAlign.CENTER,
+                "XXXXXXXXX", LableFontSize.Size_32, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+        // 第六行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 5, startX,
+                top_left_y + row_height[0] * 5 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "时间:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 5
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 6, PAlign.CENTER, PAlign.START,
+                "DATE:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第六行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 5, top_right_x,
+                top_left_y + row_height[0] * 6, PAlign.CENTER, PAlign.CENTER,
+                " 8/11/2015 10:50 AM ", LableFontSize.Size_32, 0, 0, 0, 0,
+                PRotate.Rotate_0);
+        // 第七行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 6, startX,
+                top_left_y + row_height[0] * 6 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "重量:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 6
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 7, PAlign.CENTER, PAlign.START,
+                "NET wt:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第七行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 6, top_right_x,
+                top_left_y + row_height[0] * 7, PAlign.CENTER, PAlign.CENTER,
+                "4.00 kg", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第八行内容 左边栏内容
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 7, startX,
+                top_left_y + row_height[0] * 7 + row_height[0] / 2,
+                PAlign.CENTER, PAlign.END, "长度:", LableFontSize.Size_24, 0, 0,
+                0, 0, PRotate.Rotate_0);
+        iPrinter.drawText(top_left_x, top_left_y + row_height[0] * 7
+                        + row_height[0] / 2 + 4, startX,
+                top_left_y + row_height[0] * 8, PAlign.CENTER, PAlign.START,
+                "LENGTH:", LableFontSize.Size_24, 0, 0, 0, 0, PRotate.Rotate_0);
+        // 第八行内容 右边栏内容
+        iPrinter.drawText(startX, top_left_y + row_height[0] * 7, top_right_x,
+                top_left_y + row_height[0] * 8, PAlign.CENTER, PAlign.CENTER,
+                "5000 m", LableFontSize.Size_32, 0, 0, 0, 0, PRotate.Rotate_0);
+        //打印第九行条码
+
+        Log.i("fdh", "bottom_right_x:" + bottom_right_x);
+        iPrinter.drawBarCode(top_left_x, top_left_y + row_height[0] * 8, 576, bottom_right_y, PAlign.CENTER, PAlign.CENTER, 0, 0,
+                "DF12345678900010292001", PBarcodeType.CODE128, 1, 70, PRotate.Rotate_0);
+
+    }
+
+}

+ 83 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/UpdateUtils.java

@@ -0,0 +1,83 @@
+package com.printer.demo.utils;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+
+/**
+ * Created by yangxuezhi on 2018-07-11.
+ */
+
+public class UpdateUtils {
+    /**
+     * 得到应用程序的版本名称
+     */
+
+    public static String getVersionName(Context mContext) {
+        // 用来管理手机的APK
+        PackageManager pm = mContext.getPackageManager();
+        try {
+            // 得到知道APK的功能清单文件
+            PackageInfo info = pm.getPackageInfo(mContext.getPackageName(), 0);
+            return info.versionName;
+        } catch (PackageManager.NameNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            return "";
+        }
+
+    }
+
+    /**
+     * 系统语言是不是中文
+     * @param context
+     * @return
+     */
+    public static boolean isZh(Context context) {
+        Locale locale = context.getResources().getConfiguration().locale;
+        String language = locale.getLanguage();
+        if (language.endsWith("zh"))
+            return true;
+        else
+            return false;
+    }
+
+    /**
+     * @param is 输入流
+     * @return String 返回的字符串
+     * @throws IOException
+     */
+    public static String readFromStream(InputStream is) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+        int len = 0;
+        while ((len = is.read(buffer)) != -1) {
+            baos.write(buffer, 0, len);
+        }
+        is.close();
+        String result = baos.toString();
+        baos.close();
+        return result;
+    }
+
+    public static boolean hasNet(Context mContext) {
+        ConnectivityManager connectivity = (ConnectivityManager) mContext
+                .getSystemService(Context.CONNECTIVITY_SERVICE);
+        if (connectivity != null) {
+            NetworkInfo[] info = connectivity.getAllNetworkInfo();
+            if (info != null)
+                for (int i = 0; i < info.length; i++)
+                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
+                        return true;
+                    }
+        }
+        return false;
+    }
+}

+ 481 - 0
PrintDemoV5.7.1/src/main/java/com/printer/demo/utils/XTUtils.java

@@ -0,0 +1,481 @@
+package com.printer.demo.utils;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+
+import com.printer.demo.R;
+import com.printer.sdk.PrinterConstants;
+import com.printer.sdk.PrinterConstants.Command;
+import com.printer.sdk.PrinterInstance;
+import com.printer.sdk.Table;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Enumeration;
+
+@SuppressLint("DefaultLocale")
+public class XTUtils {
+
+	private static final String TAG = "XUtils";
+
+	public static byte[] string2bytes(String content) {
+
+		Log.i(TAG, "" + content);
+		try {
+			content = new String(content.getBytes("gbk"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		char[] charArray = content.toCharArray();
+		byte[] tempByte = new byte[512];
+		tempByte[0] = 0x34;
+		int count = 0;
+		for (int i = 0; i < charArray.length; i++) {
+
+			if (charArray[i] == 'x' || charArray[i] == 'X') {
+
+				tempByte[count++] = (byte) (char2Int(charArray[i + 1]) * 16 + char2Int(charArray[i + 2]));
+			}
+
+		}
+		Log.i(TAG, "---------------");
+		byte[] retByte = new byte[count];
+		System.arraycopy(tempByte, 0, retByte, 0, count);
+		for (int i = 0; i < retByte.length; i++) {
+			Log.i(TAG, retByte[i] + "");
+		}
+
+		return tempByte;
+	}
+
+	private static int char2Int(char data) {
+		if (data >= 48 && data <= 57)// 0~9
+			data -= 48;
+		else if (data >= 65 && data <= 70)// A~F
+			data -= 55;
+		else if (data >= 97 && data <= 102)// a~f
+			data -= 87;
+		return Integer.valueOf(data);
+	}
+
+	/**
+	 * 
+	 * @Description: TODO
+	 * @param
+	 * @return String
+	 */
+	public static String bytesToHexString(byte[] src, int datalength) {
+		StringBuilder stringBuilder = new StringBuilder("");
+		if (src == null || src.length <= 0) {
+			return null;
+		}
+		for (int i = 0; i < datalength; i++) {
+			int v = src[i] & 0xFF;
+			String hv = Integer.toHexString(v);
+			if (hv.length() < 2) {
+				stringBuilder.append(0);
+			}
+			stringBuilder.append("0x").append(hv).append(" ");
+		}
+		stringBuilder.append("0x0a 0x0d");
+		return stringBuilder.toString();
+	}
+
+	/**
+	 * 字符串转换为16进制字符串
+	 * 
+	 * @param s
+	 * @return
+	 */
+
+	public static String stringToHexString(String s) {
+		String str = "";
+		for (int i = 0; i < s.length(); i++) {
+			int ch = (int) s.charAt(i);
+			String s4 = Integer.toHexString(ch);
+			str = str + s4;
+		}
+		return str;
+	}
+
+	/**
+	 * 
+	 * 
+	 * 16进制字符串转换为字符串
+	 * 
+	 * @param s
+	 * @return
+	 * 
+	 */
+
+	public static String hexStringToString(String s) {
+		if (s == null || s.equals("")) {
+			return null;
+		}
+		s = s.replace(" ", "");
+		byte[] baKeyword = new byte[s.length() / 4];
+		for (int i = 0; i < baKeyword.length; i++) {
+			try {
+				baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 4, i * 4 + 4).substring(2, 4), 16));
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		try {
+			s = new String(baKeyword, "gbk");
+			new String();
+		} catch (Exception e1) {
+			e1.printStackTrace();
+		}
+		return s;
+	}
+
+	public synchronized static void printNote(Resources resources, PrinterInstance mPrinter) {
+		mPrinter.initPrinter();
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
+		mPrinter.printText(resources.getString(R.string.str_note));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+		StringBuffer sb = new StringBuffer();
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
+		mPrinter.setFont(0, 1, 1, 0, 0);
+		mPrinter.printText(resources.getString(R.string.shop_company_title) + "\n");
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
+		// 字号使用默认
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		sb.append(resources.getString(R.string.shop_num) + "574001\n");
+		sb.append(resources.getString(R.string.shop_receipt_num) + "S00003169\n");
+		sb.append(resources.getString(R.string.shop_cashier_num) + "s004_s004\n");
+		sb.append(resources.getString(R.string.shop_receipt_date) + "2012-06-17\n");
+		sb.append(resources.getString(R.string.shop_print_time) + "2012-06-17 13:37:24\n");
+		mPrinter.printText(sb.toString()); // 打印
+
+		printTable1(resources, mPrinter); // 打印表格
+
+		sb = new StringBuffer();
+
+		if (PrinterConstants.paperWidth == 384) {
+			sb.append(resources.getString(R.string.shop_goods_number) + "                    6.00\n");
+			sb.append(resources.getString(R.string.shop_goods_total_price) + "                    35.00\n");
+			sb.append(resources.getString(R.string.shop_payment) + "                    100.00\n");
+			sb.append(resources.getString(R.string.shop_change) + "                    65.00\n");
+		} else if (PrinterConstants.paperWidth == 576) {
+			sb.append(resources.getString(R.string.shop_goods_number) + "                                6.00\n");
+			sb.append(resources.getString(R.string.shop_goods_total_price) + "                                35.00\n");
+			sb.append(resources.getString(R.string.shop_payment) + "                                100.00\n");
+			sb.append(resources.getString(R.string.shop_change) + "                                65.00\n");
+		} else if (PrinterConstants.paperWidth == 724) {
+			sb.append(resources.getString(R.string.shop_goods_number)
+					+ "                                            6.00\n");
+			sb.append(resources.getString(R.string.shop_goods_total_price)
+					+ "                                            35.00\n");
+			sb.append(resources.getString(R.string.shop_payment)
+					+ "                                            100.00\n");
+			sb.append(
+					resources.getString(R.string.shop_change) + "                                            65.00\n");
+		}
+
+		sb.append(resources.getString(R.string.shop_company_name) + "\n");
+		sb.append(resources.getString(R.string.shop_company_site) + "www.jiangsuxxxx.com\n");
+		sb.append(resources.getString(R.string.shop_company_address) + "\n");
+		sb.append(resources.getString(R.string.shop_company_tel) + "0574-12345678\n");
+		sb.append(resources.getString(R.string.shop_Service_Line) + "4008-123-456 \n");
+
+		if (PrinterConstants.paperWidth == 384) {
+			sb.append("==============================\n");
+		} else if (PrinterConstants.paperWidth == 576) {
+			sb.append("==============================================\n");
+		} else if (PrinterConstants.paperWidth == 724) {
+			sb.append("================================================================\n");
+		}
+
+		mPrinter.printText(sb.toString());
+
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
+		mPrinter.setFont(0, 0, 1, 0, 0);
+		mPrinter.printText(resources.getString(R.string.shop_thanks) + "\n");
+		mPrinter.printText(resources.getString(R.string.shop_demo) + "\n\n\n");
+
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+	}
+
+	public static void printTable1(Resources resources, PrinterInstance mPrinter) {
+
+		String column = resources.getString(R.string.note_title);
+		Table table = null;
+		if (PrinterConstants.paperWidth == 384) {
+			table = new Table(column, ";", new int[] { 14, 6, 6, 6 });
+		} else if (PrinterConstants.paperWidth == 576) {
+			table = new Table(column, ";", new int[] { 18, 10, 10, 12 });
+		} else if (PrinterConstants.paperWidth == 724) {
+			table = new Table(column, ";", new int[] { 22, 14, 14, 18 });
+		}
+		table.addRow("" + resources.getString(R.string.bags) + ";10.00;1;10.00");
+		table.addRow("" + resources.getString(R.string.hook) + ";5.00;2;10.00");
+		table.addRow("" + resources.getString(R.string.umbrella) + ";5.00;3;15.00");
+		mPrinter.printTable(table);
+	}
+
+	public static synchronized void printTest(Resources resources, PrinterInstance mPrinter) {
+
+		mPrinter.initPrinter();
+
+		mPrinter.printText(resources.getString(R.string.str_text));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);
+
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.setPrinter(Command.ALIGN, 0);
+		mPrinter.printText(resources.getString(R.string.str_text_left));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// ��2��
+
+		mPrinter.setPrinter(Command.ALIGN, 1);
+		mPrinter.printText(resources.getString(R.string.str_text_center));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// ��2��
+
+		mPrinter.setPrinter(Command.ALIGN, 2);
+		mPrinter.printText(resources.getString(R.string.str_text_right));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3); // ��3��
+
+		mPrinter.setPrinter(Command.ALIGN, 0);
+		mPrinter.setFont(0, 0, 0, 1, 0);
+		mPrinter.printText(resources.getString(R.string.str_text_strong));
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2); // ��2��
+
+		mPrinter.setFont(0, 0, 0, 0, 1);
+		mPrinter.sendBytesData(new byte[] { (byte) 0x1C, (byte) 0x21, (byte) 0x80 });
+		mPrinter.printText(resources.getString(R.string.str_text_underline));
+		mPrinter.sendBytesData(new byte[] { (byte) 0x1C, (byte) 0x21, (byte) 0x00 });
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2); // ��2��
+
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.printText(resources.getString(R.string.str_text_height));
+		for (int i = 0; i < 4; i++) {
+			mPrinter.setFont(0, i, i, 0, 0);
+			mPrinter.printText((i + 1) + resources.getString(R.string.times));
+
+		}
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+		for (int i = 0; i < 4; i++) {
+
+			mPrinter.setFont(0, i, i, 0, 0);
+			mPrinter.printText(resources.getString(R.string.bigger) + (i + 1) + resources.getString(R.string.bigger1));
+			mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+
+		}
+
+		mPrinter.setFont(0, 0, 0, 0, 0);
+		mPrinter.setPrinter(Command.ALIGN, 0);
+		mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);
+	}
+
+	/**
+	 * @param is
+	 *            输入流
+	 * @return String 返回的字符串
+	 * @throws IOException
+	 */
+	public static String readFromStream(InputStream is) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = is.read(buffer)) != -1) {
+			baos.write(buffer, 0, len);
+		}
+		is.close();
+		String result = baos.toString();
+		baos.close();
+		return result;
+	}
+
+	/**
+	 * 将一个字符串中的所有字母均转换为大写
+	 * 
+	 * @param devicesAddress
+	 * @return
+	 */
+	public static String formatTheString(String devicesAddress) {
+		StringBuffer newDevicesAddress = new StringBuffer("");
+		for (int i = 0; i < devicesAddress.length(); i++) {
+			char chars = devicesAddress.charAt(i);
+			String childString = "" + chars;
+			childString = childString.toUpperCase();
+			newDevicesAddress.append(childString);
+		}
+		return newDevicesAddress.toString().substring(0, 17);
+		// return newDevicesAddress.toString();
+	}
+
+	public static boolean isLetter(String str) {
+		java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[a-zA-Z]+");
+		java.util.regex.Matcher m = pattern.matcher(str);
+		return m.matches();
+	}
+
+	/**
+	 * Android获取当前手机IP地址的两种方式
+	 */
+	// 1
+
+	public static String getIPAddress(Context context) {
+		NetworkInfo info = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
+				.getActiveNetworkInfo();
+		if (info != null && info.isConnected()) {
+			if (info.getType() == ConnectivityManager.TYPE_MOBILE) {// 当前使用2G/3G/4G网络
+				try {
+					// Enumeration<NetworkInterface>
+					// en=NetworkInterface.getNetworkInterfaces();
+					for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
+							.hasMoreElements();) {
+						NetworkInterface intf = en.nextElement();
+						for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr
+								.hasMoreElements();) {
+							InetAddress inetAddress = enumIpAddr.nextElement();
+							if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
+								return inetAddress.getHostAddress();
+							}
+						}
+					}
+				} catch (SocketException e) {
+					e.printStackTrace();
+				}
+
+			} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {// 当前使用无线网络
+				WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+				WifiInfo wifiInfo = wifiManager.getConnectionInfo();
+				String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());// 得到IPV4地址
+				return ipAddress;
+			}
+		} else {
+			// 当前无网络连接,请在设置中打开网络
+			WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+			wifiManager.setWifiEnabled(true);
+		}
+		return null;
+	}
+
+	/**
+	 * 将得到的int类型的IP转换为String类型
+	 *
+	 * @param ip
+	 * @return
+	 */
+	public static String intIP2StringIP(int ip) {
+		return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + (ip >> 24 & 0xFF);
+	}
+
+	// 2
+	public String getLocalIpAddress() {
+		try {
+			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
+				NetworkInterface intf = en.nextElement();
+				for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
+					InetAddress inetAddress = enumIpAddr.nextElement();
+					if (!inetAddress.isLoopbackAddress()) {
+						return inetAddress.getHostAddress().toString();
+					}
+				}
+			}
+		} catch (SocketException ex) {
+			Log.e("WifiPreference IpAddress", ex.toString());
+		}
+		return null;
+	}
+
+	/**
+	 * 
+	 * @Description: TODO
+	 * @param
+	 * @return String
+	 */
+	public static String bytesToHexString2(byte[] src, int datalength) {
+		StringBuilder stringBuilder = new StringBuilder("");
+		if (src == null || src.length <= 0) {
+			return null;
+		}
+		for (int i = 0; i < datalength; i++) {
+			int v = src[i] & 0xFF;
+			String hv = Integer.toHexString(v);
+			if (hv.length() < 2) {
+				stringBuilder.append(0);
+			}
+			stringBuilder.append(hv);
+		}
+		if (!stringBuilder.toString().endsWith("0a0d")) {
+			stringBuilder.append("0a0d");
+		}
+		return stringBuilder.toString();
+	}
+
+	/**
+	 * 
+	 * 
+	 * 16进制字符串转换为字符串
+	 * 
+	 * @param s
+	 * @return
+	 * 
+	 */
+
+	public static String hexStringToString2(String s) {
+		if (s == null || s.equals("")) {
+			return null;
+		}
+		s = s.replace(" ", "");
+		byte[] baKeyword = new byte[s.length() / 2];
+		for (int i = 0; i < baKeyword.length; i++) {
+			try {
+				baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2).substring(0, 2), 16));
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		try {
+			s = new String(baKeyword, "gbk");
+			new String();
+		} catch (Exception e1) {
+			e1.printStackTrace();
+		}
+		return s;
+	}
+
+	public static byte[] string2bytes2(String content) {
+
+		Log.i(TAG, "" + content);
+		try {
+			content = new String(content.getBytes("gbk"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		char[] charArray = content.toCharArray();
+		byte[] tempByte = new byte[512];
+		tempByte[0] = 0x34;
+		int count = 0;
+		for (int i = 0; i < charArray.length; i = i + 2) {
+			tempByte[count++] = (byte) (char2Int(charArray[i]) * 16 + char2Int(charArray[i + 1]));
+		}
+		Log.i(TAG, "---------------");
+		byte[] retByte = new byte[count];
+		System.arraycopy(tempByte, 0, retByte, 0, count);
+		for (int i = 0; i < retByte.length; i++) {
+			Log.i(TAG, retByte[i] + "");
+		}
+		return tempByte;
+	}
+}

TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/a.bmp


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/ao.jpg


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/ao1.bmp


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/back_arrow_2.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/barcode.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/bbbb.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_disabled.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_focused.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_normal.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/btn_style_one_pressed.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/confirm_dialog_bg2.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/edit_normal.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/edit_pressed.9.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/goodwork.bmp


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/ic_about.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/ic_launcher.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/icon_back.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/label_icon7.bmp


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/lable.png


TEMPAT SAMPAH
PrintDemoV5.7.1/src/main/res/drawable-hdpi/mm_title_back_focused.9.png


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini