Commit 610a61ca authored by YONG-LIN SU's avatar YONG-LIN SU

添加部分說明

新增YH-TP250兼容性
parent ca126615
......@@ -12,6 +12,6 @@
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-08-23T06:16:20.971608400Z" />
<timeTargetWasSelectedWithDropDown value="2022-08-23T08:32:55.773946400Z" />
</component>
</project>
\ No newline at end of file
......@@ -10,6 +10,8 @@ import static ecom.android.newparkapp.printer.IBluetoothPrinter.ResultCode.PRINT
import android.bluetooth.BluetoothSocket;
import com.sewoo.port.android.BluetoothPort;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
......@@ -132,4 +134,114 @@ public class CarPrinter_TPB250 implements IBluetoothPrinter {
InitPrinter(outPutBT);
return PRINT_SUCCESS;
}
// 透過新的sdk列印
public ResultCode print(BluetoothPort bluetoothPort, Case thisCase) throws IOException {
OutputStream outPutBT = bluetoothPort.getOutputStream();
boolean b60Min = false;
Calendar nowCalendar;
Case carCase = thisCase;
if (outPutBT == null || !bluetoothPort.isConnected()) {
return NOT_CONNECT;
}
InitPrinter(outPutBT);
PrintChangeLine(outPutBT, 1, 76);
if (!carCase.autoPay) {
//第一段條碼//
PrintBarCode(outPutBT, carCase.billingNumber1, false);
} else {
PrintString(outPutBT, "※本車已約定金融、電信帳戶代繳,請勿重複繳費、並維持正常扣繳;如扣繳失敗請依背面說明補單繳款。", 32, false);
//PrintChangeLine(outPutBT, 1, 24);
}
PrintChangeLine(outPutBT, 1, 24);
//-------------------------------------------
//車牌
PrintString(outPutBT, " " + carCase.plateNumber, 52, true);
//-------------------------------------------
//路段、格號
PrintString(outPutBT, " " + carCase.space.id + " " + carCase.space.road.name, 52, true);
//-------------------------------------------
//日期
PrintString(outPutBT, " " + String.format("%s年%s月%s日",
Common.getDate(carCase.getCaseCalendar(), true).substring(0, 3),
Common.getDate(carCase.getCaseCalendar(), true).substring(3, 5),
Common.getDate(carCase.getCaseCalendar(), true).substring(5, 7)), 40, true);
//-------------------------------------------
//單號2
PrintBarCode(outPutBT, carCase.billingNumber2, false);
PrintChangeLine(outPutBT, 1, 34);
//-------------------------------------------
//繳費期限
PrintString(outPutBT, " " + String.format("%s %s %s",
Common.getDate(carCase.getTermCalendar(), true).substring(0, 3),
Common.getDate(carCase.getTermCalendar(), true).substring(3, 5),
Common.getDate(carCase.getTermCalendar(), true).substring(5, 7)), 90, false);
//-------------------------------------------
nowCalendar = (Calendar) carCase.getCaseCalendar().clone();
int nHour = carCase.getCaseCalendar().get(Calendar.HOUR_OF_DAY);
for (int i = 0; i < 4; i++) {//開單累加最多累積4次
if (!carCase.isWorkTime(nowCalendar)) {//若第i行時間已超過該班次區間,則停止列印(PS.列印長度太短會導致黑點定位查找距離不夠到下一個黑點,利用換行增加)
for (int j = 0; j < 4 - i; j++) {
PrintString(outPutBT, "", 52, false);
}
break;
}
String szList = (0 == i) ?
String.format(Locale.TAIWAN, " %02d:%02d %5d %s", nHour, nowCalendar.get(Calendar.MINUTE), carCase.getPricing(), carCase.user.name) :
String.format(Locale.TAIWAN, " %02d:%02d %5s %s", nHour + (b60Min ? 1 : 0), b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1), " ", "________");
if (carCase.space.spaceType == SpaceType.HANDICAPPED_SPACE) {//身障車格
if (carCase.vehicleType.id == 12) {//身心障礙(府-2)
if (i == 0) {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5d %s",
nHour,
nowCalendar.get(Calendar.MINUTE),
carCase.getPricing(),
carCase.user.name);
} else if (i == 1) {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s",
nHour + (b60Min ? 1 : 0),
b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1),
carCase.getPricing(),
"________");
} else {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s",
nHour + (b60Min ? 1 : 0),
b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1),
" ",
"________");
}
} else if (carCase.vehicleType.id == 13) {//身心障礙(社-4)
szList = (0 == i) ?
String.format(Locale.TAIWAN, " %02d:%02d %5d %s", nHour, nowCalendar.get(Calendar.MINUTE), carCase.getPricing(), carCase.user.name) :
String.format(Locale.TAIWAN, " %02d:%02d %5s %s", nHour + (b60Min ? 1 : 0), b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1), carCase.getPricing(), "________");
}
}
nowCalendar.add(Calendar.MINUTE, carCase.space.getAddMinutes());
nHour = nowCalendar.get(Calendar.HOUR_OF_DAY);
b60Min = nowCalendar.get(Calendar.MINUTE) == 59;
PrintString(outPutBT, szList, 40, new byte[]{0x1D, 0x21, 0x01});
}
PrintChangeLine(outPutBT, 1, 120);
//PrintString(outPutBT, "※如已有申請停車費自動扣款或行動支付服務,請勿持本單重複繳費。", 26, false);
PrintChangeLine(outPutBT, 2, 80);//減少黑點定位查找距離
//-------------------------------------------
ToBlackMark(outPutBT);
InitPrinter(outPutBT);
return PRINT_SUCCESS;
}
}
......@@ -32,6 +32,7 @@ import java.util.concurrent.Executors;
import ecom.android.newparkapp.R;
import ecom.android.newparkapp.entity.Case;
import ecom.android.newparkapp.printer.CarPrinter_LKP34L;
import ecom.android.newparkapp.printer.CarPrinter_TPB250;
import ecom.android.newparkapp.printer.IBluetoothPrinter;
import ecom.android.newparkapp.printer.Sample_Print;
......@@ -53,7 +54,9 @@ public class BlueToothPortViewModel extends AndroidViewModel {
private BluetoothPort bluetoothPort;
private Thread bluetoothRequestThread;
private CarPrinter_LKP34L printer = new CarPrinter_LKP34L();
private CarPrinter_TPB250 carPrinterTPB250 = new CarPrinter_TPB250();
public BlueToothPortViewModel(@NonNull Application application) {
super(application);
......@@ -103,6 +106,12 @@ public class BlueToothPortViewModel extends AndroidViewModel {
getPrinterPowerPercentFullTimerTask = new TimerTask() {
@Override
public void run() {
if (getBluetoothDevice().getValue() == null){
return;
}
if (!getBluetoothDevice().getValue().getName().equals("SW_891D")){
return;
}
updatePrinterPowerPercentFull();
}
};
......@@ -258,7 +267,20 @@ public class BlueToothPortViewModel extends AndroidViewModel {
blueToothStatusMutableLiveData.setValue(BlueToothViewModel.BlueToothStatus.PRINTING);
executorService.execute(() ->{
try {
printer.print(bluetoothPort, tempCase);
String deviceName = getBluetoothDevice().getValue().getName();
if (deviceName != null){
switch (deviceName){
case "YH-TPB250":
carPrinterTPB250.print(bluetoothPort, tempCase);
break;
case "SW_891D":
printer.print(bluetoothPort, tempCase);
break;
default:
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
......
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