@ -144,6 +144,12 @@ public class XTUtils {
return s ;
}
/ * *
*
* @Description : 打印商店购物小票
* @param
* @return String
* /
public synchronized static void printNote ( Resources resources , PrinterInstance mPrinter ) {
mPrinter . initPrinter ( ) ;
mPrinter . setFont ( 0 , 0 , 0 , 0 , 0 ) ;
@ -216,65 +222,79 @@ public class XTUtils {
}
/ * *
*
* @Description : 打印表格小票
* @param
* @return void
* /
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 } ) ;
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 = new Table ( column , ";" , new int [ ] { 14 , 6 , 6 , 6 } ) ;
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 ) ;
}
/ * *
*
* @Description : 打印测试小票
* @param
* @return void
* /
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 . setPrinter ( Command . PRINT_AND_WAKE_PAPER_BY_LINE , 2 ) ; / / 默认打印 , 并走纸2行
mPrinter . setFont ( 0 , 0 , 0 , 0 , 0 ) ;
mPrinter . setPrinter ( Command . ALIGN , 0 ) ;
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 . PRINT_AND_WAKE_PAPER_BY_LINE , 2 ) ; / / 文字居左 , 打印并走纸2行
mPrinter . setPrinter ( Command . ALIGN , 1 ) ;
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 . PRINT_AND_WAKE_PAPER_BY_LINE , 2 ) ; / / 文字居中 , 打印并走纸2行
mPrinter . setPrinter ( Command . ALIGN , 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 . PRINT_AND_WAKE_PAPER_BY_LINE , 3 ) ; / / 文字居右 , 打印并走纸3行
mPrinter . setPrinter ( Command . ALIGN , 0 ) ;
mPrinter . setFont ( 0 , 0 , 0 , 1 , 0 ) ;
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 . 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 . 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 . 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 . 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 ) ;
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 ) ;
mPrinter . setPrinter ( Command . PRINT_AND_WAKE_PAPER_BY_LINE , 1 ) ; / / 打印并走纸1行
mPrinter . setPrinter ( Command . PRINT_AND_WAKE_PAPER_BY_LINE , 3 ) ; / / 打印并走纸3行
for ( int i = 0 ; i < 4 ; i + + ) {
for ( int i = 0 ; i < 4 ; i + + ) { / / 放大倍数打印后 , 走纸3行
mPrinter . setFont ( 0 , i , i , 0 , 0 ) ;
mPrinter . printText ( resources . getString ( R . string . bigger ) + ( i + 1 ) + resources . getString ( R . string . bigger1 ) ) ;
@ -283,7 +303,7 @@ public class XTUtils {
}
mPrinter . setFont ( 0 , 0 , 0 , 0 , 0 ) ;
mPrinter . setPrinter ( Command . ALIGN , 0 ) ;
mPrinter . setPrinter ( Command . ALIGN , 0 ) ; / / 左对齐
mPrinter . setPrinter ( Command . PRINT_AND_WAKE_PAPER_BY_LINE , 3 ) ;
}
@ -383,6 +403,7 @@ public class XTUtils {
}
/ / 2
@SuppressLint ( "LongLogTag" )
public String getLocalIpAddress ( ) {
try {
for ( Enumeration < NetworkInterface > en = NetworkInterface . getNetworkInterfaces ( ) ; en . hasMoreElements ( ) ; ) {