print terminal config print method refactor
This commit is contained in:
parent
e864630aaf
commit
aa1cf12d93
BIN
app/src/main/assets/fira_code_semibold.ttf
Normal file
BIN
app/src/main/assets/fira_code_semibold.ttf
Normal file
Binary file not shown.
@ -496,5 +496,18 @@ public class SharedViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void printTerminalHostConfigs(){
|
||||||
|
PrintXReceipt.getInstance().printTerminalHostConfig(new PrintXStatus() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
Log.d("PrintConfig", "Print Terminal Config Success.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
Log.e("PrintConfig", "Print Terminal Config Success.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import com.utsmm.kbz.BR;
|
|||||||
import com.utsmm.kbz.R;
|
import com.utsmm.kbz.R;
|
||||||
import com.utsmm.kbz.config.Constants;
|
import com.utsmm.kbz.config.Constants;
|
||||||
import com.utsmm.kbz.databinding.FragmentHostConfigBinding;
|
import com.utsmm.kbz.databinding.FragmentHostConfigBinding;
|
||||||
|
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
||||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||||
import com.utsmyanmar.baselib.util.DialogCallback;
|
import com.utsmyanmar.baselib.util.DialogCallback;
|
||||||
@ -49,6 +50,8 @@ import java.util.Objects;
|
|||||||
public class HostConfigFragment extends DataBindingFragment {
|
public class HostConfigFragment extends DataBindingFragment {
|
||||||
|
|
||||||
private HostConfigViewModel viewModel;
|
private HostConfigViewModel viewModel;
|
||||||
|
|
||||||
|
private SharedViewModel sharedViewModel;
|
||||||
protected Printer printer;
|
protected Printer printer;
|
||||||
int FONT_NORMAL = 20;
|
int FONT_NORMAL = 20;
|
||||||
int FONT_HEADER = 24;
|
int FONT_HEADER = 24;
|
||||||
@ -56,6 +59,7 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void initViewModel() {
|
protected void initViewModel() {
|
||||||
viewModel = new ViewModelProvider(this).get(HostConfigViewModel.class);
|
viewModel = new ViewModelProvider(this).get(HostConfigViewModel.class);
|
||||||
|
sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -100,146 +104,7 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onPrint(){
|
public void onPrint(){
|
||||||
startPrintProcess();
|
sharedViewModel.printTerminalHostConfigs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void startPrintProcess() {
|
|
||||||
|
|
||||||
DeviceEngine engine = APIProxy.getDeviceEngine(requireContext());
|
|
||||||
printer = engine.getPrinter();
|
|
||||||
int printerStatus = printer.getStatus();
|
|
||||||
if(printerStatus != SdkResult.Success){
|
|
||||||
Log.e("Print Config", "Printer Error: " + printerStatus);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
printer.setGray(GrayLevelEnum.LEVEL_1);
|
|
||||||
Typeface typeface = ResourcesCompat.getFont(requireContext(), R.font.firacode);
|
|
||||||
printer.setTypeface(typeface);
|
|
||||||
SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
|
||||||
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(requireContext().getResources(), R.drawable.kbz_receipt_logo);
|
|
||||||
printLogo(bitmap);
|
|
||||||
printer.appendPrnStr("TERMINAL CONFIGURATION", FONT_HEADER, AlignEnum.CENTER, true);
|
|
||||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
printer.appendPrnStr(sp.getMerchantName(), FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
printer.appendPrnStr(sp.getMerchantAddress(), FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
printer.appendPrnStr(sp.getMerchantAddress2(), FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
printer.appendPrnStr("TERMINAL : " + sp.getTerminalName(), FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("\n---------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
printer.appendPrnStr("PRIMARY HOST", FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Name : " + sp.getHostName(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
printer.appendPrnStr("TID : " + sp.getTerminalId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
printer.appendPrnStr("MID : " + sp.getMerchantId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
String ipAddress = sp.getIpAddress();
|
|
||||||
String[] ipAndPort = splitIpAndPort(ipAddress);
|
|
||||||
String ip = ipAndPort[0];
|
|
||||||
String port = ipAndPort[1];
|
|
||||||
printer.appendPrnStr("Primary Ip : " + ip, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Primary Port : " + port, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
String secIpAddress = sp.getSecIpAddress();
|
|
||||||
String[] secIpAndPort = splitIpAndPort(secIpAddress);
|
|
||||||
String secIp = secIpAndPort[0];
|
|
||||||
String secPort = secIpAndPort[1];
|
|
||||||
printer.appendPrnStr("Secondary Ip : " + secIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Secondary Port: " + secPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("\n---------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(sp.getSecHostName())) {
|
|
||||||
printer.appendPrnStr("SECONDARY HOST", FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Name : " + sp.getSecHostName(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
// printer.appendPrnStr("TID : " + sp.getSecHostTerminalId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
// printer.appendPrnStr("MID : " + sp.getSecHostMerchantId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
printer.appendPrnStr("SHORT CODE : " + sp.getShortCode(), FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
String secHostIpAddress = sp.getSecHostIpAddress();
|
|
||||||
String[] secHostIpAndPort = splitIpAndPort(secHostIpAddress);
|
|
||||||
String secHostIp = secHostIpAndPort[0];
|
|
||||||
String secHostPort = secHostIpAndPort[1];
|
|
||||||
printer.appendPrnStr("Primary Ip : " + secHostIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Primary Port : " + secHostPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
String secHostSecIpAddress = sp.getSecHostSecIpAddress();
|
|
||||||
String[] SecHostSecIpAndPort = splitIpAndPort(secHostSecIpAddress);
|
|
||||||
String secHostSecIp = SecHostSecIpAndPort[0];
|
|
||||||
String secHostSecPort = SecHostSecIpAndPort[1];
|
|
||||||
printer.appendPrnStr("Secondary Ip : " + secHostSecIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Secondary Port: " + secHostSecPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), FONT_NORMAL, AlignEnum.LEFT, true);
|
|
||||||
printer.appendPrnStr("\n---------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.startPrint(true, ret -> {
|
|
||||||
Log.d("Print", "Print result = " + ret);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] splitIpAndPort(String raw) {
|
|
||||||
if (raw == null || raw.trim().isEmpty()) {
|
|
||||||
return new String[]{"", ""};
|
|
||||||
}
|
|
||||||
|
|
||||||
raw = raw.trim();
|
|
||||||
|
|
||||||
// If starts with http/https
|
|
||||||
if (raw.startsWith("http://") || raw.startsWith("https://")) {
|
|
||||||
|
|
||||||
// Attempt to extract host + port via URL
|
|
||||||
try {
|
|
||||||
java.net.URL url = new java.net.URL(raw);
|
|
||||||
|
|
||||||
String host = url.getHost(); // hostname or IP
|
|
||||||
int port = url.getPort(); // -1 if no port
|
|
||||||
String path = url.getPath(); // /api or /
|
|
||||||
|
|
||||||
// If port exists → split normally
|
|
||||||
if (port != -1) {
|
|
||||||
return new String[]{
|
|
||||||
host, // e.g. 10.10.10.10
|
|
||||||
String.valueOf(port) // e.g. 5000
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// No port → do NOT split
|
|
||||||
return new String[]{ raw, "" };
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// fail-safe: do not split
|
|
||||||
return new String[]{ raw, "" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal "IP:Port" split
|
|
||||||
int idx = raw.lastIndexOf(":");
|
|
||||||
|
|
||||||
if (idx == -1) {
|
|
||||||
return new String[]{ raw, "" };
|
|
||||||
}
|
|
||||||
|
|
||||||
return new String[]{
|
|
||||||
raw.substring(0, idx),
|
|
||||||
raw.substring(idx + 1)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void printLogo(Bitmap logoBitmap) {
|
|
||||||
try {
|
|
||||||
if (logoBitmap == null || printer == null) return;
|
|
||||||
|
|
||||||
Bitmap bmp = logoBitmap;
|
|
||||||
|
|
||||||
// Max printable width = 384px
|
|
||||||
if (bmp.getWidth() > 384) {
|
|
||||||
int newHeight = (int) (bmp.getHeight() * (384f / bmp.getWidth()));
|
|
||||||
bmp = Bitmap.createScaledBitmap(bmp, 384, newHeight, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
printer.appendImage(bmp, AlignEnum.CENTER);
|
|
||||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("PRINT", "Logo error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
BIN
app/src/main/res/font/fira_code_semibold.ttf
Normal file
BIN
app/src/main/res/font/fira_code_semibold.ttf
Normal file
Binary file not shown.
@ -51,16 +51,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!-- HEADER -->
|
<!-- HEADER -->
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="TERMINAL CONFIGURATION"
|
|
||||||
android:fontFamily="@font/rubik_regular"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:paddingBottom="12dp"
|
|
||||||
tools:text="TERMINAL CONFIGURATION"/>
|
|
||||||
|
|
||||||
<!-- Merchant Info -->
|
<!-- Merchant Info -->
|
||||||
<TextView
|
<TextView
|
||||||
@ -104,10 +95,21 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="--------------------------------------------------------------------------"
|
android:text="*************************************************"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
tools:text="--------------------------------------------------------------------------"/>
|
tools:text="*********************************************************"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="TERMINAL CONFIGURATION"
|
||||||
|
android:fontFamily="@font/rubik_regular"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
tools:text="TERMINAL CONFIGURATION"/>
|
||||||
|
|
||||||
<!-- PRIMARY HOST -->
|
<!-- PRIMARY HOST -->
|
||||||
<TextView
|
<TextView
|
||||||
@ -194,10 +196,10 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="--------------------------------------------------------------------------"
|
android:text="*************************************************"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
tools:text="--------------------------------------------------------------------------"/>
|
tools:text="********************************************************"/>
|
||||||
|
|
||||||
<!-- SECONDARY HOST -->
|
<!-- SECONDARY HOST -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@ -192,6 +192,7 @@
|
|||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:src="@drawable/ic_device_info"
|
android:src="@drawable/ic_device_info"
|
||||||
|
android:contentDescription="app version"
|
||||||
app:tint="@color/white" />
|
app:tint="@color/white" />
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
@ -266,7 +267,7 @@
|
|||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:src="@drawable/ic_device_info"
|
android:src="@drawable/ic_host"
|
||||||
app:tint="@color/white" />
|
app:tint="@color/white" />
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|||||||
@ -2,12 +2,14 @@ package com.utsmyanmar.paylibs.print.printx;
|
|||||||
|
|
||||||
import static com.utsmyanmar.paylibs.utils.enums.CurrencyType.MMK;
|
import static com.utsmyanmar.paylibs.utils.enums.CurrencyType.MMK;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
|
||||||
@ -955,7 +957,6 @@ public abstract class BaseXPrint {
|
|||||||
} else if (payDetail.getTransType().equals(SUMMARY)) {
|
} else if (payDetail.getTransType().equals(SUMMARY)) {
|
||||||
printer.appendPrnStr("HOST :" + HOST_NAME_MPU + "", fontNormal, AlignEnum.LEFT,false);
|
printer.appendPrnStr("HOST :" + HOST_NAME_MPU + "", fontNormal, AlignEnum.LEFT,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 17 Sept 2024 Yoma requested to changed slip design for QR*/
|
/* 17 Sept 2024 Yoma requested to changed slip design for QR*/
|
||||||
// printer.printColumnsString(new String[]{"MID :" + payDetail.getMerchantNo(), ""}, new int[]{3, 1}, new int[]{0, 2}, innerResultCallback);
|
// printer.printColumnsString(new String[]{"MID :" + payDetail.getMerchantNo(), ""}, new int[]{3, 1}, new int[]{0, 2}, innerResultCallback);
|
||||||
// printer.printColumnsString(new String[]{"TID :" + payDetail.getTerminalNo(), ""}, new int[]{3, 1}, new int[]{0, 2}, innerResultCallback);
|
// printer.printColumnsString(new String[]{"TID :" + payDetail.getTerminalNo(), ""}, new int[]{3, 1}, new int[]{0, 2}, innerResultCallback);
|
||||||
@ -1004,5 +1005,126 @@ public abstract class BaseXPrint {
|
|||||||
// LogUtil.d("lxy", "code:" + code + ",msg:" + msg);
|
// LogUtil.d("lxy", "code:" + code + ",msg:" + msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected void printTerminalConfiguration() {
|
||||||
|
|
||||||
|
SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
||||||
|
// ---------- PRIMARY HOST ----------
|
||||||
|
printer.appendPrnStr("PRIMARY HOST", fontNormal, AlignEnum.LEFT, true);
|
||||||
|
printer.appendPrnStr("Name : " + sp.getHostName(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("TID : " + sp.getTerminalId(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("MID : " + sp.getMerchantId(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
String[] ipPort = splitIpAndPort(sp.getIpAddress());
|
||||||
|
printer.appendPrnStr("Primary Ip : " + ipPort[0], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Primary Port : " + ipPort[1], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
String[] secIpPort = splitIpAndPort(sp.getSecIpAddress());
|
||||||
|
printer.appendPrnStr("Secondary Ip : " + secIpPort[0], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Secondary Port: " + secIpPort[1], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
lineBreak();
|
||||||
|
// ---------- SECONDARY HOST (optional) ----------
|
||||||
|
if (!TextUtils.isEmpty(sp.getSecHostName())) {
|
||||||
|
printer.appendPrnStr("SECONDARY HOST", fontNormal, AlignEnum.LEFT, true);
|
||||||
|
printer.appendPrnStr("Name : " + sp.getSecHostName(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("SHORT CODE : " + sp.getShortCode(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
String[] secHostIp = splitIpAndPort(sp.getSecHostIpAddress());
|
||||||
|
printer.appendPrnStr("Primary Ip : " + secHostIp[0], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Primary Port : " + secHostIp[1], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
String[] secHostSecIp = splitIpAndPort(sp.getSecHostSecIpAddress());
|
||||||
|
printer.appendPrnStr("Secondary Ip : " + secHostSecIp[0], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Secondary Port: " + secHostSecIp[1], fontNormal, AlignEnum.LEFT, false);
|
||||||
|
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
lineBreak();
|
||||||
|
printer.appendPrnStr("App Version : " + getAppVersion(), fontNormal, AlignEnum.LEFT, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAppVersion() {
|
||||||
|
try {
|
||||||
|
return PayLibsUtils.getInstance().context
|
||||||
|
.getPackageManager()
|
||||||
|
.getPackageInfo(
|
||||||
|
PayLibsUtils.getInstance().context.getPackageName(),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
.versionName;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] splitIpAndPort(String raw) {
|
||||||
|
if (raw == null || raw.trim().isEmpty()) {
|
||||||
|
return new String[]{"", ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
raw = raw.trim();
|
||||||
|
|
||||||
|
// If starts with http/https
|
||||||
|
if (raw.startsWith("http://") || raw.startsWith("https://")) {
|
||||||
|
|
||||||
|
// Attempt to extract host + port via URL
|
||||||
|
try {
|
||||||
|
java.net.URL url = new java.net.URL(raw);
|
||||||
|
|
||||||
|
String host = url.getHost(); // hostname or IP
|
||||||
|
int port = url.getPort(); // -1 if no port
|
||||||
|
String path = url.getPath(); // /api or /
|
||||||
|
|
||||||
|
// If port exists → split normally
|
||||||
|
if (port != -1) {
|
||||||
|
return new String[]{
|
||||||
|
host, // e.g. 10.10.10.10
|
||||||
|
String.valueOf(port) // e.g. 5000
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// No port → do NOT split
|
||||||
|
return new String[]{ raw, "" };
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// fail-safe: do not split
|
||||||
|
return new String[]{ raw, "" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal "IP:Port" split
|
||||||
|
int idx = raw.lastIndexOf(":");
|
||||||
|
|
||||||
|
if (idx == -1) {
|
||||||
|
return new String[]{ raw, "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String[]{
|
||||||
|
raw.substring(0, idx),
|
||||||
|
raw.substring(idx + 1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void printLogo(Bitmap logoBitmap) {
|
||||||
|
try {
|
||||||
|
if (logoBitmap == null || printer == null) return;
|
||||||
|
|
||||||
|
Bitmap bmp = logoBitmap;
|
||||||
|
|
||||||
|
// Max printable width = 384px
|
||||||
|
if (bmp.getWidth() > 384) {
|
||||||
|
int newHeight = (int) (bmp.getHeight() * (384f / bmp.getWidth()));
|
||||||
|
bmp = Bitmap.createScaledBitmap(bmp, 384, newHeight, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
printer.appendPrnStr("\n", fontNormal, AlignEnum.CENTER, false);
|
||||||
|
printer.appendImage(bmp, AlignEnum.CENTER);
|
||||||
|
printer.appendPrnStr("\n", fontNormal, AlignEnum.CENTER, false);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("PRINT", "Logo error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,4 +25,7 @@ public interface PrintX {
|
|||||||
|
|
||||||
void printKeyStatus();
|
void printKeyStatus();
|
||||||
|
|
||||||
|
void printTerminalConfig(PrintXStatus printXStatus);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -423,5 +423,21 @@ public class PrintXImpl extends BaseXPrint implements PrintX {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printTerminalConfig(PrintXStatus printXStatus) {
|
||||||
|
this.callbackStatus = printXStatus;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setHeight(0x12);
|
||||||
|
printLogo();
|
||||||
|
printMerchantHeader();
|
||||||
|
printer.appendPrnStr("TERMINAL CONFIGURATION", fontLarge, AlignEnum.CENTER, true);
|
||||||
|
printTerminalConfiguration();
|
||||||
|
startPrintNex();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
callbackStatus.onFailure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,4 +54,8 @@ public class PrintXReceipt {
|
|||||||
public void printDetailReport(PayDetail payDetail, List<PayDetail> lists, HostType hostType,PrintXStatus printXStatus) {
|
public void printDetailReport(PayDetail payDetail, List<PayDetail> lists, HostType hostType,PrintXStatus printXStatus) {
|
||||||
printX.printDetailReport(payDetail,lists,hostType,printXStatus);
|
printX.printDetailReport(payDetail,lists,hostType,printXStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void printTerminalHostConfig(PrintXStatus printXStatus){
|
||||||
|
printX.printTerminalConfig(printXStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user