Android-SDK Development Document
V3.0
一、 Introduction
The SDK contains Bluetooth, Usb and WiFi.
1. Software package name:com.android.print.sdk
2. Classes name:
Class Name Discription
Barcode A class of print Barcode data
Table A class of print Table data
PrinterConstants A class of all printers constant.
PrinterInstance A class that contains all operations of the printer.
CanvasPrint Print use canvas. For special print.
FontProperty Text font property for canvas print text.
二、 Class “PrinterInstance” provides the following method:
1. Construct method:
a) //use BluetoothDevice
PrinterInstance(Context context, BluetoothDevice bluetoothDevice, Handler
handler)
b) //use UsbDevice
PrinterInstance(Context context, UsbDevice usbDevice, Handler handler)
c) //use wifi address and port number
PrinterInstance(String ipAddress, int portNumber, Handler handler)
Handler: use for receive connect state change. Use constant value:
PrinterConstants.Connect.SUCCESS;
PrinterConstants.Connect.FAILED;
PrinterConstants.Connect.CLOSED;
2. Open and close connection:
a) openConnection() open connection.
b) closeConnection() close connection.
3. Common method:
a) Init printer.
init()
b) Print common text.
printText(String content)
c) Send byte data.
sendByteData(byte[] content)\
user can use this method send command to printer if the SDK don’t provide the
method in printer development document, such as:
byte[] command = new byte[3];
command[0] = 0x1B;
command[1] = 0x31;
command[2] = 49;
sendByteData (command);
d) Print image.
bitmap is image ;left is left margin;multiple is stylus printer multiple for
zoom in.
printImage(Bitmap bitmap);
printImage(String bitmap, int left);
printImage(Bitmap bitmap, int multiple);
printImage(String bitmap, int left, int multiple);
e) Print table. Use Table class set table data.
printTable(Table table)
f) Print barcode. Use Barcode class to set barcode data.
PrintBarCode(Barcode barcode)
g) Cut pager
cutPaper()
h) Ring buzzer, param is ring time
ringBuzzer(byte time)
i) Open cashbox
openCashbox(boolean cashbox1, boolean cashbox2)
4. Set method:
a) Set character encoding of print text.
setEncoding(String encoding)
b) Set character width and height. x is width, y is height. 0<=x,y<=7, default is 0.
setCharacterMultiple(int x, int y)
c) Set left edge distance of print area, usually nH value is 0.
setLeftMargin(int nL, int nH)
d) Set print model.
setPrintModel(boolean isBold, boolean isDoubleHeight,
boolean isDoubleWidth, boolean isUnderLine)
isBold:bold
isDoubleHeight:double height.
isDoubleWidth:double width.
isUnderLine:under line.
e) Set printer (Command constant start with “PrinterConstants.Command.”
setPrinter(int command)
INIT_PRINTER:init printer( equal to method init() )
WAKE_PRINTER:wake up printer
PRINT_AND_RETURN_STANDARD:page model print and return to standard
PRINT_AND_NEWLINE:print and move to next line.
PRINT_AND_ENTER:print and enter.
MOVE_NEXT_TAB_POSITION:move to the position of next tab.
DEF_LINE_SPACING:restore default line space.
setPrinter(int command, int value)
PRINT_AND_WAKE_PAPER_BY_LNCH:
print and wake paper “value ” height (lnch)….
PRINT_AND_WAKE_PAPER_BY_LINE:print and wake paper “value” lines
CLOCKWISE_ROTATE_90:clock wise rotate 90degree, 0-false, 1-true
LINE_HEIGHT:Set line height
CHARACTER_RIGHT_MARGIN:Set character right margin
ALIGN:Align model. Three model’s const value is:
ALIGN_LEFT: left margin
ALIGN_CENTER: center margin
ALIGN_RIGHT: right margin
三、 Table class
1. Table construct.
Table(String column, String regular, int[] columnWidth)
Parameter column is table title column, separate by the regular.
Such as:”index, unit price, number, price”.
Parameter regular: the separator of the column data. Such
as”,”.
Parameter Column width: width of all columns. One Chinese
character width is 2, one English character is 1.
2. Add a row data.
addRow(String row)
Add a row data to the table. Data form should equals with table
title. If the table cell width exceeds the limit, printer can word
wrap, if want manual line, can add “\n” in where you want.
3. Set Table column align left. Default is aligning right.
setColumnAlignLeft(boolean left)
四、 Barcode class
1. Construct:
Barcode(byte barcodeType)
Barcode(byte barcodeType, int param1, int param2, int param3)
Barcode(byte barcodeType, int param1, int param2, int param3, String content)
i. barcodeType is barcode type.
Constant start with “PrinterConstants.BarcodeType.”:
One-dimensional: UPC_A, UPC_E, JAN13, JAN8, CODE39,
ITF, CODABAR, CODE93, CODE128。
Two-dimensional: PDF417,DATAMATRIX,QRCODE。
ii. param1,param2,param3 are barcode param s:
Bar Code type is One-dimensional:
param1:bar code width, 2<=n<=6,default is 2.
param2:bar code height, 1<=n<=255,default is 162.
param3:bar code note position, 0-don’t print, 1-above,2-below,3-both.
Bar Code type is Two-dimensional:
a) PDF417
param1:The characters per line,1<=n<=30。
param2:Error correction level,0<=n<=8。
param3:Longitudinal magnification。
b) DATA MATRIX
param1:height,0<=n<=144(0:auto select)。
param2:width,8<=n<=144(when param1 is zero, param2 Invalid)。
param3:Longitudinal magnification。
c) QR CODE
param1:Graphical version,1<=n<=30(0:auto select)。
param2:Error correction level,
n = 76,77,81,72(L:7%,M:15%,Q:25%,H:30%)。
param3:Longitudinal magnification。
iii. Content is barcode data.
五、 CanvasPrint class
1. Init CanvasPrint, Parameter is PrinterType. If use this method. The canvas was init
to max width. Such as T9, the width is 72mm.
init(PrinterType printerType)
2. Set font property. Parameter is a FontProperty type,
setFontProperty(FontProperty fp)
FontProperty is a collections of font property. User can call method of setFont()
to set detail property.
If don’t use this method, you also can use the following method:
setLineWidth(float w) set paint width.
setTextSize(int size) set text size.
setItalic(boolean italic) set whether italic.
setStrikeThruText(boolean strike) set whether strikethrough.
setUnderlineText(boolean underline) set whether under line.
setFakeBoldText(boolean fakeBold) set fake bold.
3. Draw text on the canvas. Parameters x and y is text coordinate
in the left bottom corner. Y must greater than 0.
drawText(String nStr)
drawText(float x, String nStr)
drawText(float x, float y, String nStr)
4. Draw a line. Parameters startX, startY is start coordinate; stopX , stopY is end
coordinate.
drawLine(float startX, float startY, float stopX, float stopY)
5. Draw a rectangle. Parameters are the distance of edge to the left and top.
drawRectangle(float left, float top, float right, float bottom)
6. Draw an ellipse. Parameters is coordinate of edge which a bounding rectangle of the
ellipse.
drawEllips(float left, float top, float right, float bottom)
7. Draw an Image. “image” is bitmap file of image.
drawImage(Bitmap image);
drawImage(float left, Bitmap image);
drawImage(float left, float top, Bitmap image);
8. Get the canvas image. Return a bitmap.
getCanvasImage();
9. Set text aligns right. Against the special language. Such as Arabic.
setTextAlignRight(boolean alignRight);
10. Set print new line if the text exceeds the valid width.
setTextExceedNewLine(boolean newLine);
11. Avoid a word was split to Independent letter. Default is space.
setUseSplit(boolean useSplit);
setUseSplitAndString(boolean useSplit, String splitStr);