cordova-plugin-netcontroll-integration-getnet 1.0.104

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.
@@ -0,0 +1,652 @@
1
+ package cordova.plugin.netcontroll.integration.getnet;
2
+
3
+ import org.apache.cordova.CallbackContext;
4
+
5
+ //Json Serialize
6
+ import android.app.Activity;
7
+ import android.content.Context;
8
+ import android.os.Environment;
9
+ import android.util.Base64;
10
+
11
+ // import br.com.uol.pagseguro.plugpagservice.wrapper.PlugPagPrintResult;
12
+ // import br.com.uol.pagseguro.plugpagservice.wrapper.PlugPagPrinterData;
13
+ // import br.com.uol.pagseguro.plugpagservice.wrapper.PlugPagPrinterListener;
14
+ // import getNet.application.enums.ReceiptType;
15
+
16
+ import com.google.gson.Gson;
17
+ import com.google.gson.GsonBuilder;
18
+ import com.google.gson.annotations.SerializedName;
19
+ import com.google.zxing.WriterException;
20
+ import com.google.zxing.MultiFormatWriter;
21
+ import com.google.zxing.common.BitMatrix;
22
+ import com.google.zxing.BarcodeFormat;
23
+
24
+ import java.io.File;
25
+ import java.io.FileOutputStream;
26
+ import java.io.IOException;
27
+ import java.io.OutputStream;
28
+ import java.text.SimpleDateFormat;
29
+ import java.util.Date;
30
+ import java.util.List;
31
+ import java.util.HashMap;
32
+ import java.util.Map;
33
+
34
+ import com.google.zxing.EncodeHintType;
35
+
36
+ import android.os.AsyncTask;
37
+
38
+ import androidx.annotation.NonNull;
39
+ import androidx.core.app.ActivityCompat;
40
+ import androidx.core.content.ContextCompat;
41
+
42
+ import java.lang.reflect.Type;
43
+ import java.util.ArrayList;
44
+
45
+ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
46
+
47
+ import java.util.EnumMap;
48
+
49
+ import com.izettle.html2bitmap.Html2Bitmap;
50
+ import com.izettle.html2bitmap.content.WebViewContent;
51
+
52
+ import java.io.ByteArrayOutputStream;
53
+
54
+ import android.content.pm.PackageInfo;
55
+ import android.content.pm.PackageManager;
56
+
57
+ import android.graphics.Bitmap;
58
+ import android.graphics.BitmapFactory;
59
+ import android.graphics.Matrix;
60
+
61
+ public class NetControllPrinter {
62
+ private static final int PERMISSIONS_REQUEST_CODE = 0x1234;
63
+
64
+ //Converter Texto Impresso para HTML
65
+ public static String ConverterTextoImpressoToHtml(String linhasImpressos) {
66
+ try {
67
+ String htmlStr = NetControllPrinter.ConverterImpressaoToHtmlInicio();
68
+
69
+ List<String> linhas = NetControllPrinter.ConverterImpressaoToHtmlLinhasHtml(linhasImpressos);
70
+
71
+ for (String linha : linhas) {
72
+ htmlStr += linha;
73
+ }
74
+
75
+ htmlStr += NetControllPrinter.ConverterImpressaoToHtmlFinal();
76
+
77
+ return htmlStr;
78
+ } catch (Exception e) {
79
+ throw e;
80
+ }
81
+ }
82
+
83
+ private static String ConverterImpressaoToHtmlInicio() {
84
+ String htmlResult = "<!DOCTYPE html>\n" +
85
+ "<html lang='en'>\n" +
86
+ "\n" +
87
+ "<head>\n" +
88
+ " <!-- <meta charset='UTF-8'>\n" +
89
+ " <meta http-equiv='X-UA-Compatible' content='IE=edge'>\n" +
90
+ " <meta name='viewport' content='width=380, initial-scale=1.0'>\n" +
91
+ " <title>Document</title> -->\n" +
92
+ "\n" +
93
+ " <style>\n" +
94
+ " /* @media print {\n" +
95
+ " .printer-ticket {\n" +
96
+ " border: none !important;\n" +
97
+ " }\n" +
98
+ " } */\n" +
99
+ "\n" +
100
+ " body {\n" +
101
+ " margin: 0px;\n" +
102
+ " width: 380px;\n" +
103
+ " /*border: 1px solid black;*/\n" +
104
+ " }\n" +
105
+ "\n" +
106
+ "\n" +
107
+ "\n" +
108
+ " .printer-ticket {\n" +
109
+ " /* background-color: #ffffcc; */\n" +
110
+ " background-color: white;\n" +
111
+ " font-size: 16px;\n" +
112
+
113
+ " /* padding: 10px; */\n" +
114
+ " max-width: 380px;\n" +
115
+ " /* border: solid 1px black; */\n" +
116
+ " /* text-align: center; */\n" +
117
+ " /*padding-left: 10px;*/\n" +
118
+ " /*padding-right: 10px;*/\n" +
119
+ " }\n" +
120
+ "\n" +
121
+ " /* @media (max-width: 979px) {\n" +
122
+ " .section-printer--ticket {\n" +
123
+ " position: initial;\n" +
124
+ " top: 0;\n" +
125
+ " }\n" +
126
+ " } */\n" +
127
+ "\n" +
128
+ " .printer-ticket table {\n" +
129
+ " margin: auto;\n" +
130
+ "\n" +
131
+ " }\n" +
132
+ "\n" +
133
+ " .printer-ticket * {\n" +
134
+ " font-family: monospace;\n" +
135
+ " /* font-family: Consolas, Regular;*/\n" +
136
+ " /* font-size: 100%; */\n" +
137
+ " color: black;\n" +
138
+ " /* line-height: 80%; */\n" +
139
+ " max-width: 380px;\n" +
140
+ " /* line-height: normal; */\n" +
141
+ " /* padding-left: 15px; */\n" +
142
+ " }\n" +
143
+ "\n" +
144
+ " [data-normal='true'] {\n" +
145
+ " /* letter-spacing: 1px;\n" +
146
+ " font-size: 30px;\n" +
147
+ " text-align: left; */\n" +
148
+ " /* padding-left: 15px; */\n" +
149
+ " }\n" +
150
+ "\n" +
151
+ "\n" +
152
+ " [data-expandido='true'] {\n" +
153
+ " letter-spacing: 1px;\n" +
154
+ " font-size: 30px !important;\n" +
155
+ " /* text-align: left !important; */\n" +
156
+ " /* padding-left: 15px; */\n" +
157
+ " }\n" +
158
+ "\n" +
159
+ " [data-condensado='true'] {\n" +
160
+ " letter-spacing: -2px;\n" +
161
+ " font-size: 15px !important;\n" +
162
+ " /* text-align: left !important; */\n" +
163
+ " /* padding-left: 10px; */\n" +
164
+ " }\n" +
165
+ "\n" +
166
+ " [data-negrito='true'] {\n" +
167
+ " font-weight: bold;\n" +
168
+ " }\n" +
169
+ "\n" +
170
+ " [data-reverse='true'] {\n" +
171
+ " background-color: black !important;\n" +
172
+ " color: white;\n" +
173
+ " -webkit-print-color-adjust: exact;\n" +
174
+ " }\n" +
175
+ "\n" +
176
+ " [data-qrcode='true'] {\n" +
177
+ " text-align: center;\n" +
178
+ " }\n" +
179
+ "\n" +
180
+ " [data-barcode128='true'] {\n" +
181
+ " text-align: center;\n" +
182
+ " }\n" +
183
+ "\n" +
184
+ "\n" +
185
+ " [data-alinhamento='1'] {\n" +
186
+ " text-align: left;\n" +
187
+ " }\n" +
188
+ "\n" +
189
+ " [data-alinhamento='2'] {\n" +
190
+ " text-align: center;\n" +
191
+ " }\n" +
192
+ "\n" +
193
+ " [data-alinhamento='3'] {\n" +
194
+ " text-align: right;\n" +
195
+ " }\n" +
196
+ " </style>\n" +
197
+ "</head>\n" +
198
+ "\n" +
199
+ "<body>\n" +
200
+ "\n" +
201
+ "\n" +
202
+ " <div class='printer-ticket'>\n" +
203
+ " <div class='row'>\n";
204
+
205
+ return htmlResult;
206
+ }
207
+
208
+ private static List<String> ConverterImpressaoToHtmlLinhasHtml(String textoImpresso) {
209
+ List<String> result = new ArrayList<String>();
210
+ try {
211
+ String[] linhas = textoImpresso.split("\n");
212
+ for (String item : linhas) {
213
+ String linha = item.replace(".nomeponto", "");
214
+ linha = linha.replace(".impressovia", "");
215
+ String tipoCaracter = "feed";
216
+
217
+ if (linha.contains("<n>") && linha.contains("</n>")) {
218
+ tipoCaracter = "normal";
219
+ linha = linha.replace("<n>", "").replace("</n>", "");
220
+ if (linha.contains("<b>") && linha.contains("</b>")) {
221
+ tipoCaracter += "-bold";
222
+ linha = linha.replace("<b>", "").replace("</b>", "");
223
+ }
224
+ } else if (linha.contains("<g>") && linha.contains("</g>")) {
225
+ tipoCaracter = "drawer";
226
+ } else if (linha.contains("<e>") && linha.contains("</e>")) {
227
+ tipoCaracter = "expanded";
228
+ linha = linha.replace("<e>", "").replace("</e>", "");
229
+ if (linha.contains("<n>") && linha.contains("</n>")) {
230
+ tipoCaracter += "-normal";
231
+ linha = linha.replace("<n>", "").replace("</n>", "");
232
+ if (linha.contains("<b>") && linha.contains("</b>")) {
233
+ tipoCaracter = "bold";
234
+ linha = linha.replace("<b>", "").replace("</b>", "");
235
+ }
236
+ }
237
+ } else if (linha.contains("<b>") && linha.contains("</b>")) {
238
+ tipoCaracter = "bold";
239
+ linha = linha.replace("<b>", "").replace("</b>", "");
240
+ if (linha.contains("<c>") && linha.contains("</c>")) {
241
+ tipoCaracter += "-condensed";
242
+ linha = linha.replace("<c>", "").replace("</c>", "");
243
+ } else if (linha.contains("<n>") && linha.contains("</n>")) {
244
+ tipoCaracter += "-normal";
245
+ linha = linha.replace("<n>", "").replace("</n>", "");
246
+ }
247
+ } else if (linha.contains("<c>") && linha.contains("</c>")) {
248
+ tipoCaracter = "condensed";
249
+ linha = linha.replace("<c>", "").replace("</c>", "");
250
+ } else if (linha.contains("<f>") && linha.contains("</f>")) {
251
+ tipoCaracter = "reverse";
252
+ linha = linha.replace("<f>", "").replace("</f>", "");
253
+ } else if (linha.contains("<ce>") && linha.contains("</ce>")) {
254
+ linha = linha.replace("<ce>", "").replace("</ce>", "");
255
+ if (linha.contains("<qrcode>") && linha.contains("</qrcode>")) {
256
+ tipoCaracter = "qrcode";
257
+ linha = linha.replace("<qrcode>", "").replace("</qrcode>", "");
258
+ } else if (linha.contains("<code128>") && linha.contains("</code128>")) {
259
+ tipoCaracter = "barcode128";
260
+ linha = linha.replace("<code128>", "").replace("</code128>", "");
261
+ }
262
+ }
263
+ if (linha.contains("<esc pos>")) {
264
+ linha = linha.replace("<esc pos>", " ");
265
+ }
266
+ if (linha == "") {
267
+ tipoCaracter = "feed";
268
+ }
269
+
270
+ switch (tipoCaracter) {
271
+ case "normal":
272
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, false, false, false, false));
273
+ break;
274
+ case "normal-bold":
275
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true, false, false, false));
276
+ break;
277
+ case "bold-normal":
278
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true, false, false, false));
279
+ break;
280
+ case "bold":
281
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, true, false, false, false));
282
+ break;
283
+ case "expanded":
284
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, true, false, false, false, false, false));
285
+ break;
286
+ case "condensed":
287
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, true, false, false, false, false));
288
+ break;
289
+ case "bold-condensed":
290
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, true, true, false, false, false));
291
+ break;
292
+ case "reverse":
293
+ // ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 1, 8 + 4, 0);
294
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, true, false, true, true, false, false));
295
+ break;
296
+ case "drawer":
297
+ //ImpressaoTextoNetPrintHelper_AbreGavetaElgin();
298
+ break;
299
+ case "qrcode":
300
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, false, false, false, true));
301
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false, false));
302
+ //ImpressaoTextoNetPrintHelper_DefinirImpressao(1);
303
+ //ImpressaoTextoNetPrintHelper_PrintQrCode(linha, 5, 1);
304
+ //ImpressaoTextoNetPrintHelper_AvancaPapel(5);
305
+ break;
306
+ case "barcode128":
307
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(linha, false, false, false, false, true, false));
308
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false, false));
309
+ //ImpressaoTextoNetPrintHelper_DefinirImpressao(1);
310
+ //ImpressaoTextoNetPrintHelper_PrintBarCode(8, "{C" + linha, 50, 2, 4);
311
+ //ImpressaoTextoNetPrintHelper_AvancaPapel(5);
312
+ break;
313
+
314
+ default:
315
+ result.add(ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow("<br/>", false, false, false, false, false, false));
316
+ // ImpressaoTextoNetPrintHelper_AvancaPapel(1);
317
+ break;
318
+ }
319
+
320
+ }
321
+ } catch (Exception ex) {
322
+ String errorStr = ex.toString();
323
+ throw ex;
324
+ }
325
+ return result;
326
+ }
327
+
328
+ private static String ImpressaoTextoNetPrintHelper_ImpressaoTextoDivRow(String texto, boolean expandido, boolean condensado, boolean negrito, boolean reverse, boolean barCode, boolean qrCode) {
329
+ String result = "";
330
+ try {
331
+
332
+ if (!qrCode && !barCode) {
333
+ texto = texto.replace(" ", "&nbsp;").replace("\r", "");
334
+ }
335
+
336
+ String textoExpandido = "";
337
+ if (expandido) {
338
+ textoExpandido = " data-expandido='true'";
339
+ }
340
+
341
+ String textoCondensado = "";
342
+ if (condensado) {
343
+ textoCondensado = " data-condensado='true'";
344
+ }
345
+
346
+ String textoNegrito = "";
347
+ if (negrito) {
348
+ textoNegrito = " data-negrito='true'";
349
+ }
350
+
351
+ String textoReverse = "";
352
+ if (reverse) {
353
+ textoReverse = " data-reverse='true'";
354
+ }
355
+
356
+ String textoBarCode = "";
357
+ if (barCode) {
358
+ textoBarCode = " data-barcode128='true'";
359
+ String base64Barcode128 = NetControllPrinter.CreateBarCodeBase64(texto, BarcodeFormat.CODE_128, 150, 75);
360
+ String textoBarcode128 = "<img src=\"data:image/png;base64," + base64Barcode128 + "\" >";
361
+ texto = textoBarcode128;
362
+ }
363
+
364
+ String textoQrCode = "";
365
+ if (qrCode) {
366
+ textoQrCode = " data-qrcode='true'";
367
+
368
+ String baseQrCodeBase64 = NetControllPrinter.CreateBarCodeBase64(texto, BarcodeFormat.QR_CODE, 200, 200);
369
+ String textoQrCodeResult = "<img src=\"data:image/png;base64," + baseQrCodeBase64 + "\" >";
370
+ texto = textoQrCodeResult;
371
+
372
+ }
373
+
374
+ result = "<div class='row'>\n" +
375
+ " <div class='col-12' " + textoExpandido + textoCondensado + textoNegrito + textoReverse + textoBarCode + textoQrCode + " >" + texto + "</div>\n" +
376
+ " </div>";
377
+ return result;
378
+ } catch (Exception ex) {
379
+ throw ex;
380
+ }
381
+ }
382
+
383
+ private static String ConverterImpressaoToHtmlFinal() {
384
+ String htmlResult = " </div> " +
385
+ "</div>" +
386
+ "</body>" +
387
+ "</html>";
388
+
389
+ return htmlResult;
390
+ }
391
+
392
+ //Converter Html para Imagem
393
+ public interface ConverterHtmlToBitmapCallBack {
394
+ void onCallback(Bitmap bitmapResult);
395
+ }
396
+
397
+ public static void ConverterHtmlToBitmap(String htmlString, Context mContext, ConverterHtmlToBitmapCallBack callBack) {
398
+ try {
399
+ AsyncTask<Void, Void, Bitmap> taskBitMap = new AsyncTask<Void, Void, Bitmap>() {
400
+ @Override
401
+ protected Bitmap doInBackground(Void... voids) {
402
+ Html2Bitmap build = new Html2Bitmap.Builder().setContext(mContext).setContent(WebViewContent.html(htmlString)).setBitmapWidth(380).setMeasureDelay(300).setScreenshotDelay(300).setStrictMode(true).setTimeout(15).setTextZoom(96).build();
403
+ Bitmap bitmapResult = build.getBitmap();
404
+ return bitmapResult;
405
+ }
406
+
407
+ //
408
+ @Override
409
+ protected void onPostExecute(Bitmap bitmap) {
410
+ callBack.onCallback(bitmap);
411
+ }
412
+
413
+ }.execute();
414
+ } catch (Exception e) {
415
+ throw e;
416
+ }
417
+ }
418
+
419
+
420
+ //Converter Salvar Imagem
421
+ public static String SaveImage(Bitmap bitmap, @NonNull String directoryFileName) throws IOException {
422
+ String result = "";
423
+ try {
424
+ boolean saved;
425
+ OutputStream fos;
426
+
427
+ // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
428
+ // ContentResolver resolver = mContext.getContentResolver();
429
+ // ContentValues contentValues = new ContentValues();
430
+ // contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name);
431
+ // contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/bitmap");
432
+ // contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + IMAGES_FOLDER_NAME);
433
+ // Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
434
+ // fos = resolver.openOutputStream(imageUri);
435
+ // } else {
436
+ // String imagesDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/download.png";
437
+ String imagesDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/";
438
+ // String imagesDir = Environment.getExternalStoragePublicDirectory(
439
+ // Environment.DIRECTORY_DCIM).toString() + File.separator + IMAGES_FOLDER_NAME;
440
+
441
+ File file = new File(directoryFileName);
442
+
443
+ if (file.exists()) {
444
+ file.delete();
445
+ }
446
+
447
+ // if (!file.exists()) {
448
+ // file.mkdir();
449
+ // }
450
+
451
+ File image = new File(directoryFileName);
452
+ fos = new FileOutputStream(image);
453
+ // }
454
+ saved = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
455
+ fos.flush();
456
+ fos.close();
457
+ if (saved) {
458
+ result = directoryFileName;
459
+ }
460
+ return result;
461
+ } catch (Exception ex) {
462
+ String exStr = ex.toString();
463
+ throw ex;
464
+ }
465
+ }
466
+
467
+
468
+ //Criar BarCode Base64
469
+ public static String CreateBarCodeBase64(String valor, BarcodeFormat barcodeFormat, int width, int height) {
470
+ ErrorCorrectionLevel errCorLvl = ErrorCorrectionLevel.L;
471
+ switch (48) {
472
+ case 48:
473
+ errCorLvl = ErrorCorrectionLevel.L;
474
+ break;
475
+ case 49:
476
+ errCorLvl = ErrorCorrectionLevel.M;
477
+ break;
478
+ case 50:
479
+ errCorLvl = ErrorCorrectionLevel.Q;
480
+ break;
481
+ case 51:
482
+ errCorLvl = ErrorCorrectionLevel.H;
483
+ }
484
+
485
+ Map<EncodeHintType, Object> hints = new EnumMap(EncodeHintType.class);
486
+ hints.put(EncodeHintType.ERROR_CORRECTION, errCorLvl);
487
+
488
+ Bitmap bitmap = null;
489
+ try {
490
+ bitmap = CreateBarcodeBitmap(valor, barcodeFormat, width, height, hints);
491
+ } catch (WriterException e) {
492
+ e.printStackTrace();
493
+ }
494
+ String resultBase64 = ConverterBitmapToBase64(bitmap);
495
+ return resultBase64;
496
+ }
497
+
498
+ //Criar BarCode Bitmap
499
+ public static Bitmap CreateBarcodeBitmap(String dados, BarcodeFormat tipo, int width, int height, Map<EncodeHintType, Object> hints) throws WriterException {
500
+ int BLACK = -16777216;
501
+ boolean WHITE = true;
502
+ if (hints != null) {
503
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
504
+ hints.put(EncodeHintType.MARGIN, 0);
505
+ }
506
+
507
+ long dte = System.currentTimeMillis();
508
+
509
+ BitMatrix matrix;
510
+ try {
511
+ matrix = (new MultiFormatWriter()).encode(dados, tipo, width, height, hints);
512
+ } catch (IllegalArgumentException var29) {
513
+ var29.printStackTrace();
514
+ return null;
515
+ }
516
+
517
+ dte = System.currentTimeMillis() - dte;
518
+ width = matrix.getWidth();
519
+ height = matrix.getHeight();
520
+ long dtm = System.currentTimeMillis();
521
+ int[][] mPixels = new int[height][width];
522
+
523
+ int minX;
524
+ int maxX;
525
+ for (minX = 0; minX < height; ++minX) {
526
+ for (maxX = 0; maxX < width; ++maxX) {
527
+ mPixels[minX][maxX] = matrix.get(maxX, minX) ? -16777216 : -1;
528
+ }
529
+ }
530
+
531
+ dtm = System.currentTimeMillis() - dtm;
532
+ minX = 2147483647;
533
+ maxX = 0;
534
+ int minY = 2147483647;
535
+ int maxY = 0;
536
+ long dtp = System.currentTimeMillis();
537
+
538
+ for (int y = 0; y < height; ++y) {
539
+ for (int x = 0; x < width; ++x) {
540
+ if (mPixels[y][x] != -1) {
541
+ if (x < minX) {
542
+ minX = x;
543
+ }
544
+
545
+ if (x > maxX) {
546
+ maxX = x;
547
+ }
548
+
549
+ if (y < minY) {
550
+ minY = y;
551
+ }
552
+
553
+ if (y > maxY) {
554
+ maxY = y;
555
+ }
556
+ }
557
+ }
558
+ }
559
+
560
+ dtp = System.currentTimeMillis() - dtp;
561
+ width = maxX - minX + 1;
562
+ height = maxY - minY + 1;
563
+ long dtr = System.currentTimeMillis();
564
+ int[][] mTrimmedPixels = new int[height][width];
565
+ int y = minY;
566
+
567
+ for (int i = 0; y < maxY + 1 && i < height; ++i) {
568
+ System.arraycopy(mPixels[y], minX, mTrimmedPixels[i], 0, width);
569
+ ++y;
570
+ }
571
+
572
+ dtr = System.currentTimeMillis() - dtr;
573
+ long dtv = System.currentTimeMillis();
574
+ int[] vPixels = new int[width * height];
575
+
576
+ for (y = 0; y < height; ++y) {
577
+ int offset = y * width;
578
+ System.arraycopy(mTrimmedPixels[y], 0, vPixels, offset, width);
579
+ }
580
+
581
+ dtv = System.currentTimeMillis() - dtv;
582
+ // long dtb = System.currentTimeMillis();
583
+ Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
584
+ bitmap.setPixels(vPixels, 0, width, 0, 0, width, height);
585
+ return bitmap;
586
+ }
587
+
588
+ //Bitmap para Base64
589
+ public static String ConverterBitmapToBase64(Bitmap bitmap) {
590
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
591
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
592
+ byte[] byteArray = byteArrayOutputStream.toByteArray();
593
+ String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
594
+ return encoded;
595
+ }
596
+
597
+
598
+ // Permissoes
599
+ public static void RequestPermissions(Activity mActivity, Context mContext) {
600
+
601
+ String[] missingPermissions = null;
602
+
603
+ missingPermissions = FilterMissingPermissions(GetManifestPermissions(mContext), mContext);
604
+
605
+ if (missingPermissions != null && missingPermissions.length > 0) {
606
+ ActivityCompat.requestPermissions(mActivity, missingPermissions, PERMISSIONS_REQUEST_CODE);
607
+ } else {
608
+ String shotMessageStr = "showMessage();";
609
+ }
610
+ }
611
+
612
+ private static String[] FilterMissingPermissions(String[] permissions, Context mContext) {
613
+ String[] missingPermissions = null;
614
+ List<String> list = null;
615
+
616
+ list = new ArrayList<>();
617
+
618
+ if (permissions != null && permissions.length > 0) {
619
+ for (String permission : permissions) {
620
+ if (ContextCompat.checkSelfPermission(mContext.getApplicationContext(), permission) != PackageManager.PERMISSION_GRANTED) {
621
+ list.add(permission);
622
+ }
623
+ }
624
+ }
625
+
626
+ missingPermissions = list.toArray(new String[0]);
627
+
628
+ return missingPermissions;
629
+ }
630
+
631
+ private static String[] GetManifestPermissions(Context mContext) {
632
+ String[] permissions = null;
633
+ PackageInfo info = null;
634
+
635
+ try {
636
+ info = mContext.getPackageManager().getPackageInfo(mContext.getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS);
637
+ permissions = info.requestedPermissions;
638
+ } catch (PackageManager.NameNotFoundException ex) {
639
+ try {
640
+ throw ex;
641
+ } catch (PackageManager.NameNotFoundException e) {
642
+ e.printStackTrace();
643
+ }
644
+ }
645
+
646
+ if (permissions == null) {
647
+ permissions = new String[0];
648
+ }
649
+
650
+ return permissions;
651
+ }
652
+ }
@@ -0,0 +1,7 @@
1
+ android {
2
+ packagingOptions {
3
+ // exclude 'META-INF/DEPENDENCIES'
4
+ exclude 'META-INF/api_release.kotlin_module'
5
+ exclude 'META-INF/client_release.kotlin_module'
6
+ }
7
+ }