package com.mcdreck;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import com.citizen.jpos.command.ESCPOS;
import com.citizen.jpos.command.ESCPOSConst;
import com.citizen.jpos.printer.CMPPrint;
import com.citizen.jpos.printer.ESCPOSPrinter;
@Permissions(values = {"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN"})
@DependsOn(values={ "Citizen_Android_1056" })
@Author("Roland Nyga")
@Version((float) 1.08)
@ShortName("CitizenESCP")
public class CitizenESCP {
public int CMP_ALIGNMENT_LEFT = CMPPrint.CMP_ALIGNMENT_LEFT;
public int CMP_ALIGNMENT_CENTER = CMPPrint.CMP_ALIGNMENT_CENTER;
public int CMP_ALIGNMENT_RIGHT = CMPPrint.CMP_ALIGNMENT_RIGHT;
public int CMP_FNT_DEFAULT = CMPPrint.CMP_FNT_DEFAULT;
public int CMP_FNT_FONTB = CMPPrint.CMP_FNT_FONTB;
public int CMP_FNT_BOLD = CMPPrint.CMP_FNT_BOLD;
public int CMP_FNT_UNDERLINE = CMPPrint.CMP_FNT_UNDERLINE;
public int CMP_BCS_UPCA1 = CMPPrint.CMP_BCS_UPCA;
public int CMP_BCS_UPCE1 = CMPPrint.CMP_BCS_UPCE;
public int CMP_BCS_EAN8 = CMPPrint.CMP_BCS_EAN8;
public int CMP_BCS_EAN13 = CMPPrint.CMP_BCS_EAN13;
public int CMP_BCS_JAN8 = CMPPrint.CMP_BCS_JAN8;
public int CMP_BCS_JAN13 = CMPPrint.CMP_BCS_JAN13;
public int CMP_BCS_ITF = CMPPrint.CMP_BCS_ITF;
public int CMP_BCS_Codabar = CMPPrint.CMP_BCS_Codabar;
public int CMP_BCS_Code39 = CMPPrint.CMP_BCS_Code39;
public int CMP_BCS_Code93 = CMPPrint.CMP_BCS_Code93;
public int CMP_BCS_Code128 = CMPPrint.CMP_BCS_Code128;
public int CMP_TXT_1WIDTH = CMPPrint.CMP_TXT_1WIDTH;
public int CMP_TXT_2WIDTH = CMPPrint.CMP_TXT_2WIDTH;
public int CMP_TXT_3WIDTH = CMPPrint.CMP_TXT_3WIDTH;
public int CMP_TXT_4WIDTH = CMPPrint.CMP_TXT_4WIDTH;
public int CMP_TXT_5WIDTH = CMPPrint.CMP_TXT_5WIDTH;
public int CMP_TXT_6WIDTH = CMPPrint.CMP_TXT_6WIDTH;
public int CMP_TXT_7WIDTH = CMPPrint.CMP_TXT_7WIDTH;
public int CMP_TXT_8WIDTH = CMPPrint.CMP_TXT_8WIDTH;
public int CMP_TXT_1HEIGHT = CMPPrint.CMP_TXT_1HEIGHT;
public int CMP_TXT_2HEIGHT = CMPPrint.CMP_TXT_2HEIGHT;
public int CMP_TXT_3HEIGHT = CMPPrint.CMP_TXT_3HEIGHT;
public int CMP_TXT_4HEIGHT = CMPPrint.CMP_TXT_4HEIGHT;
public int CMP_TXT_5HEIGHT = CMPPrint.CMP_TXT_5HEIGHT;
public int CMP_TXT_6HEIGHT = CMPPrint.CMP_TXT_6HEIGHT;
public int CMP_TXT_7HEIGHT = CMPPrint.CMP_TXT_7HEIGHT;
public int CMP_TXT_8HEIGHT = CMPPrint.CMP_TXT_8HEIGHT;
public int CMP_HRI_TEXT_NONE = CMPPrint.CMP_HRI_TEXT_NONE;
public int CMP_HRI_TEXT_ABOVE = CMPPrint.CMP_HRI_TEXT_ABOVE;
public int CMP_HRI_TEXT_BELOW = CMPPrint.CMP_HRI_TEXT_BELOW;
public int CMP_STS_NORMAL = CMPPrint.CMP_STS_NORMAL;
public int CMP_STS_PAPER_EMPTY = CMPPrint.CMP_STS_PAPER_EMPTY;
public int CMP_STS_COVER_OPEN = CMPPrint.CMP_STS_COVER_OPEN;
public int CMP_STS_MSR_READ = CMPPrint.CMP_STS_MSR_READ;
public int CMP_BITMAP_NORMAL = CMPPrint.CMP_BITMAP_NORMAL;
public int CMP_BITMAP_DOUBLE_WIDTH = CMPPrint.CMP_BITMAP_DOUBLE_WIDTH;
public int CMP_BITMAP_DOUBLE_HEIGHT = CMPPrint.CMP_BITMAP_DOUBLE_HEIGHT;
public int CMP_BITMAP_QUADRUPLE = CMPPrint.CMP_BITMAP_QUADRUPLE;
public int CMP_QRCODE_EC_LEVEL_L = CMPPrint.CMP_QRCODE_EC_LEVEL_L;
public int CMP_QRCODE_EC_LEVEL_M = CMPPrint.CMP_QRCODE_EC_LEVEL_M;
public int CMP_QRCODE_EC_LEVEL_Q = CMPPrint.CMP_QRCODE_EC_LEVEL_Q;
public int CMP_QRCODE_EC_LEVEL_H = CMPPrint.CMP_QRCODE_EC_LEVEL_H;
private ESCPOSPrinter posPtr;
private ESCPOSPrinter posPtr1;
// 0x1B
private final char ESC = ESCPOS.ESC;
public CitizenESCP()
{
posPtr = new ESCPOSPrinter();
}
public String OneRow(String Test) {
return ESC+"|cA" + Test + "\n";
}
public void sample1() throws UnsupportedEncodingException {
Log.i("sample1", "für printNormal");
posPtr.printNormal(ESC+"|cA"+ESC+"|2CReceipt\r\n\r\n\r\n");
posPtr.printNormal(ESC+"|rATEL (123)-456-7890\n\n\n");
posPtr.printNormal(ESC+"|cAThank you for coming to our shop!\n");
posPtr.printNormal(ESC+"|cADate\n\n");
posPtr.printNormal("Chicken $10.00\n");
posPtr.printNormal("Hamburger $20.00\n");
posPtr.printNormal("Pizza $30.00\n");
posPtr.printNormal("Lemons $40.00\n");
posPtr.printNormal("Drink $50.00\n");
posPtr.printNormal("Excluded tax $150.00\n");
posPtr.printNormal(ESC+"|uCTax(5%) $7.50\n");
posPtr.printNormal(ESC+"|bC"+ESC+"|2CTotal $157.50\n\n");
posPtr.printNormal("Payment $200.00\n");
posPtr.printNormal("Change $42.50\n\n");
posPtr.printBarCode("{Babc456789012", CMPPrint.CMP_BCS_Code128, 40, 512, CMPPrint.CMP_ALIGNMENT_CENTER, CMPPrint.CMP_HRI_TEXT_BELOW); // Print Barcode
}
public void sample2() throws UnsupportedEncodingException {
posPtr.printText("Receipt\r\n\r\n\r\n", CMPPrint.CMP_ALIGNMENT_CENTER, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_2WIDTH);
posPtr.printText("TEL (123)-456-7890\r\n", CMPPrint.CMP_ALIGNMENT_RIGHT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Thank you for coming to our shop!\r\n", CMPPrint.CMP_ALIGNMENT_CENTER, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Chicken $10.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Hamburger $20.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Pizza $30.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Lemons $40.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Drink $50.00\r\n\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Excluded tax $150.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Tax(5%) $7.50\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_UNDERLINE, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Total $157.50\r\n\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_2WIDTH);
posPtr.printText("Payment $200.00\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printText("Change $42.50\r\n\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
posPtr.printBarCode("0123456789", CMPPrint.CMP_BCS_Code39, 40, 512, CMPPrint.CMP_ALIGNMENT_CENTER, CMPPrint.CMP_HRI_TEXT_BELOW);
}
public void imageTest() throws IOException {
posPtr.printBitmap("//sdcard//temp//citizen//car_s.jpg", CMPPrint.CMP_ALIGNMENT_CENTER);
posPtr.printBitmap("//sdcard//temp//citizen//danmark_windmill.jpg", CMPPrint.CMP_ALIGNMENT_LEFT);
posPtr.printBitmap("//sdcard//temp//citizen//denmark_flag.jpg", CMPPrint.CMP_ALIGNMENT_RIGHT);
}
public void westernLatinCharTest() throws UnsupportedEncodingException {
final char [] diff = {0x23,0x24,0x40,0x5B,0x5C,0x5D,0x5E,0x6C,0x7B,0x7C,0x7D,0x7E,
0xA4,0xA6,0xA8,0xB4,0xB8,0xBC,0xBD,0xBE};
String ad = new String(diff);
posPtr.printText(ad+"\r\n\r\n", CMPPrint.CMP_ALIGNMENT_LEFT, CMPPrint.CMP_FNT_DEFAULT, CMPPrint.CMP_TXT_1WIDTH);
}
public int multiply(int x){
return 10*(x+25);
}
@SuppressWarnings("static-access")
public void barcode2DTest(final BA ba) throws UnsupportedEncodingException {
Runnable r = new Runnable() {
@Override
public void run() {
posPtr1 = new ESCPOSPrinter();
String data = "ABCDEFGHIJKLMN";
try {
posPtr1.printString("PDF417 1\r\n");
posPtr1.printPDF417(data, data.length(), 2, 20, ESCPOSConst.CMP_ALIGNMENT_LEFT);
posPtr1.printString("PDF417 2\r\n");
posPtr1.printPDF417(data, data.length(), 10, 30, ESCPOSConst.CMP_ALIGNMENT_LEFT);
posPtr1.printString("QR 1\r\n");
posPtr1.printQRCode(data, data.length(), 3, ESCPOSConst.CMP_QRCODE_EC_LEVEL_L, ESCPOSConst.CMP_ALIGNMENT_CENTER);
posPtr1.printString("QR 2\r\n");
posPtr1.printQRCode(data, data.length(), 11, ESCPOSConst.CMP_QRCODE_EC_LEVEL_L, ESCPOSConst.CMP_ALIGNMENT_CENTER);
}
catch (Exception e) {
ba.setLastException(e);
}
}
};
ba.submitRunnable(r, this, 0);
}
}
Nothing works :BangHead:
Ill hope somebody can help me. I don't want to give up!!!:cool:
Link to Citizen Download for Android
[Code]
http://www.citizen-europe.com/de/printer/support/software/Mobile