Commit b2f7cb8f authored by YONG-LIN SU's avatar YONG-LIN SU

1. 新增LK-P34L印表機,印製嘉義路邊停車單功能

2. 新增LK-P34L,電量讀取功能
parent 7296d6e9
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="577125220043" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-08-18T02:22:35.164972600Z" />
</component>
</project>
\ No newline at end of file
......@@ -56,6 +56,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs\\Sewoo_Android_1110.jar')
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
......
......@@ -13,9 +13,9 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
......
......@@ -318,4 +318,6 @@ public class BlueToothComm {
e.printStackTrace();
}
}
}
\ No newline at end of file
package ecom.android.newparkapp.adapter;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.res.ResourcesCompat;
import androidx.databinding.BindingAdapter;
import java.text.SimpleDateFormat;
......@@ -62,4 +65,54 @@ public class ConvertBindingAdapter {
textView.setTextColor(colorCode);
}
@BindingAdapter("printerPowerPercent2String")
public static void PrinterPowerPercent2String(TextView textView, float printerPowerPercent){
String printerPowerPercentString = "未偵測到電池";
if (printerPowerPercent >= 0){
printerPowerPercentString = printerPowerPercent + "%";
}
textView.setText(printerPowerPercentString);
}
@BindingAdapter("printerPowerPercent2Image")
public static void PrinterPowerPercent2Image(ImageView imageView, float printerPowerPercent){
String uri = "@drawable/no_battery";
int batteryLevel = (int) printerPowerPercent/20;
if (printerPowerPercent < 0)
{
batteryLevel = -1;
}
switch (batteryLevel){
case 0:
uri = "@drawable/low_battery";
break;
case 1:
uri = "@drawable/low_battery";
break;
case 2:
uri = "@drawable/middle_battery";
break;
case 3:
uri = "@drawable/middle_battery";
break;
case 4:
uri = "@drawable/full_battery";
break;
case 5:
uri = "@drawable/full_battery";
break;
default:
uri = "@drawable/no_battery";
break;
}
int imageResource = imageView.getResources().getIdentifier(uri, null, imageView.getContext().getPackageName());
int currentImageResource = imageView.getTag()==null ? -1 : (int)imageView.getTag();
if (imageResource != currentImageResource){
Drawable res = ResourcesCompat.getDrawable(imageView.getResources(), imageResource, null);
imageView.setImageDrawable(res);
imageView.setTag(imageResource);
}
}
}
\ No newline at end of file
package ecom.android.newparkapp.entity;
import android.bluetooth.BluetoothDevice;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.os.Environment;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.MutableLiveData;
import androidx.room.ColumnInfo;
import androidx.room.Embedded;
import androidx.room.Entity;
......@@ -23,7 +18,6 @@ import java.util.Locale;
import java.util.Objects;
import ecom.android.newparkapp.Common;
import ecom.android.newparkapp.R;
import ecom.android.newparkapp.printer.CarPrinter_TPB250;
import ecom.android.newparkapp.printer.IBluetoothPrinter;
......@@ -289,12 +283,16 @@ public class Case {
if (Objects.equals(bluetoothDeviceName.toUpperCase().trim(), "P58C")
|| Objects.equals(bluetoothDeviceName.toUpperCase().trim(), "YH-TPB250")) {
printer = new CarPrinter_TPB250();//汽車用TPB250型印表機版面
} else {
}else if (Objects.equals(bluetoothDeviceName.toUpperCase().trim(), "SW_891D")){
// TODO: 2022/8/3 加入 CarPrinter_LK-P34L 印表機功能
printer = null;
}
else {
// TODO: 2022/8/3 實作 CarPrinter_PK105B 印表機功能
printer = null;
//printer = new CarPrinter_PK105B();//汽車用PK105B型印表機版面
}
// TODO: 2022/8/3 加入 CarPrinter_LK-P34L 印表機功能
return printer;
}
......
package ecom.android.newparkapp.printer;
import static ecom.android.newparkapp.printer.IBluetoothPrinter.ResultCode.NOT_CONNECT;
import static ecom.android.newparkapp.printer.IBluetoothPrinter.ResultCode.PRINT_SUCCESS;
import android.bluetooth.BluetoothSocket;
import android.graphics.Typeface;
import com.sewoo.jpos.command.CPCLConst;
import com.sewoo.jpos.command.ESCPOS;
import com.sewoo.jpos.command.ESCPOSConst;
import com.sewoo.jpos.printer.CPCLPrinter;
import com.sewoo.jpos.printer.ESCPOSPrinter;
import com.sewoo.jpos.printer.LKPrint;
import com.sewoo.port.android.BluetoothPort;
import java.io.IOException;
import java.io.OutputStream;
import ecom.android.newparkapp.entity.Case;
public class CarPrinter_LKP34L{
private ExtendCPCLPrinter cpclPrinter;
public CarPrinter_LKP34L() {
// 設置中文編碼
cpclPrinter = new ExtendCPCLPrinter("Big5");
}
public IBluetoothPrinter.ResultCode print(BluetoothPort bluetoothPort, Case thisCase) throws IOException {
Case carCase = thisCase;
if (!bluetoothPort.isConnected()) {
return NOT_CONNECT;
}
//2-inch
// 嘉義路邊停車列印測試
// 紙張 黑色標記底部 至 黑色標記頂部 距離為 14.6 cm,減去 1.5 mm 為 印表機最大高度 14.45 cm
// 紙張 寬為 5.6 cm
// LK-P34L dpi 為 203,最大高度為 1155 px,最大寬度為 448px
int nLineWidth = 448;
cpclPrinter.setForm(102, 203, 203, 1155, nLineWidth,1);
int paper_type = 0; // 0 -> Gas Paper, 1 -> Black Mark Paper, 2 -> Continuous Paper
cpclPrinter.setMedia(paper_type);
// 列印 billNumber1 Code 39
String billNumber1 = carCase.billingNumber1;
cpclPrinter.setCPCLBarcode(7,0,0);
cpclPrinter.printCPCLBarcode(CPCLConst.LK_CPCL_0_ROTATION, CPCLConst.LK_CPCL_BCS_39,1,CPCLConst.LK_CPCL_BCS_1RATIO, 60, 0, 0, billNumber1, 0);
// 列印 車號
String plateNumber = "8052-LZ";
cpclPrinter.printAndroidFont(110,100, Typeface.SANS_SERIF, plateNumber, nLineWidth, 35);
// 列印 車格編號
String spaceWithRoad = "A213 中山路A";
cpclPrinter.printAndroidFont(110,150, Typeface.SANS_SERIF, spaceWithRoad, nLineWidth, 35);
// 列印 停車日期
String parkingDate = "111年08月03日";
cpclPrinter.printAndroidFont(110,200,Typeface.SANS_SERIF, parkingDate, nLineWidth, 35);
// 列印 billNumber2 Code 39
String billNumber2 = "77B18300298";
cpclPrinter.setCPCLBarcode(7,0,0);
cpclPrinter.printCPCLBarcode(CPCLConst.LK_CPCL_0_ROTATION, CPCLConst.LK_CPCL_BCS_39,1,CPCLConst.LK_CPCL_BCS_1RATIO, 70, 0, 260, billNumber2, 0);
// 列印 繳費期限
String terminateYear = "111";
String terminateMonth = "08";
String terminateDay = "29";
cpclPrinter.printAndroidFont(103, 380, Typeface.SANS_SERIF, terminateYear, nLineWidth, 25);
cpclPrinter.printAndroidFont(203, 380, Typeface.SANS_SERIF, terminateMonth, nLineWidth, 25);
cpclPrinter.printAndroidFont(303, 380, Typeface.SANS_SERIF, terminateDay, nLineWidth, 25);
// 列印 停車時間
String parkingTime = "14:58";
String parkingFee = "25";
String userName = "系統測試";
int printYMovement = 50;
int printY = 480;
for (int i = 0; i < 4; i++){
if (i == 0){
// 繳費金額
cpclPrinter.printAndroidFont(130, printY, Typeface.SANS_SERIF, parkingFee, nLineWidth, 30);
// 簽章
cpclPrinter.printAndroidFont(240, printY, Typeface.SANS_SERIF, userName, nLineWidth, 30);
}else {
printY+=printYMovement;
}
// 停車時間
cpclPrinter.printAndroidFont(15, printY, Typeface.SANS_SERIF, parkingTime, nLineWidth, 30);
// 簽章
cpclPrinter.printAndroidFont(240, printY, Typeface.SANS_SERIF, "________", nLineWidth, 30);
}
// 開始列印
cpclPrinter.printForm();
return PRINT_SUCCESS;
}
public String getPowerPercentFull(){
return cpclPrinter.getPowerPercentFull();
}
// 基於原先 SDK CPCLPrinter 進行命令擴充
private class ExtendCPCLPrinter extends CPCLPrinter {
public ExtendCPCLPrinter(){
super();
}
public ExtendCPCLPrinter(String charset){
super(charset);
}
public String getPowerPercentFull(){
return getVar("power.PercentFull");
}
public String getPowerStatus(){
return getVar("power.status");
}
public String getPowerVoltage(){
return getVar("power.voltage");
}
private String getVar(String parameter){
String varString = "";
byte[] recivedBuffer = new byte[8];
this.clearBuffer();
StringBuffer currentStringBuffer = this.getBuffer();
currentStringBuffer.append("!");
currentStringBuffer.append(" ");
currentStringBuffer.append("U1");
currentStringBuffer.append(" ");
currentStringBuffer.append("getvar");
currentStringBuffer.append(" ");
currentStringBuffer.append(parameter);
// currentStringBuffer.append("power.PercentFull"); // 34, 57, 49, 37, 34 -> "91%"
// currentStringBuffer.append("power.status"); // 34, 111, 107, 34 -> "ok"
// currentStringBuffer.append("power.voltage"); // 34, 56, 46, 49, 34 -> "8.1"
currentStringBuffer.append(" ");
currentStringBuffer.append("\r\n");
this.requestQueue.addRequest(currentStringBuffer.toString().getBytes());
int resultCode = -1;
try {
resultCode = this.receiveByte(recivedBuffer);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (resultCode == -1){
return varString;
}
byte[] bytes = new byte[resultCode];
for (int i = 0; i < resultCode; i++){
bytes[i] = recivedBuffer[i];
}
return new String(bytes);
}
}
}
package ecom.android.newparkapp.printer;
import com.sewoo.jpos.command.ESCPOSConst;
import com.sewoo.jpos.printer.ESCPOSPrinter;
public class LKP34LCheckPrinterStatus {
private int returnValue;
public int PrinterStatus(ESCPOSPrinter posPtr)
{
returnValue = posPtr.printerCheck();
if(ESCPOSConst.LK_SUCCESS == returnValue)
{
returnValue = posPtr.status();
if(ESCPOSConst.LK_STS_NORMAL == returnValue)
{ // No errors
return returnValue;
} else {
// Cover open error.
if((ESCPOSConst.LK_STS_COVER_OPEN & returnValue) > 0)
{
return ESCPOSConst.LK_STS_COVER_OPEN;
}
// Paper empty error.
if((ESCPOSConst.LK_STS_PAPER_EMPTY & returnValue) > 0)
{
return ESCPOSConst.LK_STS_PAPER_EMPTY;
}
// Battery low warning.
if((ESCPOSConst.LK_STS_BATTERY_LOW & returnValue) > 0)
{
return ESCPOSConst.LK_STS_BATTERY_LOW;
}
}
} else { // Error(LK_FAIL, LK_STS_PRINTEROFF, LK_STS_TIMEOUT)
return returnValue;
}
return 0;
}
}
......@@ -49,6 +49,7 @@ import ecom.android.newparkapp.entity.Space;
import ecom.android.newparkapp.entity.User;
import ecom.android.newparkapp.entity.VehicleType;
import ecom.android.newparkapp.repository.ParkApiRepository;
import ecom.android.newparkapp.viewModel.BlueToothPortViewModel;
import ecom.android.newparkapp.viewModel.BlueToothViewModel;
import ecom.android.newparkapp.viewModel.FusedGpsViewModel;
import ecom.android.newparkapp.viewModel.T01SettingViewModel;
......@@ -62,7 +63,9 @@ public class T02StartActivity extends AppCompatActivity {
private T02StartViewModel t02StartViewModel;
private T01SettingViewModel t01SettingViewModel;
private FusedGpsViewModel fusedGpsViewModel;
private BlueToothViewModel blueToothViewModel;
//private BlueToothViewModel blueToothViewModel;
private BlueToothPortViewModel blueToothViewModel;
//藍芽相關
private ArrayAdapter<String> deviceNameArrayAdapter;
......@@ -100,7 +103,10 @@ public class T02StartActivity extends AppCompatActivity {
t02StartViewModel = viewModelProvider.get(T02StartViewModel.class);
t01SettingViewModel = viewModelProvider.get(T01SettingViewModel.class);
fusedGpsViewModel = viewModelProvider.get(FusedGpsViewModel.class);
blueToothViewModel = viewModelProvider.get(BlueToothViewModel.class);
//blueToothViewModel = viewModelProvider.get(BlueToothViewModel.class);
// 測試
blueToothViewModel = viewModelProvider.get(BlueToothPortViewModel.class);
currentUser = t01SettingViewModel.getCurrentUser();
shift = getIntent().getParcelableExtra("Shift");
......
......@@ -24,6 +24,8 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.sewoo.port.android.BluetoothPort;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
......
......@@ -15,7 +15,7 @@
<variable
name="blueToothViewModel"
type="ecom.android.newparkapp.viewModel.BlueToothViewModel" />
type="ecom.android.newparkapp.viewModel.BlueToothPortViewModel" />
</data>
<androidx.core.widget.NestedScrollView
android:id="@+id/t02_start_border"
......@@ -74,23 +74,25 @@ tools:layout_editor_absoluteY="25dp">
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="20dp"
android:layout_weight="1"
android:rotation="0"
app:srcCompat="@android:drawable/button_onoff_indicator_on" />
app:printerPowerPercent2Image="@{blueToothViewModel.printerPowerPercentFull}"/>
<TextView
android:id="@+id/textView22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 98%"
android:textAlignment="center"
android:textSize="16sp" />
android:textSize="16sp"
app:printerPowerPercent2String="@{blueToothViewModel.printerPowerPercentFull}"/>
</LinearLayout>
</LinearLayout>
......
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