Commit d315d8ac by Wyh

1、針式打印prj重複問題 2、打印進度

parent a4496333
...@@ -52,5 +52,6 @@ dependencies { ...@@ -52,5 +52,6 @@ dependencies {
releaseImplementation rootProject.ext.dependencies["canary-release"] releaseImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["canary-release"] testImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["junit"] testImplementation rootProject.ext.dependencies["junit"]
implementation rootProject.ext.dependencies["lottie"]
implementation files('libs/ePOS2.jar') implementation files('libs/ePOS2.jar')
} }
...@@ -287,7 +287,7 @@ public class EpsonPrint implements ReceiveListener { ...@@ -287,7 +287,7 @@ public class EpsonPrint implements ReceiveListener {
} }
private void printData(String ip, Bitmap bitmap) { private void printData(String ip, Bitmap bitmap) {
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機開始連接", ip, 0, 0, 0); PrinterPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(0, 0, "針式打印機", ip);
mPrinter.clearCommandBuffer(); mPrinter.clearCommandBuffer();
Log.d("eee", "針式打印機創建數據中,任務數:" + bitmaps.size()); Log.d("eee", "針式打印機創建數據中,任務數:" + bitmaps.size());
if (!createPrintData(bitmap)) { if (!createPrintData(bitmap)) {
...@@ -301,32 +301,31 @@ public class EpsonPrint implements ReceiveListener { ...@@ -301,32 +301,31 @@ public class EpsonPrint implements ReceiveListener {
} }
//連接打印機 //連接打印機
connectByIp(ip, mPrinter.getStatus()); connectByIp(ip, mPrinter.getStatus());
if (mPrinter == null) { //獲取打印機狀態
Log.d("eee", "針式打印機為空");
//連接失敗
updatePrintState(PrintSocketHolder.ERROR_7);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("針式打印機連接失敗" + ip));
isPrint = false;
return;
}
PrinterStatusInfo statusInfo = mPrinter.getStatus(); PrinterStatusInfo statusInfo = mPrinter.getStatus();
Log.d("eee", "針式打印機:" + "紙張狀態:" + statusInfo.getPaper() + "連接狀態:" + statusInfo.getConnection() + ",任務數:" + bitmaps.size()); Log.d("eee", "針式打印機:" + "紙張狀態:" + statusInfo.getPaper() + "連接狀態:" + statusInfo.getConnection() + ",任務數:" + bitmaps.size());
if (statusInfo.getPaper() == 2) { if (statusInfo.getConnection() != 1) {
//沒紙了
updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機缺紙,打印失敗" + ip));
isPrint = false;
return;
} else if (statusInfo.getConnection() != 1) {
//未連接到打印機 //未連接到打印機
updatePrintState(PrintSocketHolder.ERROR_7); updatePrintState(PrintSocketHolder.ERROR_7);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("針式打印機連接失敗" + ip)); PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("針式打印機連接失敗" + ip));
isPrint = false; isPrint = false;
return; return;
} else if (statusInfo.getPaper() != 0) {
//紙張不正常
if (statusInfo.getPaper() == 2) {
//沒紙了
updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機缺紙,打印失敗" + ip));
} else {
//紙張狀態異常
updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機紙張異常,請重啟打印機" + ip));
}
isPrint = false;
return;
} }
try { try {
mPrinter.sendData(Printer.PARAM_DEFAULT); mPrinter.sendData(Printer.PARAM_DEFAULT);
isPrint = false;
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess(); PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
Log.d("eee", "針式打印機打印成功" + ",任務數:" + bitmaps.size()); Log.d("eee", "針式打印機打印成功" + ",任務數:" + bitmaps.size());
} catch (Exception e) { } catch (Exception e) {
...@@ -407,6 +406,13 @@ public class EpsonPrint implements ReceiveListener { ...@@ -407,6 +406,13 @@ public class EpsonPrint implements ReceiveListener {
} }
} }
/**
* 打印結果回調
* @param printer 打印類
* @param i 打印結果
* @param printerStatusInfo 打印機狀態
* @param s
*/
@Override @Override
public void onPtrReceive(Printer printer, int i, PrinterStatusInfo printerStatusInfo, String s) { public void onPtrReceive(Printer printer, int i, PrinterStatusInfo printerStatusInfo, String s) {
this.mPrinter = printer; this.mPrinter = printer;
......
...@@ -9,6 +9,7 @@ import android.os.Build; ...@@ -9,6 +9,7 @@ import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
...@@ -74,6 +75,8 @@ import com.joe.print.mvp.ui.view.BillTypeView; ...@@ -74,6 +75,8 @@ import com.joe.print.mvp.ui.view.BillTypeView;
import com.joe.print.mvp.ui.view.BillView; import com.joe.print.mvp.ui.view.BillView;
import com.joe.print.mvp.ui.view.PrintFoodView; import com.joe.print.mvp.ui.view.PrintFoodView;
import com.sunmi.peripheral.printer.InnerResultCallbcak; import com.sunmi.peripheral.printer.InnerResultCallbcak;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -333,14 +336,17 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -333,14 +336,17 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
if ((printerDeviceBean.getPrinterName() != null && printerDeviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))) { if ((printerDeviceBean.getPrinterName() != null && printerDeviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))) {
if (printerDeviceBean.getModel() != null) { if (printerDeviceBean.getModel() != null) {
if (printerDeviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase())) { if (printerDeviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase())) {
ThreadPoolManager.getInstence().putExecutableTasks(() -> { RxJavaUtils.doInIOThread(new RxIOTask<Object>(0) {
EpsonPrint mPrinter = new EpsonPrint(); @Override
mPrinter.initializeObject(GsaCloudApplication.getAppContext(), PrinterRoot.this, PrinterRoot.this); public Void doInIOThread(Object o) {
for (int j = 0; j < bitmaps.size(); j++) { EpsonPrint mPrinter = new EpsonPrint();
mPrinter.putPrintData(printerDeviceBean.getIp(), bitmaps.get(j), ""); mPrinter.initializeObject(GsaCloudApplication.getAppContext(), PrinterRoot.this, PrinterRoot.this);
} for (int j = 0; j < bitmaps.size(); j++) {
mPrinter.putPrintData(printerDeviceBean.getIp(), bitmaps.get(j), "");
} }
); return null;
}
});
return; return;
} }
} }
...@@ -434,6 +440,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -434,6 +440,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
@Override @Override
public void onResult(int errorCode) { public void onResult(int errorCode) {
Log.e("eee", "打印結果:" + errorCode);
switch (errorCode) { switch (errorCode) {
case PrintSocketHolder.ERROR_0: case PrintSocketHolder.ERROR_0:
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess(); PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
......
...@@ -512,14 +512,12 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -512,14 +512,12 @@ public class PrjService extends Service implements ReceiveListener {
List<Map<String, Bitmap>> bitmapMaps = generatePrintMaps(key, beans, printerDeviceBean); List<Map<String, Bitmap>> bitmapMaps = generatePrintMaps(key, beans, printerDeviceBean);
//將打印的圖片保存到手機中 //將打印的圖片保存到手機中
hookPrinterBitmap(bitmapMaps, beans); hookPrinterBitmap(bitmapMaps, beans);
//獲取prj的id集合
String epsonIds = getPrintIds(bitmapMaps);
EpsonPrint mPrinter = EpsonPrint.getInstance(); EpsonPrint mPrinter = EpsonPrint.getInstance();
boolean initResult = EpsonPrint.getInstance().initializeObject(this, this, errorCode -> updatePrjState(errorCode, epsonIds)); boolean initResult = EpsonPrint.getInstance().initializeObject(this, this, errorCode -> updatePrjState(errorCode, getPrintIds(bitmapMaps)));
if (!initResult) { if (!initResult) {
//初始化打印機失敗 //初始化打印機失敗
updatePrjState(UpdateBean.FAIL_EPSON_INIT, epsonIds); updatePrjState(UpdateBean.FAIL_EPSON_INIT, getPrintIds(bitmapMaps));
return; return;
} }
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0); PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0);
...@@ -744,7 +742,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -744,7 +742,7 @@ public class PrjService extends Service implements ReceiveListener {
updatePrjSuccess(ids); updatePrjSuccess(ids);
} else { } else {
//打印失敗 //打印失敗
updatePrjFailure(ids); updatePrjState(i, ids);
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, i); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, i);
} }
} }
......
...@@ -5,23 +5,19 @@ import android.content.Context; ...@@ -5,23 +5,19 @@ import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.airbnb.lottie.LottieAnimationView; import com.airbnb.lottie.LottieAnimationView;
import com.gingersoft.gsa.cloud.pay.pos.hywebpos.constant.HywebActionStatusCode;
import com.gingersoft.gsa.cloud.ui.widget.dialog.BaseRetryDialog; import com.gingersoft.gsa.cloud.ui.widget.dialog.BaseRetryDialog;
import com.joe.print.R; import com.joe.print.R;
import com.qmuiteam.qmui.layout.QMUILinearLayout; import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.qmuiteam.qmui.util.QMUIDisplayHelper; import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import butterknife.BindDrawable;
/** /**
* 作者:ELEGANT_BIN * 作者:ELEGANT_BIN
* 版本:1.6.0 * 版本:1.6.0
...@@ -56,6 +52,10 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -56,6 +52,10 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
super(context, R.style.MyDialogTheme2); super(context, R.style.MyDialogTheme2);
mContext = context; mContext = context;
mRadius = QMUIDisplayHelper.dp2px(mContext, 8); mRadius = QMUIDisplayHelper.dp2px(mContext, 8);
drawables = new Drawable[3];
drawables[0] = getDrawableByResId(R.drawable.print_grey_point);
drawables[1] = getDrawableByResId(R.drawable.print_green_point);
drawables[2] = getDrawableByResId(R.drawable.print_red_point);
} }
@Override @Override
...@@ -92,13 +92,13 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -92,13 +92,13 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
tv_printing = view.findViewById(R.id.tv_printing); tv_printing = view.findViewById(R.id.tv_printing);
tv_print_result = view.findViewById(R.id.tv_print_result); tv_print_result = view.findViewById(R.id.tv_print_result);
textViews = new TextView[]{tv_generate_print_data, tv_connecting, tv_printing, tv_print_result};
ll_container.setRadiusAndShadow(mRadius, QMUIDisplayHelper.dp2px(mContext, mShadowElevationDp), mShadowAlpha); ll_container.setRadiusAndShadow(mRadius, QMUIDisplayHelper.dp2px(mContext, mShadowElevationDp), mShadowAlpha);
printLottieView.setAnimation(R.raw.printer_loading3); printLottieView.setAnimation(R.raw.printer_loading3);
printLottieView.loop(true); printLottieView.setRepeatCount(ValueAnimator.INFINITE);
// printLottieView.addAnimatorUpdateListener((animation) -> { // printLottieView.addAnimatorUpdateListener((animation) -> {
// // Do something.动画状态监听回调 // // Do something.动画状态监听回调
//
// }); // });
printLottieView.playAnimation();//播放动画 printLottieView.playAnimation();//播放动画
// //progress范围0~1f,设置动画进度 // //progress范围0~1f,设置动画进度
...@@ -109,73 +109,23 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -109,73 +109,23 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
return view; return view;
} }
private Drawable[] drawables;
private TextView[] textViews;
public void setStep(int step, int status) { public void setStep(int step, int status) {
tv_generate_print_data.post(new Runnable() { tv_generate_print_data.post(() -> setCompoundDrawableByStatus(status, textViews[step - 1]));
@Override
public void run() {
switch (step) {
case 1:
if (status == PrinterLoadingDialog.status_success) {
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_generate_print_data.setCompoundDrawables(null,getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
case 2:
if (status == PrinterLoadingDialog.status_success) {
tv_connecting.setCompoundDrawables(null,getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_connecting.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_connecting.setCompoundDrawables(null,getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
case 3:
if (status == PrinterLoadingDialog.status_success) {
tv_printing.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_printing.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_printing.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
case 4:
if (status == PrinterLoadingDialog.status_success) {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
default:
break;
}
}
});
} }
private Drawable getDrawableByResId(int resId) { private void setCompoundDrawableByStatus(int status, TextView textView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { textView.setCompoundDrawablesWithIntrinsicBounds(textView.getCompoundDrawables()[0], drawables[status], textView.getCompoundDrawables()[2], textView.getCompoundDrawables()[0]);
return mContext.getDrawable(resId);
}
return mContext.getResources().getDrawable(resId);
}
protected int getContentViewLayoutId() {
return R.layout.print_dialog_loading;
} }
private OnClickListener onClickListener; private Drawable getDrawableByResId(int resId) {
return ContextCompat.getDrawable(mContext, resId);
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
} }
public interface OnClickListener { protected int getContentViewLayoutId() {
// void onItemClick(FoodReason item, int position, int deleteNumber); return R.layout.print_dialog_loading;
} }
} }
...@@ -66,7 +66,7 @@ ext { ...@@ -66,7 +66,7 @@ ext {
"paginate" : "com.github.markomilos:paginate:0.5.1", "paginate" : "com.github.markomilos:paginate:0.5.1",
"vlayout" : "com.alibaba.android:vlayout:1.1.0@aar", "vlayout" : "com.alibaba.android:vlayout:1.1.0@aar",
"loadsir" : "com.kingja.loadsir:loadsir:1.3.8", "loadsir" : "com.kingja.loadsir:loadsir:1.3.8",
"lottie" : "com.airbnb.android:lottie:2.7.0", "lottie" : "com.airbnb.android:lottie:3.6.1",
//rx1 //rx1
"rxandroid" : "io.reactivex:rxandroid:1.2.1", "rxandroid" : "io.reactivex:rxandroid:1.2.1",
......
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