Commit 2fd4d7af by Wyh

7.22

parent 51a1f96b
...@@ -72,7 +72,7 @@ dependencies { ...@@ -72,7 +72,7 @@ dependencies {
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"] annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
api rootProject.ext.dependencies["BaseRecyclerViewAdapter"] api rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
implementation rootProject.ext.dependencies["fastjson"] implementation rootProject.ext.dependencies["fastjson"]
implementation rootProject.ext.dependencies["zxing"] api rootProject.ext.dependencies["zxing"]
implementation rootProject.ext.dependencies["progressmanager"] implementation rootProject.ext.dependencies["progressmanager"]
implementation rootProject.ext.dependencies["autosize"] implementation rootProject.ext.dependencies["autosize"]
// test // test
......
...@@ -29,8 +29,11 @@ public class PrinterDeviceBean implements Serializable { ...@@ -29,8 +29,11 @@ public class PrinterDeviceBean implements Serializable {
private Long printerModelId;//打印機機型id private Long printerModelId;//打印機機型id
private String paperSpecification;//紙張規格 private String paperSpecification;//紙張規格
private int lineFontStop;//打印機一行最多顯示多少字
private String printerName;//打印機機型名稱 private String printerName;//打印機機型名稱
private String model;//打印機型號 private String model;//打印機型號
private String noteContent;//備註 private String noteContent;//備註
private Long printerDeviceDefaultId; private Long printerDeviceDefaultId;
/** /**
...@@ -56,6 +59,7 @@ public class PrinterDeviceBean implements Serializable { ...@@ -56,6 +59,7 @@ public class PrinterDeviceBean implements Serializable {
private int numberIsFlip;//數量大於1顔色是否翻轉 1是 2否 private int numberIsFlip;//數量大於1顔色是否翻轉 1是 2否
@Generated(hash = 626885316) @Generated(hash = 626885316)
public PrinterDeviceBean() { public PrinterDeviceBean() {
} }
...@@ -66,8 +70,8 @@ public class PrinterDeviceBean implements Serializable { ...@@ -66,8 +70,8 @@ public class PrinterDeviceBean implements Serializable {
this.paperSpecification = paperSpecification; this.paperSpecification = paperSpecification;
} }
@Generated(hash = 1904986682) @Generated(hash = 1637885194)
public PrinterDeviceBean(Long id, Long dbid, String name, Integer restaurantId, String ip, Long uid, Integer port, Integer type, Long printerModelId, String paperSpecification, String printerName, String model, String noteContent, Long printerDeviceDefaultId, Long flyPrinterDeviceId, Long flyPrinterDeviceId2, int foodIsBold, String foodFont, int foodIsItalic, int modifierIsBold, String modifierFont, int modifierIsItalic, public PrinterDeviceBean(Long id, Long dbid, String name, Integer restaurantId, String ip, Long uid, Integer port, Integer type, Long printerModelId, String paperSpecification, int lineFontStop, String printerName, String model, String noteContent, Long printerDeviceDefaultId, Long flyPrinterDeviceId, Long flyPrinterDeviceId2, int foodIsBold, String foodFont, int foodIsItalic, int modifierIsBold, String modifierFont, int modifierIsItalic,
int numberIsFlip) { int numberIsFlip) {
this.id = id; this.id = id;
this.dbid = dbid; this.dbid = dbid;
...@@ -79,6 +83,7 @@ public class PrinterDeviceBean implements Serializable { ...@@ -79,6 +83,7 @@ public class PrinterDeviceBean implements Serializable {
this.type = type; this.type = type;
this.printerModelId = printerModelId; this.printerModelId = printerModelId;
this.paperSpecification = paperSpecification; this.paperSpecification = paperSpecification;
this.lineFontStop = lineFontStop;
this.printerName = printerName; this.printerName = printerName;
this.model = model; this.model = model;
this.noteContent = noteContent; this.noteContent = noteContent;
...@@ -284,4 +289,12 @@ public class PrinterDeviceBean implements Serializable { ...@@ -284,4 +289,12 @@ public class PrinterDeviceBean implements Serializable {
public void setNumberIsFlip(int numberIsFlip) { public void setNumberIsFlip(int numberIsFlip) {
this.numberIsFlip = numberIsFlip; this.numberIsFlip = numberIsFlip;
} }
public int getLineFontStop() {
return lineFontStop;
}
public void setLineFontStop(int lineFontStop) {
this.lineFontStop = lineFontStop;
}
} }
...@@ -34,19 +34,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -34,19 +34,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
public final static Property Type = new Property(7, Integer.class, "type", false, "TYPE"); public final static Property Type = new Property(7, Integer.class, "type", false, "TYPE");
public final static Property PrinterModelId = new Property(8, Long.class, "printerModelId", false, "PRINTER_MODEL_ID"); public final static Property PrinterModelId = new Property(8, Long.class, "printerModelId", false, "PRINTER_MODEL_ID");
public final static Property PaperSpecification = new Property(9, String.class, "paperSpecification", false, "PAPER_SPECIFICATION"); public final static Property PaperSpecification = new Property(9, String.class, "paperSpecification", false, "PAPER_SPECIFICATION");
public final static Property PrinterName = new Property(10, String.class, "printerName", false, "PRINTER_NAME"); public final static Property LineFontStop = new Property(10, int.class, "lineFontStop", false, "LINE_FONT_STOP");
public final static Property Model = new Property(11, String.class, "model", false, "MODEL"); public final static Property PrinterName = new Property(11, String.class, "printerName", false, "PRINTER_NAME");
public final static Property NoteContent = new Property(12, String.class, "noteContent", false, "NOTE_CONTENT"); public final static Property Model = new Property(12, String.class, "model", false, "MODEL");
public final static Property PrinterDeviceDefaultId = new Property(13, Long.class, "printerDeviceDefaultId", false, "PRINTER_DEVICE_DEFAULT_ID"); public final static Property NoteContent = new Property(13, String.class, "noteContent", false, "NOTE_CONTENT");
public final static Property FlyPrinterDeviceId = new Property(14, Long.class, "flyPrinterDeviceId", false, "FLY_PRINTER_DEVICE_ID"); public final static Property PrinterDeviceDefaultId = new Property(14, Long.class, "printerDeviceDefaultId", false, "PRINTER_DEVICE_DEFAULT_ID");
public final static Property FlyPrinterDeviceId2 = new Property(15, Long.class, "flyPrinterDeviceId2", false, "FLY_PRINTER_DEVICE_ID2"); public final static Property FlyPrinterDeviceId = new Property(15, Long.class, "flyPrinterDeviceId", false, "FLY_PRINTER_DEVICE_ID");
public final static Property FoodIsBold = new Property(16, int.class, "foodIsBold", false, "FOOD_IS_BOLD"); public final static Property FlyPrinterDeviceId2 = new Property(16, Long.class, "flyPrinterDeviceId2", false, "FLY_PRINTER_DEVICE_ID2");
public final static Property FoodFont = new Property(17, String.class, "foodFont", false, "FOOD_FONT"); public final static Property FoodIsBold = new Property(17, int.class, "foodIsBold", false, "FOOD_IS_BOLD");
public final static Property FoodIsItalic = new Property(18, int.class, "foodIsItalic", false, "FOOD_IS_ITALIC"); public final static Property FoodFont = new Property(18, String.class, "foodFont", false, "FOOD_FONT");
public final static Property ModifierIsBold = new Property(19, int.class, "modifierIsBold", false, "MODIFIER_IS_BOLD"); public final static Property FoodIsItalic = new Property(19, int.class, "foodIsItalic", false, "FOOD_IS_ITALIC");
public final static Property ModifierFont = new Property(20, String.class, "modifierFont", false, "MODIFIER_FONT"); public final static Property ModifierIsBold = new Property(20, int.class, "modifierIsBold", false, "MODIFIER_IS_BOLD");
public final static Property ModifierIsItalic = new Property(21, int.class, "modifierIsItalic", false, "MODIFIER_IS_ITALIC"); public final static Property ModifierFont = new Property(21, String.class, "modifierFont", false, "MODIFIER_FONT");
public final static Property NumberIsFlip = new Property(22, int.class, "numberIsFlip", false, "NUMBER_IS_FLIP"); public final static Property ModifierIsItalic = new Property(22, int.class, "modifierIsItalic", false, "MODIFIER_IS_ITALIC");
public final static Property NumberIsFlip = new Property(23, int.class, "numberIsFlip", false, "NUMBER_IS_FLIP");
} }
...@@ -72,19 +73,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -72,19 +73,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
"\"TYPE\" INTEGER," + // 7: type "\"TYPE\" INTEGER," + // 7: type
"\"PRINTER_MODEL_ID\" INTEGER," + // 8: printerModelId "\"PRINTER_MODEL_ID\" INTEGER," + // 8: printerModelId
"\"PAPER_SPECIFICATION\" TEXT," + // 9: paperSpecification "\"PAPER_SPECIFICATION\" TEXT," + // 9: paperSpecification
"\"PRINTER_NAME\" TEXT," + // 10: printerName "\"LINE_FONT_STOP\" INTEGER NOT NULL ," + // 10: lineFontStop
"\"MODEL\" TEXT," + // 11: model "\"PRINTER_NAME\" TEXT," + // 11: printerName
"\"NOTE_CONTENT\" TEXT," + // 12: noteContent "\"MODEL\" TEXT," + // 12: model
"\"PRINTER_DEVICE_DEFAULT_ID\" INTEGER," + // 13: printerDeviceDefaultId "\"NOTE_CONTENT\" TEXT," + // 13: noteContent
"\"FLY_PRINTER_DEVICE_ID\" INTEGER," + // 14: flyPrinterDeviceId "\"PRINTER_DEVICE_DEFAULT_ID\" INTEGER," + // 14: printerDeviceDefaultId
"\"FLY_PRINTER_DEVICE_ID2\" INTEGER," + // 15: flyPrinterDeviceId2 "\"FLY_PRINTER_DEVICE_ID\" INTEGER," + // 15: flyPrinterDeviceId
"\"FOOD_IS_BOLD\" INTEGER NOT NULL ," + // 16: foodIsBold "\"FLY_PRINTER_DEVICE_ID2\" INTEGER," + // 16: flyPrinterDeviceId2
"\"FOOD_FONT\" TEXT," + // 17: foodFont "\"FOOD_IS_BOLD\" INTEGER NOT NULL ," + // 17: foodIsBold
"\"FOOD_IS_ITALIC\" INTEGER NOT NULL ," + // 18: foodIsItalic "\"FOOD_FONT\" TEXT," + // 18: foodFont
"\"MODIFIER_IS_BOLD\" INTEGER NOT NULL ," + // 19: modifierIsBold "\"FOOD_IS_ITALIC\" INTEGER NOT NULL ," + // 19: foodIsItalic
"\"MODIFIER_FONT\" TEXT," + // 20: modifierFont "\"MODIFIER_IS_BOLD\" INTEGER NOT NULL ," + // 20: modifierIsBold
"\"MODIFIER_IS_ITALIC\" INTEGER NOT NULL ," + // 21: modifierIsItalic "\"MODIFIER_FONT\" TEXT," + // 21: modifierFont
"\"NUMBER_IS_FLIP\" INTEGER NOT NULL );"); // 22: numberIsFlip "\"MODIFIER_IS_ITALIC\" INTEGER NOT NULL ," + // 22: modifierIsItalic
"\"NUMBER_IS_FLIP\" INTEGER NOT NULL );"); // 23: numberIsFlip
} }
/** Drops the underlying database table. */ /** Drops the underlying database table. */
...@@ -146,51 +148,52 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -146,51 +148,52 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
if (paperSpecification != null) { if (paperSpecification != null) {
stmt.bindString(10, paperSpecification); stmt.bindString(10, paperSpecification);
} }
stmt.bindLong(11, entity.getLineFontStop());
String printerName = entity.getPrinterName(); String printerName = entity.getPrinterName();
if (printerName != null) { if (printerName != null) {
stmt.bindString(11, printerName); stmt.bindString(12, printerName);
} }
String model = entity.getModel(); String model = entity.getModel();
if (model != null) { if (model != null) {
stmt.bindString(12, model); stmt.bindString(13, model);
} }
String noteContent = entity.getNoteContent(); String noteContent = entity.getNoteContent();
if (noteContent != null) { if (noteContent != null) {
stmt.bindString(13, noteContent); stmt.bindString(14, noteContent);
} }
Long printerDeviceDefaultId = entity.getPrinterDeviceDefaultId(); Long printerDeviceDefaultId = entity.getPrinterDeviceDefaultId();
if (printerDeviceDefaultId != null) { if (printerDeviceDefaultId != null) {
stmt.bindLong(14, printerDeviceDefaultId); stmt.bindLong(15, printerDeviceDefaultId);
} }
Long flyPrinterDeviceId = entity.getFlyPrinterDeviceId(); Long flyPrinterDeviceId = entity.getFlyPrinterDeviceId();
if (flyPrinterDeviceId != null) { if (flyPrinterDeviceId != null) {
stmt.bindLong(15, flyPrinterDeviceId); stmt.bindLong(16, flyPrinterDeviceId);
} }
Long flyPrinterDeviceId2 = entity.getFlyPrinterDeviceId2(); Long flyPrinterDeviceId2 = entity.getFlyPrinterDeviceId2();
if (flyPrinterDeviceId2 != null) { if (flyPrinterDeviceId2 != null) {
stmt.bindLong(16, flyPrinterDeviceId2); stmt.bindLong(17, flyPrinterDeviceId2);
} }
stmt.bindLong(17, entity.getFoodIsBold()); stmt.bindLong(18, entity.getFoodIsBold());
String foodFont = entity.getFoodFont(); String foodFont = entity.getFoodFont();
if (foodFont != null) { if (foodFont != null) {
stmt.bindString(18, foodFont); stmt.bindString(19, foodFont);
} }
stmt.bindLong(19, entity.getFoodIsItalic()); stmt.bindLong(20, entity.getFoodIsItalic());
stmt.bindLong(20, entity.getModifierIsBold()); stmt.bindLong(21, entity.getModifierIsBold());
String modifierFont = entity.getModifierFont(); String modifierFont = entity.getModifierFont();
if (modifierFont != null) { if (modifierFont != null) {
stmt.bindString(21, modifierFont); stmt.bindString(22, modifierFont);
} }
stmt.bindLong(22, entity.getModifierIsItalic()); stmt.bindLong(23, entity.getModifierIsItalic());
stmt.bindLong(23, entity.getNumberIsFlip()); stmt.bindLong(24, entity.getNumberIsFlip());
} }
@Override @Override
...@@ -246,51 +249,52 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -246,51 +249,52 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
if (paperSpecification != null) { if (paperSpecification != null) {
stmt.bindString(10, paperSpecification); stmt.bindString(10, paperSpecification);
} }
stmt.bindLong(11, entity.getLineFontStop());
String printerName = entity.getPrinterName(); String printerName = entity.getPrinterName();
if (printerName != null) { if (printerName != null) {
stmt.bindString(11, printerName); stmt.bindString(12, printerName);
} }
String model = entity.getModel(); String model = entity.getModel();
if (model != null) { if (model != null) {
stmt.bindString(12, model); stmt.bindString(13, model);
} }
String noteContent = entity.getNoteContent(); String noteContent = entity.getNoteContent();
if (noteContent != null) { if (noteContent != null) {
stmt.bindString(13, noteContent); stmt.bindString(14, noteContent);
} }
Long printerDeviceDefaultId = entity.getPrinterDeviceDefaultId(); Long printerDeviceDefaultId = entity.getPrinterDeviceDefaultId();
if (printerDeviceDefaultId != null) { if (printerDeviceDefaultId != null) {
stmt.bindLong(14, printerDeviceDefaultId); stmt.bindLong(15, printerDeviceDefaultId);
} }
Long flyPrinterDeviceId = entity.getFlyPrinterDeviceId(); Long flyPrinterDeviceId = entity.getFlyPrinterDeviceId();
if (flyPrinterDeviceId != null) { if (flyPrinterDeviceId != null) {
stmt.bindLong(15, flyPrinterDeviceId); stmt.bindLong(16, flyPrinterDeviceId);
} }
Long flyPrinterDeviceId2 = entity.getFlyPrinterDeviceId2(); Long flyPrinterDeviceId2 = entity.getFlyPrinterDeviceId2();
if (flyPrinterDeviceId2 != null) { if (flyPrinterDeviceId2 != null) {
stmt.bindLong(16, flyPrinterDeviceId2); stmt.bindLong(17, flyPrinterDeviceId2);
} }
stmt.bindLong(17, entity.getFoodIsBold()); stmt.bindLong(18, entity.getFoodIsBold());
String foodFont = entity.getFoodFont(); String foodFont = entity.getFoodFont();
if (foodFont != null) { if (foodFont != null) {
stmt.bindString(18, foodFont); stmt.bindString(19, foodFont);
} }
stmt.bindLong(19, entity.getFoodIsItalic()); stmt.bindLong(20, entity.getFoodIsItalic());
stmt.bindLong(20, entity.getModifierIsBold()); stmt.bindLong(21, entity.getModifierIsBold());
String modifierFont = entity.getModifierFont(); String modifierFont = entity.getModifierFont();
if (modifierFont != null) { if (modifierFont != null) {
stmt.bindString(21, modifierFont); stmt.bindString(22, modifierFont);
} }
stmt.bindLong(22, entity.getModifierIsItalic()); stmt.bindLong(23, entity.getModifierIsItalic());
stmt.bindLong(23, entity.getNumberIsFlip()); stmt.bindLong(24, entity.getNumberIsFlip());
} }
@Override @Override
...@@ -311,19 +315,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -311,19 +315,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7), // type cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7), // type
cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8), // printerModelId cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8), // printerModelId
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // paperSpecification cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // paperSpecification
cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // printerName cursor.getInt(offset + 10), // lineFontStop
cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // model cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // printerName
cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // noteContent cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // model
cursor.isNull(offset + 13) ? null : cursor.getLong(offset + 13), // printerDeviceDefaultId cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // noteContent
cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14), // flyPrinterDeviceId cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14), // printerDeviceDefaultId
cursor.isNull(offset + 15) ? null : cursor.getLong(offset + 15), // flyPrinterDeviceId2 cursor.isNull(offset + 15) ? null : cursor.getLong(offset + 15), // flyPrinterDeviceId
cursor.getInt(offset + 16), // foodIsBold cursor.isNull(offset + 16) ? null : cursor.getLong(offset + 16), // flyPrinterDeviceId2
cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // foodFont cursor.getInt(offset + 17), // foodIsBold
cursor.getInt(offset + 18), // foodIsItalic cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // foodFont
cursor.getInt(offset + 19), // modifierIsBold cursor.getInt(offset + 19), // foodIsItalic
cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20), // modifierFont cursor.getInt(offset + 20), // modifierIsBold
cursor.getInt(offset + 21), // modifierIsItalic cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21), // modifierFont
cursor.getInt(offset + 22) // numberIsFlip cursor.getInt(offset + 22), // modifierIsItalic
cursor.getInt(offset + 23) // numberIsFlip
); );
return entity; return entity;
} }
...@@ -340,19 +345,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> { ...@@ -340,19 +345,20 @@ public class PrinterDeviceBeanDao extends AbstractDao<PrinterDeviceBean, Long> {
entity.setType(cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7)); entity.setType(cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7));
entity.setPrinterModelId(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8)); entity.setPrinterModelId(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
entity.setPaperSpecification(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); entity.setPaperSpecification(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
entity.setPrinterName(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); entity.setLineFontStop(cursor.getInt(offset + 10));
entity.setModel(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); entity.setPrinterName(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
entity.setNoteContent(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12)); entity.setModel(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
entity.setPrinterDeviceDefaultId(cursor.isNull(offset + 13) ? null : cursor.getLong(offset + 13)); entity.setNoteContent(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
entity.setFlyPrinterDeviceId(cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14)); entity.setPrinterDeviceDefaultId(cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14));
entity.setFlyPrinterDeviceId2(cursor.isNull(offset + 15) ? null : cursor.getLong(offset + 15)); entity.setFlyPrinterDeviceId(cursor.isNull(offset + 15) ? null : cursor.getLong(offset + 15));
entity.setFoodIsBold(cursor.getInt(offset + 16)); entity.setFlyPrinterDeviceId2(cursor.isNull(offset + 16) ? null : cursor.getLong(offset + 16));
entity.setFoodFont(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17)); entity.setFoodIsBold(cursor.getInt(offset + 17));
entity.setFoodIsItalic(cursor.getInt(offset + 18)); entity.setFoodFont(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
entity.setModifierIsBold(cursor.getInt(offset + 19)); entity.setFoodIsItalic(cursor.getInt(offset + 19));
entity.setModifierFont(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); entity.setModifierIsBold(cursor.getInt(offset + 20));
entity.setModifierIsItalic(cursor.getInt(offset + 21)); entity.setModifierFont(cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21));
entity.setNumberIsFlip(cursor.getInt(offset + 22)); entity.setModifierIsItalic(cursor.getInt(offset + 22));
entity.setNumberIsFlip(cursor.getInt(offset + 23));
} }
@Override @Override
......
...@@ -37,7 +37,7 @@ import java.util.ArrayList; ...@@ -37,7 +37,7 @@ import java.util.ArrayList;
public abstract class PrinterWriter { public abstract class PrinterWriter {
public static final int HEIGHT_PARTING_DEFAULT = 255; public static final int HEIGHT_PARTING_DEFAULT = 255;
private static final String CHARSET = "gb2312"; private static final String CHARSET = "gb2312";//
private ByteArrayOutputStream bos; private ByteArrayOutputStream bos;
private int heightParting; private int heightParting;
......
package com.gingersoft.gsa.other_order_mode.data.model.bean package com.gingersoft.gsa.other_order_mode.data.model.bean
data class EstimatedBean( data class EstimatedBean(
val `data`: Data, val `data`: Data?,
val success: Boolean, val success: Boolean,
val sysTime: Long val sysTime: Long
) )
\ No newline at end of file
...@@ -249,7 +249,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -249,7 +249,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
} }
val estimatedBean = withContext(Dispatchers.Default) { repository.getShipanyOrderTime(restaurantId, orderId, type) }//1、预计整张订单完成时间2、預計配送員接單時間3、預計配送員到店時間4、配送員預計送達時間 val estimatedBean = withContext(Dispatchers.Default) { repository.getShipanyOrderTime(restaurantId, orderId, type) }//1、预计整张订单完成时间2、預計配送員接單時間3、預計配送員到店時間4、配送員預計送達時間
// if (estimatedBean.data.estimated_time > 0) { // if (estimatedBean.data.estimated_time > 0) {
if(estimatedBean.data != null){
data.estimatedTime = estimatedTime + ("${estimatedBean.data.estimated_time}分鐘後") data.estimatedTime = estimatedTime + ("${estimatedBean.data.estimated_time}分鐘後")
}
orderDetails.postValue(orderDetail) orderDetails.postValue(orderDetail)
// } else { // } else {
// data.estimatedTime = "" // data.estimatedTime = ""
......
...@@ -12,6 +12,4 @@ class OrderDetailsAdapter(list: MutableList<BtnBuilder.BtnBean>) : BaseQuickAdap ...@@ -12,6 +12,4 @@ class OrderDetailsAdapter(list: MutableList<BtnBuilder.BtnBean>) : BaseQuickAdap
holder.setBackgroundResource(R.id.layout_btn_item, item.btnColor) holder.setBackgroundResource(R.id.layout_btn_item, item.btnColor)
holder.setImageResource(R.id.iv_btn_mark, item.btnImg) holder.setImageResource(R.id.iv_btn_mark, item.btnImg)
} }
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
android:roundIcon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.PrintAddCurrencyActivity"></activity> <activity android:name=".mvp.ui.activity.PrintAddCurrencyActivity"/>
<activity android:name=".mvp.ui.activity.PrintActivity" /> <activity android:name=".mvp.ui.activity.PrintActivity" />
<activity android:name=".mvp.ui.activity.PrinterAddActivity" /> <activity android:name=".mvp.ui.activity.PrinterAddActivity" />
<activity android:name=".mvp.ui.activity.PrintTestActivity"> <activity android:name=".mvp.ui.activity.PrintTestActivity">
......
package com.joe.print.mvp.model.bean; package com.joe.print.mvp.model.bean;
import android.content.Context;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.other.TextUtil; import com.gingersoft.gsa.cloud.base.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean; import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean; import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.print.bean.OrderDetails;
import com.joe.print.R;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -19,9 +24,10 @@ public class PrintInfoBean { ...@@ -19,9 +24,10 @@ public class PrintInfoBean {
private Boolean[] isItalic = new Boolean[]{false}; private Boolean[] isItalic = new Boolean[]{false};
private int[] color = new int[]{0}; private Integer[] color = new Integer[]{0};
private double[] size = new double[]{1}; //文字大小
private Double[] size = new Double[]{1d};
//語言,每列是什麼語言 //語言,每列是什麼語言
private String[] Language = new String[]{"tw"}; private String[] Language = new String[]{"tw"};
...@@ -37,12 +43,12 @@ public class PrintInfoBean { ...@@ -37,12 +43,12 @@ public class PrintInfoBean {
Language = language; Language = language;
} }
public PrintInfoBean(String[] content, double[] size) { public PrintInfoBean(String[] content, Double[] size) {
this.content = content; this.content = content;
this.size = size; this.size = size;
} }
public PrintInfoBean(String[] content, double[] size, String[] language) { public PrintInfoBean(String[] content, Double[] size, String[] language) {
this.content = content; this.content = content;
this.size = size; this.size = size;
Language = language; Language = language;
...@@ -59,13 +65,13 @@ public class PrintInfoBean { ...@@ -59,13 +65,13 @@ public class PrintInfoBean {
this.isBold = isBold; this.isBold = isBold;
} }
public PrintInfoBean(String[] content, double[] size, int gravity) { public PrintInfoBean(String[] content, Double[] size, int gravity) {
this.content = content; this.content = content;
this.size = size; this.size = size;
this.gravity = gravity; this.gravity = gravity;
} }
public PrintInfoBean(String[] content, int[] color, double[] size, int gravity) { public PrintInfoBean(String[] content, Integer[] color, Double[] size, int gravity) {
this.content = content; this.content = content;
this.color = color; this.color = color;
this.size = size; this.size = size;
...@@ -78,27 +84,27 @@ public class PrintInfoBean { ...@@ -78,27 +84,27 @@ public class PrintInfoBean {
this.gravity = gravity; this.gravity = gravity;
} }
public PrintInfoBean(String[] content, Boolean[] isBold, double[] size) { public PrintInfoBean(String[] content, Boolean[] isBold, Double[] size) {
this.content = content; this.content = content;
this.isBold = isBold; this.isBold = isBold;
this.size = size; this.size = size;
} }
public PrintInfoBean(String[] content, Boolean[] isBold, double[] size, String[] language) { public PrintInfoBean(String[] content, Boolean[] isBold, Double[] size, String[] language) {
this.content = content; this.content = content;
this.isBold = isBold; this.isBold = isBold;
this.size = size; this.size = size;
Language = language; Language = language;
} }
public PrintInfoBean(String[] content, Boolean[] isBold, double[] size, int gravity) { public PrintInfoBean(String[] content, Boolean[] isBold, Double[] size, int gravity) {
this.content = content; this.content = content;
this.isBold = isBold; this.isBold = isBold;
this.size = size; this.size = size;
this.gravity = gravity; this.gravity = gravity;
} }
public PrintInfoBean(String[] content, Boolean[] isBold, int[] color, double[] size, int gravity) { public PrintInfoBean(String[] content, Boolean[] isBold, Integer[] color, Double[] size, int gravity) {
this.content = content; this.content = content;
this.isBold = isBold; this.isBold = isBold;
this.color = color; this.color = color;
...@@ -106,7 +112,7 @@ public class PrintInfoBean { ...@@ -106,7 +112,7 @@ public class PrintInfoBean {
this.gravity = gravity; this.gravity = gravity;
} }
public PrintInfoBean(String[] content, Boolean[] isBold, Boolean[] isItalic, int[] color, double[] size, int gravity) { public PrintInfoBean(String[] content, Boolean[] isBold, Boolean[] isItalic, Integer[] color, Double[] size, int gravity) {
this.content = content; this.content = content;
this.isBold = isBold; this.isBold = isBold;
this.isItalic = isItalic; this.isItalic = isItalic;
...@@ -139,19 +145,19 @@ public class PrintInfoBean { ...@@ -139,19 +145,19 @@ public class PrintInfoBean {
this.isItalic = isItalic; this.isItalic = isItalic;
} }
public int[] getColor() { public Integer[] getColor() {
return color; return color;
} }
public void setColor(int[] color) { public void setColor(Integer[] color) {
this.color = color; this.color = color;
} }
public double[] getSize() { public Double[] getSize() {
return size; return size;
} }
public void setSize(double[] size) { public void setSize(Double[] size) {
this.size = size; this.size = size;
} }
...@@ -171,6 +177,17 @@ public class PrintInfoBean { ...@@ -171,6 +177,17 @@ public class PrintInfoBean {
Language = language; Language = language;
} }
/**
* 將prj數據轉為打印類
*
* @param datas prj數據
* @param paperWidth 紙張寬度
* @param printLocation 廚房位置
* @param deviceBean 打印機信息
* @param printCurrencyBean 堂食or外賣配置
* @return 打印類集合
*/
public static List<List<PrintInfoBean>> transPrjBean(List<PrjBean.DataBean.Bean> datas, int paperWidth, String printLocation, PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) { public static List<List<PrintInfoBean>> transPrjBean(List<PrjBean.DataBean.Bean> datas, int paperWidth, String printLocation, PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) {
List<List<PrintInfoBean>> prjPrintBeans = new ArrayList<>(); List<List<PrintInfoBean>> prjPrintBeans = new ArrayList<>();
//通過打印位置生成多張用於打印的bitmap //通過打印位置生成多張用於打印的bitmap
...@@ -193,6 +210,20 @@ public class PrintInfoBean { ...@@ -193,6 +210,20 @@ public class PrintInfoBean {
return prjPrintBeans; return prjPrintBeans;
} }
private static boolean foodIsBold = false;//食品是否加粗
private static boolean foodItemIsBold = false;//細項是否加粗
private static boolean foodIsItalic = false;//食品是否斜體
private static boolean modifierIsItalic = false;//細項是否斜體
private static boolean numberIsFlip = false;//數量大於1顏色是否翻轉
private static int foodFontSize = 1;//食品名字體大小
private static int modifierFontSize = 1;//細項名字體大小
private static int foodColor = 0;//食品顏色
private static int modifierColor = 0;//細項顏色
private static double cnLength = 2;//中文字符占的寬度
private static int foodNameWidth = 21;//食品名所佔寬度
private static int foodNumWidth = 8;//食品數量佔的寬度
private static int foodPriceWidth = 12;//食品價格佔的寬度
/** /**
* 生成一張prj打印數據 * 生成一張prj打印數據
* *
...@@ -200,48 +231,7 @@ public class PrintInfoBean { ...@@ -200,48 +231,7 @@ public class PrintInfoBean {
*/ */
private static List<PrintInfoBean> getPrjPrintInfoBean(String key, int peparWidth, List<PrjBean.DataBean.Bean> prjBeans, PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) { private static List<PrintInfoBean> getPrjPrintInfoBean(String key, int peparWidth, List<PrjBean.DataBean.Bean> prjBeans, PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) {
List<PrintInfoBean> printInfoBeans = new ArrayList<>(); List<PrintInfoBean> printInfoBeans = new ArrayList<>();
boolean foodIsBold = false;//食品是否加粗 initPrintConfig(deviceBean, printCurrencyBean);
boolean foodItemIsBolde = false;//細項是否加粗
boolean foodIsItalic = false;//食品是否斜體
boolean modifierIsItalic = false;//細項是否斜體
boolean numberIsFlip = false;//數量大於1顏色是否翻轉
int foodColor = 0;//食品顏色
int modifierColor = 0;//細項顏色
if (printCurrencyBean != null) {
foodColor = printCurrencyBean.getFoodComplexion();
modifierColor = printCurrencyBean.getModifierComplexion();
}
if (deviceBean.getFoodIsBold() == 1) {
foodIsBold = true;
} else if (printCurrencyBean != null) {
foodIsBold = printCurrencyBean.getFoodIsBold() == 1;
}
if (deviceBean.getModifierIsBold() == 1) {
foodItemIsBolde = true;
} else if (printCurrencyBean != null) {
foodItemIsBolde = printCurrencyBean.getModifierIsBold() == 1;
}
if (deviceBean.getFoodIsItalic() == 1) {
foodIsItalic = true;
} else if (printCurrencyBean != null) {
foodIsItalic = printCurrencyBean.getFoodIsItalic() == 1;
}
if (deviceBean.getModifierIsItalic() == 1) {
modifierIsItalic = true;
} else if (printCurrencyBean != null) {
modifierIsItalic = printCurrencyBean.getModifierIsItalic() == 1;
}
if (deviceBean.getNumberIsFlip() == 1) {
numberIsFlip = true;
} else if (printCurrencyBean != null) {
numberIsFlip = printCurrencyBean.getNumberIsFlip() == 1;
}
if (prjBeans == null || prjBeans.size() <= 0) { if (prjBeans == null || prjBeans.size() <= 0) {
return null; return null;
} }
...@@ -251,33 +241,36 @@ public class PrintInfoBean { ...@@ -251,33 +241,36 @@ public class PrintInfoBean {
} }
if (TextUtil.isEmptyOrNullOrUndefined(prjBean.getTableName())) { if (TextUtil.isEmptyOrNullOrUndefined(prjBean.getTableName())) {
if (prjBean.getOrderType() == 7) { if (prjBean.getOrderType() == 7) {
printInfoBeans.add(new PrintInfoBean(new String[]{"自取"}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"自取"}, new Boolean[]{true}, new Double[]{2d}, 0));
if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getTakeFoodCode())) {
printInfoBeans.add(new PrintInfoBean(new String[]{"取餐碼:", prjBean.getTakeFoodCode()}, new Boolean[]{false, true}, new double[]{1, 2}, 0));
}
if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getBillNo())) { if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getBillNo())) {
//訂單碼不為空 //訂單碼不為空
printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", prjBean.getBillNo()}, new Boolean[]{false, true}, new double[]{1, 2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", prjBean.getBillNo()}, new Boolean[]{false, true}, new Double[]{1d, 2d}, 0));
}
if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getTakeFoodCode())) {
printInfoBeans.add(new PrintInfoBean(new String[]{"取餐碼:", prjBean.getTakeFoodCode()}, new Boolean[]{false, true}, new Double[]{1d, 2d}, 0));
} }
} else { } else {
printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new Double[]{2d}, 0));
if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getBillNo())) { if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getBillNo())) {
//訂單碼不為空 //訂單碼不為空
printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", prjBean.getBillNo()}, new Boolean[]{false, true}, new double[]{1, 2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", prjBean.getBillNo()}, new Boolean[]{false, true}, new Double[]{1d, 2d}, 0));
} else if (!TextUtil.isEmptyOrNullOrUndefined(prjBean.getTakeFoodCode())) {
//取餐碼不為空
printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", prjBean.getTakeFoodCode()}, new Boolean[]{false, true}, new Double[]{1d, 2d}, 0));
} }
} }
} else { } else {
printInfoBeans.add(new PrintInfoBean(new String[]{prjBean.getTableName()}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{prjBean.getTableName()}, new Boolean[]{true}, new Double[]{2d}, 0));
} }
//落單時間 //落單時間
printInfoBeans.add(new PrintInfoBean(new String[]{"落單時間:" + TimeUtils.getCurrentTimeInString(TimeUtils.DEFAULT_DATE_MDHM)}, new double[]{1}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"落單時間:" + TimeUtils.getCurrentTimeInString(TimeUtils.DEFAULT_DATE_MDHM)}, new Double[]{1d}, 0));
//廚房位置 //廚房位置
if (!TextUtil.isEmptyOrNullOrUndefined(key) && !key.equals("-1")) { if (!TextUtil.isEmptyOrNullOrUndefined(key) && !key.equals("-1")) {
printInfoBeans.add(new PrintInfoBean(new String[]{key + "廚房", " " + prjBean.getUserName()}, new double[]{1}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{key + "廚房", " " + prjBean.getUserName()}, new Double[]{1d}, 0));
} }
//人數 //人數
if (prjBean.getPerson() != 0) { if (prjBean.getPerson() != 0) {
printInfoBeans.add(new PrintInfoBean(new String[]{"人數:" + prjBean.getPerson(), GsaCloudApplication.getMemberName(GsaCloudApplication.getAppContext())}, new double[]{1}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"人數:" + prjBean.getPerson(), GsaCloudApplication.getMemberName(GsaCloudApplication.getAppContext())}, new Double[]{1d}, 0));
} }
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 1, peparWidth)}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 1, peparWidth)}, 0));
for (PrjBean.DataBean.Bean bean : prjBeans) { for (PrjBean.DataBean.Bean bean : prjBeans) {
...@@ -297,7 +290,7 @@ public class PrintInfoBean { ...@@ -297,7 +290,7 @@ public class PrintInfoBean {
} }
} }
} }
int beforeColor = 0; int beforeColor;
if (bean.getItemType() == 1) { if (bean.getItemType() == 1) {
//如果是主食品 //如果是主食品
beforeColor = foodColor; beforeColor = foodColor;
...@@ -307,7 +300,7 @@ public class PrintInfoBean { ...@@ -307,7 +300,7 @@ public class PrintInfoBean {
} }
if (bean.getNumber() > 1 && numberIsFlip) { if (bean.getNumber() > 1 && numberIsFlip) {
//翻轉顏色 //翻轉顏色
if(beforeColor == 0){ if (beforeColor == 0) {
beforeColor = 2; beforeColor = 2;
} else { } else {
beforeColor = 0; beforeColor = 0;
...@@ -315,13 +308,13 @@ public class PrintInfoBean { ...@@ -315,13 +308,13 @@ public class PrintInfoBean {
} }
if (bean.getItemType() == 1) { if (bean.getItemType() == 1) {
//主食品 //主食品
printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", bean.getProductName()}, new Boolean[]{foodIsBold}, new Boolean[]{foodIsItalic}, new int[]{beforeColor}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", bean.getProductName()}, new Boolean[]{foodIsBold}, new Boolean[]{foodIsItalic}, new Integer[]{beforeColor}, new Double[]{2d}, 0));
} else if (bean.getItemType() == 2) { } else if (bean.getItemType() == 2) {
//細項 //細項
printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", " " + bean.getProductName()}, new Boolean[]{foodItemIsBolde}, new Boolean[]{modifierIsItalic}, new int[]{beforeColor}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", " " + bean.getProductName()}, new Boolean[]{foodItemIsBold}, new Boolean[]{modifierIsItalic}, new Integer[]{beforeColor}, new Double[]{2d}, 0));
} else if (bean.getItemType() == 3) { } else if (bean.getItemType() == 3) {
//二級細項 //二級細項
printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", " " + bean.getProductName()}, new Boolean[]{foodItemIsBolde}, new Boolean[]{modifierIsItalic}, new int[]{beforeColor}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{bean.getNumber() + " ", " " + bean.getProductName()}, new Boolean[]{foodItemIsBold}, new Boolean[]{modifierIsItalic}, new Integer[]{beforeColor}, new Double[]{2d}, 0));
} }
} }
PrintInfoBean printInfoBean = printInfoBeans.get(0); PrintInfoBean printInfoBean = printInfoBeans.get(0);
...@@ -330,6 +323,204 @@ public class PrintInfoBean { ...@@ -330,6 +323,204 @@ public class PrintInfoBean {
return printInfoBeans; return printInfoBeans;
} }
/**
* 生成外送印單
*
* @return
*/
private static List<PrintInfoBean> getTakeAwayBillPrint(Context context, OrderDetails.DataBean data, PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) {
List<PrintInfoBean> printInfoBeans = new ArrayList<>();
initPrintConfig(deviceBean, printCurrencyBean);
if (data == null) {
return null;
}
printInfoBeans.add(new PrintInfoBean(new String[]{GsaCloudApplication.getBrandName(context)}, new Boolean[]{true}, new Double[]{2d}));
printInfoBeans.add(new PrintInfoBean(new String[]{GsaCloudApplication.getRestaurantName(context)}, new Boolean[]{true}, new Double[]{2d}));
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder(data.getOrder_type() == 2 ? "外送" : "自取", 2, deviceBean.getLineFontStop())}, new Boolean[]{true}, new Double[]{2d}));
String payType = "";
if (data.getOrderPayType() == 1) {
payType = "貨到付款";
} else if (data.getOrderPayType() == 0) {
payType = "店內支付";
} else if (data.getOrderPayType() == 2) {
payType = "在線支付";
}
printInfoBeans.add(new PrintInfoBean(new String[]{payType}, new Boolean[]{true}, new Double[]{2d}));
//送達時間或者取餐時間
printInfoBeans.add(new PrintInfoBean(new String[]{data.getOrder_type() == 2 ? data.getSEND_TIME() : data.getTakeTime()}, new Boolean[]{true}, new Double[]{1d}));
//加線
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 2, deviceBean.getLineFontStop())}, new Double[]{2d}));
printInfoBeans.add(new PrintInfoBean(new String[]{"單號:" + data.getORDER_NO()}, new Double[]{1d}, 0));
if (data.getOrder_type() == 7) {
//自取 顯示 取餐碼
if (!TextUtil.isEmptyOrNullOrUndefined(data.getTakeFoodCode())) {
printInfoBeans.add(new PrintInfoBean(new String[]{"取餐碼:" + data.getTakeFoodCode()}, new Double[]{3d}, 0));
}
} else {
//外送 顯示訂單碼
printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:" + data.getTakeFoodCode()}, new Double[]{3d}, 0));
}
printInfoBeans.add(new PrintInfoBean(new String[]{"單號:" + data.getORDER_NO()}, new Double[]{1d}, 0));
//開單時間
printInfoBeans.add(new PrintInfoBean(new String[]{context.getString(R.string.create_order_time) + TimeUtils.parseTimeRepeat(data.getCREATE_TIME(), TimeUtils.DEFAULT_DATE_FORMAT)}, new Double[]{1d}, 0));
if (data.getOrderPayType() == 2) {
//支付時間
if (data.getPayTime() != null) {
printInfoBeans.add(new PrintInfoBean(new String[]{"支付時間:" + data.getPayTime()}, new Double[]{1d}, 0));
}
}
//下面開始打印食品
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("項目", 1, deviceBean.getLineFontStop())}, new Double[]{1d}));
if (data.getPRODUCT_NAME() != null) {
for (OrderDetails.DataBean.PRODUCTNAMEBean productnameBean : data.getPRODUCT_NAME()) {
//遍歷食品
String foodName = productnameBean.getPRODUCT_NAME();
String foodNum = "X" + productnameBean.getNum();
String foodPrice = productnameBean.getPRICE();
if (foodName != null) {
if (getChineseValueLength(foodName) > foodNameWidth) {
//如果食品名的長度大於設定的最大長度
printInfoBeans.add(new PrintInfoBean(new String[]{MyPrintUtils.getFormatText(foodName, foodNameWidth), getSpaceByTextLength(foodNum, foodNumWidth) + foodNum, getSpaceByTextLength(foodPrice, foodPriceWidth) + foodPrice}, new Double[]{1d}));
} else {
printInfoBeans.add(new PrintInfoBean(new String[]{foodName + getSpaceByTextLength(foodName, foodNameWidth), getSpaceByTextLength(foodNum, foodNumWidth) + foodNum, getSpaceByTextLength(foodPrice, foodPriceWidth) + foodPrice}, new Double[]{1d}));
}
}
// for (OrderDetails.DataBean.PRODUCTNAMEBean.ChildBeanX childBeanX : item.getChild()) {
// View secondView = getChild(childBeanX.getPRODUCT_NAME(), childBeanX.getNum(), childBeanX.getPRICE(), indentation);
// childLayout.addView(secondView);
// if (childBeanX.getChild() != null && childBeanX.getChild().size() > 0) {
// LinearLayout secondLayout = secondView.findViewById(R.id.layout_food_content);
// for (OrderDetails.DataBean.PRODUCTNAMEBean.ChildBeanX.ChildBean childBean : childBeanX.getChild()) {
// secondLayout.addView(getChild(childBean.getPRODUCT_NAME(), childBean.getNum(), childBean.getPRICE(), indentation * 2));
// }
// }
// }
}
}
printInfoBeans.add(new PrintInfoBean(new String[]{"支付時間:" + data.getPayTime()}, new Double[]{1d}, 0));
//
// //計算金額
// billData.add(getBillBean("合計:", amountUnit + MoneyUtil.sub(MoneyUtil.sub(Double.parseDouble(data.getTOTAL_AMOUNT()), data.getLunchbox()), data.getDELIVERY_CHARGE())));
// if (data.getLunchbox() != 0) {
// billData.add(getBillBean("餐盒費:", amountUnit + data.getLunchbox()));
// }
// if (data.getDELIVERY_CHARGE() != 0) {
// billData.add(getBillBean("送貨費:", amountUnit + data.getDELIVERY_CHARGE()));
// }
// if (data.getCouponList() != null && data.getCouponList().size() > 0) {
// for (OrderDetails.DataBean.CouponBean coupon : data.getCouponList()) {
// billData.add(getBillBean(coupon.getCouponName() + ":", "-$" + coupon.getDiscount_amount()));
// }
// }
return printInfoBeans;
}
/**
* 左右顯示文字
*
* @param leftText 左側內容
* @param rightText 右側內容
* @param maxLength 最大長度
* @return
*/
// private static String getLeftRightText(String leftText, String rightText, int maxLength) {
// int leftLength = maxLength / 2 - 2;
// if (getChineseValueLength(leftText) > leftLength) {
// //如果左側文本的長度大於設定的最大長度,換行
//
// }
//
//
// }
/**
* 獲取縮進,通過文字和最大長度
*
* @param text
* @param MaxLength
* @return
*/
private static String getSpaceByTextLength(String text, int MaxLength) {
int spaceLength = (int) Math.ceil(MaxLength - getChineseValueLength(text));
StringBuilder space = new StringBuilder();
for (int i = 0; i < spaceLength; i++) {
space.append(" ");
}
return space.toString();
}
/**
* 初始化打印配置
*
* @param deviceBean 打印機
* @param printCurrencyBean 通用打印配置
*/
private static void initPrintConfig(PrinterDeviceBean deviceBean, PrintCurrencyBean printCurrencyBean) {
if (printCurrencyBean != null) {
foodColor = printCurrencyBean.getFoodComplexion();
modifierColor = printCurrencyBean.getModifierComplexion();
}
if (deviceBean.getFoodIsBold() == 1) {
foodIsBold = true;
} else if (printCurrencyBean != null) {
foodIsBold = printCurrencyBean.getFoodIsBold() == 1;
}
if (deviceBean.getModifierIsBold() == 1) {
foodItemIsBold = true;
} else if (printCurrencyBean != null) {
foodItemIsBold = printCurrencyBean.getModifierIsBold() == 1;
}
if (deviceBean.getFoodIsItalic() == 1) {
foodIsItalic = true;
} else if (printCurrencyBean != null) {
foodIsItalic = printCurrencyBean.getFoodIsItalic() == 1;
}
if (deviceBean.getModifierIsItalic() == 1) {
modifierIsItalic = true;
} else if (printCurrencyBean != null) {
modifierIsItalic = printCurrencyBean.getModifierIsItalic() == 1;
}
if (deviceBean.getNumberIsFlip() == 1) {
numberIsFlip = true;
} else if (printCurrencyBean != null) {
numberIsFlip = printCurrencyBean.getNumberIsFlip() == 1;
}
if ((deviceBean.getPrinterName() != null && deviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))
&& (deviceBean.getModel() != null && deviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase()))) {
cnLength = 1.5;
} else {
cnLength = 2;
}
if (deviceBean.getLineFontStop() > 0) {
foodNameWidth = (int) (deviceBean.getLineFontStop() * 0.5);
foodNumWidth = (int) (deviceBean.getLineFontStop() * 0.2);
foodPriceWidth = (int) (deviceBean.getLineFontStop() * 0.3);
}
}
/**
* 獲取一條直線
*
* @param text 直線中間需要顯示的文字
* @param fontSize 字體大小
* @param paperWidth 紙張寬度
* @return
*/
private static String getLineBorder(String text, double fontSize, int paperWidth) { private static String getLineBorder(String text, double fontSize, int paperWidth) {
if (fontSize == 0) { if (fontSize == 0) {
fontSize = 1; fontSize = 1;
...@@ -351,13 +542,19 @@ public class PrintInfoBean { ...@@ -351,13 +542,19 @@ public class PrintInfoBean {
return builder.toString(); return builder.toString();
} }
/**
* 根據字符串獲取長度,中文長度為2,在那台針式打印機長度為1.5
*
* @param value
* @return
*/
private static double getChineseValueLength(String value) { private static double getChineseValueLength(String value) {
double valueLength = 0; double valueLength = 0;
String chinese = "[\u4e00-\u9fa5]"; String chinese = "[\u4e00-\u9fa5]";
for (int i = 0; i < value.length(); i++) { for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1); String temp = value.substring(i, i + 1);
if (temp.matches(chinese)) { if (temp.matches(chinese)) {
valueLength += 1.5; valueLength += cnLength;
} else { } else {
valueLength += 1; valueLength += 1;
} }
......
...@@ -89,9 +89,6 @@ public class PrjBean { ...@@ -89,9 +89,6 @@ public class PrjBean {
private int itemType; private int itemType;
private String sender; private String sender;
public int getId() { public int getId() {
return id; return id;
} }
......
...@@ -9,6 +9,7 @@ import com.epson.epos2.printer.Printer; ...@@ -9,6 +9,7 @@ import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo; import com.epson.epos2.printer.PrinterStatusInfo;
import com.epson.epos2.printer.ReceiveListener; import com.epson.epos2.printer.ReceiveListener;
import com.joe.print.mvp.model.bean.PrintInfoBean; import com.joe.print.mvp.model.bean.PrintInfoBean;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -244,6 +245,9 @@ public class EpsonPrint implements ReceiveListener { ...@@ -244,6 +245,9 @@ public class EpsonPrint implements ReceiveListener {
return; return;
} }
connectByIp(ip, mPrinter.getStatus()); connectByIp(ip, mPrinter.getStatus());
if (mPrinter == null) {
return;
}
mPrinter.clearCommandBuffer(); mPrinter.clearCommandBuffer();
try { try {
for (PrintInfoBean printInfoBean : printInfoBeans) { for (PrintInfoBean printInfoBean : printInfoBeans) {
...@@ -277,116 +281,31 @@ public class EpsonPrint implements ReceiveListener { ...@@ -277,116 +281,31 @@ public class EpsonPrint implements ReceiveListener {
if (i == 0) { if (i == 0) {
location = 0; location = 0;
} }
int color; int textSize = (int) MyPrintUtils.getContentByLength(printInfoBean.getSize(), i);
int textSize;
int isItalic; //是否傾斜字體
if (printInfoBean.getColor().length == 1) { int isItalic = ((Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsItalic(), i)) ? 1 : 0;
color = printInfoBean.getColor()[0]; int isBold = ((Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsBold(), i)) ? 1 : 0;
} else { int color = (int) MyPrintUtils.getContentByLength(printInfoBean.getColor(), i);
color = printInfoBean.getColor()[i];
}
if (color > 4) { if (color > 4) {
color = 4; color = 4;
} }
if (printInfoBean.getIsItalic().length == 1) { // mPrinter.addTextRotate(isItalic);
isItalic = printInfoBean.getIsItalic()[0] ? 1 : 0;
} else {
isItalic = printInfoBean.getIsItalic()[i] ? 1 : 0;
}
mPrinter.addTextRotate(isItalic);
if (printInfoBean.getIsBold().length == 1) {
//reverse取值0,1沒效果,ul下劃線,em加粗, //reverse取值0,1沒效果,ul下劃線,em加粗,
mPrinter.addTextStyle(1, 0, printInfoBean.getIsBold()[0] ? 1 : 0, color); mPrinter.addTextStyle(1, 0, isBold, color);
} else { setLanguage((String) MyPrintUtils.getContentByLength(printInfoBean.getLanguage(), i));
if (printInfoBean.getIsBold()[i]) {
mPrinter.addTextStyle(1, 0, 1, color);
} else {
mPrinter.addTextStyle(1, 0, 0, color);
}
}
StringBuilder space = new StringBuilder();//縮進
StringBuilder space = new StringBuilder(); for (int j = 0; j < location / textSize; j++) {
if (printInfoBean.getSize().length == 1) {
for (int j = 0; j < location / printInfoBean.getSize()[0]; j++) {
space.append(" ");
}
textSize = (int) printInfoBean.getSize()[0];
mPrinter.addTextSize(textSize, textSize);
location += getChineseValueLength(printInfoBean.getContent()[i]) * printInfoBean.getSize()[0];
} else {
for (int j = 0; j < location / printInfoBean.getSize()[i]; j++) {
space.append(" "); space.append(" ");
} }
textSize = (int) printInfoBean.getSize()[i];
mPrinter.addTextSize(textSize, textSize); mPrinter.addTextSize(textSize, textSize);
location += getChineseValueLength(printInfoBean.getContent()[i]) * printInfoBean.getSize()[i]; location += MyPrintUtils.getChineseValueLength(printInfoBean.getContent()[i]) * printInfoBean.getSize()[0];
}
if (printInfoBean.getLanguage().length == 1) {
setLanguage(printInfoBean.getLanguage()[0]);
} else {
setLanguage(printInfoBean.getLanguage()[i]);
}
mPrinter.addText(getFormatText(space + printInfoBean.getContent()[i], paperWidth / textSize));
// mPrinter.addLineSpace(100);//行間距
}
private static String abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/** mPrinter.addText(MyPrintUtils.getFormatText(space + printInfoBean.getContent()[i], paperWidth / textSize));
* 如果超過紙張寬度的英文,換行時,要截取得當 // mPrinter.addLineSpace(100);//行間距
* 23
*
* @return
*/
private static String getFormatText(String content, int paperWidth) {
if (content.length() > paperWidth) {
int lastIndex = 0;//上次截取時最後的下標
StringBuilder stringBuilder = new StringBuilder();
while (true) {
if (lastIndex + paperWidth >= content.length()) {
String footStr = content.substring(lastIndex);
stringBuilder.append(footStr);
return stringBuilder.toString();
} else {
String headerStr = content.substring(lastIndex, lastIndex + paperWidth);
String nextContext = content.substring(lastIndex + paperWidth, lastIndex + paperWidth + 1);
if (abc.contains(headerStr.charAt(headerStr.length() - 1) + "") && abc.contains(nextContext)) {
//如果最後一位是英文單詞,往前找找到空格或者不是英文的,然後換行
for (int j = headerStr.length() - 1; j >= 0; j--) {
String tchar = headerStr.charAt(j) + "";
if (j == 0) {
//循環完了都沒找到,就不管了
stringBuilder.append(headerStr);
stringBuilder.append("\n");
lastIndex += paperWidth;
break;
}
if (!abc.contains(tchar)) {
//找到不是英文的那個
String newHeaderStr = headerStr.substring(0, j + 1);
stringBuilder.append(newHeaderStr);
stringBuilder.append("\n");
lastIndex += j + 1;
break;
}
}
} else {
lastIndex += paperWidth;
stringBuilder.append(headerStr);
stringBuilder.append("\n");
}
}
}
} else {
return content;
}
} }
public static void main(String[] args) {
String str = "asd asdfa asdf sdjn sdf0";
System.out.println(getFormatText(str, 20));
}
private void setLanguage(String language) throws Epos2Exception { private void setLanguage(String language) throws Epos2Exception {
if ("en".equals(language)) { if ("en".equals(language)) {
...@@ -409,20 +328,6 @@ public class EpsonPrint implements ReceiveListener { ...@@ -409,20 +328,6 @@ public class EpsonPrint implements ReceiveListener {
} }
} }
public static double getChineseValueLength(String value) {
double valueLength = 0;
String chinese = "[\u4e00-\u9fa5]";
for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1);
if (temp.matches(chinese)) {
valueLength += 1.5;
} else {
valueLength += 1;
}
}
return valueLength;
}
public int putPrintData(String ip, Bitmap bitmap) { public int putPrintData(String ip, Bitmap bitmap) {
//把bitmap存隊列中,下次打印 //把bitmap存隊列中,下次打印
bitmaps.add(bitmap); bitmaps.add(bitmap);
......
...@@ -60,264 +60,4 @@ public class IpPrintMaker implements PrintDataMaker { ...@@ -60,264 +60,4 @@ public class IpPrintMaker implements PrintDataMaker {
return new ArrayList<>(); return new ArrayList<>();
} }
} }
/*************************************************************************
     * 假设一个240*240的图片,分辨率设为24, 共分10行打印
     * 每一行,是一个 240*24 的点阵, 每一列有24个点,存储在3个byte里面。
     * 每个byte存储8个像素点信息。因为只有黑白两色,所以对应为1的位是黑色,对应为0的位是白色
     **************************************************************************/
/**
* 把一张Bitmap图片转化为打印机可以打印的字节流
*
* @param bmp
* @return
*/
public void draw2PxPoint(Bitmap bmp) throws IOException {
//用来存储转换后的 bitmap 数据。为什么要再加1000,这是为了应对当图片高度无法
//整除24时的情况。比如bitmap 分辨率为 240 * 250,占用 7500 byte,
//但是实际上要存储11行数据,每一行需要 24 * 240 / 8 =720byte 的空间。再加上一些指令存储的开销,
//所以多申请 1000byte 的空间是稳妥的,不然运行时会抛出数组访问越界的异常。
int size = bmp.getWidth() * bmp.getHeight() / 8 + 1000;
byte[] data = new byte[size];
int k = 0;
//设置行距为0的指令
data[k++] = 0x1B;
data[k++] = 0x33;
data[k++] = 0x00;
// 逐行打印
for (int j = 0; j < bmp.getHeight() / 24f; j++) {
//打印图片的指令
data[k++] = 0x1B;
data[k++] = 0x2A;
data[k++] = 33;
data[k++] = (byte) (bmp.getWidth() % 256); //nL
data[k++] = (byte) (bmp.getWidth() / 256); //nH
//对于每一行,逐列打印
for (int i = 0; i < bmp.getWidth(); i++) {
//每一列24个像素点,分为3个字节存储
for (int m = 0; m < 3; m++) {
//每个字节表示8个像素点,0表示白色,1表示黑色
for (int n = 0; n < 8; n++) {
byte b = px2Byte(i, j * 24 + m * 8 + n, bmp);
data[k] += data[k] + b;
}
k++;
}
}
data[k++] = 10;//换行
}
// socketOut.write(data);
// socketOut.flush();
}
/*************************************************************************
* 我们的热敏打印机是RP-POS80S或RP-POS80P或RP-POS80CS或RP-POS80CP打印机
* 360*360的图片,8个字节(8个像素点)是一个二进制,将二进制转化为十进制数值
* y轴:24个像素点为一组,即360就是15组(0-14)
* x轴:360个像素点(0-359)
* 里面的每一组(24*360),每8个像素点为一个二进制,(每组有3个,3*8=24)
**************************************************************************/
/**
* 把一张Bitmap图片转化为打印机可以打印的bit(将图片压缩为360*360)
* 效率很高(相对于下面)
*
* @param bit
* @return
*/
public static byte[] draw2PxPoint2(Bitmap bit) {
byte[] data = new byte[16290];
int height = bit.getHeight() + (24 - bit.getHeight() % 24);
int y = height / 24;
int k = 0;
for (int j = 0; j < y; j++) {
data[k++] = 0x1B;
data[k++] = 0x2A;
data[k++] = 33; // m=33时,选择24点双密度打印,分辨率达到200DPI。
data[k++] = 0x68;
data[k++] = 0x01;
for (int i = 0; i < bit.getWidth(); i++) {
for (int m = 0; m < 3; m++) {
for (int n = 0; n < 8; n++) {
byte b = px2Byte(i, j * 24 + m * 8 + n, bit);
data[k] += data[k] + b;
}
k++;
}
}
data[k++] = 10;
}
return data;
}
/**
* 把一张Bitmap图片转化为打印机可以打印的bit
*
* @param bit
* @return
*/
public static byte[] pic2PxPoint(Bitmap bit) {
long start = System.currentTimeMillis();
byte[] data = new byte[16290];
int k = 0;
for (int i = 0; i < 15; i++) {
data[k++] = 0x1B;
data[k++] = 0x2A;
data[k++] = 33; // m=33时,选择24点双密度打印,分辨率达到200DPI。
data[k++] = 0x68;
data[k++] = 0x01;
for (int x = 0; x < 360; x++) {
for (int m = 0; m < 3; m++) {
byte[] by = new byte[8];
for (int n = 0; n < 8; n++) {
byte b = px2Byte(x, i * 24 + m * 8 + 7 - n, bit);
by[n] = b;
}
data[k] = (byte) changePointPx1(by);
k++;
}
}
data[k++] = 10;
}
long end = System.currentTimeMillis();
long str = end - start;
return data;
}
/**
* 图片二值化,黑色是1,白色是0
*
* @param x 横坐标
* @param y 纵坐标
* @param bit 位图
* @return
*/
public static byte px2Byte(int x, int y, Bitmap bit) {
byte b;
if (y >= bit.getHeight()) {
return 0;
}
int pixel = bit.getPixel(x, y);
int red = (pixel & 0x00ff0000) >> 16; // 取高两位
int green = (pixel & 0x0000ff00) >> 8; // 取中两位
int blue = pixel & 0x000000ff; // 取低两位
int gray = RGB2Gray(red, green, blue);
if (gray < 128) {
b = 1;
} else {
b = 0;
}
return b;
}
/**
* 图片灰度的转化
*
* @param r
* @param g
* @param b
* @return
*/
private static int RGB2Gray(int r, int g, int b) {
int gray = (int) (0.29900 * r + 0.58700 * g + 0.11400 * b); //灰度转化公式
return gray;
}
/**
* 对图片进行压缩(去除透明度)
*
* @param bitmapOrg
*/
public static Bitmap compressPic(Bitmap bitmapOrg) {
// 获取这个图片的宽和高
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
// 定义预转换成的图片的宽度和高度
int newWidth = 360;
int newHeight = 360;
Bitmap targetBmp = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
Canvas targetCanvas = new Canvas(targetBmp);
targetCanvas.drawColor(0xffffffff);
targetCanvas.drawBitmap(bitmapOrg, new Rect(0, 0, width, height), new Rect(0, 0, newWidth, newHeight), null);
return targetBmp;
}
/**
* 对图片进行压缩(不去除透明度)
*
* @param bitmapOrg
*/
public static Bitmap compressBitmap(Bitmap bitmapOrg) {
// 加载需要操作的图片,这里是一张图片
// Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.alipay);
// 获取这个图片的宽和高
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
// 定义预转换成的图片的宽度和高度
int newWidth = 360;
int newHeight = 360;
// 计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
// 将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中
// BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
return resizedBitmap;
}
/**
* 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值(效率更高)
*
* @param arry
* @return
*/
public static int changePointPx1(byte[] arry) {
int v = 0;
for (int j = 0; j < arry.length; j++) {
if (arry[j] == 1) {
v = v | 1 << j;
}
}
return v;
}
/**
* 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值
*
* @param arry
* @return
*/
public byte changePointPx(byte[] arry) {
byte v = 0;
for (int i = 0; i < 8; i++) {
v += v + arry[i];
}
return v;
}
/**
* 得到位图的某个点的像素值
*
* @param bitmap
* @return
*/
public byte[] getPicPx(Bitmap bitmap) {
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];// 保存所有的像素的数组,图片宽×高
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < pixels.length; i++) {
int clr = pixels[i];
int red = (clr & 0x00ff0000) >> 16; // 取高两位
int green = (clr & 0x0000ff00) >> 8; // 取中两位
int blue = clr & 0x000000ff; // 取低两位
System.out.println("r=" + red + ",g=" + green + ",b=" + blue);
}
return null;
}
} }
...@@ -2,9 +2,10 @@ package com.joe.print.mvp.print; ...@@ -2,9 +2,10 @@ package com.joe.print.mvp.print;
import com.gingersoft.gsa.cloud.print.PrintDataMaker; import com.gingersoft.gsa.cloud.print.PrintDataMaker;
import com.gingersoft.gsa.cloud.print.PrinterWriter; import com.gingersoft.gsa.cloud.print.PrinterWriter;
import com.gingersoft.gsa.cloud.print.PrinterWriterExecutor;
import com.joe.print.mvp.model.bean.PrintInfoBean; import com.joe.print.mvp.model.bean.PrintInfoBean;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -27,38 +28,9 @@ public class TestPrintMaker implements PrintDataMaker { ...@@ -27,38 +28,9 @@ public class TestPrintMaker implements PrintDataMaker {
ArrayList<byte[]> data = new ArrayList<>(); ArrayList<byte[]> data = new ArrayList<>();
try { try {
for (PrintInfoBean printInfoBean : printInfoBeans) { for (PrintInfoBean printInfoBean : printInfoBeans) {
if (printInfoBean.getGravity() == 0) {
printer.setAlignLeft();
}
if (printInfoBean.getGravity() == 1) {
printer.setAlignCenter();
}
if (printInfoBean.getGravity() == 2) {
printer.setAlignRight();
}
if(printInfoBean.getSize().length > 1){
//如果打印多列內容,並且字體大小配置多個,則每一列取自己對應的字體大小 //如果打印多列內容,並且字體大小配置多個,則每一列取自己對應的字體大小
for (int i = 0; i < printInfoBean.getSize().length; i++) { for (int i = 0; i < printInfoBean.getContent().length; i++) {
//打印多列 print(printInfoBean, i);
if (printInfoBean.getIsBold()[i]) {
printer.setEmphasizedOn();
} else {
printer.setEmphasizedOff();
}
printer.setFontSize(printInfoBean.getSize()[i]);
printer.print(printInfoBean.getContent()[i]);
}
} else {
if(printInfoBean.getContent().length == 1){
//如果只打印一列內容,則字體大小只取size數組的第一個
if (printInfoBean.getIsBold()[0]) {
printer.setEmphasizedOn();
} else {
printer.setEmphasizedOff();
}
printer.setFontSize(printInfoBean.getSize()[0]);
printer.print(printInfoBean.getContent()[0]);
}
} }
printer.print("\n"); printer.print("\n");
} }
...@@ -69,7 +41,40 @@ public class TestPrintMaker implements PrintDataMaker { ...@@ -69,7 +41,40 @@ public class TestPrintMaker implements PrintDataMaker {
data.add(printer.getDataAndClose()); data.add(printer.getDataAndClose());
return data; return data;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return new ArrayList<>(); return new ArrayList<>();
} }
} }
private void print(PrintInfoBean printInfoBean, int i) throws IOException {
// if (i == 0) {
// location = 0;
// }
if (printInfoBean.getGravity() == 0) {
printer.setAlignLeft();
} else if (printInfoBean.getGravity() == 1) {
printer.setAlignCenter();
} else if (printInfoBean.getGravity() == 2) {
printer.setAlignRight();
}
double textSize = (Double) MyPrintUtils.getContentByLength(printInfoBean.getSize(), i);
//是否傾斜字體
int isItalic = ((Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsItalic(), i)) ? 1 : 0;
boolean isBold = (Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsBold(), i);
// int color = (int) MyPrintUtils.getContentByLength(printInfoBean.getColor(), i);熱敏打印沒有顏色
if (isBold) {
printer.setEmphasizedOn();
} else {
printer.setEmphasizedOff();
}
printer.setFontSize(textSize);
printer.print(printInfoBean.getContent()[i]);
// mPrinter.addTextRotate(isItalic);
//reverse取值0,1沒效果,ul下劃線,em加粗,
// mPrinter.addLineSpace(100);//行間距
}
} }
\ No newline at end of file
package com.joe.print.mvp.print.common;
import java.util.List;
public interface PrinterFinderCallback<C> {
void onStart();
void onFound(C c);
void onFinished(List<C> cs);
}
package com.joe.print.mvp.print.common;
public interface SendCallback {
void onCallback(int code, String printId);
}
package com.joe.print.mvp.print.common;
public final class SendResultCode {
public static final int SEND_SUCCESS = 0;
public static final int SEND_FAILED = 1;
}
...@@ -55,7 +55,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -55,7 +55,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
private Disposable wakeDisposable; private Disposable wakeDisposable;
private List<PrinterDeviceBean> printerDeviceBeans; private List<PrinterDeviceBean> printerDeviceBeans;
private List<PrjBean.DataBean.Bean> printDatas = new ArrayList<>(); private List<PrjBean.DataBean.Bean> printDatas = new ArrayList<>();
// private List<PrintCurrencyBean> printCurrencyBeans;//通用打印配置
// @Override // @Override
// public void onCreate() { // public void onCreate() {
// super.onCreate(); // super.onCreate();
...@@ -81,6 +81,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -81,6 +81,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean(); printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
printerDeviceDaoUtils.closeConnection(); printerDeviceDaoUtils.closeConnection();
} }
printCurrencyBeans = MyPrintUtils.getPrintCurrencyBeans(this);
} }
@Nullable @Nullable
...@@ -191,11 +192,14 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -191,11 +192,14 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
private PrinterRoot printerInIt; private PrinterRoot printerInIt;
private String json = "{\"success\":true,\"sysTime\":1595066909048,\"data\":{\"K1\":[{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"}]}}\n"; private String json = "{\"success\":true,\"sysTime\":1595066909048,\"data\":{\"K1\":[{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"}]}}\n";
/** /**
* 開始打印 * 開始打印
*/ */
private void startPrint(String json) { private void startPrint(String json) {
printDatas.clear(); printDatas.clear();
PrintCurrencyBean printCurrencyBean;
PrjBean prjBean = JsonUtils.parseObject(json, PrjBean.class); PrjBean prjBean = JsonUtils.parseObject(json, PrjBean.class);
if (prjBean == null || prjBean.getData() == null) { if (prjBean == null || prjBean.getData() == null) {
return; return;
...@@ -218,9 +222,13 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -218,9 +222,13 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
//獲取通用打印配置
printCurrencyBean = getCurrencyBean();
if (printerInIt == null) { if (printerInIt == null) {
printerInIt = PrinterRoot.getPrinterByType(PRINT_KITCHEN); printerInIt = PrinterRoot.getPrinterByType(PRINT_KITCHEN);
} }
//獲取打印機列表
getPrintList(); getPrintList();
for (Map.Entry<String, List<PrjBean.DataBean.Bean>> prjMap : listMap.entrySet()) { for (Map.Entry<String, List<PrjBean.DataBean.Bean>> prjMap : listMap.entrySet()) {
for (PrinterDeviceBean deviceBean : printerDeviceBeans) { for (PrinterDeviceBean deviceBean : printerDeviceBeans) {
...@@ -239,8 +247,6 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -239,8 +247,6 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
if (deviceBean.getPaperSpecification() != null) { if (deviceBean.getPaperSpecification() != null) {
paperWidth = (int) (Double.parseDouble(deviceBean.getPaperSpecification()) / 6); paperWidth = (int) (Double.parseDouble(deviceBean.getPaperSpecification()) / 6);
} }
PrintCurrencyBean printCurrencyBean = MyPrintUtils.getInstance().getPrintCurrencyBeanByType(this, 2);
List<List<PrintInfoBean>> prjBeans = PrintInfoBean.transPrjBean(prjMap.getValue(), paperWidth, prjMap.getKey(), deviceBean, printCurrencyBean); List<List<PrintInfoBean>> prjBeans = PrintInfoBean.transPrjBean(prjMap.getValue(), paperWidth, prjMap.getKey(), deviceBean, printCurrencyBean);
for (List<PrintInfoBean> prjPrintBean : prjBeans) { for (List<PrintInfoBean> prjPrintBean : prjBeans) {
mPrinter.putPrintString(deviceBean.getIp(), paperWidth, prjPrintBean); mPrinter.putPrintString(deviceBean.getIp(), paperWidth, prjPrintBean);
...@@ -270,6 +276,21 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan ...@@ -270,6 +276,21 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
} }
} }
private PrintCurrencyBean getCurrencyBean() {
if (printDatas != null && printDatas.size() > 0) {
PrjBean.DataBean.Bean bean = printDatas.get(0);
if (bean != null) {
if (bean.getOrderType() == 1) {
//堂食
return MyPrintUtils.getInstance().getPrintCurrencyBeanByType(this, 1);
} else {
return MyPrintUtils.getInstance().getPrintCurrencyBeanByType(this, 2);
}
}
}
return null;
}
/** /**
* @param printState 打印狀態 1未打印 2打印中 3已打印 * @param printState 打印狀態 1未打印 2打印中 3已打印
*/ */
......
package com.joe.print.mvp.print.utils;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.util.Hashtable;
public class BytesUtil {
//字节流转16进制字符串
public static String getHexStringFromBytes(byte[] data) {
if (data == null || data.length <= 0) {
return null;
}
String hexString = "0123456789ABCDEF";
int size = data.length * 2;
StringBuilder sb = new StringBuilder(size);
for (int i = 0; i < data.length; i++) {
sb.append(hexString.charAt((data[i] & 0xF0) >> 4));
sb.append(hexString.charAt((data[i] & 0x0F) >> 0));
}
return sb.toString();
}
//单字符转字节
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
//16进制字符串转字节数组
@SuppressLint("DefaultLocale")
public static byte[] getBytesFromHexString(String hexstring){
if(hexstring == null || hexstring.equals("")){
return null;
}
hexstring = hexstring.replace(" ", "");
hexstring = hexstring.toUpperCase();
int size = hexstring.length()/2;
char[] hexarray = hexstring.toCharArray();
byte[] rv = new byte[size];
for(int i=0; i<size; i++){
int pos = i * 2;
rv[i] = (byte) (charToByte(hexarray[pos]) << 4 | charToByte(hexarray[pos + 1]));
}
return rv;
}
//十进制字符串转字节数组
@SuppressLint("DefaultLocale")
public static byte[] getBytesFromDecString(String decstring){
if(decstring == null || decstring.equals("")){
return null;
}
decstring = decstring.replace(" ", "");
int size = decstring.length()/2;
char[] decarray = decstring.toCharArray();
byte[] rv = new byte[size];
for(int i=0; i<size; i++){
int pos = i * 2;
rv[i] = (byte) (charToByte(decarray[pos])*10 + charToByte(decarray[pos + 1]));
}
return rv;
}
//字节数组组合操作1
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {
byte[] byte_3 = new byte[byte_1.length + byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}
//字节数组组合操作2
public static byte[] byteMerger(byte[][] byteList) {
int length = 0;
for (int i = 0; i < byteList.length; i++) {
length += byteList[i].length;
}
byte[] result = new byte[length];
int index = 0;
for (int i = 0; i < byteList.length; i++) {
byte[] nowByte = byteList[i];
for (int k = 0; k < byteList[i].length; k++) {
result[index] = nowByte[k];
index++;
}
}
for (int i = 0; i < index; i++) {
// CommonUtils.LogWuwei("", "result[" + i + "] is " + result[i]);
}
return result;
}
//生成表格字节流
public static byte[] initTable(int h, int w){
int hh = h * 32;
int ww = w * 4;
byte[] data = new byte[ hh * ww + 5];
data[0] = (byte)ww;//xL
data[1] = (byte)(ww >> 8);//xH
data[2] = (byte)hh;
data[3] = (byte)(hh >> 8);
int k = 4;
int m = 31;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
}
if(i == h-1) m =30;
for(int t=0; t< m; t++){
for(int j=0; j<w-1; j++){
data[k++] = (byte)0x80;
data[k++] = (byte)0;
data[k++] = (byte)0;
data[k++] = (byte)0;
}
data[k++] = (byte)0x80;
data[k++] = (byte)0;
data[k++] = (byte)0;
data[k++] = (byte)0x01;
}
}
for(int j=0; j<w; j++){
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
data[k++] = (byte)0xFF;
}
data[k++] = 0x0A;
return data;
}
/**
* 生成二维码字节流
*
* @param data
* @param size
* @return
*/
public static byte[] getZXingQRCode(String data, int size) {
try {
Hashtable<EncodeHintType, String> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, size, size, hints);
//System.out.println("bitmatrix height:" + bitMatrix.getHeight() + " width:" + bitMatrix.getWidth());
return getBytesFromBitMatrix(bitMatrix);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static byte[] getBytesFromBitMatrix(BitMatrix bits) {
if (bits == null) return null;
int h = bits.getHeight();
int w = (bits.getWidth() + 7) / 8;
byte[] rv = new byte[h * w + 4];
rv[0] = (byte) w;//xL
rv[1] = (byte) (w >> 8);//xH
rv[2] = (byte) h;
rv[3] = (byte) (h >> 8);
int k = 4;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
for (int n = 0; n < 8; n++) {
byte b = getBitMatrixColor(bits, j * 8 + n, i);
rv[k] += rv[k] + b;
}
k++;
}
}
return rv;
}
private static byte getBitMatrixColor(BitMatrix bits, int x, int y) {
int width = bits.getWidth();
int height = bits.getHeight();
if (x >= width || y >= height || x < 0 || y < 0) return 0;
if (bits.get(x, y)) {
return 1;
} else {
return 0;
}
}
/**
* 将bitmap图转换为头四位有宽高的光栅位图
*/
public static byte[] getBytesFromBitMap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int bw = (width - 1) / 8 + 1;
byte[] rv = new byte[height * bw + 4];
rv[0] = (byte) bw;//xL
rv[1] = (byte) (bw >> 8);//xH
rv[2] = (byte) height;
rv[3] = (byte) (height >> 8);
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int clr = pixels[width * i + j];
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
byte gray = (RGB2Gray(red, green, blue));
rv[(width * i + j) / 8 + 4] = (byte) (rv[(width * i + j) / 8 + 4] | (gray << (7 - ((width * i + j) % 8))));
}
}
return rv;
}
/**
* 将bitmap转成按mode指定的N点行数据
*/
public static byte[] getBytesFromBitMap(Bitmap bitmap, int mode) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width*height];
if(mode == 0 || mode == 1){
byte[] res = new byte[width*height/8 + 5*height/8];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for(int i = 0; i < height/8; i++){
res[0 + i*(width+5)] = 0x1b;
res[1 + i*(width+5)] = 0x2a;
res[2 + i*(width+5)] = (byte) mode;
res[3 + i*(width+5)] = (byte) (width%256);
res[4 + i*(width+5)] = (byte) (width/256);
for(int j = 0; j < width; j++){
byte gray = 0;
for(int m = 0; m < 8; m++){
int clr = pixels[j + width*(i*8+m)];
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
gray = (byte) ((RGB2Gray(red, green, blue)<<(7-m))|gray);
}
res[5 + j + i*(width+5)] = gray;
}
}
return res;
}else if(mode == 32 || mode == 33){
byte[] res = new byte[width*height/8 + 5*height/24];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for(int i = 0; i < height/24; i++){
res[0 + i*(width*3+5)] = 0x1b;
res[1 + i*(width*3+5)] = 0x2a;
res[2 + i*(width*3+5)] = (byte) mode;
res[3 + i*(width*3+5)] = (byte) (width%256);
res[4 + i*(width*3+5)] = (byte) (width/256);
for(int j = 0; j < width; j++){
for(int n = 0; n < 3; n++){
byte gray = 0;
for(int m = 0; m < 8; m++){
int clr = pixels[j + width*(i*24 + m + n*8)];
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
gray = (byte) ((RGB2Gray(red, green, blue)<<(7-m))|gray);
}
res[5 + j*3 + i*(width*3+5) + n] = gray;
}
}
}
return res;
}else{
return new byte[]{0x0A};
}
}
private static byte RGB2Gray(int r, int g, int b) {
return (false ? ((int) (0.29900 * r + 0.58700 * g + 0.11400 * b) > 200)
: ((int) (0.29900 * r + 0.58700 * g + 0.11400 * b) < 200)) ? (byte) 1 : (byte) 0;
}
/**
* 生成间断性黑块数据
* @param w : 打印纸宽度, 单位点
* @return
*/
public static byte[] initBlackBlock(int w){
int ww = (w + 7)/8 ;
int n = (ww + 11)/12;
int hh = n * 24;
byte[] data = new byte[ hh * ww + 5];
data[0] = (byte)ww;//xL
data[1] = (byte)(ww >> 8);//xH
data[2] = (byte)hh;
data[3] = (byte)(hh >> 8);
int k = 4;
for(int i=0; i < n; i++){
for(int j=0; j<24; j++){
for(int m =0; m<ww; m++){
if(m/12 == i){
data[k++] = (byte)0xFF;
}else{
data[k++] = 0;
}
}
}
}
data[k++] = 0x0A;
return data;
}
/**
* 生成一大块黑块数据
* @param h : 黑块高度, 单位点
* @param w : 黑块宽度, 单位点, 8的倍数
* @return
*/
public static byte[] initBlackBlock(int h, int w){
int hh = h;
int ww = (w - 1)/8 + 1;
byte[] data = new byte[ hh * ww + 6];
data[0] = (byte)ww;//xL
data[1] = (byte)(ww >> 8);//xH
data[2] = (byte)hh;
data[3] = (byte)(hh >> 8);
int k = 4;
for(int i=0; i<hh; i++){
for(int j=0; j<ww; j++){
data[k++] = (byte)0xFF;
}
}
data[k++] = 0x00;data[k++] = 0x00;
return data;
}
//基本覆盖热敏小票打印中所有epson指令的操作
public static byte[] customData(){
byte[] rv = new byte[]{
(byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xBB, (byte) 0xFA, (byte) 0xD7, (byte) 0xD4, (byte) 0xBC, (byte) 0xEC, 0x0A,
//打印机自检
0x1F, 0X1B, 0x1F, 0x53,
//初始化打印机
0x1B, 0x40,
//分割线---
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D, 0x0A,
(byte) 0xB8, (byte) 0xC4, (byte) 0xB1, (byte) 0xE4, (byte) 0xD7, (byte) 0xD6, (byte) 0xBC, (byte) 0xE4, (byte) 0xBE, (byte) 0xE0,0x0A,
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x0A,
//设置字符右间距
0x30,0x2E, 0x30, 0x3A,(byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, 0x0A,
0x30,0x2E, 0x35, 0x3A, 0x1B, 0x20, 0x0C,(byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, 0x0A,
0x1B, 0x20, 0x00,
0x31,0x2E, 0x30, 0x3A, 0x1B, 0x20, 0x18, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, 0x0A,
0x1B, 0x20, 0x00,
0x32,0x2E, 0x30, 0x3A, 0x1B, 0x20, 0x30, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, (byte) 0xB2, (byte) 0xE2, (byte) 0xCA, (byte) 0xD4, 0x0A,
0x1B, 0x20, 0x00,
//分割线===
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
(byte) 0xD7, (byte) 0xD6, (byte) 0xCC, (byte) 0xE5, (byte) 0xD0, (byte) 0xA7, (byte) 0xB9, (byte) 0xFB, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
//字体效果 商米科技
//设置加粗、倍高、倍宽、下划线、反白
0x1B, 0x21, 0x08, (byte) 0xBC, (byte) 0xD3, (byte) 0xB4, (byte) 0xD6, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1B, 0x21, 0x00,
0x1B, 0x45, 0x01, (byte) 0xBC, (byte) 0xD3, (byte) 0xB4, (byte) 0xD6, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1B, 0x45, 0x00,
0x1B, 0x21, 0x10, (byte) 0xB1, (byte) 0xB6, (byte) 0xB8, (byte) 0xDF, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1B, 0x21, 0x20, (byte) 0xB1, (byte) 0xB6, (byte) 0xBF, (byte) 0xED, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1D, 0x21, 0x11, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC,
0x1D, 0x21, 0x22, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1D, 0x21, 0x00,
0x1B, 0x21, (byte) 0x80, (byte) 0xCF, (byte) 0xC2, (byte) 0xBB, (byte) 0xAE, (byte) 0xCF, (byte) 0xDF, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1B, 0x21, 0x00,
0x1B, 0x2D, 0x01, (byte) 0xCF, (byte) 0xC2, (byte) 0xBB, (byte) 0xAE, (byte) 0xCF, (byte) 0xDF, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1B, 0x2D, 0x00,
0x1D, 0x42, 0x01,0x1B, 0x21, 0x08, (byte) 0xB7, (byte) 0xB4, (byte) 0xB0, (byte) 0xD7, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC, 0x0A,
0x1D, 0x42, 0x00,0x1B, 0x21, 0x00,
//分割线***
0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A, 0x0A,
(byte) 0xC5, (byte) 0xC5, (byte) 0xB0, (byte) 0xE6, (byte) 0xCE, (byte) 0xBB, (byte) 0xD6, (byte) 0xC3, 0x0A,
0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A, 0x0A,
//排版位置
//设置绝对位置和设置相对位置
(byte) 0xD5, (byte) 0xE2, (byte) 0xBE, (byte) 0xE4, (byte) 0xBB, (byte) 0xB0, (byte) 0xB4, (byte) 0xD3, (byte) 0xD0, (byte) 0xD0, (byte) 0xCA, (byte) 0xD7, (byte) 0xBF, (byte) 0xAA, (byte) 0xCA, (byte) 0xBC, 0x0A,
(byte) 0xBE, (byte) 0xF8, (byte) 0xB6, (byte) 0xD4, (byte) 0xCE, (byte) 0xBB, (byte) 0xD6, (byte) 0xC3, 0x1B, 0x24, (byte) 0xC0, 0x00, (byte) 0xC6, (byte) 0xAB, (byte) 0xD2, (byte) 0xC6, 0x38, (byte) 0xB8, (byte) 0xF6, (byte) 0xD7, (byte) 0xD6, 0x0A,
(byte) 0xCF, (byte) 0xE0, (byte) 0xB6, (byte) 0xD4, (byte) 0xCE, (byte) 0xBB, (byte) 0xD6, (byte) 0xC3, 0x1B, 0x5C, 0x30, 0x00, (byte) 0xC6, (byte) 0xAB, (byte) 0xD2, (byte) 0xC6, 0x32, (byte) 0xB8, (byte) 0xF6, (byte) 0xD7, (byte) 0xD6, 0x0A,
//设置对齐方式
(byte) 0xBE, (byte) 0xD3, (byte) 0xD7, (byte) 0xF3, 0x0A,
0x1B, 0x61, 0x01, (byte) 0xBE, (byte) 0xD3, (byte) 0xD6, (byte) 0xD0, 0x0A,
0x1B, 0x61, 0x02, (byte) 0xBE, (byte) 0xD3, (byte) 0xD3, (byte) 0xD2, 0x0A,
0x1B, 0x61, 0x00,
//设置左边距
0x1D, 0x4C, 0x30, 0x00,
(byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, (byte) 0xD7, (byte) 0xF3, (byte) 0xB1, (byte) 0xDF, (byte) 0xBE, (byte) 0xE0, 0x34, 0x38, (byte) 0xCF, (byte) 0xF1, (byte) 0xCB, (byte) 0xD8, 0x0A,
//设置打印区域宽度
0x1D, 0x57, (byte) 0xF0, 0x00,
(byte) 0xB8, (byte) 0xC4, (byte) 0xB1, (byte) 0xE4, (byte) 0xBF, (byte) 0xC9, (byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xC7, (byte) 0xF8, (byte) 0xD3, (byte) 0xF2, (byte) 0xCE, (byte) 0xAA, 0x32, 0x34, 0x30, (byte) 0xCF, (byte) 0xF1, (byte) 0xCB, (byte) 0xD8, 0x0A,
//设置左边距
0x1D, 0x4C, 0x60, 0x00,
(byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, (byte) 0xD7, (byte) 0xF3, (byte) 0xB1, (byte) 0xDF, (byte) 0xBE, (byte) 0xE0, 0x39, 0x36, (byte) 0xCF, (byte) 0xF1, (byte) 0xCB, (byte) 0xD8, 0x0A,
//设置打印区域宽度
0x1D, 0x57, (byte) 0x78, 0x00,
(byte) 0xB8, (byte) 0xC4, (byte) 0xB1, (byte) 0xE4, (byte) 0xBF, (byte) 0xC9, (byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xC7, (byte) 0xF8, (byte) 0xD3, (byte) 0xF2, (byte) 0xCE, (byte) 0xAA, 0x31, 0x32, 0x30, (byte) 0xCF, (byte) 0xF1, (byte) 0xCB, (byte) 0xD8, 0x0A,
0x1D, 0x4C, 0x00, 0x00,
0x1D, 0x57, (byte) 0x80, 0x01,
//水平制表符-跳格
(byte) 0xC4, (byte) 0xAC, 0x09, (byte) 0xC8, (byte) 0xCF, 0x09, (byte) 0xCC, (byte) 0xF8, 0x09, (byte) 0xB8, (byte) 0xF1, 0x09, 0x0A,
0x1B, 0x44, 0x01, 0x02, 0x04, 0x08, 0x0A, 0x00,
(byte) 0xD7, (byte) 0xD4, 0x09, (byte) 0xB6, (byte) 0xA8, 0x09, (byte) 0xD2, (byte) 0xE5, 0x09, (byte) 0xCC, (byte) 0xF8, 0x09, (byte) 0xB8, (byte) 0xF1, 0x09, 0x0A,
//设置行高
0x1B, 0x33, 0x60, (byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, (byte) 0xD0, (byte) 0xD0, (byte) 0xB8, (byte) 0xDF, 0x3A, 0x39, 0x36, (byte) 0xB5, (byte) 0xE3, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x33, 0x40, (byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, (byte) 0xD0, (byte) 0xD0, (byte) 0xB8, (byte) 0xDF, 0x3A, 0x36, 0x34, (byte) 0xB5, (byte) 0xE3, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x33, 0x00, (byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, (byte) 0xD0, (byte) 0xD0, (byte) 0xB8, (byte) 0xDF, 0x3A, 0x30, (byte) 0xB5, (byte) 0xE3, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x32, (byte) 0xC4, (byte) 0xAC, (byte) 0xC8, (byte) 0xCF, (byte) 0xD0, (byte) 0xD0, (byte) 0xB8, (byte) 0xDF, 0x0A,
//分割线---
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D, 0x0A,
(byte) 0xD6, (byte) 0xAE, (byte) 0xBA, (byte) 0xF3, (byte) 0xBD, (byte) 0xAB, (byte) 0xD7, (byte) 0xDF, (byte) 0xD6, (byte) 0xBD, 0x0A,
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D, 0x0A,
//打印并走纸
0x1B, 0x4A, 0x40, (byte) 0xD7, (byte) 0xDF, (byte) 0xD6, (byte) 0xBD, 0x36, 0x34, (byte) 0xB5, (byte) 0xE3, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x4A, 0x60, (byte) 0xD7, (byte) 0xDF, (byte) 0xD6, (byte) 0xBD, 0x39, 0x36, (byte) 0xB5, (byte) 0xE3, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x64, 0x0A, (byte) 0xD7, (byte) 0xDF, (byte) 0xD6, (byte) 0xBD, 0x31, 0x30, (byte) 0xD0, (byte) 0xD0, 0x0A,
0x1B, 0x64, 0x01, (byte) 0xD7, (byte) 0xDF, (byte) 0xD6, (byte) 0xBD, 0x31, (byte) 0xD0, (byte) 0xD0, 0x0A,
//分割线===
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
(byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xCC, (byte) 0xF5, (byte) 0xC2, (byte) 0xEB, 0x0A,
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
//打印条码
0x1D, 0x48, 0x02,
//upca
0x1B, 0x61, 0x00, 0x1D, 0x68, 0x20, 0x1D, 0x77, 0x02,
0x1D, 0x6B, 0x41, 0x0c, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x0A,
0x1D, 0x6B, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x00, 0x0A,
//upce
0x1B, 0x61, 0x01, 0x1D, 0x68, 0x40, 0x1D, 0x77, 0x04,
0x1D, 0x6B, 0x42, 0x08, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x0A,
0x1D, 0x6B, 0x01, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x00, 0x0A,
//ean13
0x1B, 0x61, 0x02, 0x1D, 0x68, 0x60, 0x1D, 0x77, 0x02,
0x1D, 0x6B, 0x43, 0x0D, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x0A,
0x1D, 0x6B, 0x02, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x00, 0x0A,
//ean8
0x1B, 0x61, 0x00, 0x1D, 0x68, (byte) 0x80, 0x1D, 0x77, 0x05,
0x1D, 0x6B, 0x44, 0x08, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x0A,
0x1D, 0x6B, 0x03, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x00, 0x0A,
//code39
0x1B, 0x61, 0x01, 0x1D, 0x68, (byte) 0xA0, 0x1D, 0x77, 0x02,
0x1D, 0x6B, 0x45, 0x0A, 0x33, 0x36, 0x39, 0x53, 0x55, 0x4E, 0x4D, 0x49, 0x25, 0x24, 0x0A,
0x1D, 0x6B, 0x04, 0x33, 0x36, 0x39, 0x53, 0x55, 0x4E, 0x4D, 0x49, 0x25, 0x24, 0x00, 0x0A,
//itf
0x1B, 0x61, 0x02, 0x1D, 0x68, (byte) 0xC0, 0x1D, 0x77, 0x03,
0x1D, 0x6B, 0x46, 0x0C, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x0A,
0x1D, 0x6B, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x00, 0x0A,
//codebar
0x1B, 0x61, 0x00, 0x1D, 0x68, (byte) 0xE0, 0x1D, 0x77, 0x03,
0x1D, 0x6B, 0x47, 0x0A, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x41, 0x0A,
//0x1D, 0x6B, 0x06, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x41, 0x00, 0x0A,
//code93
0x1B, 0x61, 0x01, 0x1D, 0x68, (byte) 0xFF, 0x1D, 0x77, 0x02,
0x1D, 0x6B, 0x48, 0x0C, 0x53, 0x55, 0x4E, 0x4D, 0x49, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x0A,
//code128
0x1B, 0x61, 0x00, 0x1D, 0x68, (byte) 0xB0, 0x1D, 0x77, 0x02,
0x1D, 0x6B, 0x49, 0x0A, 0x7B, 0x41, 0x53, 0x55, 0x4E, 0x4D, 0x49, 0x30, 0x31, 0x32, 0x0A,
0x1D, 0x6B, 0x49, 0x0C, 0x7B, 0x42, 0x53, 0x55, 0x4E, 0x4D, 0x49, 0x73, 0x75, 0x6E, 0x6D, 0x69, 0x0A,
0x1D, 0x6B, 0x49, 0x0B, 0x7B, 0x43, 0x01, 0xc, 0x17, 0x22, 0x2d, 0x38, 0x4e, 0x59, 0x5a, 0x0A,
//分割线***
0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A, 0x0A,
(byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xB6, (byte) 0xFE, (byte) 0xCE, (byte) 0xAC, (byte) 0xC2, (byte) 0xEB, 0x0A,
0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A,0x2A, 0x2A, 0x2A, 0x2A, 0x0A,
//打印二维码
0x1B, 0x61, 0x01,
0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x43, 0x09,
0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x45, 0x32,
0x1D, 0x28, 0x6B, 0x0B, 0x00, 0x31, 0x50, 0x30, (byte) 0xC9, (byte) 0xCC, (byte) 0xC3, (byte) 0xD7, (byte) 0xBF, (byte) 0xC6, (byte) 0xBC, (byte) 0xBC,
0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x51, 0x30, 0x0A,
0x1B, 0x61, 0x00,
//分割线--- (之后将实现打印光栅位图的方法,再次之前使用1b 61 01 居中)
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D, 0x0A,
(byte) 0xB4, (byte) 0xF2, (byte) 0xD3, (byte) 0xA1, (byte) 0xB9, (byte) 0xE2, (byte) 0xD5, (byte) 0xA4, (byte) 0xCD, (byte) 0xBC, (byte) 0xCF, (byte) 0xF1, 0x0A,
0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D, 0x0A,
0x1B, 0x61, 0x01,
};
return rv;
}
//部分字符打印的分割线标志
public static byte[] wordData(){
byte rv[] = new byte[]{
//分割线===
0x1B, 0x61, 0x00,
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
(byte) 0xD7, (byte) 0xD6, (byte) 0xB7, (byte) 0xFB, (byte) 0xBC, (byte) 0xAF, (byte) 0xC9, (byte) 0xE8, (byte) 0xD6, (byte) 0xC3, 0x0A,
0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D,0x3D, 0x3D, 0x3D, 0x3D, 0x0A,
0x1C, 0x26, 0x1C, 0x43, 0x00,
};
return rv;
}
}
package com.joe.print.mvp.print.utils;
import android.graphics.Bitmap;
import android.util.Log;
import java.io.ByteArrayOutputStream;
public class ESCUtil {
public static final byte ESC = 0x1B;// Escape
public static final byte FS = 0x1C;// Text delimiter
public static final byte GS = 0x1D;// Group separator
public static final byte DLE = 0x10;// data link escape
public static final byte EOT = 0x04;// End of transmission
public static final byte ENQ = 0x05;// Enquiry character
public static final byte SP = 0x20;// Spaces
public static final byte HT = 0x09;// Horizontal list
public static final byte LF = 0x0A;//Print and wrap (horizontal orientation)
public static final byte CR = 0x0D;// Home key
public static final byte FF = 0x0C;// Carriage control (print and return to the standard mode (in page mode))
public static final byte CAN = 0x18;// Canceled (cancel print data in page mode)
//初始化打印机
public static byte[] init_printer() {
byte[] result = new byte[2];
result[0] = ESC;
result[1] = 0x40;
return result;
}
//打印浓度指令
public static byte[] setPrinterDarkness(int value){
byte[] result = new byte[9];
result[0] = GS;
result[1] = 40;
result[2] = 69;
result[3] = 4;
result[4] = 0;
result[5] = 5;
result[6] = 5;
result[7] = (byte) (value >> 8);
result[8] = (byte) value;
return result;
}
/**
* 打印单个二维码 sunmi自定义指令
* @param code: 二维码数据
* @param modulesize: 二维码块大小(单位:点, 取值 1 至 16 )
* @param errorlevel: 二维码纠错等级(0 至 3)
* 0 -- 纠错级别L ( 7%)
* 1 -- 纠错级别M (15%)
* 2 -- 纠错级别Q (25%)
* 3 -- 纠错级别H (30%)
*/
public static byte[] getPrintQRCode(String code, int modulesize, int errorlevel){
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
buffer.write(setQRCodeSize(modulesize));
buffer.write(setQRCodeErrorLevel(errorlevel));
buffer.write(getQCodeBytes(code));
buffer.write(getBytesForPrintQRCode(true));
}catch(Exception e){
e.printStackTrace();
}
return buffer.toByteArray();
}
/**
* 横向两个二维码 sunmi自定义指令
* @param code1: 二维码数据
* @param code2: 二维码数据
* @param modulesize: 二维码块大小(单位:点, 取值 1 至 16 )
* @param errorlevel: 二维码纠错等级(0 至 3)
* 0 -- 纠错级别L ( 7%)
* 1 -- 纠错级别M (15%)
* 2 -- 纠错级别Q (25%)
* 3 -- 纠错级别H (30%)
*/
public static byte[] getPrintDoubleQRCode(String code1, String code2, int modulesize, int errorlevel){
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
buffer.write(setQRCodeSize(modulesize));
buffer.write(setQRCodeErrorLevel(errorlevel));
buffer.write(getQCodeBytes(code1));
buffer.write(getBytesForPrintQRCode(false));
buffer.write(getQCodeBytes(code2));
//加入横向间隔
buffer.write(new byte[]{0x1B, 0x5C, 0x18, 0x00});
buffer.write(getBytesForPrintQRCode(true));
}catch(Exception e){
e.printStackTrace();
}
return buffer.toByteArray();
}
/**
* 光栅打印二维码
*/
public static byte[] getPrintQRCode2(String data, int size){
byte[] bytes1 = new byte[4];
bytes1[0] = GS;
bytes1[1] = 0x76;
bytes1[2] = 0x30;
bytes1[3] = 0x00;
byte[] bytes2 = BytesUtil.getZXingQRCode(data, size);
return BytesUtil.byteMerger(bytes1, bytes2);
}
/**
* 打印一维条形码
*/
public static byte[] getPrintBarCode(String data, int symbology, int height, int width, int textposition){
if(symbology < 0 || symbology > 10){
return new byte[]{LF};
}
if(width < 2 || width > 6){
width = 2;
}
if(textposition <0 || textposition > 3){
textposition = 0;
}
if(height < 1 || height>255){
height = 162;
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
buffer.write(new byte[]{0x1D,0x66,0x01,0x1D,0x48,(byte)textposition,
0x1D,0x77,(byte)width,0x1D,0x68,(byte)height,0x0A});
byte[] barcode;
if(symbology == 10){
barcode = BytesUtil.getBytesFromDecString(data);
}else{
barcode = data.getBytes("GB18030");
}
if(symbology > 7){
buffer.write(new byte[]{0x1D,0x6B,0x49,(byte)(barcode.length+2),0x7B, (byte) (0x41+symbology-8)});
}else{
buffer.write(new byte[]{0x1D,0x6B,(byte)(symbology + 0x41),(byte)barcode.length});
}
buffer.write(barcode);
}catch(Exception e){
e.printStackTrace();
}
return buffer.toByteArray();
}
//光栅位图打印
public static byte[] printBitmap(Bitmap bitmap){
byte[] bytes1 = new byte[4];
bytes1[0] = GS;
bytes1[1] = 0x76;
bytes1[2] = 0x30;
bytes1[3] = 0x00;
byte[] bytes2 = BytesUtil.getBytesFromBitMap(bitmap);
return BytesUtil.byteMerger(bytes1, bytes2);
}
//光栅位图打印 设置mode
public static byte[] printBitmap(Bitmap bitmap, int mode){
byte[] bytes1 = new byte[4];
bytes1[0] = GS;
bytes1[1] = 0x76;
bytes1[2] = 0x30;
bytes1[3] = (byte) mode;
byte[] bytes2 = BytesUtil.getBytesFromBitMap(bitmap);
return BytesUtil.byteMerger(bytes1, bytes2);
}
//光栅位图打印
public static byte[] printBitmap(byte[] bytes){
byte[] bytes1 = new byte[4];
bytes1[0] = GS;
bytes1[1] = 0x76;
bytes1[2] = 0x30;
bytes1[3] = 0x00;
return BytesUtil.byteMerger(bytes1, bytes);
}
/*
* 选择位图指令 设置mode
* 需要设置1B 33 00将行间距设为0
*/
public static byte[] selectBitmap(Bitmap bitmap, int mode){
return BytesUtil.byteMerger(BytesUtil.byteMerger(new byte[]{0x1B, 0x33, 0x00}, BytesUtil.getBytesFromBitMap(bitmap, mode)), new byte[]{0x0A, 0x1B, 0x32});
}
/**
* 跳指定行数
*/
public static byte[] nextLine(int lineNum) {
byte[] result = new byte[lineNum];
for (int i = 0; i < lineNum; i++) {
result[i] = LF;
}
return result;
}
// ------------------------underline-----------------------------
//设置下划线1点
public static byte[] underlineWithOneDotWidthOn() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 1;
return result;
}
//设置下划线2点
public static byte[] underlineWithTwoDotWidthOn() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 2;
return result;
}
//取消下划线
public static byte[] underlineOff() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 0;
return result;
}
// ------------------------bold-----------------------------
/**
* 字体加粗
*/
public static byte[] boldOn() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 69;
result[2] = 0xF;
return result;
}
/**
* 取消字体加粗
*/
public static byte[] boldOff() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 69;
result[2] = 0;
return result;
}
// ------------------------character-----------------------------
/*
*单字节模式开启
*/
public static byte[] singleByte(){
byte[] result = new byte[2];
result[0] = FS;
result[1] = 0x2E;
return result;
}
/*
*单字节模式关闭
*/
public static byte[] singleByteOff(){
byte[] result = new byte[2];
result[0] = FS;
result[1] = 0x26;
return result;
}
/**
* 设置单字节字符集
*/
public static byte[] setCodeSystemSingle(byte charset){
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 0x74;
result[2] = charset;
return result;
}
/**
* 设置多字节字符集
*/
public static byte[] setCodeSystem(byte charset){
byte[] result = new byte[3];
result[0] = FS;
result[1] = 0x43;
result[2] = charset;
return result;
}
// ------------------------Align-----------------------------
/**
* 居左
*/
public static byte[] alignLeft() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 0;
return result;
}
/**
* 居中对齐
*/
public static byte[] alignCenter() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 1;
return result;
}
/**
* 居右
*/
public static byte[] alignRight() {
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 2;
return result;
}
//切刀
public static byte[] cutter() {
byte[] data = new byte[]{0x1d, 0x56, 0x01};
return data;
}
//走纸到黑标
public static byte[] gogogo(){
byte[] data = new byte[]{0x1C, 0x28, 0x4C, 0x02, 0x00, 0x42, 0x31};
return data;
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////// private /////////////////////////
////////////////////////////////////////////////////////////////////////////////////
private static byte[] setQRCodeSize(int modulesize){
//二维码块大小设置指令
byte[] dtmp = new byte[8];
dtmp[0] = GS;
dtmp[1] = 0x28;
dtmp[2] = 0x6B;
dtmp[3] = 0x03;
dtmp[4] = 0x00;
dtmp[5] = 0x31;
dtmp[6] = 0x43;
dtmp[7] = (byte)modulesize;
return dtmp;
}
private static byte[] setQRCodeErrorLevel(int errorlevel){
//二维码纠错等级设置指令
byte[] dtmp = new byte[8];
dtmp[0] = GS;
dtmp[1] = 0x28;
dtmp[2] = 0x6B;
dtmp[3] = 0x03;
dtmp[4] = 0x00;
dtmp[5] = 0x31;
dtmp[6] = 0x45;
dtmp[7] = (byte)(48+errorlevel);
return dtmp;
}
private static byte[] getBytesForPrintQRCode(boolean single){
//打印已存入数据的二维码
byte[] dtmp;
if(single){ //同一行只打印一个QRCode, 后面加换行
dtmp = new byte[9];
dtmp[8] = 0x0A;
}else{
dtmp = new byte[8];
}
dtmp[0] = 0x1D;
dtmp[1] = 0x28;
dtmp[2] = 0x6B;
dtmp[3] = 0x03;
dtmp[4] = 0x00;
dtmp[5] = 0x31;
dtmp[6] = 0x51;
dtmp[7] = 0x30;
return dtmp;
}
private static byte[] getQCodeBytes(String code) {
//二维码存入指令
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
byte[] d = code.getBytes("GB18030");
int len = d.length + 3;
if (len > 7092) len = 7092;
buffer.write((byte) 0x1D);
buffer.write((byte) 0x28);
buffer.write((byte) 0x6B);
buffer.write((byte) len);
buffer.write((byte) (len >> 8));
buffer.write((byte) 0x31);
buffer.write((byte) 0x50);
buffer.write((byte) 0x30);
for (int i = 0; i < d.length && i < len; i++) {
buffer.write(d[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
return buffer.toByteArray();
}
/**
* 设置字体大小
*/
public static byte[] setTextSize(int size) {
byte[] bytes = CMD_FontSize(size).getBytes();
return bytes;
}
// 字体的大小
// 0:正常大小 1:两倍高 2:两倍宽 3:两倍大小 4:三倍高 5:三倍宽 6:三倍大小
// 7:四倍高 8:四倍宽 9:四倍大小 10:五倍高 11:五倍宽 12:五倍大小
public static String CMD_FontSize(int nfontsize) {
String _cmdstr = "";
// 设置字体大小
switch (nfontsize) {
case -1:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 0).toString();// 29 33
break;
case 0:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 0).toString();// 29 33
break;
case 1:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 1).toString();
break;
case 2:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 16).toString();
break;
case 3:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 17).toString();
break;
case 4:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 2).toString();
break;
case 5:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 32).toString();
break;
case 6:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 34).toString();
break;
case 7:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 3).toString();
break;
case 8:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 48).toString();
break;
case 9:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 51).toString();
break;
case 10:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 4).toString();
break;
case 11:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 64).toString();
break;
case 12:
_cmdstr = new StringBuffer().append((char) 29).append((char) 33)
.append((char) 68).toString();
break;
}
Log.d("textSize",_cmdstr);
return _cmdstr;
}
}
...@@ -3,6 +3,8 @@ package com.joe.print.mvp.print.utils; ...@@ -3,6 +3,8 @@ package com.joe.print.mvp.print.utils;
import android.content.Context; import android.content.Context;
import android.widget.TextView; import android.widget.TextView;
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean; import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean; import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
...@@ -10,6 +12,7 @@ import com.gingersoft.gsa.cloud.database.utils.PrintCurrencyDaoUtils; ...@@ -10,6 +12,7 @@ import com.gingersoft.gsa.cloud.database.utils.PrintCurrencyDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.PrinterDeviceDaoUtils; import com.gingersoft.gsa.cloud.database.utils.PrinterDeviceDaoUtils;
import com.joe.print.R; import com.joe.print.R;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MyPrintUtils { public class MyPrintUtils {
...@@ -18,6 +21,9 @@ public class MyPrintUtils { ...@@ -18,6 +21,9 @@ public class MyPrintUtils {
private static MyPrintUtils myPrintUtils; private static MyPrintUtils myPrintUtils;
private static boolean isUpdateCurrencyBeans = false;
private static List<PrintCurrencyBean> printCurrencyBeans;//通用打印配置
public static MyPrintUtils getInstance() { public static MyPrintUtils getInstance() {
if (myPrintUtils == null) { if (myPrintUtils == null) {
myPrintUtils = new MyPrintUtils(); myPrintUtils = new MyPrintUtils();
...@@ -34,8 +40,10 @@ public class MyPrintUtils { ...@@ -34,8 +40,10 @@ public class MyPrintUtils {
* @return * @return
*/ */
public PrintCurrencyBean getPrintCurrencyBeanByType(Context context, int type) { public PrintCurrencyBean getPrintCurrencyBeanByType(Context context, int type) {
if (isUpdateCurrencyBeans || printCurrencyBeans == null || printCurrencyBeans.size() == 0) {
PrintCurrencyDaoUtils printCurrencyDaoUtils = new PrintCurrencyDaoUtils(context); PrintCurrencyDaoUtils printCurrencyDaoUtils = new PrintCurrencyDaoUtils(context);
List<PrintCurrencyBean> printCurrencyBeans = printCurrencyDaoUtils.queryAllPrintCurrencyBean(); printCurrencyBeans = printCurrencyDaoUtils.queryAllPrintCurrencyBean();
}
for (PrintCurrencyBean printCurrencyBean : printCurrencyBeans) { for (PrintCurrencyBean printCurrencyBean : printCurrencyBeans) {
if (printCurrencyBean.getType() == type) { if (printCurrencyBean.getType() == type) {
return printCurrencyBean; return printCurrencyBean;
...@@ -44,6 +52,19 @@ public class MyPrintUtils { ...@@ -44,6 +52,19 @@ public class MyPrintUtils {
return null; return null;
} }
/**
* 獲取打印通用配置集合
*
* @param context
* @return
*/
public static List<PrintCurrencyBean> getPrintCurrencyBeans(Context context) {
if (isUpdateCurrencyBeans || printCurrencyBeans == null || printCurrencyBeans.size() == 0) {
PrintCurrencyDaoUtils printCurrencyDaoUtils = new PrintCurrencyDaoUtils(context);
printCurrencyBeans = printCurrencyDaoUtils.queryAllPrintCurrencyBean();
}
return printCurrencyBeans;
}
/** /**
* 通過打印位置獲取打印機 * 通過打印位置獲取打印機
...@@ -109,4 +130,99 @@ public class MyPrintUtils { ...@@ -109,4 +130,99 @@ public class MyPrintUtils {
} }
public static Object getContentByLength(Object[] text, int i) {
if (text.length == 1) {
return text[0];
} else {
return text[i];
}
}
private static String abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/**
* 如果超過紙張寬度的英文,換行時,要截取得當
* 23
*
* @return
*/
public static String getFormatText(String content, int paperWidth) {
if (content.length() > paperWidth) {
int lastIndex = 0;//上次截取時最後的下標
StringBuilder stringBuilder = new StringBuilder();
while (true) {
if (lastIndex + paperWidth >= content.length()) {
String footStr = content.substring(lastIndex);
stringBuilder.append(footStr);
return stringBuilder.toString();
} else {
String headerStr = content.substring(lastIndex, lastIndex + paperWidth);
String nextContext = content.substring(lastIndex + paperWidth, lastIndex + paperWidth + 1);
if (abc.contains(headerStr.charAt(headerStr.length() - 1) + "") && abc.contains(nextContext)) {
//如果最後一位是英文單詞,往前找找到空格或者不是英文的,然後換行
for (int j = headerStr.length() - 1; j >= 0; j--) {
String tchar = headerStr.charAt(j) + "";
if (j == 0) {
//循環完了都沒找到,就不管了
stringBuilder.append(headerStr);
stringBuilder.append("\n");
lastIndex += paperWidth;
break;
}
if (!abc.contains(tchar)) {
//找到不是英文的那個
String newHeaderStr = headerStr.substring(0, j + 1);
stringBuilder.append(newHeaderStr);
stringBuilder.append("\n");
lastIndex += j + 1;
break;
}
}
} else {
lastIndex += paperWidth;
stringBuilder.append(headerStr);
stringBuilder.append("\n");
}
}
}
} else {
return content;
}
}
// private void setLanguage(String language) throws Epos2Exception {
// if ("en".equals(language)) {
// //切換對應語言
// mPrinter.addTextLang(Printer.LANG_EN);
// } else if ("ja".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_JA);
// } else if ("cn".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_ZH_CN);
// } else if ("tw".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_ZH_TW);
// } else if ("ko".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_KO);
// } else if ("th".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_TH);
// } else if ("vi".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_VI);
// } else if ("multi".equals(language)) {
// mPrinter.addTextLang(Printer.LANG_MULTI);
// }
// }
public static double getChineseValueLength(String value) {
double valueLength = 0;
String chinese = "[\u4e00-\u9fa5]";
for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1);
if (temp.matches(chinese)) {
valueLength += 1.5;
} else {
valueLength += 1;
}
}
return valueLength;
}
} }
package com.joe.print.mvp.print.utils;
import android.content.Context;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Handler;
import android.os.Message;
import com.joe.print.mvp.print.common.SendCallback;
import com.joe.print.mvp.print.common.SendResultCode;
import java.lang.ref.WeakReference;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class UsbPrint {
private static UsbPrint INSTANCE;
private final UsbManager usbManager;
private SendCallback sendCallback;
private final ExecutorService threadPool;
private MyHandler myHandler;
private UsbPrint(Context context, SendCallback sendCallback) {
this.usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
this.sendCallback = sendCallback;
this.threadPool = Executors.newFixedThreadPool(3);
this.myHandler = new MyHandler(this);
}
public static UsbPrint getInstance(Context context, SendCallback sendCallback) {
if (INSTANCE == null) {
synchronized (UsbPrint.class) {
if (INSTANCE == null) {
INSTANCE = new UsbPrint(context, sendCallback);
}
}
}
return INSTANCE;
}
public void sendPrintCommand(UsbPrinter printer, byte[] bytes) {
if (printer == null || printer.getUsbDevice() == null) {
return;
}
SendCommandThread thread = new SendCommandThread(usbManager, printer, bytes);
threadPool.execute(thread);
}
private class SendCommandThread extends Thread {
private UsbManager usbManager;
private UsbPrinter usbPrinter;
private byte[] bytes;
public SendCommandThread(UsbManager usbManager, UsbPrinter usbPrinter, byte[] bytes) {
this.usbManager = usbManager;
this.usbPrinter = usbPrinter;
this.bytes = bytes;
}
@Override
public void run() {
super.run();
UsbDeviceConnection connection = usbManager.openDevice(usbPrinter.getUsbDevice());
if (connection != null && connection.claimInterface(usbPrinter.getUsbInterface(), true)) {
int result = connection.bulkTransfer(usbPrinter.getUsbOut(), bytes, bytes.length, 500);
connection.close();
int sendResultCode = result > 0 ? SendResultCode.SEND_SUCCESS : SendResultCode.SEND_FAILED;
sendMessage(sendResultCode, usbPrinter.getPrinterName());
}
}
}
private void sendMessage(int resultCode, String printerId) {
Message msg = new Message();
msg.obj = printerId;
msg.what = resultCode;
myHandler.sendMessage(msg);
}
private static class MyHandler extends Handler {
private WeakReference<UsbPrint> weakReference;
public MyHandler(UsbPrint usbPrint) {
this.weakReference = new WeakReference<>(usbPrint);
}
@Override
public void handleMessage(Message msg) {
UsbPrint usbPrint = weakReference.get();
if (usbPrint != null && usbPrint.sendCallback != null) {
usbPrint.sendCallback.onCallback(msg.what, (String) msg.obj);
}
}
}
}
package com.joe.print.mvp.print.utils;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.text.TextUtils;
public class UsbPrinter {
private UsbDevice usbDevice;
private UsbInterface usbInterface;
private UsbEndpoint usbIn;
private UsbEndpoint usbOut;
private UsbDeviceConnection usbDeviceConnection;
public UsbPrinter(UsbDevice usbDevice,
UsbInterface usbInterface,
UsbEndpoint usbIn,
UsbEndpoint usbOut,
UsbDeviceConnection usbDeviceConnection
) {
this.usbDevice = usbDevice;
this.usbInterface = usbInterface;
this.usbIn = usbIn;
this.usbOut = usbOut;
this.usbDeviceConnection = usbDeviceConnection;
}
public UsbDevice getUsbDevice() {
return usbDevice;
}
public void setUsbDevice(UsbDevice usbDevice) {
this.usbDevice = usbDevice;
}
public UsbInterface getUsbInterface() {
return usbInterface;
}
public void setUsbInterface(UsbInterface usbInterface) {
this.usbInterface = usbInterface;
}
public UsbEndpoint getUsbIn() {
return usbIn;
}
public void setUsbIn(UsbEndpoint usbIn) {
this.usbIn = usbIn;
}
public UsbEndpoint getUsbOut() {
return usbOut;
}
public void setUsbOut(UsbEndpoint usbOut) {
this.usbOut = usbOut;
}
public UsbDeviceConnection getUsbDeviceConnection() {
return usbDeviceConnection;
}
public void setUsbDeviceConnection(UsbDeviceConnection usbDeviceConnection) {
this.usbDeviceConnection = usbDeviceConnection;
}
public String getPrinterName() {
UsbDevice usbDevice = getUsbDevice();
if (usbDevice == null) {
return "null usbDevice";
}
StringBuilder nameSb = new StringBuilder();
String manufacturerName = null;
String productName = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
manufacturerName = usbDevice.getManufacturerName();
productName = usbDevice.getProductName();
}
if (!TextUtils.isEmpty(manufacturerName)) {
nameSb.append(manufacturerName).append(" ");
}
if (!TextUtils.isEmpty(productName)) {
nameSb.append(productName);
}
return nameSb.toString();
}
}
package com.joe.print.mvp.print.utils;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.util.Log;
import com.joe.print.mvp.print.common.PrinterFinderCallback;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class UsbPrinterFinder {
private static final String TAG = "UsbPrinterFinder";
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private final UsbManager usbManager;
private final PendingIntent usbPermissionIntent;
private Context context;
private PrinterFinderCallback<UsbPrinter> finderCallback;
private List<UsbPrinter> usbPrinters;
public UsbPrinterFinder(Context context, PrinterFinderCallback<UsbPrinter> finderCallback) {
this.usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
this.usbPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
this.context = context;
this.finderCallback = finderCallback;
this.usbPrinters = new ArrayList<>();
IntentFilter usbFilter = new IntentFilter();
usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
context.registerReceiver(usbReceiver, usbFilter);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
context.registerReceiver(usbPermissionReceiver, filter);
}
private BroadcastReceiver usbReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
startFinder();
}
};
private BroadcastReceiver usbPermissionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
boolean hasPermission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
if (hasPermission && usbDevice != null) {
UsbPrinter usbPrinter = getUsbPrinter(usbDevice);
if (usbPrinter != null) {
usbPrinters.add(usbPrinter);
if (finderCallback != null) {
finderCallback.onFound(usbPrinter);
finderCallback.onFinished(usbPrinters);
}
Log.d(TAG, "usbPermissionReceiver add " + usbPrinter.getPrinterName());
}
}
}
}
};
public void startFinder() {
usbPrinters.clear();
if (finderCallback != null) {
finderCallback.onStart();
}
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
Set<Map.Entry<String, UsbDevice>> entries = deviceList.entrySet();
for (Map.Entry<String, UsbDevice> entry : entries) {
UsbDevice usbDevice = entry.getValue();
if (!isUsbPrinter(usbDevice)) {
continue;
}
if (usbManager.hasPermission(usbDevice)) {
UsbPrinter usbPrinter = getUsbPrinter(usbDevice);
if (usbPrinter != null) {
usbPrinters.add(usbPrinter);
if (finderCallback != null) {
finderCallback.onFound(usbPrinter);
}
Log.d(TAG, "hasPermission add " + usbPrinter.getPrinterName());
}
} else {
usbManager.requestPermission(usbDevice, usbPermissionIntent);
Log.d(TAG, "requestPermission " + usbDevice.getDeviceName());
}
}
if (finderCallback != null) {
finderCallback.onFinished(usbPrinters);
Log.d(TAG, "for startFinder finished");
}
}
private boolean isUsbPrinter(UsbDevice usbDevice) {
if (usbDevice == null) {
return false;
}
UsbInterface usbInterface = null;
for (int intf = 0; intf < usbDevice.getInterfaceCount(); intf++) {
if (usbDevice.getInterface(intf).getInterfaceClass() == 7) {
usbInterface = usbDevice.getInterface(intf);
break;
}
}
return usbInterface != null;
}
private UsbPrinter getUsbPrinter(UsbDevice usbDevice) {
if (usbDevice == null) {
return null;
}
UsbInterface usbInterface = null;
UsbEndpoint usbIn = null;
UsbEndpoint usbOut = null;
UsbDeviceConnection usbDeviceConnection = null;
for (int intf = 0; intf < usbDevice.getInterfaceCount(); intf++) {
if (usbDevice.getInterface(intf).getInterfaceClass() == 7) {
usbInterface = usbDevice.getInterface(intf);
break;
}
}
if (usbInterface != null) {
for (int ep = 0; ep < usbInterface.getEndpointCount(); ep++) {
int dir = usbInterface.getEndpoint(ep).getDirection();
if (usbInterface.getEndpoint(ep).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && dir == UsbConstants.USB_DIR_OUT) {
usbOut = usbInterface.getEndpoint(ep);
} else if (usbInterface.getEndpoint(ep).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && dir == UsbConstants.USB_DIR_IN) {
usbIn = usbInterface.getEndpoint(ep);
}
}
}
if (usbIn != null && usbOut != null) {
usbDeviceConnection = usbManager.openDevice(usbDevice);
}
if (usbDeviceConnection != null) {
usbDeviceConnection.close();
return new UsbPrinter(usbDevice, usbInterface, usbIn, usbOut, usbDeviceConnection);
}
return null;
}
public void unregisterReceiver() {
Log.d(TAG, "unregisterReceiver");
if (context != null) {
context.unregisterReceiver(usbReceiver);
context.unregisterReceiver(usbPermissionReceiver);
}
}
}
package com.joe.print.mvp.ui.activity; package com.joe.print.mvp.ui.activity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.epson.epos2.printer.PrinterStatusInfo;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean; import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.print.PrintExecutor; import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder; import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.PrinterWriter80mm;
import com.joe.print.R; import com.joe.print.R;
import com.joe.print.mvp.model.bean.PrintInfoBean; import com.joe.print.mvp.model.bean.PrintInfoBean;
import com.joe.print.mvp.print.EpsonPrint; import com.joe.print.mvp.print.TestPrintMaker;
import com.joe.print.mvp.print.common.PrinterFinderCallback;
import com.joe.print.mvp.print.common.SendCallback;
import com.joe.print.mvp.print.common.SendResultCode;
import com.joe.print.mvp.print.utils.UsbPrinter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class PrintTestActivity extends AppCompatActivity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener { public class PrintTestActivity extends AppCompatActivity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
private int lineLength = 24;//一行42個 private int lineLength = 24;//一行42個
private int LEFT_TEXT_LENGTH = 8; private int LEFT_TEXT_LENGTH = 8;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -36,45 +40,46 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH ...@@ -36,45 +40,46 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH
// printInfoBeans.add(new PrintInfoBean(new String[]{"asdfskjflsjflsjlfjslfjsldjflsjfsd"}, new double[]{1}, new String[]{"tw"})); // printInfoBeans.add(new PrintInfoBean(new String[]{"asdfskjflsjflsjlfjslfjsldjflsjfsd"}, new double[]{1}, new String[]{"tw"}));
// printInfoBeans.add(new PrintInfoBean(new String[]{"純屬餐廳"}, new double[]{1}, new String[]{"tw"})); // printInfoBeans.add(new PrintInfoBean(new String[]{"純屬餐廳"}, new double[]{1}, new String[]{"tw"}));
printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new Double[]{2d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", "0046"}, new Boolean[]{false, true}, new double[]{1, 2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"訂單碼:", "0046"}, new Boolean[]{false, true}, new Double[]{1d, 2d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"落單時間:", "07-13 19:05"}, new double[]{1}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"落單時間:", "07-13 19:05"}, new Double[]{1d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"D1廚房", "BARRY1"}, new double[]{1}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"D1廚房", "BARRY1"}, new Double[]{1d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 1)}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 1)}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"1","食品名稱"}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"1", "食品名稱"}, new Boolean[]{true}, new Double[]{2d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"1"," 細項名稱"}, new Boolean[]{true}, new double[]{2}, 0)); printInfoBeans.add(new PrintInfoBean(new String[]{"1", " 細項名稱"}, new Boolean[]{true}, new Double[]{2d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new double[]{2}, 1));
printInfoBeans.add(new PrintInfoBean(new String[]{"精選牛肉 ", "x1 ", " 29.3"}, new Boolean[]{true}, new Double[]{1d}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"牛肉名字"}, new Boolean[]{true}, new Double[]{1d}, 0));
findViewById(R.id.btn_test).setOnClickListener(view -> { findViewById(R.id.btn_test).setOnClickListener(view -> {
//打印測試 //打印測試
// PrintExecutor executor = new PrintExecutor(printerDeviceBean); PrintExecutor executor = new PrintExecutor(printerDeviceBean);
// executor.setOnStateChangedListener(this); executor.setOnStateChangedListener(this);
// executor.setOnPrintResultListener(this); executor.setOnPrintResultListener(this);
// TestPrintMaker maker = null;
// TestPrintMaker maker = null; try {
// try { maker = new TestPrintMaker(new PrinterWriter80mm(255), printInfoBeans);
// maker = new TestPrintMaker(new PrinterWriter80mm(255), printInfoBeans); } catch (IOException e) {
// } catch (IOException e) { e.printStackTrace();
// e.printStackTrace(); }
// } executor.doPrinterRequestAsync(maker);
// executor.doPrinterRequestAsync(maker);
EpsonPrint mPrinter = EpsonPrint.getInstance();
PrinterStatusInfo status = mPrinter.getStatus();
if (status != null && status.getPaper() == 2) {
ToastUtils.show(this, "缺紙了");
}
mPrinter.initializeObject(GsaCloudApplication.getAppContext(), null);
mPrinter.putPrintString("192.168.1.203", 42, printInfoBeans);
// new Thread(() -> {
// for (int j = 0; j < finalZoomBitmap.size(); j++) {
// mPrinter.putPrintData(printerDeviceBean.getIp(), finalZoomBitmap.get(j));
// }
// }).start();
}); });
} }
private void printTestText(UsbPrinter printer) {
// EscCommand esc = new EscCommand();
// esc.addText("This is test print\n");
// esc.addText("This is test hehe\n");
// esc.addText("This is test haha\n");
// esc.addText("This is test xixi\n");
// esc.addText("打印測試,圖片有沒有打印\n");
// esc.addPrintAndFeedLines((byte) 8);
// esc.addArrayToCommand(draw2PxPoint2(BitmapFactory.decodeResource(getResources(), R.mipmap.meal_takeaway_mode)));
// esc.addCutPaper();
//esc.addCleanCache();
// usbPrint.sendPrintCommand(printer, esc.getByteArrayCommand());
}
@Override @Override
public void onResult(int errorCode, PrinterDeviceBean printerDeviceBean) { public void onResult(int errorCode, PrinterDeviceBean printerDeviceBean) {
...@@ -85,7 +90,6 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH ...@@ -85,7 +90,6 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH
} }
private String getLineBorder(String text, double fontSize) { private String getLineBorder(String text, double fontSize) {
if (fontSize == 0) { if (fontSize == 0) {
fontSize = 1; fontSize = 1;
...@@ -120,4 +124,35 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH ...@@ -120,4 +124,35 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH
} }
return valueLength; return valueLength;
} }
private String TAG = "eee";
private PrinterFinderCallback<UsbPrinter> printerFinderCallback = new PrinterFinderCallback<UsbPrinter>() {
@Override
public void onStart() {
Log.d(TAG, "startFind print");
}
@Override
public void onFound(UsbPrinter usbPrinter) {
//listAdapter.addData(usbPrinter);
Log.d(TAG, "onFound deviceName = " + usbPrinter.getPrinterName());
}
@Override
public void onFinished(List<UsbPrinter> usbPrinters) {
Log.d(TAG, "printCount = " + usbPrinters.size());
// listAdapter.replaceDatas(usbPrinters);
}
};
private SendCallback sendCallback = (code, printId) -> {
String msg = "";
if (code == SendResultCode.SEND_SUCCESS) {
Log.d(TAG, "打印成功");
} else if (code == SendResultCode.SEND_FAILED) {
Log.d(TAG, "打印失敗");
}
};
} }
...@@ -331,20 +331,20 @@ ...@@ -331,20 +331,20 @@
android:maxLines="1" android:maxLines="1"
android:text="@string/print_split_line" android:text="@string/print_split_line"
android:textColor="@color/theme_333_color" android:textColor="@color/theme_333_color"
android:visibility="visible" /> android:visibility="gone" />
<TextView <TextView
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="親愛的顧客,祝您用餐愉快,如您遇到任何問題請撥打8200 2022聯繫我們,期待您的下次光臨。" android:text="親愛的顧客,祝您用餐愉快,如您遇到任何問題請撥打8200 2022聯繫我們,期待您的下次光臨。"
android:visibility="visible" /> android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10" android:layout_marginTop="@dimen/dp_10"
android:visibility="visible"> android:visibility="gone">
<TextView <TextView
android:id="@+id/tv_bottom_time" android:id="@+id/tv_bottom_time"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment