Printer
Printer class initial
On this printer class initial function from DeviceHelper.me() class
class Printer {
// call function from DeviceHelper.me().printer
private val printer: UPrinter = DeviceHelper.me().printer
// call function from DeviceHelper.me().vectorPrinter
private val vectorPrinter: UVectorPrinter? = DeviceHelper.me().vectorPrinter
private val utils = Utils()
}
1
2
3
4
5
6
7
2
3
4
5
6
7
Print bitmap debug
@RequiresApi(Build.VERSION_CODES.O)
suspend fun printBitmap(
data: ArrayList<String>,
type: String,
host: String,
) {
if (getDataSetting()?.enable_print_test == true) {
ISO8583().getISO8583Extract(data).let {
val json = JSONObject(it)
val jsonArray = json.getJSONArray("data")
Log.d("Extract", it)
printer.setPrintFormat(
PrintFormat.FORMAT_MOREDATAPROC,
PrintFormat.VALUE_MOREDATAPROC_PRNTOEND
);
val time = Date(System.currentTimeMillis().toString().toLong())
printer.addText(AlignMode.LEFT, "[Time] $time");
printer.addText(AlignMode.LEFT, "[$type]");
printer.addText(AlignMode.LEFT, "[Host] $host");
printer.addText(AlignMode.LEFT, "[TPDU] " + json.getString("tpdu"));
printer.addText(AlignMode.LEFT, "[Message Type] " + json.getString("messageType"));
printer.addText(AlignMode.LEFT, "[Bitmap] " + json.getString("bitmap"));
for (i in 0 until jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(i)
val bit = if (jsonObject.getString("id").length == 1) {
"0" + jsonObject.getString("id")
} else {
jsonObject.getString("id")
}
printer.addText(
AlignMode.LEFT,
"[DE" + bit + "] " + jsonObject.getString("originalData")
);
Log.d("Bit", "[DE" + bit + "] " + jsonObject.getString("originalData"))
}
}
printer.feedLine(5)
printer.startPrint(object : OnPrintListener.Stub() {
@Throws(RemoteException::class)
override fun onFinish() {
Log.d("Printing", "Finish")
}
@Throws(RemoteException::class)
override fun onError(error: Int) {
}
})
delay(1500)
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54