Commit 2fd4d7af by Wyh

7.22

parent 51a1f96b
......@@ -72,7 +72,7 @@ dependencies {
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
api rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
implementation rootProject.ext.dependencies["fastjson"]
implementation rootProject.ext.dependencies["zxing"]
api rootProject.ext.dependencies["zxing"]
implementation rootProject.ext.dependencies["progressmanager"]
implementation rootProject.ext.dependencies["autosize"]
// test
......
......@@ -29,8 +29,11 @@ public class PrinterDeviceBean implements Serializable {
private Long printerModelId;//打印機機型id
private String paperSpecification;//紙張規格
private int lineFontStop;//打印機一行最多顯示多少字
private String printerName;//打印機機型名稱
private String model;//打印機型號
private String noteContent;//備註
private Long printerDeviceDefaultId;
/**
......@@ -56,6 +59,7 @@ public class PrinterDeviceBean implements Serializable {
private int numberIsFlip;//數量大於1顔色是否翻轉 1是 2否
@Generated(hash = 626885316)
public PrinterDeviceBean() {
}
......@@ -66,8 +70,8 @@ public class PrinterDeviceBean implements Serializable {
this.paperSpecification = paperSpecification;
}
@Generated(hash = 1904986682)
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,
@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, 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) {
this.id = id;
this.dbid = dbid;
......@@ -79,6 +83,7 @@ public class PrinterDeviceBean implements Serializable {
this.type = type;
this.printerModelId = printerModelId;
this.paperSpecification = paperSpecification;
this.lineFontStop = lineFontStop;
this.printerName = printerName;
this.model = model;
this.noteContent = noteContent;
......@@ -284,4 +289,12 @@ public class PrinterDeviceBean implements Serializable {
public void setNumberIsFlip(int numberIsFlip) {
this.numberIsFlip = numberIsFlip;
}
public int getLineFontStop() {
return lineFontStop;
}
public void setLineFontStop(int lineFontStop) {
this.lineFontStop = lineFontStop;
}
}
......@@ -37,7 +37,7 @@ import java.util.ArrayList;
public abstract class PrinterWriter {
public static final int HEIGHT_PARTING_DEFAULT = 255;
private static final String CHARSET = "gb2312";
private static final String CHARSET = "gb2312";//
private ByteArrayOutputStream bos;
private int heightParting;
......
package com.gingersoft.gsa.other_order_mode.data.model.bean
data class EstimatedBean(
val `data`: Data,
val `data`: Data?,
val success: Boolean,
val sysTime: Long
)
\ No newline at end of file
......@@ -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、配送員預計送達時間
// if (estimatedBean.data.estimated_time > 0) {
if(estimatedBean.data != null){
data.estimatedTime = estimatedTime + ("${estimatedBean.data.estimated_time}分鐘後")
}
orderDetails.postValue(orderDetail)
// } else {
// data.estimatedTime = ""
......
......@@ -12,6 +12,4 @@ class OrderDetailsAdapter(list: MutableList<BtnBuilder.BtnBean>) : BaseQuickAdap
holder.setBackgroundResource(R.id.layout_btn_item, item.btnColor)
holder.setImageResource(R.id.iv_btn_mark, item.btnImg)
}
}
\ No newline at end of file
......@@ -20,7 +20,7 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
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.PrinterAddActivity" />
<activity android:name=".mvp.ui.activity.PrintTestActivity">
......
......@@ -89,9 +89,6 @@ public class PrjBean {
private int itemType;
private String sender;
public int getId() {
return id;
}
......
......@@ -9,6 +9,7 @@ import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;
import com.epson.epos2.printer.ReceiveListener;
import com.joe.print.mvp.model.bean.PrintInfoBean;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -244,6 +245,9 @@ public class EpsonPrint implements ReceiveListener {
return;
}
connectByIp(ip, mPrinter.getStatus());
if (mPrinter == null) {
return;
}
mPrinter.clearCommandBuffer();
try {
for (PrintInfoBean printInfoBean : printInfoBeans) {
......@@ -277,116 +281,31 @@ public class EpsonPrint implements ReceiveListener {
if (i == 0) {
location = 0;
}
int color;
int textSize;
int isItalic;
if (printInfoBean.getColor().length == 1) {
color = printInfoBean.getColor()[0];
} else {
color = printInfoBean.getColor()[i];
}
int textSize = (int) MyPrintUtils.getContentByLength(printInfoBean.getSize(), i);
//是否傾斜字體
int isItalic = ((Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsItalic(), i)) ? 1 : 0;
int isBold = ((Boolean) MyPrintUtils.getContentByLength(printInfoBean.getIsBold(), i)) ? 1 : 0;
int color = (int) MyPrintUtils.getContentByLength(printInfoBean.getColor(), i);
if (color > 4) {
color = 4;
}
if (printInfoBean.getIsItalic().length == 1) {
isItalic = printInfoBean.getIsItalic()[0] ? 1 : 0;
} else {
isItalic = printInfoBean.getIsItalic()[i] ? 1 : 0;
}
mPrinter.addTextRotate(isItalic);
if (printInfoBean.getIsBold().length == 1) {
// mPrinter.addTextRotate(isItalic);
//reverse取值0,1沒效果,ul下劃線,em加粗,
mPrinter.addTextStyle(1, 0, printInfoBean.getIsBold()[0] ? 1 : 0, color);
} else {
if (printInfoBean.getIsBold()[i]) {
mPrinter.addTextStyle(1, 0, 1, color);
} else {
mPrinter.addTextStyle(1, 0, 0, color);
}
}
mPrinter.addTextStyle(1, 0, isBold, color);
setLanguage((String) MyPrintUtils.getContentByLength(printInfoBean.getLanguage(), i));
StringBuilder space = new StringBuilder();
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++) {
StringBuilder space = new StringBuilder();//縮進
for (int j = 0; j < location / textSize; j++) {
space.append(" ");
}
textSize = (int) printInfoBean.getSize()[i];
mPrinter.addTextSize(textSize, textSize);
location += getChineseValueLength(printInfoBean.getContent()[i]) * printInfoBean.getSize()[i];
}
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";
location += MyPrintUtils.getChineseValueLength(printInfoBean.getContent()[i]) * printInfoBean.getSize()[0];
/**
* 如果超過紙張寬度的英文,換行時,要截取得當
* 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;
}
mPrinter.addText(MyPrintUtils.getFormatText(space + printInfoBean.getContent()[i], paperWidth / textSize));
// mPrinter.addLineSpace(100);//行間距
}
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 {
if ("en".equals(language)) {
......@@ -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) {
//把bitmap存隊列中,下次打印
bitmaps.add(bitmap);
......
......@@ -60,264 +60,4 @@ public class IpPrintMaker implements PrintDataMaker {
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;
import com.gingersoft.gsa.cloud.print.PrintDataMaker;
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.print.utils.MyPrintUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -27,38 +28,9 @@ public class TestPrintMaker implements PrintDataMaker {
ArrayList<byte[]> data = new ArrayList<>();
try {
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++) {
//打印多列
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]);
}
for (int i = 0; i < printInfoBean.getContent().length; i++) {
print(printInfoBean, i);
}
printer.print("\n");
}
......@@ -69,7 +41,40 @@ public class TestPrintMaker implements PrintDataMaker {
data.add(printer.getDataAndClose());
return data;
} catch (Exception e) {
e.printStackTrace();
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
private Disposable wakeDisposable;
private List<PrinterDeviceBean> printerDeviceBeans;
private List<PrjBean.DataBean.Bean> printDatas = new ArrayList<>();
//
private List<PrintCurrencyBean> printCurrencyBeans;//通用打印配置
// @Override
// public void onCreate() {
// super.onCreate();
......@@ -81,6 +81,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
printerDeviceDaoUtils.closeConnection();
}
printCurrencyBeans = MyPrintUtils.getPrintCurrencyBeans(this);
}
@Nullable
......@@ -191,11 +192,14 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
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 void startPrint(String json) {
printDatas.clear();
PrintCurrencyBean printCurrencyBean;
PrjBean prjBean = JsonUtils.parseObject(json, PrjBean.class);
if (prjBean == null || prjBean.getData() == null) {
return;
......@@ -218,9 +222,13 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
} catch (JSONException e) {
e.printStackTrace();
}
//獲取通用打印配置
printCurrencyBean = getCurrencyBean();
if (printerInIt == null) {
printerInIt = PrinterRoot.getPrinterByType(PRINT_KITCHEN);
}
//獲取打印機列表
getPrintList();
for (Map.Entry<String, List<PrjBean.DataBean.Bean>> prjMap : listMap.entrySet()) {
for (PrinterDeviceBean deviceBean : printerDeviceBeans) {
......@@ -239,8 +247,6 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
if (deviceBean.getPaperSpecification() != null) {
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);
for (List<PrintInfoBean> prjPrintBean : prjBeans) {
mPrinter.putPrintString(deviceBean.getIp(), paperWidth, prjPrintBean);
......@@ -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已打印
*/
......
......@@ -3,6 +3,8 @@ package com.joe.print.mvp.print.utils;
import android.content.Context;
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.database.bean.PrintCurrencyBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
......@@ -10,6 +12,7 @@ import com.gingersoft.gsa.cloud.database.utils.PrintCurrencyDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.PrinterDeviceDaoUtils;
import com.joe.print.R;
import java.util.ArrayList;
import java.util.List;
public class MyPrintUtils {
......@@ -18,6 +21,9 @@ public class MyPrintUtils {
private static MyPrintUtils myPrintUtils;
private static boolean isUpdateCurrencyBeans = false;
private static List<PrintCurrencyBean> printCurrencyBeans;//通用打印配置
public static MyPrintUtils getInstance() {
if (myPrintUtils == null) {
myPrintUtils = new MyPrintUtils();
......@@ -34,8 +40,10 @@ public class MyPrintUtils {
* @return
*/
public PrintCurrencyBean getPrintCurrencyBeanByType(Context context, int type) {
if (isUpdateCurrencyBeans || printCurrencyBeans == null || printCurrencyBeans.size() == 0) {
PrintCurrencyDaoUtils printCurrencyDaoUtils = new PrintCurrencyDaoUtils(context);
List<PrintCurrencyBean> printCurrencyBeans = printCurrencyDaoUtils.queryAllPrintCurrencyBean();
printCurrencyBeans = printCurrencyDaoUtils.queryAllPrintCurrencyBean();
}
for (PrintCurrencyBean printCurrencyBean : printCurrencyBeans) {
if (printCurrencyBean.getType() == type) {
return printCurrencyBean;
......@@ -44,6 +52,19 @@ public class MyPrintUtils {
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 {
}
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;
import android.os.Bundle;
import android.util.Log;
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.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.PrinterWriter80mm;
import com.joe.print.R;
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.List;
import java.util.Objects;
public class PrintTestActivity extends AppCompatActivity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
private int lineLength = 24;//一行42個
private int LEFT_TEXT_LENGTH = 8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -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[]{"純屬餐廳"}, 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[]{"訂單碼:", "0046"}, new Boolean[]{false, true}, new double[]{1, 2}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"落單時間:", "07-13 19:05"}, new double[]{1}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"D1廚房", "BARRY1"}, new double[]{1}, 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[]{1d, 2d}, 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[]{1d}, 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[]{2}, 0));
printInfoBeans.add(new PrintInfoBean(new String[]{"外賣"}, new Boolean[]{true}, new double[]{2}, 1));
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[]{2d}, 0));
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 -> {
//打印測試
// PrintExecutor executor = new PrintExecutor(printerDeviceBean);
// executor.setOnStateChangedListener(this);
// executor.setOnPrintResultListener(this);
//
// TestPrintMaker maker = null;
// try {
// maker = new TestPrintMaker(new PrinterWriter80mm(255), printInfoBeans);
// } catch (IOException e) {
// e.printStackTrace();
// }
// 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();
PrintExecutor executor = new PrintExecutor(printerDeviceBean);
executor.setOnStateChangedListener(this);
executor.setOnPrintResultListener(this);
TestPrintMaker maker = null;
try {
maker = new TestPrintMaker(new PrinterWriter80mm(255), printInfoBeans);
} catch (IOException e) {
e.printStackTrace();
}
executor.doPrinterRequestAsync(maker);
});
}
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
public void onResult(int errorCode, PrinterDeviceBean printerDeviceBean) {
......@@ -85,7 +90,6 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH
}
private String getLineBorder(String text, double fontSize) {
if (fontSize == 0) {
fontSize = 1;
......@@ -120,4 +124,35 @@ public class PrintTestActivity extends AppCompatActivity implements PrintSocketH
}
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 @@
android:maxLines="1"
android:text="@string/print_split_line"
android:textColor="@color/theme_333_color"
android:visibility="visible" />
android:visibility="gone" />
<TextView
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="親愛的顧客,祝您用餐愉快,如您遇到任何問題請撥打8200 2022聯繫我們,期待您的下次光臨。"
android:visibility="visible" />
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:visibility="visible">
android:visibility="gone">
<TextView
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