cordova-plugin-netcontroll-integration 1.0.73 → 1.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/Cielo/CieloLioLocal.java +717 -0
- package/www/Cielo/LioLocal.js +2 -1
package/README.md
CHANGED
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-netcontroll-integration" version="1.0.
|
|
2
|
+
<plugin id="cordova-plugin-netcontroll-integration" version="1.0.74"
|
|
3
3
|
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
4
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
5
5
|
|
|
@@ -9,6 +9,17 @@ import org.json.JSONArray;
|
|
|
9
9
|
import org.json.JSONException;
|
|
10
10
|
import org.json.JSONObject;
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
import android.graphics.Bitmap;
|
|
14
|
+
import android.os.AsyncTask;
|
|
15
|
+
|
|
16
|
+
import com.google.zxing.EncodeHintType;
|
|
17
|
+
import com.google.zxing.MultiFormatWriter;
|
|
18
|
+
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
19
|
+
import com.izettle.html2bitmap.Html2Bitmap;
|
|
20
|
+
import com.izettle.html2bitmap.content.WebViewContent;
|
|
21
|
+
|
|
22
|
+
|
|
12
23
|
// import androidx.annotation.NonNull;
|
|
13
24
|
import androidx.annotation.NonNull;
|
|
14
25
|
import android.app.Activity;
|
|
@@ -61,6 +72,28 @@ import cielo.sdk.printer.PrinterManager;
|
|
|
61
72
|
import cielo.sdk.info.InfoManager;
|
|
62
73
|
|
|
63
74
|
|
|
75
|
+
import com.google.zxing.BarcodeFormat;
|
|
76
|
+
import com.google.zxing.WriterException;
|
|
77
|
+
import com.google.zxing.qrcode.QRCodeWriter;
|
|
78
|
+
import com.google.zxing.common.BitMatrix;
|
|
79
|
+
|
|
80
|
+
//Bitmap
|
|
81
|
+
import android.graphics.Bitmap;
|
|
82
|
+
import android.graphics.BitmapFactory;
|
|
83
|
+
import android.graphics.Matrix;
|
|
84
|
+
|
|
85
|
+
import android.util.Base64;
|
|
86
|
+
import java.io.ByteArrayOutputStream;
|
|
87
|
+
import java.util.Objects;
|
|
88
|
+
import java.util.stream.Collectors;
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
import java.lang.reflect.Type;
|
|
92
|
+
import java.util.ArrayList;
|
|
93
|
+
import java.util.EnumMap;
|
|
94
|
+
import java.util.HashMap;
|
|
95
|
+
import java.util.Map;
|
|
96
|
+
|
|
64
97
|
/**
|
|
65
98
|
* This class echoes a string called from JavaScript.
|
|
66
99
|
*/
|
|
@@ -218,6 +251,18 @@ public class CieloLioLocal {
|
|
|
218
251
|
}
|
|
219
252
|
}
|
|
220
253
|
|
|
254
|
+
else if (action.equals("ImpressaoTextoNetPrint")) {
|
|
255
|
+
JSONObject params = args.getJSONObject(0);
|
|
256
|
+
try {
|
|
257
|
+
String dados = params.getString("dados");
|
|
258
|
+
String html = this.ConverterTextoImpressoToHtml(dados);
|
|
259
|
+
this.ConverterHtmlToBitmap( html, callbackContext);
|
|
260
|
+
callbackContext.success(html);
|
|
261
|
+
} catch (Exception e) {
|
|
262
|
+
callbackContext.error("ImpressaoTextoNetPrint error: " + e.toString());
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
221
266
|
|
|
222
267
|
else if (action.equals("PrintSimpleText")) {
|
|
223
268
|
JSONObject params = args.getJSONObject(0);
|
|
@@ -769,4 +814,676 @@ public class CieloLioLocal {
|
|
|
769
814
|
order = null;
|
|
770
815
|
}
|
|
771
816
|
|
|
817
|
+
|
|
818
|
+
private boolean ConverterHtmlToBitmap(String htmlString, CallbackContext callbackContext) {
|
|
819
|
+
try{
|
|
820
|
+
AsyncTask<Void, Void, Bitmap> taskBitMap = new AsyncTask<Void, Void, Bitmap>() {
|
|
821
|
+
@Override
|
|
822
|
+
protected Bitmap doInBackground(Void... voids) {
|
|
823
|
+
Html2Bitmap build = new Html2Bitmap.Builder().setContext(mContext).setContent(WebViewContent.html(htmlString)).setBitmapWidth(380).setMeasureDelay(300).setScreenshotDelay(300).setStrictMode(true).setTimeout(15).setTextZoom(96).build();
|
|
824
|
+
Bitmap bitmapResult = build.getBitmap();
|
|
825
|
+
return bitmapResult;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
@Override
|
|
829
|
+
protected void onPostExecute(Bitmap bitmap) {
|
|
830
|
+
if (bitmap != null) {
|
|
831
|
+
try {
|
|
832
|
+
print_initialize();
|
|
833
|
+
printerManager.printImage(bitmap, alignCenter, printerListener);
|
|
834
|
+
callbackContext.success("ImpressoOk");
|
|
835
|
+
// // PosPrintProvider customPosPrintProvider = new PosPrintProvider(mContext);
|
|
836
|
+
// // // PosPrintProvider posPrintReceiptProvider = new PosPrintProvider(mContext, transactionObject, receiptType);
|
|
837
|
+
// // customPosPrintProvider.addBitmap(bitmap);
|
|
838
|
+
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
839
|
+
// bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
|
|
840
|
+
// byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
841
|
+
// String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
// customPosPrintProvider.setConnectionCallback(new StoneCallbackInterface() {
|
|
846
|
+
// @Override
|
|
847
|
+
// public void onSuccess() {
|
|
848
|
+
// callbackContext.success("ImpressoOk");
|
|
849
|
+
// }
|
|
850
|
+
|
|
851
|
+
// @Override
|
|
852
|
+
// public void onError() {
|
|
853
|
+
// callbackContext.error("Erro ao imprimir: " + customPosPrintProvider.getListOfErrors());
|
|
854
|
+
// }
|
|
855
|
+
// });
|
|
856
|
+
// customPosPrintProvider.execute();
|
|
857
|
+
} catch (Exception errorPost) {
|
|
858
|
+
callbackContext.error("Result - ConverterHtmlToBitmap: " + "Error Detail: " + errorPost);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}.execute();
|
|
863
|
+
} catch (Exception e){
|
|
864
|
+
throw e;
|
|
865
|
+
}
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
private String ConverterTextoImpressoToHtml(String linhasImpressos) {
|
|
870
|
+
try {
|
|
871
|
+
String htmlStr = this.ConverterImpressaoToHtmlInicio();
|
|
872
|
+
|
|
873
|
+
List<String> linhas = ConverterImpressaoToHtmlLinhasHtml(linhasImpressos);
|
|
874
|
+
|
|
875
|
+
for (String linha : linhas) {
|
|
876
|
+
htmlStr += linha;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
htmlStr += this.ConverterImpressaoToHtmlFinal();
|
|
880
|
+
|
|
881
|
+
return htmlStr;
|
|
882
|
+
} catch (Exception e) {
|
|
883
|
+
throw e;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
private String ConverterImpressaoToHtmlInicio()
|
|
888
|
+
{
|
|
889
|
+
String htmlResult = "<!DOCTYPE html>\n" +
|
|
890
|
+
"<html lang='en'>\n" +
|
|
891
|
+
"\n" +
|
|
892
|
+
"<head>\n" +
|
|
893
|
+
" <!-- <meta charset='UTF-8'>\n" +
|
|
894
|
+
" <meta http-equiv='X-UA-Compatible' content='IE=edge'>\n" +
|
|
895
|
+
" <meta name='viewport' content='width=380, initial-scale=1.0'>\n" +
|
|
896
|
+
" <title>Document</title> -->\n" +
|
|
897
|
+
"\n" +
|
|
898
|
+
" <style>\n" +
|
|
899
|
+
" /* @media print {\n" +
|
|
900
|
+
" .printer-ticket {\n" +
|
|
901
|
+
" border: none !important;\n" +
|
|
902
|
+
" }\n" +
|
|
903
|
+
" } */\n" +
|
|
904
|
+
"\n" +
|
|
905
|
+
" body {\n" +
|
|
906
|
+
" margin: 0px;\n" +
|
|
907
|
+
" width: 380px;\n" +
|
|
908
|
+
" /*border: 1px solid black;*/\n" +
|
|
909
|
+
" }\n" +
|
|
910
|
+
"\n" +
|
|
911
|
+
"\n" +
|
|
912
|
+
"\n" +
|
|
913
|
+
" .printer-ticket {\n" +
|
|
914
|
+
" /*border: solid 1px black;*/\n" +
|
|
915
|
+
" /* background-color: #ffffcc; */\n" +
|
|
916
|
+
" background-color: white;\n" +
|
|
917
|
+
" font-size: 16px;\n" +
|
|
918
|
+
" /* padding: 10px; */\n" +
|
|
919
|
+
" max-width: 380px;\n" +
|
|
920
|
+
" /* border: solid 1px black; */\n" +
|
|
921
|
+
" /* text-align: center; */\n" +
|
|
922
|
+
" /*padding-left: 10px;*/\n" +
|
|
923
|
+
" /*padding-right: 10px;*/\n" +
|
|
924
|
+
" }\n" +
|
|
925
|
+
"\n" +
|
|
926
|
+
" /* @media (max-width: 979px) {\n" +
|
|
927
|
+
" .section-printer--ticket {\n" +
|
|
928
|
+
" position: initial;\n" +
|
|
929
|
+
" top: 0;\n" +
|
|
930
|
+
" }\n" +
|
|
931
|
+
" } */\n" +
|
|
932
|
+
"\n" +
|
|
933
|
+
" .printer-ticket table {\n" +
|
|
934
|
+
" margin: auto;\n" +
|
|
935
|
+
"\n" +
|
|
936
|
+
" }\n" +
|
|
937
|
+
"\n" +
|
|
938
|
+
" .printer-ticket * {\n" +
|
|
939
|
+
" /*border-left: 1px solid black;*/\n" +
|
|
940
|
+
" /*border-right: 1px solid black;*/\n" +
|
|
941
|
+
" font-family: monospace;\n" +
|
|
942
|
+
" /* font-family: Consolas, Regular;*/\n" +
|
|
943
|
+
" /* font-size: 100%; */\n" +
|
|
944
|
+
" color: black;\n" +
|
|
945
|
+
" /* line-height: 80%; */\n" +
|
|
946
|
+
" max-width: 380px;\n" +
|
|
947
|
+
" /* line-height: normal; */\n" +
|
|
948
|
+
" /* padding-left: 15px; */\n" +
|
|
949
|
+
" }\n" +
|
|
950
|
+
"\n" +
|
|
951
|
+
" [data-normal='true'] {\n" +
|
|
952
|
+
" /* letter-spacing: 1px;\n" +
|
|
953
|
+
" font-size: 30px;\n" +
|
|
954
|
+
" text-align: left; */\n" +
|
|
955
|
+
" /* padding-left: 15px; */\n" +
|
|
956
|
+
" }\n" +
|
|
957
|
+
"\n" +
|
|
958
|
+
"\n" +
|
|
959
|
+
" [data-expandido='true'] {\n" +
|
|
960
|
+
" letter-spacing: 1px;\n" +
|
|
961
|
+
" font-size: 30px !important;\n" +
|
|
962
|
+
" /* text-align: left !important; */\n" +
|
|
963
|
+
" /* padding-left: 15px; */\n" +
|
|
964
|
+
" }\n" +
|
|
965
|
+
"\n" +
|
|
966
|
+
" [data-condensado='true'] {\n" +
|
|
967
|
+
" letter-spacing: -2px;\n" +
|
|
968
|
+
" font-size: 15px !important;\n" +
|
|
969
|
+
" /* text-align: left !important; */\n" +
|
|
970
|
+
" /* padding-left: 10px; */\n" +
|
|
971
|
+
" }\n" +
|
|
972
|
+
"\n" +
|
|
973
|
+
" [data-negrito='true'] {\n" +
|
|
974
|
+
" font-weight: bold;\n" +
|
|
975
|
+
" }\n" +
|
|
976
|
+
"\n" +
|
|
977
|
+
" [data-reverse='true'] {\n" +
|
|
978
|
+
" background-color: black !important;\n" +
|
|
979
|
+
" color: white;\n" +
|
|
980
|
+
" -webkit-print-color-adjust: exact;\n" +
|
|
981
|
+
" }\n" +
|
|
982
|
+
"\n" +
|
|
983
|
+
" [data-qrcode='true'] {\n" +
|
|
984
|
+
" text-align: center;\n" +
|
|
985
|
+
" }\n" +
|
|
986
|
+
"\n" +
|
|
987
|
+
" [data-barcode128='true'] {\n" +
|
|
988
|
+
" text-align: center;\n" +
|
|
989
|
+
" }\n" +
|
|
990
|
+
"\n" +
|
|
991
|
+
"\n" +
|
|
992
|
+
" [data-alinhamento='1'] {\n" +
|
|
993
|
+
" text-align: left;\n" +
|
|
994
|
+
" }\n" +
|
|
995
|
+
"\n" +
|
|
996
|
+
" [data-alinhamento='2'] {\n" +
|
|
997
|
+
" text-align: center;\n" +
|
|
998
|
+
" }\n" +
|
|
999
|
+
"\n" +
|
|
1000
|
+
" [data-alinhamento='3'] {\n" +
|
|
1001
|
+
" text-align: right;\n" +
|
|
1002
|
+
" }\n" +
|
|
1003
|
+
" </style>\n" +
|
|
1004
|
+
"</head>\n" +
|
|
1005
|
+
"\n" +
|
|
1006
|
+
"<body>\n" +
|
|
1007
|
+
"\n" +
|
|
1008
|
+
"\n" +
|
|
1009
|
+
" <div class='printer-ticket'>\n" +
|
|
1010
|
+
" <div class='row'>\n";
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
return htmlResult;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
private String ConverterImpressaoToHtmlInicioTentativa1()
|
|
1017
|
+
{
|
|
1018
|
+
String htmlResult = "<!DOCTYPE html>\n" +
|
|
1019
|
+
"<html lang='en'>\n" +
|
|
1020
|
+
"\n" +
|
|
1021
|
+
"<head>\n" +
|
|
1022
|
+
" <meta charset='UTF-8'>\n" +
|
|
1023
|
+
" <meta http-equiv='X-UA-Compatible' content='IE=edge'>\n" +
|
|
1024
|
+
" <meta name='viewport' content='width=380, initial-scale=1.0'>\n" +
|
|
1025
|
+
" <title>Document</title>\n" +
|
|
1026
|
+
"\n" +
|
|
1027
|
+
" <style>\n" +
|
|
1028
|
+
" /* @media print {\n" +
|
|
1029
|
+
" .printer-ticket {\n" +
|
|
1030
|
+
" border: none !important;\n" +
|
|
1031
|
+
" }\n" +
|
|
1032
|
+
" } */\n" +
|
|
1033
|
+
"\n" +
|
|
1034
|
+
" body {\n" +
|
|
1035
|
+
" margin: 0px;\n" +
|
|
1036
|
+
" width: 380px;\n" +
|
|
1037
|
+
" /*border: 1px solid black;*/\n" +
|
|
1038
|
+
" }\n" +
|
|
1039
|
+
"\n" +
|
|
1040
|
+
"\n" +
|
|
1041
|
+
"\n" +
|
|
1042
|
+
" .printer-ticket {\n" +
|
|
1043
|
+
" /* background-color: #ffffcc; */\n" +
|
|
1044
|
+
" background-color: white;\n" +
|
|
1045
|
+
" /* padding: 10px; */\n" +
|
|
1046
|
+
" max-width: 380px;\n" +
|
|
1047
|
+
" /* border: solid 1px black; */\n" +
|
|
1048
|
+
" /* text-align: center; */\n" +
|
|
1049
|
+
" padding-left: 10px;\n" +
|
|
1050
|
+
" padding-right: 10px;\n" +
|
|
1051
|
+
" }\n" +
|
|
1052
|
+
"\n" +
|
|
1053
|
+
" /* @media (max-width: 979px) {\n" +
|
|
1054
|
+
" .section-printer--ticket {\n" +
|
|
1055
|
+
" position: initial;\n" +
|
|
1056
|
+
" top: 0;\n" +
|
|
1057
|
+
" }\n" +
|
|
1058
|
+
" } */\n" +
|
|
1059
|
+
"\n" +
|
|
1060
|
+
" .printer-ticket table {\n" +
|
|
1061
|
+
" margin: auto;\n" +
|
|
1062
|
+
"\n" +
|
|
1063
|
+
" }\n" +
|
|
1064
|
+
"\n" +
|
|
1065
|
+
" .printer-ticket * {\n" +
|
|
1066
|
+
" font-family: monospace;\n" +
|
|
1067
|
+
" /* font-size: 100%; */\n" +
|
|
1068
|
+
" color: black;\n" +
|
|
1069
|
+
" /* line-height: 80%; */\n" +
|
|
1070
|
+
" max-width: 380px;\n" +
|
|
1071
|
+
" /* line-height: normal; */\n" +
|
|
1072
|
+
" /* padding-left: 15px; */\n" +
|
|
1073
|
+
" }\n" +
|
|
1074
|
+
"\n" +
|
|
1075
|
+
" [data-normal='true'] {\n" +
|
|
1076
|
+
" /* letter-spacing: 1px;\n" +
|
|
1077
|
+
" font-size: 30px;\n" +
|
|
1078
|
+
" text-align: left; */\n" +
|
|
1079
|
+
" /* padding-left: 15px; */\n" +
|
|
1080
|
+
" }\n" +
|
|
1081
|
+
"\n" +
|
|
1082
|
+
"\n" +
|
|
1083
|
+
" [data-expandido='true'] {\n" +
|
|
1084
|
+
" letter-spacing: 1px;\n" +
|
|
1085
|
+
" font-size: 30px !important;\n" +
|
|
1086
|
+
" /* text-align: left !important; */\n" +
|
|
1087
|
+
" /* padding-left: 15px; */\n" +
|
|
1088
|
+
" }\n" +
|
|
1089
|
+
"\n" +
|
|
1090
|
+
" [data-condensado='true'] {\n" +
|
|
1091
|
+
" letter-spacing: -2px;\n" +
|
|
1092
|
+
" font-size: 15px !important;\n" +
|
|
1093
|
+
" /* text-align: left !important; */\n" +
|
|
1094
|
+
" /* padding-left: 10px; */\n" +
|
|
1095
|
+
" }\n" +
|
|
1096
|
+
"\n" +
|
|
1097
|
+
" [data-negrito='true'] {\n" +
|
|
1098
|
+
" font-weight: bold;\n" +
|
|
1099
|
+
" }\n" +
|
|
1100
|
+
"\n" +
|
|
1101
|
+
" [data-reverse='true'] {\n" +
|
|
1102
|
+
" background-color: black !important;\n" +
|
|
1103
|
+
" color: white;\n" +
|
|
1104
|
+
" -webkit-print-color-adjust: exact;\n" +
|
|
1105
|
+
" }\n" +
|
|
1106
|
+
"\n" +
|
|
1107
|
+
" [data-qrcode='true'] {\n" +
|
|
1108
|
+
" text-align: center;\n" +
|
|
1109
|
+
" }\n" +
|
|
1110
|
+
"\n" +
|
|
1111
|
+
" [data-barcode128='true'] {\n" +
|
|
1112
|
+
" text-align: center;\n" +
|
|
1113
|
+
" }\n" +
|
|
1114
|
+
"\n" +
|
|
1115
|
+
"\n" +
|
|
1116
|
+
" [data-alinhamento='1'] {\n" +
|
|
1117
|
+
" text-align: left;\n" +
|
|
1118
|
+
" }\n" +
|
|
1119
|
+
"\n" +
|
|
1120
|
+
" [data-alinhamento='2'] {\n" +
|
|
1121
|
+
" text-align: center;\n" +
|
|
1122
|
+
" }\n" +
|
|
1123
|
+
"\n" +
|
|
1124
|
+
" [data-alinhamento='3'] {\n" +
|
|
1125
|
+
" text-align: right;\n" +
|
|
1126
|
+
" }\n" +
|
|
1127
|
+
" </style>\n" +
|
|
1128
|
+
"</head>\n" +
|
|
1129
|
+
"\n" +
|
|
1130
|
+
"<body>\n" +
|
|
1131
|
+
"\n" +
|
|
1132
|
+
"\n" +
|
|
1133
|
+
" <div class='printer-ticket'>\n" +
|
|
1134
|
+
" <div class='row'>\n";
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
return htmlResult;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
private List<String> ConverterImpressaoToHtmlLinhasHtml(String textoImpresso)
|
|
1141
|
+
{
|
|
1142
|
+
List<String> result = new ArrayList<String>();;
|
|
1143
|
+
try
|
|
1144
|
+
{
|
|
1145
|
+
String[] linhas = textoImpresso.split("\n");
|
|
1146
|
+
for (String item: linhas) {
|
|
1147
|
+
String linha = item.replace(".nomeponto", "");
|
|
1148
|
+
linha = linha.replace(".impressovia", "");
|
|
1149
|
+
String tipoCaracter = "feed";
|
|
1150
|
+
|
|
1151
|
+
if (linha.contains("<n>") && linha.contains("</n>"))
|
|
1152
|
+
{
|
|
1153
|
+
tipoCaracter = "normal";
|
|
1154
|
+
linha = linha.replace("<n>", "").replace("</n>", "");
|
|
1155
|
+
if (linha.contains("<b>") && linha.contains("</b>"))
|
|
1156
|
+
{
|
|
1157
|
+
tipoCaracter += "-bold";
|
|
1158
|
+
linha = linha.replace("<b>", "").replace("</b>", "");
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
else if (linha.contains("<g>") && linha.contains("</g>"))
|
|
1162
|
+
{
|
|
1163
|
+
tipoCaracter = "drawer";
|
|
1164
|
+
}
|
|
1165
|
+
else if (linha.contains("<e>") && linha.contains("</e>"))
|
|
1166
|
+
{
|
|
1167
|
+
tipoCaracter = "expanded";
|
|
1168
|
+
linha = linha.replace("<e>", "").replace("</e>", "");
|
|
1169
|
+
if (linha.contains("<n>") && linha.contains("</n>"))
|
|
1170
|
+
{
|
|
1171
|
+
tipoCaracter += "-normal";
|
|
1172
|
+
linha = linha.replace("<n>", "").replace("</n>", "");
|
|
1173
|
+
if (linha.contains("<b>") && linha.contains("</b>"))
|
|
1174
|
+
{
|
|
1175
|
+
tipoCaracter = "bold";
|
|
1176
|
+
linha = linha.replace("<b>", "").replace("</b>", "");
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
else if (linha.contains("<b>") && linha.contains("</b>"))
|
|
1181
|
+
{
|
|
1182
|
+
tipoCaracter = "bold";
|
|
1183
|
+
linha = linha.replace("<b>", "").replace("</b>", "");
|
|
1184
|
+
if (linha.contains("<c>") && linha.contains("</c>"))
|
|
1185
|
+
{
|
|
1186
|
+
tipoCaracter += "-condensed";
|
|
1187
|
+
linha = linha.replace("<c>", "").replace("</c>", "");
|
|
1188
|
+
}
|
|
1189
|
+
else if (linha.contains("<n>") && linha.contains("</n>"))
|
|
1190
|
+
{
|
|
1191
|
+
tipoCaracter += "-normal";
|
|
1192
|
+
linha = linha.replace("<n>", "").replace("</n>", "");
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
else if (linha.contains("<c>") && linha.contains("</c>"))
|
|
1196
|
+
{
|
|
1197
|
+
tipoCaracter = "condensed";
|
|
1198
|
+
linha = linha.replace("<c>", "").replace("</c>", "");
|
|
1199
|
+
}
|
|
1200
|
+
else if (linha.contains("<f>") && linha.contains("</f>"))
|
|
1201
|
+
{
|
|
1202
|
+
tipoCaracter = "reverse";
|
|
1203
|
+
linha = linha.replace("<f>", "").replace("</f>", "");
|
|
1204
|
+
}
|
|
1205
|
+
else if (linha.contains("<ce>") && linha.contains("</ce>"))
|
|
1206
|
+
{
|
|
1207
|
+
linha = linha.replace("<ce>", "").replace("</ce>", "");
|
|
1208
|
+
if (linha.contains("<qrcode>") && linha.contains("</qrcode>"))
|
|
1209
|
+
{
|
|
1210
|
+
tipoCaracter = "qrcode";
|
|
1211
|
+
linha = linha.replace("<qrcode>", "").replace("</qrcode>", "");
|
|
1212
|
+
}
|
|
1213
|
+
else if (linha.contains("<code128>") && linha.contains("</code128>"))
|
|
1214
|
+
{
|
|
1215
|
+
tipoCaracter = "barcode128";
|
|
1216
|
+
linha = linha.replace("<code128>", "").replace("</code128>", "");
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (linha.contains("<esc pos>"))
|
|
1220
|
+
{
|
|
1221
|
+
linha = linha.replace("<esc pos>", " ");
|
|
1222
|
+
}
|
|
1223
|
+
if (linha == "")
|
|
1224
|
+
{
|
|
1225
|
+
tipoCaracter = "feed";
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
switch (tipoCaracter)
|
|
1229
|
+
{
|
|
1230
|
+
case "normal":
|
|
1231
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false,false,false,false, false,false));
|
|
1232
|
+
break;
|
|
1233
|
+
case "normal-bold":
|
|
1234
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true,false, false,false));
|
|
1235
|
+
break;
|
|
1236
|
+
case "bold-normal":
|
|
1237
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true,false, false,false));
|
|
1238
|
+
break;
|
|
1239
|
+
case "bold":
|
|
1240
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true,false, false,false));
|
|
1241
|
+
break;
|
|
1242
|
+
case "expanded":
|
|
1243
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, true, false, false, false, false,false));
|
|
1244
|
+
break;
|
|
1245
|
+
case "condensed":
|
|
1246
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, true,false,false, false,false));
|
|
1247
|
+
break;
|
|
1248
|
+
case "bold-condensed":
|
|
1249
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, true, true,false, false,false));
|
|
1250
|
+
break;
|
|
1251
|
+
case "reverse":
|
|
1252
|
+
// ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 1, 8 + 4, 0);
|
|
1253
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, true, false, true, true, false,false));
|
|
1254
|
+
break;
|
|
1255
|
+
case "drawer":
|
|
1256
|
+
//ImpressaoTextoNetPrintHelper_AbreGavetaElgin();
|
|
1257
|
+
break;
|
|
1258
|
+
case "qrcode":
|
|
1259
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, false, false, false,true));
|
|
1260
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false,false));
|
|
1261
|
+
//ImpressaoTextoNetPrintHelper_DefinirImpressao(1);
|
|
1262
|
+
//ImpressaoTextoNetPrintHelper_PrintQrCode(linha, 5, 1);
|
|
1263
|
+
//ImpressaoTextoNetPrintHelper_AvancaPapel(5);
|
|
1264
|
+
break;
|
|
1265
|
+
case "barcode128":
|
|
1266
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, false, false, true,false));
|
|
1267
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false,false));
|
|
1268
|
+
//ImpressaoTextoNetPrintHelper_DefinirImpressao(1);
|
|
1269
|
+
//ImpressaoTextoNetPrintHelper_PrintBarCode(8, "{C" + linha, 50, 2, 4);
|
|
1270
|
+
//ImpressaoTextoNetPrintHelper_AvancaPapel(5);
|
|
1271
|
+
break;
|
|
1272
|
+
|
|
1273
|
+
default:
|
|
1274
|
+
result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false,false));
|
|
1275
|
+
// ImpressaoTextoNetPrintHelper_AvancaPapel(1);
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
catch (Exception ex)
|
|
1282
|
+
{
|
|
1283
|
+
String errorStr = ex.toString();
|
|
1284
|
+
throw ex;
|
|
1285
|
+
}
|
|
1286
|
+
return result;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
String ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(String texto, boolean expandido, boolean condensado, boolean negrito, boolean reverse, boolean barCode, boolean qrCode) {
|
|
1290
|
+
String result = "";
|
|
1291
|
+
try {
|
|
1292
|
+
|
|
1293
|
+
texto = texto.replace(" ", " ").replace("\r", "");
|
|
1294
|
+
|
|
1295
|
+
String textoExpandido = "";
|
|
1296
|
+
if (expandido) {
|
|
1297
|
+
textoExpandido = " data-expandido='true'";
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
String textoCondensado = "";
|
|
1301
|
+
if (condensado) {
|
|
1302
|
+
textoCondensado = " data-condensado='true'";
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
String textoNegrito = "";
|
|
1306
|
+
if (negrito) {
|
|
1307
|
+
textoNegrito = " data-negrito='true'";
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
String textoReverse = "";
|
|
1311
|
+
if (reverse) {
|
|
1312
|
+
textoReverse = " data-reverse='true'";
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
String textoBarCode = "";
|
|
1316
|
+
if (barCode) {
|
|
1317
|
+
textoBarCode = " data-barcode128='true'";
|
|
1318
|
+
String base64Barcode128 = this.CreateBarCodeBase64(texto,BarcodeFormat.CODE_128, 150, 75);
|
|
1319
|
+
String textoBarcode128 = "<img src=\"data:image/png;base64," + base64Barcode128 + "\" >";
|
|
1320
|
+
texto = textoBarcode128;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
String textoQrCode = "";
|
|
1324
|
+
if (qrCode) {
|
|
1325
|
+
textoQrCode = " data-qrcode='true'";
|
|
1326
|
+
|
|
1327
|
+
String baseQrCodeBase64 = this.CreateBarCodeBase64(texto,BarcodeFormat.QR_CODE, 200, 200);
|
|
1328
|
+
String textoQrCodeResult = "<img src=\"data:image/png;base64," + baseQrCodeBase64 + "\" >";
|
|
1329
|
+
texto = textoQrCodeResult;
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
result = "<div class='row'>\n" +
|
|
1335
|
+
" <div class='col-12' " + textoExpandido + textoCondensado + textoNegrito + textoReverse + textoBarCode + textoQrCode + " >" + texto + "</div>\n" +
|
|
1336
|
+
" </div>";
|
|
1337
|
+
return result;
|
|
1338
|
+
} catch (Exception ex) {
|
|
1339
|
+
throw ex;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
private String ConverterImpressaoToHtmlFinal()
|
|
1346
|
+
{
|
|
1347
|
+
String htmlResult = " </div> " +
|
|
1348
|
+
"</div>" +
|
|
1349
|
+
"</body>" +
|
|
1350
|
+
"</html>";
|
|
1351
|
+
|
|
1352
|
+
return htmlResult;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
private String CreateBarCodeBase64(String valor, BarcodeFormat barcodeFormat, int width, int height) {
|
|
1356
|
+
ErrorCorrectionLevel errCorLvl = ErrorCorrectionLevel.L;
|
|
1357
|
+
switch(48) {
|
|
1358
|
+
case 48:
|
|
1359
|
+
errCorLvl = ErrorCorrectionLevel.L;
|
|
1360
|
+
break;
|
|
1361
|
+
case 49:
|
|
1362
|
+
errCorLvl = ErrorCorrectionLevel.M;
|
|
1363
|
+
break;
|
|
1364
|
+
case 50:
|
|
1365
|
+
errCorLvl = ErrorCorrectionLevel.Q;
|
|
1366
|
+
break;
|
|
1367
|
+
case 51:
|
|
1368
|
+
errCorLvl = ErrorCorrectionLevel.H;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
Map<EncodeHintType, Object> hints = new EnumMap(EncodeHintType.class);
|
|
1372
|
+
hints.put(EncodeHintType.ERROR_CORRECTION, errCorLvl);
|
|
1373
|
+
|
|
1374
|
+
Bitmap bitmap = null;
|
|
1375
|
+
try {
|
|
1376
|
+
bitmap = CreateBarcode(valor, barcodeFormat, width,height ,hints);
|
|
1377
|
+
} catch (WriterException e) {
|
|
1378
|
+
e.printStackTrace();
|
|
1379
|
+
}
|
|
1380
|
+
String resultBase64 = ConverterBitmapToBase64(bitmap);
|
|
1381
|
+
return resultBase64;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
private Bitmap CreateBarcode(String dados, BarcodeFormat tipo, int width, int height, Map<EncodeHintType, Object> hints) throws WriterException {
|
|
1385
|
+
int BLACK = -16777216;
|
|
1386
|
+
boolean WHITE = true;
|
|
1387
|
+
if (hints != null) {
|
|
1388
|
+
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
1389
|
+
hints.put(EncodeHintType.MARGIN, 0);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
long dte = System.currentTimeMillis();
|
|
1393
|
+
|
|
1394
|
+
BitMatrix matrix;
|
|
1395
|
+
try {
|
|
1396
|
+
matrix = (new MultiFormatWriter()).encode(dados, tipo, width, height, hints);
|
|
1397
|
+
} catch (IllegalArgumentException var29) {
|
|
1398
|
+
var29.printStackTrace();
|
|
1399
|
+
return null;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
dte = System.currentTimeMillis() - dte;
|
|
1403
|
+
width = matrix.getWidth();
|
|
1404
|
+
height = matrix.getHeight();
|
|
1405
|
+
long dtm = System.currentTimeMillis();
|
|
1406
|
+
int[][] mPixels = new int[height][width];
|
|
1407
|
+
|
|
1408
|
+
int minX;
|
|
1409
|
+
int maxX;
|
|
1410
|
+
for(minX = 0; minX < height; ++minX) {
|
|
1411
|
+
for(maxX = 0; maxX < width; ++maxX) {
|
|
1412
|
+
mPixels[minX][maxX] = matrix.get(maxX, minX) ? -16777216 : -1;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
dtm = System.currentTimeMillis() - dtm;
|
|
1417
|
+
minX = 2147483647;
|
|
1418
|
+
maxX = 0;
|
|
1419
|
+
int minY = 2147483647;
|
|
1420
|
+
int maxY = 0;
|
|
1421
|
+
long dtp = System.currentTimeMillis();
|
|
1422
|
+
|
|
1423
|
+
for(int y = 0; y < height; ++y) {
|
|
1424
|
+
for(int x = 0; x < width; ++x) {
|
|
1425
|
+
if (mPixels[y][x] != -1) {
|
|
1426
|
+
if (x < minX) {
|
|
1427
|
+
minX = x;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
if (x > maxX) {
|
|
1431
|
+
maxX = x;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
if (y < minY) {
|
|
1435
|
+
minY = y;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
if (y > maxY) {
|
|
1439
|
+
maxY = y;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
dtp = System.currentTimeMillis() - dtp;
|
|
1446
|
+
width = maxX - minX + 1;
|
|
1447
|
+
height = maxY - minY + 1;
|
|
1448
|
+
long dtr = System.currentTimeMillis();
|
|
1449
|
+
int[][] mTrimmedPixels = new int[height][width];
|
|
1450
|
+
int y = minY;
|
|
1451
|
+
|
|
1452
|
+
for(int i = 0; y < maxY + 1 && i < height; ++i) {
|
|
1453
|
+
System.arraycopy(mPixels[y], minX, mTrimmedPixels[i], 0, width);
|
|
1454
|
+
++y;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
dtr = System.currentTimeMillis() - dtr;
|
|
1458
|
+
long dtv = System.currentTimeMillis();
|
|
1459
|
+
int[] vPixels = new int[width * height];
|
|
1460
|
+
|
|
1461
|
+
for(y = 0; y < height; ++y) {
|
|
1462
|
+
int offset = y * width;
|
|
1463
|
+
System.arraycopy(mTrimmedPixels[y], 0, vPixels, offset, width);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
dtv = System.currentTimeMillis() - dtv;
|
|
1467
|
+
// long dtb = System.currentTimeMillis();
|
|
1468
|
+
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
1469
|
+
bitmap.setPixels(vPixels, 0, width, 0, 0, width, height);
|
|
1470
|
+
// dtb = System.currentTimeMillis() - dtb;
|
|
1471
|
+
// System.out.println("Tempo para codificar dados: " + dte + " ms");
|
|
1472
|
+
// System.out.println("Tempo para gerar matriz: " + dtm + " ms");
|
|
1473
|
+
// System.out.println("Tempo para varrer matriz: " + dtp + " ms");
|
|
1474
|
+
// System.out.println("Tempo para remover margens: " + dtr + " ms");
|
|
1475
|
+
// System.out.println("Tempo para gerar vetor: " + dtv + " ms");
|
|
1476
|
+
// System.out.println("Tempo para gerar bitmap: " + dtb + " ms");
|
|
1477
|
+
// System.out.println("Tempo total (createBarcode): " + (dte + dtm + dtp + dtr + dtv + dtb) + " ms");
|
|
1478
|
+
return bitmap;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
private String ConverterBitmapToBase64(Bitmap bitmap) {
|
|
1482
|
+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
1483
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
|
|
1484
|
+
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
1485
|
+
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
1486
|
+
return encoded;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
772
1489
|
}
|
package/www/Cielo/LioLocal.js
CHANGED
|
@@ -66,7 +66,8 @@ exports.TerminalInformation = function (success, error) {
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
exports.ImpressaoTextoNetPrint = function (params, success, error) {
|
|
69
|
-
|
|
69
|
+
exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ImpressaoTextoNetPrint', [params]);
|
|
70
|
+
// ImpressaoTextoNetPrintHelper(params.dados, success, error);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
|