Commit 522480e0 by 宁斌

PrinterFlowProxy类调整

parent 32aeaa84
......@@ -9,7 +9,7 @@ import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;
import com.epson.epos2.printer.ReceiveListener;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.joe.print.mvp.model.bean.PrintInfoBean;
......@@ -279,7 +279,7 @@ public class EpsonPrint implements ReceiveListener {
ids.add(foodId);
if (isPrint) {
Log.d("eee", "針式打印機隊列中,前面還有" + bitmaps.size() + "個任務");
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機隊列中,前面還有" + bitmaps.size() + "個任務", ip, 0, 0, 0);
PrinterFlowProxy.newInstance().dispatchConnectionBefore("針式打印機隊列中,前面還有" + bitmaps.size() + "個任務", ip, 0, 0, 0);
return;
}
isPrint = true;
......@@ -287,7 +287,7 @@ public class EpsonPrint implements ReceiveListener {
}
private void printData(String ip, Bitmap bitmap) {
PrinterPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(0, 0, "針式打印機", ip);
PrinterFlowProxy.newInstance().dispatchPrinterDataBefore(0, 0, "針式打印機", ip);
mPrinter.clearCommandBuffer();
Log.d("eee", "針式打印機創建數據中,任務數:" + bitmaps.size());
if (!createPrintData(bitmap)) {
......@@ -306,7 +306,7 @@ public class EpsonPrint implements ReceiveListener {
if (statusInfo.getConnection() != 1) {
//未連接到打印機
updatePrintState(PrintSocketHolder.ERROR_7);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("針式打印機連接失敗" + ip));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException("針式打印機連接失敗" + ip));
isPrint = false;
return;
} else if (statusInfo.getPaper() != 0) {
......@@ -314,23 +314,23 @@ public class EpsonPrint implements ReceiveListener {
if (statusInfo.getPaper() == 2) {
//沒紙了
updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("針式打印機缺紙,打印失敗" + ip),0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("針式打印機缺紙,打印失敗" + ip),0);
} else {
//紙張狀態異常
updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("針式打印機紙張異常,請重啟打印機" + ip),0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("針式打印機紙張異常,請重啟打印機" + ip),0);
}
isPrint = false;
return;
}
try {
mPrinter.sendData(Printer.PARAM_DEFAULT);
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
Log.d("eee", "針式打印機打印成功" + ",任務數:" + bitmaps.size());
} catch (Exception e) {
Log.d("eee", "針式打印機打印失敗" + ",任務數:" + bitmaps.size() + e.getMessage());
updatePrintState(PrintSocketHolder.ERROR_10);
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印機連接成功,發送數據出現問題"),0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("打印機連接成功,發送數據出現問題"),0);
mPrinter.clearCommandBuffer();
disconnectPrinter();
isPrint = false;
......@@ -392,10 +392,10 @@ public class EpsonPrint implements ReceiveListener {
LoganManager.w_printer(TAG, "連接打印機報錯:" + e.getMessage());
disconnectPrinter();
finalizeObject();
PrinterPlugins.getOnPrinterFlowHandler().connectionError(e);
PrinterFlowProxy.newInstance().dispatchConnectionError(e);
return false;
}
PrinterPlugins.getOnPrinterFlowHandler().connectionSuccess();
PrinterFlowProxy.newInstance().dispatchConnectionSuccess();
return true;
}
......
......@@ -17,7 +17,7 @@ import com.gingersoft.gsa.cloud.common.constans.PrintConstans;
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.AidlUtil;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils;
......@@ -46,7 +46,6 @@ import com.joe.print.mvp.print.usb.UsbPrinter;
import com.joe.print.mvp.print.usb.UsbPrinterFinder;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import com.sunmi.peripheral.printer.InnerResultCallbcak;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -61,7 +60,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
......@@ -309,7 +307,7 @@ public class PrjPtinterManager implements ReceiveListener {
if (beans != null && beans.size() > 0) {
orderType = beans.get(0).getOrderType();
}
PrinterPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(orderType, PrintConstans.PRINT_KITCHEN, GsonUtils.GsonString(beans), GsonUtils.GsonString(printerDeviceBean));
PrinterFlowProxy.newInstance().dispatchPrinterDataBefore(orderType, PrintConstans.PRINT_KITCHEN, GsonUtils.GsonString(beans), GsonUtils.GsonString(printerDeviceBean));
if (isPinPrinter(printerDeviceBean) && printerDeviceBean.getPrinterDeviceType() == PRINT_IP) {
//針式打印
......@@ -458,11 +456,11 @@ public class PrjPtinterManager implements ReceiveListener {
boolean initResult = EpsonPrint.getInstance().initializeObject(mContext, this, errorCode -> updatePrjState(errorCode, getPrintIds(bitmapMaps)));
if (!initResult) {
//初始化打印機失敗
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("初始化針式打印機失敗"));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException("初始化針式打印機失敗"));
updatePrjState(UpdateBean.FAIL_EPSON_INIT, getPrintIds(bitmapMaps));
return;
}
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0);
PrinterFlowProxy.newInstance().dispatchConnectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0);
Log.d("eee", "針式打印機本次PRJ數量:" + bitmapMaps.size());
for (int i = 0; i < bitmapMaps.size(); i++) {
for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) {
......@@ -507,10 +505,10 @@ public class PrjPtinterManager implements ReceiveListener {
UsbPrint usbPrint = new UsbPrint(mContext, (code, printId) -> {
//打印結果
if (code == SendResultCode.SEND_SUCCESS) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
updatePrjSuccess(key);
} else if (code == SendResultCode.SEND_FAILED) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("發送打印數據失敗"), code);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("發送打印數據失敗"), code);
updatePrjFailure(key);
}
});
......@@ -621,7 +619,7 @@ public class PrjPtinterManager implements ReceiveListener {
@Override
public void onRaiseException(int code, String msg) {
//接⼝执⾏失败时,返回的异常状态
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(msg), code);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(msg), code);
LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg);
switch (code) {
case 3:
......@@ -684,7 +682,7 @@ public class PrjPtinterManager implements ReceiveListener {
updatePrjSuccess(ids);
} else {
//打印失敗
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
updatePrjState(i, ids);
}
}
......@@ -697,7 +695,7 @@ public class PrjPtinterManager implements ReceiveListener {
});
} catch (RemoteException e) {
e.printStackTrace();
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(e, i);
PrinterFlowProxy.newInstance().dispatchPrintError(e, i);
LoganManager.w_printer(TAG, "N5 RemoteException :" + e.getLocalizedMessage());
updatePrjFailure(ids);
}
......@@ -766,7 +764,7 @@ public class PrjPtinterManager implements ReceiveListener {
bitmapList.add(bitmapIterator.next().getValue());
}
}
PrinterPlugins.getOnPrinterFlowHandler().onPrinterBitmapBefore(orderType, PrintConstans.PRINT_KITCHEN, prjName, bitmapList);
PrinterFlowProxy.newInstance().dispatchPrinterBitmapBefore(orderType, PrintConstans.PRINT_KITCHEN, prjName, bitmapList);
}
}
......@@ -841,11 +839,11 @@ public class PrjPtinterManager implements ReceiveListener {
public void onPtrReceive(Printer printer, int i, PrinterStatusInfo printerStatusInfo, String s) {
//針式打印回調
if (i == 0) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
//打印成功
updatePrjSuccess(s);
} else {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印失敗"), i);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("打印失敗"), i);
//打印失敗
updatePrjFailure(s);
}
......
......@@ -9,7 +9,6 @@ import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.View;
......@@ -35,10 +34,8 @@ import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager;
import com.gingersoft.gsa.cloud.common.core.restaurant.utils.RestaurantExpandInfoUtils;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.AidlUtil;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.threadPool.ThreadPoolManager;
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.common.utils.view.ImageUtils;
import com.gingersoft.gsa.cloud.common.utils.view.LayoutToBitmapUtils;
......@@ -81,7 +78,6 @@ import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
......@@ -235,7 +231,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
new BBposPrint().print(BBPosPrintDatas, listener, false);
} else {
// listener.printFailure("暫不支持本機型打印");
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("暫不支持本機型打印"));
PrinterFlowProxy.newInstance().dispatchConnectionError(new Exception("暫不支持本機型打印"));
}
}
......@@ -268,7 +264,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
*/
private void sunmiPrint(List<Bitmap> bitmaps, PrintListener listener) {
//商米打印
PrinterPlugins.getOnPrinterFlowHandler().connectionSuccess();
PrinterFlowProxy.newInstance().dispatchConnectionSuccess();
AidlUtil.getInstance().printBitmaps(bitmaps, SUNMI_PAPER_WIDTH, new InnerResultCallbcak() {
@Override
public void onRunResult(boolean isSuccess) {
......@@ -288,14 +284,14 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
@Override
public void onRaiseException(int code, String msg) {
//接⼝执⾏失败时,返回的异常状态
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(msg), code);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(msg), code);
LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg);
}
@Override
public void onPrintResult(int code, String msg) {
//事务模式下真实的打印结果返回
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
}
});
}
......@@ -308,7 +304,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
if (i == 0) {
//打印成功
listener.printSuccess();
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
} else {
//打印失敗
listener.printFailure(UpdateBean.getStateByCode(i));
......
......@@ -21,7 +21,7 @@ import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager;
import com.gingersoft.gsa.cloud.common.core.user.UserContext;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.AidlUtil;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils;
......@@ -367,7 +367,7 @@ public class PrjService extends Service implements ReceiveListener {
if (beans != null && beans.size() > 0) {
orderType = beans.get(0).getOrderType();
}
PrinterPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(orderType, PrintConstans.PRINT_KITCHEN, GsonUtils.GsonString(beans), GsonUtils.GsonString(printerDeviceBean));
PrinterFlowProxy.newInstance().dispatchPrinterDataBefore(orderType, PrintConstans.PRINT_KITCHEN, GsonUtils.GsonString(beans), GsonUtils.GsonString(printerDeviceBean));
if (isPinPrinter(printerDeviceBean) && printerDeviceBean.getPrinterDeviceType() == PRINT_IP) {
//針式打印
......@@ -516,11 +516,11 @@ public class PrjService extends Service implements ReceiveListener {
boolean initResult = EpsonPrint.getInstance().initializeObject(this, this, errorCode -> updatePrjState(errorCode, getPrintIds(bitmapMaps)));
if (!initResult) {
//初始化打印機失敗
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("初始化針式打印機失敗"));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException("初始化針式打印機失敗"));
updatePrjState(UpdateBean.FAIL_EPSON_INIT, getPrintIds(bitmapMaps));
return;
}
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0);
PrinterFlowProxy.newInstance().dispatchConnectionBefore("針式打印機" + bitmapMaps.size(), printerDeviceBean.getIp(), printerDeviceBean.getPort(), 0, 0);
Log.d("eee", "針式打印機本次PRJ數量:" + bitmapMaps.size());
for (int i = 0; i < bitmapMaps.size(); i++) {
for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) {
......@@ -565,10 +565,10 @@ public class PrjService extends Service implements ReceiveListener {
UsbPrint usbPrint = new UsbPrint(mContext, (code, printId) -> {
//打印結果
if (code == SendResultCode.SEND_SUCCESS) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
updatePrjSuccess(key);
} else if (code == SendResultCode.SEND_FAILED) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("發送打印數據失敗"), code);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("發送打印數據失敗"), code);
updatePrjFailure(key);
}
});
......@@ -679,7 +679,7 @@ public class PrjService extends Service implements ReceiveListener {
@Override
public void onRaiseException(int code, String msg) {
//接⼝执⾏失败时,返回的异常状态
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(msg), code);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(msg), code);
LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg);
switch (code) {
case 3:
......@@ -742,7 +742,7 @@ public class PrjService extends Service implements ReceiveListener {
updatePrjSuccess(ids);
} else {
//打印失敗
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
updatePrjState(i, ids);
}
}
......@@ -755,7 +755,7 @@ public class PrjService extends Service implements ReceiveListener {
});
} catch (RemoteException e) {
e.printStackTrace();
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(e, i);
PrinterFlowProxy.newInstance().dispatchPrintError(e, i);
LoganManager.w_printer(TAG, "N5 RemoteException :" + e.getLocalizedMessage());
updatePrjFailure(ids);
}
......@@ -824,7 +824,7 @@ public class PrjService extends Service implements ReceiveListener {
bitmapList.add(bitmapIterator.next().getValue());
}
}
PrinterPlugins.getOnPrinterFlowHandler().onPrinterBitmapBefore(orderType, PrintConstans.PRINT_KITCHEN, prjName, bitmapList);
PrinterFlowProxy.newInstance().dispatchPrinterBitmapBefore(orderType, PrintConstans.PRINT_KITCHEN, prjName, bitmapList);
}
}
......@@ -901,11 +901,11 @@ public class PrjService extends Service implements ReceiveListener {
public void onPtrReceive(Printer printer, int i, PrinterStatusInfo printerStatusInfo, String s) {
//針式打印回調
if (i == 0) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
//打印成功
updatePrjSuccess(s);
} else {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印失敗"), i);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception("打印失敗"), i);
//打印失敗
updatePrjFailure(s);
}
......
package com.joe.print.mvp.ui.activity;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
......@@ -20,21 +18,19 @@ import com.gingersoft.gsa.cloud.app.GsaCloudApplication;
import com.gingersoft.gsa.cloud.common.constans.PrintConstans;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowListener;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.common.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.database.utils.FoodModifierDaoUtils;
import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.bean.PrintContent;
import com.gingersoft.gsa.cloud.print.bean.PrjBean;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.integration.AppManager;
import com.jess.arms.utils.ArmsUtils;
import com.joe.print.di.component.DaggerPrintComponent;
import com.joe.print.mvp.contract.PrintContract;
......@@ -53,13 +49,6 @@ import com.lxj.xpopup.XPopup;
import java.net.ConnectException;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import javax.inject.Inject;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import static com.gingersoft.gsa.cloud.common.constans.PrintConstans.PRINT_BILL;
import static com.gingersoft.gsa.cloud.common.constans.PrintConstans.PRINT_OTHER_CLOSING;
......@@ -143,7 +132,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
// .asLoading("加载中...");
// loadingPopup.show();
PrinterPlugins.setOnPrinterFlowHandler(new PrinterFlowListener() {
PrinterFlowProxy.newInstance().registerPrinterFlowListener(new PrinterFlowListener() {
@Override
public void connectionBefore(String deviceName, String IP, int port, long ioTimeout, long printTimeout) {
......@@ -152,13 +141,11 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void connectionSuccess() {
LoganManager.w_code(TAG, "PrinterPlugins connectionSuccess ThreadName=" + Thread.currentThread().getName());
printerLoadingDialog.setStep(2, PrinterLoadingDialog.status_success, null);
}
@Override
public void connectionError(Exception e) {
LoganManager.w_code(TAG, "PrinterPlugins connectionError ThreadName=" + Thread.currentThread().getName());
printerResult = false;
printerLoadingDialog.setStep(2, PrinterLoadingDialog.status_error, e.getMessage());
}
......@@ -169,26 +156,22 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void onPrinterDataBefore(int orderType, int printType, String printerData, String printerDeviceInfo) {
LoganManager.w_code(TAG, "PrinterPlugins onPrinterDataBefore ThreadName=" + Thread.currentThread().getName());
printerLoadingDialog.setStep(1, PrinterLoadingDialog.status_success, null);
}
@Override
public void onPrinterBitmapBefore(int orderType, int printType, String directoryName, List<Bitmap> bitmaps) {
LoganManager.w_code(TAG, "PrinterPlugins onPrinterBitmapBefore ThreadName=" + Thread.currentThread().getName());
printerLoadingDialog.setStep(1, PrinterLoadingDialog.status_success, null);
}
@Override
public void onPrintSuccess() {
LoganManager.w_code(TAG, "PrinterPlugins onPrintSuccess ThreadName=" + Thread.currentThread().getName());
printerResult = true;
printerLoadingDialog.setStep(3, PrinterLoadingDialog.status_success, null);
}
@Override
public void onPrintError(Exception e, int errorCode) {
LoganManager.w_code(TAG, "PrinterPlugins onPrintError ThreadName=" + Thread.currentThread().getName());
printerResult = false;
printerLoadingDialog.setStep(3, PrinterLoadingDialog.status_error, e.getMessage());
}
......@@ -254,7 +237,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
private void initPrintConfig(PrintContent printContent) {
PrinterPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(type, type, GsonUtils.GsonString(printContent), GsonUtils.GsonString(defaultPrint));
PrinterFlowProxy.newInstance().dispatchPrinterDataBefore(type, type, GsonUtils.GsonString(printContent), GsonUtils.GsonString(defaultPrint));
//獲取通用打印配置
PrintCurrencyBean printCurrencyBean = getCurrencyConfig();
......@@ -420,7 +403,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
private void setPrinterBitmapToLocation(int orderType, int printType, String orderNo, Map<String, List<Bitmap>> bitmapMaps) {
if (bitmapMaps.size() > 0 && bitmapMaps.get("") != null) {
String prjName = orderNo + "-" + System.currentTimeMillis();
PrinterPlugins.getOnPrinterFlowHandler().onPrinterBitmapBefore(orderType, printType, prjName, bitmapMaps.get(""));
PrinterFlowProxy.newInstance().dispatchPrinterBitmapBefore(orderType, printType, prjName, bitmapMaps.get(""));
}
}
......@@ -451,38 +434,38 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
switch (state) {
case PrintSocketHolder.ERROR_0:
tip = "打印成功";
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
PrinterFlowProxy.newInstance().dispatchPrintSuccess();
break;
case PrintSocketHolder.ERROR_6:
tip = "生成打印數據失敗";
break;
case PrintSocketHolder.ERROR_7:
tip = "連接打印機失敗";
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException(tip));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException(tip));
break;
case PrintSocketHolder.ERROR_4:
tip = "寫入數據失敗";
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(tip), 0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(tip), 0);
break;
case PrintSocketHolder.ERROR_9:
tip = "ip地址不能為空";
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException(tip));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException(tip));
break;
case PrintSocketHolder.ERROR_10:
tip = "打印機連接成功,獲取輸入流失敗或者發送數據出現問題";
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(tip), 0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(tip), 0);
break;
case PrintSocketHolder.ERROR_11:
tip = "打印機沒紙了";
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(tip), 0);
PrinterFlowProxy.newInstance().dispatchPrintError(new Exception(tip), 0);
break;
case PrintSocketHolder.ERROR_12:
tip = " 打印機初始化失敗,暫時只有針式打印機有";
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException(tip));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException(tip));
break;
case PrintSocketHolder.ERROR_TIMEOUT:
tip = "連接打印機超時";
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException(tip));
PrinterFlowProxy.newInstance().dispatchConnectionError(new ConnectException(tip));
break;
case PrintSocketHolder.STATE_0:
break;
......@@ -509,7 +492,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
//缺紙
printFailure("打印機缺紙");
tip = "打印機缺紙";
// PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(tip), 0);
// PrinterPlugins.newInstance().dispatchPrintError(new Exception(tip), 0);
break;
default:
break;
......@@ -588,9 +571,9 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void killMyself() {
if (printerResult) {
// if (printerResult) {
finish();
}
// }
}
@Override
......
......@@ -5,10 +5,22 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.gingersoft.gsa.cloud.common.utils.threadPool.ThreadPoolManager;
import com.gingersoft.gsa.cloud.table.R;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import java.util.Timer;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.RecursiveTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import io.reactivex.internal.schedulers.ScheduledDirectTask;
/**
* @作者: bin
* @創建時間: 2021-02-02 11:42
......@@ -34,7 +46,6 @@ public class CoordinatorlayoutActivity extends BaseActivity {
@Override
public void initIntent() {
}
@Override
......
......@@ -14,7 +14,6 @@ import androidx.annotation.NonNull;
import com.billy.cc.core.component.CC;
import com.dianping.logan.Logan;
import com.dianping.logan.OnLoganProtocolStatus;
import com.didichuxing.doraemonkit.DoraemonKit;
import com.elvishew.xlog.LogConfiguration;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
......@@ -27,7 +26,6 @@ import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy;
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator;
import com.gingersoft.gsa.cloud.common.BuildConfig;
import com.gingersoft.gsa.cloud.common.R;
import com.gingersoft.gsa.cloud.common.config.DoraemonKitConfig;
import com.gingersoft.gsa.cloud.common.config.LoganConfig;
import com.gingersoft.gsa.cloud.common.config.expandconfig.ExpandInfoSetting;
import com.gingersoft.gsa.cloud.common.config.expandconfig.FunctionExtendedConfiguration;
......@@ -49,35 +47,27 @@ import com.gingersoft.gsa.cloud.common.oaId.DeviceID;
import com.gingersoft.gsa.cloud.common.printer.AidlUtil;
import com.gingersoft.gsa.cloud.common.printer.PrinterFileUtils;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowListener;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.AppDevices;
import com.gingersoft.gsa.cloud.common.utils.FileUtils;
import com.gingersoft.gsa.cloud.common.utils.crash.AppCrashHandler;
import com.gingersoft.gsa.cloud.common.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.common.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.common.utils.view.BitmapUtil;
import com.gingersoft.gsa.cloud.common.utils.xlog.MyBackupStrategy;
import com.gingersoft.gsa.cloud.component.ComponentAction;
import com.gingersoft.gsa.cloud.component.ComponentName;
import com.gingersoft.gsa.cloud.database.DaoManager;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.hyweb.n5.lib.exception.NoInitPrinterException;
import com.hyweb.n5.lib.util.PrinterUtil;
import com.jess.arms.base.BaseApplication;
import com.kingja.loadsir.core.LoadSir;
import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;
......@@ -166,7 +156,6 @@ public class GsaCloudApplication extends BaseApplication {
//上傳餐廳擴展信息
ExpandInfoSetting.initUpdateExtendedConfiguration(uiStyleConfiguration, functionConfiguration);
LoganManager.w_action(TAG, TAG + ": onCreate end.....");
}
......@@ -184,7 +173,7 @@ public class GsaCloudApplication extends BaseApplication {
if (BuildConfig.DEBUG) {
LoganConfig.UPLOAD_LOG_URL = "http://192.168.1.131:8080/logan-web/logan/upload.json";
} else {
LoganConfig.UPLOAD_LOG_URL = HttpsConstans.HTTP_ADDRESS_URL_HK + "/logan-web/logan/upload.json";
LoganConfig.UPLOAD_LOG_URL = HttpsConstans.ROOT_HK_TEST_URL + "/logan-web/logan/upload.json";
}
com.dianping.logan.LoganConfig config = new com.dianping.logan.LoganConfig.Builder()
.setCachePath(getFilesDir().getAbsolutePath())
......@@ -347,7 +336,7 @@ public class GsaCloudApplication extends BaseApplication {
SPUtils.put(PrintConstans.DEFAULT_PRINT_METHOD, PrintConstans.IP_PRINT);
}
//打印流程
PrinterPlugins.setOnPrinterFlowHandler(new PrinterFlowListener() {
PrinterFlowProxy.newInstance().registerPrinterFlowListener(new PrinterFlowListener() {
private final String TAG = "PrinterPlugins";
......
......@@ -15,7 +15,7 @@ public class LoganConfig {
public static final String EncryptIV16 = "0123456789012345";
public static final String APP_ID = "gingersoft1008611";
// public static final String UPLOAD_LOG_URL = HttpsConstans.HTTP_ADDRESS_URL_HK+ "/logan-web/logan/upload.json";
public static String UPLOAD_LOG_URL = "http://192.168.1.131:8080/logan-web/logan/upload.json";
public static String UPLOAD_LOG_URL = "https://hktest.ricepon.com:64377/logan-web/logan/upload.json";
/**
* 日誌保留天數
......
package com.gingersoft.gsa.cloud.common.printer.plugins;
import android.graphics.Bitmap;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;
import io.reactivex.functions.Consumer;
/**
* @作者: bin
* @創建時間: 2021-01-25 9:46
* @更新時間: 2021-01-25 9:46
* @描述:
*/
public class PrinterFlowProxy {
private static volatile PrinterFlowProxy sPrinterPlugins = null;
private ArrayList<PrinterFlowListener> mPrinterFlowListeners = new ArrayList<>();
@Nullable
private Consumer<? super Throwable> errorHandler;
private PrinterFlowProxy() {
}
public static PrinterFlowProxy newInstance() {
if (sPrinterPlugins == null) {
synchronized (PrinterFlowProxy.class) {
if (sPrinterPlugins == null) {
sPrinterPlugins = new PrinterFlowProxy();
}
}
}
return sPrinterPlugins;
}
public void onError(@NonNull Throwable error) {
Consumer<? super Throwable> f = errorHandler;
if (error == null) {
error = new NullPointerException("onError called with null");
}
if (f != null) {
try {
f.accept(error);
return;
} catch (Throwable e) {
e.printStackTrace();
uncaught(e);
}
}
error.printStackTrace();
uncaught(error);
}
void uncaught(@NonNull Throwable error) {
Thread currentThread = Thread.currentThread();
Thread.UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
handler.uncaughtException(currentThread, error);
}
public void setErrorHandler(Consumer<? super Throwable> errorHandler) {
this.errorHandler = errorHandler;
}
public void registerPrinterFlowListener(PrinterFlowListener listener) {
mPrinterFlowListeners.add(listener);
}
public void unregisterPrinterFlowListener(PrinterFlowListener listener) {
mPrinterFlowListeners.remove(listener);
}
public void dispatchPrinterDataBefore(int orderType, int printType, String printerData, String printerDeviceInfo) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).onPrinterDataBefore(orderType, printType, printerData, printerDeviceInfo);
}
}
}
public void dispatchPrinterBitmapBefore(int orderType, int printType, String directoryName, List<Bitmap> bitmaps) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).onPrinterBitmapBefore(orderType, printType, directoryName, bitmaps);
}
}
}
public void dispatchPrintSuccess() {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).onPrintSuccess();
}
}
}
public void dispatchPrintError(Exception e, int errorCode) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).onPrintError(e, errorCode);
}
}
}
public void dispatchConnectionBefore(String deviceName, String IP, int port, long ioTimeout, long printTimeout) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).connectionBefore(deviceName, IP, port, ioTimeout, printTimeout);
}
}
}
public void dispatchConnectionSuccess() {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).connectionSuccess();
}
}
}
public void dispatchConnectionError(Exception e) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).connectionError(e);
}
}
}
public void dispatchDisconnect(Exception e) {
Object[] listeners = collectPrinterFlowListener();
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
((PrinterFlowListener) listeners[i]).disconnect(e);
}
}
}
private Object[] collectPrinterFlowListener() {
Object[] listeners = null;
synchronized (mPrinterFlowListeners) {
if (mPrinterFlowListeners.size() > 0) {
listeners = mPrinterFlowListeners.toArray();
}
}
return listeners;
}
}
package com.gingersoft.gsa.cloud.common.printer.plugins;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;
import io.reactivex.functions.Consumer;
/**
* @作者: bin
* @創建時間: 2021-01-25 9:46
* @更新時間: 2021-01-25 9:46
* @描述:
*/
public class PrinterPlugins {
@Nullable
static volatile Consumer<? super Throwable> errorHandler;
@Nullable
static volatile PrinterFlowListener onPrinterFlowHandler;
public static void onError(@NonNull Throwable error) {
Consumer<? super Throwable> f = errorHandler;
if (error == null) {
error = new NullPointerException("onError called with null");
}
if (f != null) {
try {
f.accept(error);
return;
} catch (Throwable e) {
e.printStackTrace();
uncaught(e);
}
}
error.printStackTrace();
uncaught(error);
}
static void uncaught(@NonNull Throwable error) {
Thread currentThread = Thread.currentThread();
Thread.UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
handler.uncaughtException(currentThread, error);
}
public static void setErrorHandler(Consumer<? super Throwable> errorHandler) {
PrinterPlugins.errorHandler = errorHandler;
}
public static PrinterFlowListener getOnPrinterFlowHandler() {
if (onPrinterFlowHandler == null) {
new NullPointerException("onPrinterFlowHandler called with null");
}
return onPrinterFlowHandler;
}
public static void setOnPrinterFlowHandler(PrinterFlowListener onPrinterFlowHandler) {
PrinterPlugins.onPrinterFlowHandler = onPrinterFlowHandler;
}
}
......@@ -2,7 +2,7 @@ package com.gingersoft.gsa.cloud.print;
import com.gingersoft.gsa.cloud.common.constans.PrintConstans;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterPlugins;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrinterFlowProxy;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import java.io.IOException;
......@@ -62,7 +62,7 @@ public class PrintSocketHolder {
return ERROR_9;
}
try {
PrinterPlugins.getOnPrinterFlowHandler().connectionBefore("網絡打印機", ip, port, PrintConstans.SO_TIMEOUT, PrintConstans.PRINT_TIMEOUT);
PrinterFlowProxy.newInstance().dispatchConnectionBefore("網絡打印機", ip, port, PrintConstans.SO_TIMEOUT, PrintConstans.PRINT_TIMEOUT);
socket = new Socket();
//建立連接
InetSocketAddress socketAddress = new InetSocketAddress(ip, port);
......@@ -79,7 +79,7 @@ public class PrintSocketHolder {
return ERROR_7;
} catch (IOException e) {
e.printStackTrace();
PrinterPlugins.getOnPrinterFlowHandler().connectionError(e);
PrinterFlowProxy.newInstance().dispatchConnectionError(e);
return ERROR_7;
} catch (Exception e) {
closeSocket();
......@@ -97,7 +97,7 @@ public class PrintSocketHolder {
} catch (IOException e) {
LoganManager.w_printer(TAG, "獲取打印機輸入流異常: " + socket.getInetAddress() + e.getMessage());
closeSocket();
PrinterPlugins.getOnPrinterFlowHandler().connectionError(e);
PrinterFlowProxy.newInstance().dispatchConnectionError(e);
return ERROR_10;
}
return ERROR_0;
......@@ -127,7 +127,7 @@ public class PrintSocketHolder {
out.flush();
} catch (IOException | NullPointerException e) {
LoganManager.w_printer(TAG, "打印prj寫入數據异常: " + e.getMessage());
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(e, ERROR_10);
PrinterFlowProxy.newInstance().dispatchPrintError(e, ERROR_10);
closeSocket();
return ERROR_10;
}
......@@ -147,9 +147,9 @@ public class PrintSocketHolder {
//獲取打印機寫入
int result = getOutputStream();
if (result == ERROR_0) {
PrinterPlugins.getOnPrinterFlowHandler().connectionSuccess();
PrinterFlowProxy.newInstance().dispatchConnectionSuccess();
} else {
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("失敗"));
PrinterFlowProxy.newInstance().dispatchConnectionError(new Exception("失敗"));
}
return result;
}
......@@ -182,7 +182,7 @@ public class PrintSocketHolder {
socket = null;
error = true;
}
PrinterPlugins.getOnPrinterFlowHandler().disconnect(null);
PrinterFlowProxy.newInstance().dispatchDisconnect(null);
return error ? ERROR_66 : ERROR_0;
}
......
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