react-native-printer-imin 0.4.2 → 0.5.0

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.
@@ -6,12 +6,13 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
6
6
 
7
7
  import android.graphics.Bitmap;
8
8
  import android.graphics.Typeface;
9
+ import android.os.RemoteException;
9
10
  import android.graphics.BitmapFactory;
10
11
  import android.os.Build;
11
12
  import android.util.Log;
12
13
 
13
14
  import androidx.annotation.NonNull;
14
-
15
+ import androidx.annotation.Nullable;
15
16
 
16
17
  import com.facebook.react.bridge.Arguments;
17
18
  import com.facebook.react.bridge.Promise;
@@ -24,17 +25,16 @@ import com.facebook.react.bridge.ReadableMap;
24
25
  import com.facebook.react.bridge.WritableMap;
25
26
 
26
27
  import com.facebook.react.module.annotations.ReactModule;
28
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
27
29
 
28
30
 
29
- import com.imin.library.SystemPropManager;
31
+ import com.imin.printer.INeoPrinterCallback;
30
32
  import com.imin.printer.PrinterHelper;
31
33
  import com.imin.printerlib.Callback;
32
34
  import com.imin.printerlib.IminPrintUtils;
33
35
 
34
-
35
36
  import java.util.ArrayList;
36
37
  import java.util.Arrays;
37
-
38
38
  import java.util.HashMap;
39
39
  import java.util.List;
40
40
  import java.util.Map;
@@ -44,30 +44,51 @@ import org.json.JSONObject;
44
44
 
45
45
  import org.json.JSONException;
46
46
 
47
+
48
+ import java.lang.RuntimeException;
49
+
50
+ import android.content.Context;
51
+ import android.content.Intent;
52
+ import android.content.IntentFilter;
53
+ import android.content.BroadcastReceiver;
54
+
47
55
  @ReactModule(name = PrinterIminModule.NAME)
48
56
  public class PrinterIminModule extends ReactContextBaseJavaModule {
49
57
  private final ReactApplicationContext reactContext;
50
58
  public static final String NAME = "PrinterImin";
51
59
  private IminPrintUtils iminPrintUtils;
52
- private IminPrintUtils.PrintConnectType connectType = IminPrintUtils.PrintConnectType.SPI;
60
+ private String[] modelArry = {"W27_Pro", "I23M01", "I23M02", "I23D01", "D4-503 Pro", "D4-504 Pro", "D4-505 Pro", "MS2-11", "MS2-12", "MS1-15"};
61
+ private static final String ACTION_PRITER_STATUS_CHANGE = "com.imin.printerservice.PRITER_STATUS_CHANGE";
62
+ private static final String ACTION_POGOPIN_STATUS_CHANGE = "com.imin.printerservice.PRITER_CONNECT_STATUS_CHANGE";
63
+ private String sdkVersion = "1.0.0";
64
+ private static final String ACTION_PRITER_STATUS = "status";
65
+ private IminPrintUtils.PrintConnectType connectType = IminPrintUtils.PrintConnectType.USB;
66
+ private static final String TAG = "IminPrinterReactNativePlugin";
67
+ private BroadcastReceiver mBroadcastReceiver;
53
68
 
54
69
  public PrinterIminModule(ReactApplicationContext reactContext) {
55
70
  super(reactContext);
56
71
  this.reactContext = reactContext;
57
- if (Build.MODEL.equals("W27_Pro") || Build.MODEL.equals("I23D01") || Build.MODEL.equals("I23M01") || Build.MODEL.equals("I23M02")) {
72
+ List<String> modelList = Arrays.asList(modelArry);
73
+ if (modelList.contains(Build.MODEL)) {
58
74
  //初始化 2.0 的 SDK。
59
75
  PrinterHelper.getInstance().initPrinterService(reactContext);
76
+ sdkVersion = "2.0.0";
60
77
  } else {
61
78
  //初始化 1.0 SDK
79
+
62
80
  iminPrintUtils = IminPrintUtils.getInstance(reactContext);
63
- String deviceModel = SystemPropManager.getModel();
81
+ String deviceModel = Utils.getInstance().getModel();
64
82
  if (deviceModel.contains("M2-203") || deviceModel.contains("M2-202") || deviceModel.contains("M2-Pro")) {
65
83
  connectType = IminPrintUtils.PrintConnectType.SPI;
66
84
  } else {
67
85
  connectType = IminPrintUtils.PrintConnectType.USB;
68
86
  }
87
+ iminPrintUtils.setIsOpenLog(IminPrintUtils.isOpenLog == 1 ? 0 : 1);
69
88
  iminPrintUtils.resetDevice();
89
+ sdkVersion = "1.0.0";
70
90
  }
91
+ initializeBroadcastReceiver();
71
92
  }
72
93
 
73
94
  @Override
@@ -76,12 +97,22 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
76
97
  return NAME;
77
98
  }
78
99
 
100
+ private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
101
+
102
+ try {
103
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
104
+ } catch (RuntimeException e) {
105
+ Log.e(TAG, "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!", e);
106
+ }
107
+ }
79
108
 
80
109
  @ReactMethod
81
110
  public void initPrinter(final Promise promise) {
82
111
  try {
83
112
  if (iminPrintUtils != null) {
84
113
  iminPrintUtils.initPrinter(connectType);
114
+ } else {
115
+ PrinterHelper.getInstance().initPrinter(reactContext.getPackageName(), null);
85
116
  }
86
117
  promise.resolve(true);
87
118
  } catch (Exception e) {
@@ -91,24 +122,37 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
91
122
 
92
123
  @ReactMethod
93
124
  public void getPrinterStatus(final Promise promise) {
94
- WritableMap payload = Arguments.createMap();
95
- if (iminPrintUtils != null) {
96
- if (connectType.equals(IminPrintUtils.PrintConnectType.SPI)) {
97
- iminPrintUtils.getPrinterStatus(connectType, new Callback() {
98
- @Override
99
- public void callback(int status) {
100
- payload.putString("message", getPrinterStatusText(status));
101
- payload.putString("code", String.format("%d", status));
102
- promise.resolve(payload);
103
- }
104
- });
125
+ try {
126
+ WritableMap payload = Arguments.createMap();
127
+ if (iminPrintUtils != null) {
128
+ if (connectType.equals(IminPrintUtils.PrintConnectType.SPI)) {
129
+ iminPrintUtils.getPrinterStatus(connectType, new Callback() {
130
+ @Override
131
+ public void callback(int status) {
132
+ payload.putString("message", Utils.getInstance().getPrinterStatusText(status));
133
+ payload.putString("code", String.format("%d", status));
134
+ promise.resolve(payload);
135
+ }
136
+ });
137
+ } else {
138
+ int status = iminPrintUtils.getPrinterStatus(connectType);
139
+ payload.putString("message", Utils.getInstance().getPrinterStatusText(status));
140
+ payload.putString("code", String.format("%d", status));
141
+ promise.resolve(payload);
142
+ }
105
143
  } else {
106
- int status = iminPrintUtils.getPrinterStatus(connectType);
107
- payload.putString("message", getPrinterStatusText(status));
144
+ int status = PrinterHelper.getInstance().getPrinterStatus();
145
+ payload.putString("message", Utils.getInstance().getPrinterStatusText(status));
108
146
  payload.putString("code", String.format("%d", status));
109
147
  promise.resolve(payload);
110
148
  }
149
+ payload.putString("message", "sdsd");
150
+ payload.putString("code", "1");
151
+ promise.resolve(payload);
152
+ } catch (Exception e) {
153
+ promise.reject("getPrinterStatus_failed", e.getMessage());
111
154
  }
155
+
112
156
  }
113
157
 
114
158
  @ReactMethod
@@ -191,7 +235,9 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
191
235
  public void printText(String text, final Promise promise) {
192
236
  try {
193
237
  if (iminPrintUtils != null) {
194
- iminPrintUtils.printText(text);
238
+ iminPrintUtils.printText(text + "\n");
239
+ } else {
240
+ PrinterHelper.getInstance().printText(text + "\n", null);
195
241
  }
196
242
  promise.resolve(null);
197
243
  } catch (Exception e) {
@@ -228,6 +274,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
228
274
  try {
229
275
  if (iminPrintUtils != null) {
230
276
  iminPrintUtils.printAndLineFeed();
277
+ } else {
278
+ PrinterHelper.getInstance().printAndLineFeed();
231
279
  }
232
280
  promise.resolve(null);
233
281
  } catch (Exception e) {
@@ -240,6 +288,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
240
288
  try {
241
289
  if (iminPrintUtils != null) {
242
290
  iminPrintUtils.printAndFeedPaper(height);
291
+ } else {
292
+ PrinterHelper.getInstance().printAndFeedPaper(height);
243
293
  }
244
294
  promise.resolve(null);
245
295
  } catch (Exception e) {
@@ -259,14 +309,21 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
259
309
  String textColumn = col.getString("text");
260
310
  int widthColumn = col.getInt("width");
261
311
  int alignColumn = col.getInt("align");
312
+ Log.d(TAG, "printColumnsText: colsText" + textColumn);
262
313
  int fontSizeColumn = col.getInt("fontSize");
263
314
  colsText[i] = textColumn;
264
315
  colsWidth[i] = widthColumn;
265
316
  colsAlign[i] = alignColumn;
266
317
  colsFontSize[i] = fontSizeColumn;
267
318
  }
319
+ Log.d(TAG, "printColumnsText: colsText" + colsText);
320
+ Log.d(TAG, "printColumnsText: colsWidth" + colsWidth);
321
+ Log.d(TAG, "printColumnsText: colsAlign" + colsAlign);
322
+ Log.d(TAG, "printColumnsText: colsFontSize" + colsFontSize);
268
323
  if (iminPrintUtils != null) {
269
324
  iminPrintUtils.printColumnsText(colsText, colsWidth, colsAlign, colsFontSize);
325
+ } else {
326
+ PrinterHelper.getInstance().printColumnsText(colsText, colsWidth, colsAlign, colsFontSize, null);
270
327
  }
271
328
  promise.resolve(null);
272
329
  } catch (Exception e) {
@@ -279,6 +336,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
279
336
  try {
280
337
  if (iminPrintUtils != null) {
281
338
  iminPrintUtils.setPageFormat(style);
339
+ } else {
340
+ PrinterHelper.getInstance().setPageFormat(style);
282
341
  }
283
342
  promise.resolve(null);
284
343
  } catch (Exception e) {
@@ -291,6 +350,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
291
350
  try {
292
351
  if (iminPrintUtils != null) {
293
352
  iminPrintUtils.partialCut();
353
+ } else {
354
+ PrinterHelper.getInstance().partialCut();
294
355
  }
295
356
  promise.resolve(null);
296
357
  } catch (Exception e) {
@@ -298,6 +359,18 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
298
359
  }
299
360
  }
300
361
 
362
+ @ReactMethod
363
+ public void fullCut(final Promise promise) {
364
+ try {
365
+ if (iminPrintUtils == null) {
366
+ PrinterHelper.getInstance().fullCut();
367
+ }
368
+ promise.resolve(null);
369
+ } catch (Exception e) {
370
+ promise.reject("fullCut_failed", e.getMessage());
371
+ }
372
+ }
373
+
301
374
  @ReactMethod
302
375
  public void printSingleBitmap(ReadableMap config, final Promise promise) {
303
376
  try {
@@ -306,7 +379,6 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
306
379
  int width = config.getInt("width");
307
380
  int height = config.getInt("height");
308
381
  Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
309
- Log.d("printSingleBitmap", "image:" + image);
310
382
  if (image.isRecycled()) {
311
383
  return;
312
384
  }
@@ -317,10 +389,16 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
317
389
  } else {
318
390
  iminPrintUtils.printSingleBitmap(image);
319
391
  }
392
+ } else {
393
+ if (config.hasKey("align")) {
394
+ int align = config.getInt("align");
395
+ PrinterHelper.getInstance().printBitmapWithAlign(image, align, null);
396
+ } else {
397
+ PrinterHelper.getInstance().printBitmap(image, null);
398
+ }
320
399
  }
321
400
  } else {
322
401
  Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
323
- Log.d("printSingleBitmap", "image:" + image);
324
402
  if (image.isRecycled()) {
325
403
  return;
326
404
  }
@@ -331,10 +409,15 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
331
409
  } else {
332
410
  iminPrintUtils.printSingleBitmap(image);
333
411
  }
412
+ } else {
413
+ if (config.hasKey("align")) {
414
+ int align = config.getInt("align");
415
+ PrinterHelper.getInstance().printBitmapWithAlign(image, align, null);
416
+ } else {
417
+ PrinterHelper.getInstance().printBitmap(image, null);
418
+ }
334
419
  }
335
420
  }
336
-
337
-
338
421
  promise.resolve(null);
339
422
  } catch (Exception e) {
340
423
  promise.reject("printSingleBitmap_failed", e.getMessage());
@@ -344,14 +427,16 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
344
427
  @ReactMethod
345
428
  public void printMultiBitmap(ReadableMap config, final Promise promise) {
346
429
  try {
347
- Log.d("printMultiBitmap", "config:" + config.getArray("urls"));
348
430
  ReadableArray urls = config.getArray("urls");
349
431
  ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
350
432
  if (config.hasKey("width") && config.hasKey("height")) {
351
433
  int width = config.getInt("width");
352
434
  int height = config.getInt("height");
353
435
  for (int i = 0; i < urls.size(); i++) {
354
- bitmaps.add(Glide.with(reactContext).asBitmap().load(urls.getString(i)).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get());
436
+ Bitmap image = Glide.with(reactContext).asBitmap().load(urls.getString(i)).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
437
+ if (!image.isRecycled()) {
438
+ bitmaps.add(image);
439
+ }
355
440
  }
356
441
  if (iminPrintUtils != null) {
357
442
  if (config.hasKey("align")) {
@@ -360,10 +445,20 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
360
445
  } else {
361
446
  iminPrintUtils.printMultiBitmap(bitmaps, 0);
362
447
  }
448
+ } else {
449
+ if (config.hasKey("align")) {
450
+ int align = config.getInt("align");
451
+ PrinterHelper.getInstance().printMultiBitmapWithAlign(bitmaps, align, null);
452
+ } else {
453
+ PrinterHelper.getInstance().printMultiBitmap(bitmaps, null);
454
+ }
363
455
  }
364
456
  } else {
365
457
  for (int i = 0; i < urls.size(); i++) {
366
- bitmaps.add(Glide.with(reactContext).asBitmap().load(urls.getString(i)).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get());
458
+ Bitmap image = Glide.with(reactContext).asBitmap().load(urls.getString(i)).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
459
+ if (!image.isRecycled()) {
460
+ bitmaps.add(image);
461
+ }
367
462
  }
368
463
  if (iminPrintUtils != null) {
369
464
  if (config.hasKey("align")) {
@@ -372,11 +467,15 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
372
467
  } else {
373
468
  iminPrintUtils.printMultiBitmap(bitmaps, 0);
374
469
  }
470
+ } else {
471
+ if (config.hasKey("align")) {
472
+ int align = config.getInt("align");
473
+ PrinterHelper.getInstance().printMultiBitmapWithAlign(bitmaps, align, null);
474
+ } else {
475
+ PrinterHelper.getInstance().printMultiBitmap(bitmaps, null);
476
+ }
375
477
  }
376
478
  }
377
- // // if (image.isRecycled()) {
378
- // // return;
379
- // // }
380
479
  promise.resolve(null);
381
480
  } catch (Exception e) {
382
481
  promise.reject("printMultiBitmap_failed", e.getMessage());
@@ -394,7 +493,6 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
394
493
  if (image.isRecycled()) {
395
494
  return;
396
495
  }
397
- Log.d("printSingleBitmap", "image:" + image);
398
496
  if (iminPrintUtils != null) {
399
497
  iminPrintUtils.printSingleBitmapBlackWhite(image);
400
498
  }
@@ -403,8 +501,6 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
403
501
  if (image.isRecycled()) {
404
502
  return;
405
503
  }
406
- Log.d("printSingleBitmap", "image:" + image);
407
-
408
504
  if (iminPrintUtils != null) {
409
505
  iminPrintUtils.printSingleBitmapBlackWhite(image);
410
506
  }
@@ -420,6 +516,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
420
516
  try {
421
517
  if (iminPrintUtils != null) {
422
518
  iminPrintUtils.setQrCodeSize(qrSize);
519
+ } else {
520
+ PrinterHelper.getInstance().setQrCodeSize(qrSize);
423
521
  }
424
522
  promise.resolve(null);
425
523
  } catch (Exception e) {
@@ -432,6 +530,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
432
530
  try {
433
531
  if (iminPrintUtils != null) {
434
532
  iminPrintUtils.setLeftMargin(margin);
533
+ } else {
534
+ PrinterHelper.getInstance().setLeftMargin(margin);
435
535
  }
436
536
  promise.resolve(null);
437
537
  } catch (Exception e) {
@@ -444,6 +544,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
444
544
  try {
445
545
  if (iminPrintUtils != null) {
446
546
  iminPrintUtils.setBarCodeWidth(width);
547
+ } else {
548
+ PrinterHelper.getInstance().setBarCodeWidth(width);
447
549
  }
448
550
  promise.resolve(null);
449
551
  } catch (Exception e) {
@@ -456,6 +558,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
456
558
  try {
457
559
  if (iminPrintUtils != null) {
458
560
  iminPrintUtils.setBarCodeHeight(height);
561
+ } else {
562
+ PrinterHelper.getInstance().setBarCodeHeight(height);
459
563
  }
460
564
  promise.resolve(null);
461
565
  } catch (Exception e) {
@@ -468,6 +572,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
468
572
  try {
469
573
  if (iminPrintUtils != null) {
470
574
  iminPrintUtils.setBarCodeContentPrintPos(position);
575
+ } else {
576
+ PrinterHelper.getInstance().setBarCodeContentPrintPos(position);
471
577
  }
472
578
  promise.resolve(null);
473
579
  } catch (Exception e) {
@@ -487,6 +593,20 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
487
593
  } else {
488
594
  iminPrintUtils.printBarCode(barCodeType, barCodeContent);
489
595
  }
596
+ } else {
597
+ if (config.hasKey("align")) {
598
+ int barCodeAlign = config.getInt("align");
599
+ if (config.hasKey("position") && config.hasKey("height") && config.hasKey("width")) {
600
+ int position = config.getInt("position");
601
+ int height = config.getInt("height");
602
+ int width = config.getInt("width");
603
+ PrinterHelper.getInstance().printBarCodeWithFull(barCodeContent, barCodeType, width, height, barCodeAlign, position, null);
604
+ } else {
605
+ PrinterHelper.getInstance().printBarCodeWithAlign(barCodeContent, barCodeType, barCodeAlign, null);
606
+ }
607
+ } else {
608
+ PrinterHelper.getInstance().printBarCode(barCodeContent, barCodeType, null);
609
+ }
490
610
  }
491
611
  promise.resolve(null);
492
612
  } catch (Exception e) {
@@ -500,6 +620,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
500
620
  try {
501
621
  if (iminPrintUtils != null) {
502
622
  iminPrintUtils.setDoubleQRSize(size);
623
+ } else {
624
+ PrinterHelper.getInstance().setDoubleQRSize(size);
503
625
  }
504
626
  promise.resolve(null);
505
627
  } catch (Exception e) {
@@ -512,6 +634,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
512
634
  try {
513
635
  if (iminPrintUtils != null) {
514
636
  iminPrintUtils.setDoubleQR1Level(level);
637
+ } else {
638
+ PrinterHelper.getInstance().setDoubleQR1Level(level);
515
639
  }
516
640
  promise.resolve(null);
517
641
  } catch (Exception e) {
@@ -524,6 +648,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
524
648
  try {
525
649
  if (iminPrintUtils != null) {
526
650
  iminPrintUtils.setDoubleQR2Level(level);
651
+ } else {
652
+ PrinterHelper.getInstance().setDoubleQR2Level(level);
527
653
  }
528
654
  promise.resolve(null);
529
655
  } catch (Exception e) {
@@ -536,6 +662,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
536
662
  try {
537
663
  if (iminPrintUtils != null) {
538
664
  iminPrintUtils.setDoubleQR1MarginLeft(leftMargin);
665
+ } else {
666
+ PrinterHelper.getInstance().setDoubleQR1MarginLeft(leftMargin);
539
667
  }
540
668
  promise.resolve(null);
541
669
  } catch (Exception e) {
@@ -548,6 +676,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
548
676
  try {
549
677
  if (iminPrintUtils != null) {
550
678
  iminPrintUtils.setDoubleQR2MarginLeft(leftMargin);
679
+ } else {
680
+ PrinterHelper.getInstance().setDoubleQR2MarginLeft(leftMargin);
551
681
  }
552
682
  promise.resolve(null);
553
683
  } catch (Exception e) {
@@ -560,6 +690,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
560
690
  try {
561
691
  if (iminPrintUtils != null) {
562
692
  iminPrintUtils.setQrCodeErrorCorrectionLev(level);
693
+ } else {
694
+ PrinterHelper.getInstance().setQrCodeErrorCorrectionLev(level);
563
695
  }
564
696
  promise.resolve(null);
565
697
  } catch (Exception e) {
@@ -572,6 +704,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
572
704
  try {
573
705
  if (iminPrintUtils != null) {
574
706
  iminPrintUtils.setDoubleQR1Version(version);
707
+ } else {
708
+ PrinterHelper.getInstance().setDoubleQR1Version(version);
575
709
  }
576
710
  promise.resolve(null);
577
711
  } catch (Exception e) {
@@ -584,6 +718,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
584
718
  try {
585
719
  if (iminPrintUtils != null) {
586
720
  iminPrintUtils.setDoubleQR2Version(version);
721
+ } else {
722
+ PrinterHelper.getInstance().setDoubleQR2Version(version);
587
723
  }
588
724
  promise.resolve(null);
589
725
  } catch (Exception e) {
@@ -595,15 +731,27 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
595
731
  public void printQrCode(ReadableMap config, final Promise promise) {
596
732
  try {
597
733
  String qrStr = config.getString("data");
598
- if (iminPrintUtils != null) {
599
- if (config.hasKey("align")) {
600
- int align = config.getInt("align");
734
+ if (config.hasKey("align")) {
735
+ int align = config.getInt("align");
736
+ if (iminPrintUtils != null) {
601
737
  iminPrintUtils.printQrCode(qrStr, align);
602
738
  } else {
739
+ if (config.hasKey("qrSize") && config.hasKey("level")) {
740
+ int qrSize = config.getInt("qrSize");
741
+ int qrLevel = config.getInt("level");
742
+ PrinterHelper.getInstance().printQRCodeWithFull(qrStr, qrSize, qrLevel, align, null);
743
+ } else {
744
+ PrinterHelper.getInstance().printQrCodeWithAlign(qrStr, align, null);
745
+ }
746
+ }
747
+ } else {
748
+ if (iminPrintUtils != null) {
603
749
  iminPrintUtils.printQrCode(qrStr);
750
+ } else {
751
+ PrinterHelper.getInstance().printQrCode(qrStr, null);
604
752
  }
605
- promise.resolve(null);
606
753
  }
754
+ promise.resolve(null);
607
755
  } catch (Exception e) {
608
756
  promise.reject("printQrCode_failed", e.getMessage());
609
757
  }
@@ -616,6 +764,8 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
616
764
  String qrCode2Text = config.getString("qrCode2Text");
617
765
  if (iminPrintUtils != null) {
618
766
  iminPrintUtils.printDoubleQR(qrCode1Text, qrCode2Text);
767
+ } else {
768
+ PrinterHelper.getInstance().printDoubleQR(qrCode1Text, qrCode2Text, null);
619
769
  }
620
770
  promise.resolve(null);
621
771
  } catch (Exception e) {
@@ -625,17 +775,20 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
625
775
 
626
776
  @ReactMethod
627
777
  public void openCashBox(final Promise promise) {
628
- try {
629
- if (iminPrintUtils != null) {
630
- iminPrintUtils.openCashBox();
631
- }
632
- promise.resolve(null);
633
- } catch (Exception e) {
778
+ try {
779
+ if (iminPrintUtils != null) {
780
+ Utils.getInstance().opencashBox();
781
+ } else {
782
+ PrinterHelper.getInstance().openDrawer();
783
+ }
784
+ promise.resolve(null);
785
+ } catch (Exception e) {
634
786
  promise.reject("openCashBox_failed", e.getMessage());
635
787
  }
636
788
 
637
789
  }
638
790
 
791
+
639
792
  @ReactMethod
640
793
  public void setInitIminPrinter(boolean isDefault, final Promise promise) {
641
794
  try {
@@ -654,32 +807,828 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
654
807
  if (iminPrintUtils != null) {
655
808
  iminPrintUtils.resetDevice();
656
809
  }
810
+ promise.resolve(null);
657
811
  } catch (Exception e) {
658
812
  promise.reject("resetDevice_failed", e.getMessage());
659
813
  }
660
814
  }
661
815
 
662
- private String getPrinterStatusText(int code) {
663
- if (code == 0) {
664
- return "Printer is normal!";
665
- } else if (code == 1) {
666
- return "The printer and call library do not match!";
667
- } else if (code == 3) {
668
- return "Print head open!";
669
- } else if (code == 4) {
670
- return "The cutter is not reset!!";
671
- } else if (code == 5) {
672
- return "Overheated!";
673
- } else if (code == 6) {
674
- return "Black label error!";
675
- } else if (code == 7) {
676
- return "Paper Jam!";
677
- } else if (code == 8) {
678
- return "Paper Out!";
679
- } else if (code == 99) {
680
- return "Other errors!";
681
- } else {
682
- return "Printer is not connected or powered on!";
816
+ @ReactMethod
817
+ public void printerSelfChecking(final Promise promise) {
818
+ try {
819
+ if (iminPrintUtils == null) {
820
+ PrinterHelper.getInstance().printerSelfChecking(null);
821
+ }
822
+ promise.resolve(null);
823
+ } catch (Exception e) {
824
+ promise.reject("printerSelfChecking_failed", e.getMessage());
825
+ }
826
+ }
827
+
828
+ @ReactMethod
829
+ public void printSingleBitmapColorChart(ReadableMap config, final Promise promise) {
830
+ try {
831
+ String url = config.getString("url");
832
+ if (config.hasKey("width") && config.hasKey("height")) {
833
+ int width = config.getInt("width");
834
+ int height = config.getInt("height");
835
+ Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
836
+ if (image.isRecycled()) {
837
+ return;
838
+ }
839
+ if (iminPrintUtils == null) {
840
+ if (config.hasKey("align")) {
841
+ int align = config.getInt("align");
842
+ PrinterHelper.getInstance().printBitmapColorChartWithAlign(image, align, null);
843
+ } else {
844
+ PrinterHelper.getInstance().printBitmapColorChart(image, null);
845
+ }
846
+ }
847
+ } else {
848
+ Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
849
+ if (image.isRecycled()) {
850
+ return;
851
+ }
852
+ if (iminPrintUtils == null) {
853
+ if (config.hasKey("align")) {
854
+ int align = config.getInt("align");
855
+ PrinterHelper.getInstance().printBitmapColorChartWithAlign(image, align, null);
856
+ } else {
857
+ PrinterHelper.getInstance().printBitmapColorChart(image, null);
858
+ }
859
+ }
860
+ }
861
+ promise.resolve(null);
862
+ } catch (Exception e) {
863
+ promise.reject("printSingleBitmap_failed", e.getMessage());
864
+ }
865
+ }
866
+
867
+
868
+ @ReactMethod
869
+ public void sendRAWData(ReadableArray bytes, final Promise promise) {
870
+ try {
871
+ // 处理接收到的 Uint8Array 数据
872
+ byte[] rawData = new byte[bytes.size()];
873
+ for (int i = 0; i < bytes.size(); i++) {
874
+ rawData[i] = (byte) bytes.getInt(i);
875
+ }
876
+ if (iminPrintUtils == null) {
877
+ PrinterHelper.getInstance().sendRAWData(rawData, null);
878
+ }
879
+ promise.resolve(null);
880
+ } catch (Exception e) {
881
+ promise.reject("sendRAWData_failed", e.getMessage());
882
+ }
883
+ }
884
+
885
+ @ReactMethod
886
+ public void printColumnsString(ReadableArray cols, final Promise promise) {
887
+ try {
888
+ String[] colsText = new String[cols.size()];
889
+ int[] colsWidth = new int[cols.size()];
890
+ int[] colsAlign = new int[cols.size()];
891
+ int[] colsFontSize = new int[cols.size()];
892
+ for (int i = 0; i < cols.size(); i++) {
893
+ ReadableMap col = cols.getMap(i);
894
+ String textColumn = col.getString("text");
895
+ int widthColumn = col.getInt("width");
896
+ int alignColumn = col.getInt("align");
897
+ int fontSizeColumn = col.getInt("fontSize");
898
+ colsText[i] = textColumn;
899
+ colsWidth[i] = widthColumn;
900
+ colsAlign[i] = alignColumn;
901
+ colsFontSize[i] = fontSizeColumn;
902
+ }
903
+ if (iminPrintUtils == null) {
904
+ PrinterHelper.getInstance().printColumnsString(colsText, colsWidth, colsAlign, colsFontSize, null);
905
+ }
906
+ promise.resolve(null);
907
+ } catch (Exception e) {
908
+ promise.reject("printColumnsString_failed", e.getMessage());
909
+ }
910
+ }
911
+
912
+ @ReactMethod
913
+ public void unBindService(final Promise promise) {
914
+ try {
915
+ if (iminPrintUtils == null) {
916
+ PrinterHelper.getInstance().deInitPrinterService(reactContext);
917
+ }
918
+ } catch (Exception e) {
919
+ promise.reject("unBindService_failed", e.getMessage());
920
+ }
921
+ }
922
+
923
+ @ReactMethod
924
+ public void initPrinterParams(final Promise promise) {
925
+ try {
926
+ if (iminPrintUtils == null) {
927
+ PrinterHelper.getInstance().initPrinterParams();
928
+ }
929
+ promise.resolve(null);
930
+ } catch (Exception e) {
931
+ promise.reject("initPrinterParams_failed", e.getMessage());
932
+ }
933
+ }
934
+
935
+ @ReactMethod
936
+ public void getFontCodepage(final Promise promise) {
937
+ try {
938
+ if (iminPrintUtils == null) {
939
+ List<String> fontCodepage = PrinterHelper.getInstance().getFontCodepage();
940
+ promise.resolve(fontCodepage);
941
+ } else {
942
+ promise.resolve(null);
943
+ }
944
+ } catch (Exception e) {
945
+ promise.reject("getFontCodepage_failed", e.getMessage());
946
+ }
947
+ }
948
+
949
+ @ReactMethod
950
+ public void setFontCodepage(int codepage, final Promise promise) {
951
+ try {
952
+ if (iminPrintUtils == null) {
953
+ PrinterHelper.getInstance().setFontCodepage(codepage);
954
+ }
955
+ promise.resolve(null);
956
+ } catch (Exception e) {
957
+ promise.reject("setFontCodepage_failed", e.getMessage());
958
+ }
959
+ }
960
+
961
+ @ReactMethod
962
+ public void getCurCodepage(final Promise promise) {
963
+ try {
964
+ if (iminPrintUtils == null) {
965
+ String curCodepage = PrinterHelper.getInstance().getCurCodepage();
966
+ promise.resolve(curCodepage);
967
+ } else {
968
+ promise.resolve(null);
969
+ }
970
+ } catch (Exception e) {
971
+ promise.reject("getCurCodepage_failed", e.getMessage());
972
+ }
973
+ }
974
+
975
+ @ReactMethod
976
+ public void getEncodeList(final Promise promise) {
977
+ try {
978
+ if (iminPrintUtils == null) {
979
+ List<String> encodeList = PrinterHelper.getInstance().getEncodeList();
980
+ promise.resolve(encodeList);
981
+ } else {
982
+ promise.resolve(null);
983
+ }
984
+ } catch (Exception e) {
985
+ promise.reject("getEncodeList_failed", e.getMessage());
986
+ }
987
+ }
988
+
989
+ @ReactMethod
990
+ public void setPrinterEncode(int encode, final Promise promise) {
991
+ try {
992
+ if (iminPrintUtils == null) {
993
+ PrinterHelper.getInstance().setPrinterEncode(encode);
994
+ }
995
+ promise.resolve(null);
996
+ } catch (Exception e) {
997
+ promise.reject("setPrinterEncode_failed", e.getMessage());
998
+ }
999
+ }
1000
+
1001
+ @ReactMethod
1002
+ public void getCurEncode(final Promise promise) {
1003
+ try {
1004
+ if (iminPrintUtils == null) {
1005
+ String curEncode = PrinterHelper.getInstance().getCurEncode();
1006
+ promise.resolve(curEncode);
1007
+ } else {
1008
+ promise.resolve(null);
1009
+ }
1010
+ } catch (Exception e) {
1011
+ promise.reject("getCurEncode_failed", e.getMessage());
1012
+ }
1013
+ }
1014
+
1015
+ @ReactMethod
1016
+ public void getPrinterDensityList(final Promise promise) {
1017
+ try {
1018
+ if (iminPrintUtils == null) {
1019
+ List<String> printerDensityList = PrinterHelper.getInstance().getPrinterDensityList();
1020
+ promise.resolve(printerDensityList);
1021
+ } else {
1022
+ promise.resolve(null);
1023
+ }
1024
+ } catch (Exception e) {
1025
+ promise.reject("getPrinterDensityList_failed", e.getMessage());
1026
+ }
1027
+ }
1028
+
1029
+ @ReactMethod
1030
+ public void setPrinterDensity(int density, final Promise promise) {
1031
+ try {
1032
+ if (iminPrintUtils == null) {
1033
+ PrinterHelper.getInstance().setPrinterDensity(density);
1034
+ }
1035
+ promise.resolve(null);
1036
+ } catch (Exception e) {
1037
+ promise.reject("setPrinterDensity_failed", e.getMessage());
683
1038
  }
684
1039
  }
1040
+
1041
+ @ReactMethod
1042
+ public void getPrinterDensity(final Promise promise) {
1043
+ try {
1044
+ if (iminPrintUtils == null) {
1045
+ promise.resolve(PrinterHelper.getInstance().getPrinterDensity());
1046
+ } else {
1047
+ promise.resolve(null);
1048
+ }
1049
+
1050
+ } catch (Exception e) {
1051
+ promise.reject("getPrinterDensity_failed", e.getMessage());
1052
+ }
1053
+ }
1054
+
1055
+ @ReactMethod
1056
+ public void getPrinterSpeedList(final Promise promise) {
1057
+ try {
1058
+ if (iminPrintUtils == null) {
1059
+ List<String> printerSpeedList = PrinterHelper.getInstance().getPrinterSpeedList();
1060
+ promise.resolve(printerSpeedList);
1061
+ } else {
1062
+ promise.resolve(null);
1063
+ }
1064
+
1065
+ } catch (Exception e) {
1066
+ promise.reject("getPrinterSpeedList_failed", e.getMessage());
1067
+ }
1068
+ }
1069
+
1070
+ @ReactMethod
1071
+ public void setPrinterSpeed(int speed, final Promise promise) {
1072
+ try {
1073
+ if (iminPrintUtils == null) {
1074
+ PrinterHelper.getInstance().setPrinterSpeed(speed);
1075
+ }
1076
+ promise.resolve(null);
1077
+ } catch (Exception e) {
1078
+ promise.reject("setPrinterSpeed_failed", e.getMessage());
1079
+ }
1080
+ }
1081
+
1082
+ @ReactMethod
1083
+ public void getPrinterSpeed(final Promise promise) {
1084
+ try {
1085
+ if (iminPrintUtils == null) {
1086
+ int printerSpeed = PrinterHelper.getInstance().getPrinterSpeed();
1087
+ promise.resolve(printerSpeed);
1088
+ } else {
1089
+ promise.resolve(null);
1090
+ }
1091
+ } catch (Exception e) {
1092
+ promise.reject("getPrinterSpeed_failed", e.getMessage());
1093
+ }
1094
+ }
1095
+
1096
+ @ReactMethod
1097
+ public void getPrinterPaperTypeList(final Promise promise) {
1098
+ try {
1099
+ if (iminPrintUtils == null) {
1100
+ List<String> printerPaperTypeList = PrinterHelper.getInstance().getPrinterPaperTypeList();
1101
+ promise.resolve(printerPaperTypeList);
1102
+ } else {
1103
+ promise.resolve(null);
1104
+ }
1105
+ } catch (Exception e) {
1106
+ promise.reject("getPrinterPaperTypeList_failed", e.getMessage());
1107
+ }
1108
+ }
1109
+
1110
+ @ReactMethod
1111
+ public void getPrinterPaperType(final Promise promise) {
1112
+ try {
1113
+ if (iminPrintUtils == null) {
1114
+ promise.resolve(PrinterHelper.getInstance().getPrinterPaperType());
1115
+ } else {
1116
+ promise.resolve(null);
1117
+ }
1118
+ } catch (Exception e) {
1119
+ promise.reject("getPrinterPaperType_failed", e.getMessage());
1120
+ }
1121
+ }
1122
+
1123
+ @ReactMethod
1124
+ public void getPrinterSerialNumber(final Promise promise) {
1125
+ try {
1126
+ if (iminPrintUtils == null) {
1127
+ PrinterHelper.getInstance().getPrinterSerialNumber(new INeoPrinterCallback() {
1128
+ @Override
1129
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1130
+ }
1131
+
1132
+ @Override
1133
+ public void onReturnString(String s) throws RemoteException {
1134
+ promise.resolve(s);
1135
+ }
1136
+
1137
+ @Override
1138
+ public void onRaiseException(int code, String msg) throws RemoteException {
1139
+ }
1140
+
1141
+ @Override
1142
+ public void onPrintResult(int code, String msg) throws RemoteException {
1143
+ }
1144
+ });
1145
+ } else {
1146
+ promise.resolve(null);
1147
+ }
1148
+ } catch (Exception e) {
1149
+ promise.reject("getPrinterSerialNumber_failed", e.getMessage());
1150
+ }
1151
+ }
1152
+
1153
+ @ReactMethod
1154
+ public void getPrinterModelName(final Promise promise) {
1155
+ try {
1156
+ if (iminPrintUtils == null) {
1157
+ PrinterHelper.getInstance().getPrinterModelName(new INeoPrinterCallback() {
1158
+ @Override
1159
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1160
+ }
1161
+
1162
+ @Override
1163
+ public void onReturnString(String s) throws RemoteException {
1164
+ promise.resolve(s);
1165
+ }
1166
+
1167
+ @Override
1168
+ public void onRaiseException(int code, String msg) throws RemoteException {
1169
+ }
1170
+
1171
+ @Override
1172
+ public void onPrintResult(int code, String msg) throws RemoteException {
1173
+ }
1174
+ });
1175
+ } else {
1176
+ promise.resolve(null);
1177
+ }
1178
+ } catch (Exception e) {
1179
+ promise.reject("getPrinterModelName_failed", e.getMessage());
1180
+ }
1181
+ }
1182
+
1183
+ @ReactMethod
1184
+ public void getPrinterThermalHead(final Promise promise) {
1185
+ try {
1186
+ if (iminPrintUtils == null) {
1187
+ PrinterHelper.getInstance().getPrinterThermalHead(new INeoPrinterCallback() {
1188
+ @Override
1189
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1190
+ }
1191
+
1192
+ @Override
1193
+ public void onReturnString(String s) throws RemoteException {
1194
+ promise.resolve(s);
1195
+ }
1196
+
1197
+ @Override
1198
+ public void onRaiseException(int code, String msg) throws RemoteException {
1199
+ }
1200
+
1201
+ @Override
1202
+ public void onPrintResult(int code, String msg) throws RemoteException {
1203
+ }
1204
+ });
1205
+ } else {
1206
+ promise.resolve(null);
1207
+ }
1208
+ } catch (Exception e) {
1209
+ promise.reject("getPrinterThermalHead_failed", e.getMessage());
1210
+ }
1211
+ }
1212
+
1213
+ @ReactMethod
1214
+ public void getPrinterFirmwareVersion(final Promise promise) {
1215
+ try {
1216
+ if (iminPrintUtils == null) {
1217
+ PrinterHelper.getInstance().getPrinterFirmwareVersion(new INeoPrinterCallback() {
1218
+ @Override
1219
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1220
+ }
1221
+
1222
+ @Override
1223
+ public void onReturnString(String s) throws RemoteException {
1224
+ promise.resolve(s);
1225
+ }
1226
+
1227
+ @Override
1228
+ public void onRaiseException(int code, String msg) throws RemoteException {
1229
+ }
1230
+
1231
+ @Override
1232
+ public void onPrintResult(int code, String msg) throws RemoteException {
1233
+ }
1234
+ });
1235
+ } else {
1236
+ promise.resolve(null);
1237
+ }
1238
+ } catch (Exception e) {
1239
+ promise.reject("getPrinterFirmwareVersion_failed", e.getMessage());
1240
+ }
1241
+ }
1242
+
1243
+ @ReactMethod
1244
+ public void getPrinterHardwareVersion(final Promise promise) {
1245
+ try {
1246
+ if (iminPrintUtils == null) {
1247
+ PrinterHelper.getInstance().getPrinterHardwareVersion(new INeoPrinterCallback() {
1248
+ @Override
1249
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1250
+ }
1251
+
1252
+ @Override
1253
+ public void onReturnString(String s) throws RemoteException {
1254
+ promise.resolve(s);
1255
+ }
1256
+
1257
+ @Override
1258
+ public void onRaiseException(int code, String msg) throws RemoteException {
1259
+ }
1260
+
1261
+ @Override
1262
+ public void onPrintResult(int code, String msg) throws RemoteException {
1263
+ }
1264
+ });
1265
+ } else {
1266
+ promise.resolve(null);
1267
+ }
1268
+ } catch (Exception e) {
1269
+ promise.reject("getPrinterHardwareVersion_failed", e.getMessage());
1270
+ }
1271
+ }
1272
+
1273
+ @ReactMethod
1274
+ public void getPrinterPaperDistance(final Promise promise) {
1275
+ try {
1276
+ if (iminPrintUtils == null) {
1277
+ PrinterHelper.getInstance().getPrinterPaperDistance(new INeoPrinterCallback() {
1278
+ @Override
1279
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1280
+ }
1281
+
1282
+ @Override
1283
+ public void onReturnString(String s) throws RemoteException {
1284
+ promise.resolve(s);
1285
+ }
1286
+
1287
+ @Override
1288
+ public void onRaiseException(int code, String msg) throws RemoteException {
1289
+ }
1290
+
1291
+ @Override
1292
+ public void onPrintResult(int code, String msg) throws RemoteException {
1293
+ }
1294
+ });
1295
+ } else {
1296
+ promise.resolve(null);
1297
+ }
1298
+ } catch (Exception e) {
1299
+ promise.reject("getPrinterPaperDistance_failed", e.getMessage());
1300
+ }
1301
+ }
1302
+
1303
+ @ReactMethod
1304
+ public void getPrinterCutTimes(final Promise promise) {
1305
+ try {
1306
+ if (iminPrintUtils == null) {
1307
+ PrinterHelper.getInstance().getPrinterCutTimes(new INeoPrinterCallback() {
1308
+ @Override
1309
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1310
+ }
1311
+
1312
+ @Override
1313
+ public void onReturnString(String s) throws RemoteException {
1314
+ promise.resolve(s);
1315
+ }
1316
+
1317
+ @Override
1318
+ public void onRaiseException(int code, String msg) throws RemoteException {
1319
+ }
1320
+
1321
+ @Override
1322
+ public void onPrintResult(int code, String msg) throws RemoteException {
1323
+ }
1324
+ });
1325
+ } else {
1326
+ promise.resolve(null);
1327
+ }
1328
+ } catch (Exception e) {
1329
+ promise.reject("getPrinterCutTimes_failed", e.getMessage());
1330
+ }
1331
+ }
1332
+
1333
+
1334
+ @ReactMethod
1335
+ public void getPrinterMode(final Promise promise) {
1336
+ try {
1337
+ if (iminPrintUtils == null) {
1338
+ promise.resolve(PrinterHelper.getInstance().getPrinterMode());
1339
+ } else {
1340
+ promise.resolve(null);
1341
+ }
1342
+ } catch (Exception e) {
1343
+ promise.reject("getPrinterMode_failed", e.getMessage());
1344
+ }
1345
+ }
1346
+
1347
+ @ReactMethod
1348
+ public void getDrawerStatus(final Promise promise) {
1349
+ try {
1350
+ if (iminPrintUtils == null) {
1351
+ promise.resolve(PrinterHelper.getInstance().getDrawerStatus());
1352
+ } else {
1353
+ promise.resolve(null);
1354
+ }
1355
+ } catch (Exception e) {
1356
+ promise.reject("getDrawerStatus_failed", e.getMessage());
1357
+ }
1358
+ }
1359
+
1360
+ @ReactMethod
1361
+ public void getOpenDrawerTimes(final Promise promise) {
1362
+ try {
1363
+ if (iminPrintUtils == null) {
1364
+ promise.resolve(PrinterHelper.getInstance().getOpenDrawerTimes());
1365
+ } else {
1366
+ promise.resolve(null);
1367
+ }
1368
+ } catch (Exception e) {
1369
+ promise.reject("getOpenDrawerTimes_failed", e.getMessage());
1370
+ }
1371
+ }
1372
+
1373
+ @ReactMethod
1374
+ public void getServiceVersion(final Promise promise) {
1375
+ try {
1376
+ if (iminPrintUtils == null) {
1377
+ promise.resolve(PrinterHelper.getInstance().getServiceVersion());
1378
+ } else {
1379
+ promise.resolve(null);
1380
+ }
1381
+ } catch (Exception e) {
1382
+ promise.reject("getServiceVersion_failed", e.getMessage());
1383
+ }
1384
+ }
1385
+
1386
+ @ReactMethod
1387
+ public void getUsbPrinterVidPid(final Promise promise) {
1388
+ try {
1389
+ if (iminPrintUtils == null) {
1390
+ promise.resolve(PrinterHelper.getInstance().getUsbPrinterVidPid());
1391
+ } else {
1392
+ promise.resolve(null);
1393
+ }
1394
+ } catch (Exception e) {
1395
+ promise.reject("getUsbPrinterVidPid_failed", e.getMessage());
1396
+ }
1397
+ }
1398
+
1399
+ @ReactMethod
1400
+ public void getUsbDevicesName(final Promise promise) {
1401
+ try {
1402
+ if (iminPrintUtils == null) {
1403
+ promise.resolve(PrinterHelper.getInstance().getUsbDevicesName());
1404
+ } else {
1405
+ promise.resolve(null);
1406
+ }
1407
+ } catch (Exception e) {
1408
+ promise.reject("getUsbDevicesName_failed", e.getMessage());
1409
+ }
1410
+ }
1411
+
1412
+
1413
+ @ReactMethod
1414
+ public void setCodeAlignment(int align, final Promise promise) {
1415
+ try {
1416
+ if (iminPrintUtils == null) {
1417
+ PrinterHelper.getInstance().setCodeAlignment(align);
1418
+ }
1419
+ promise.resolve(null);
1420
+ } catch (Exception e) {
1421
+ promise.reject("setCodeAlignment_failed", e.getMessage());
1422
+ }
1423
+ }
1424
+
1425
+ @ReactMethod
1426
+ public void setTextBitmapTypeface(int typeface, final Promise promise) {
1427
+ try {
1428
+ if (iminPrintUtils == null) {
1429
+ switch (typeface) {
1430
+ case 1:
1431
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.MONOSPACE");
1432
+ break;
1433
+ case 2:
1434
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.DEFAULT_BOLD");
1435
+ break;
1436
+ case 3:
1437
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.SANS_SERIF");
1438
+ break;
1439
+ case 4:
1440
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.SERIF");
1441
+ break;
1442
+ default:
1443
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.DEFAULT");
1444
+ break;
1445
+ }
1446
+ }
1447
+ promise.resolve(null);
1448
+ } catch (Exception e) {
1449
+ promise.reject("setTextBitmapTypeface_failed", e.getMessage());
1450
+ }
1451
+ }
1452
+
1453
+ @ReactMethod
1454
+ public void setTextBitmapSize(int size, final Promise promise) {
1455
+ try {
1456
+ if (iminPrintUtils == null) {
1457
+ PrinterHelper.getInstance().setTextBitmapSize(size);
1458
+ }
1459
+ promise.resolve(null);
1460
+ } catch (Exception e) {
1461
+ promise.reject("setTextBitmapSize_failed", e.getMessage());
1462
+ }
1463
+ }
1464
+
1465
+ @ReactMethod
1466
+ public void setTextBitmapStyle(int style, final Promise promise) {
1467
+ try {
1468
+ if (iminPrintUtils == null) {
1469
+ PrinterHelper.getInstance().setTextBitmapStyle(style);
1470
+ }
1471
+ promise.resolve(null);
1472
+ } catch (Exception e) {
1473
+ promise.reject("setTextBitmapStyle_failed", e.getMessage());
1474
+ }
1475
+ }
1476
+
1477
+ @ReactMethod
1478
+ public void setTextBitmapStrikeThru(boolean strikeThru, final Promise promise) {
1479
+ try {
1480
+ if (iminPrintUtils == null) {
1481
+ PrinterHelper.getInstance().setTextBitmapStrikeThru(strikeThru);
1482
+ }
1483
+ promise.resolve(null);
1484
+ } catch (Exception e) {
1485
+ promise.reject("setTextBitmapStrikeThru_failed", e.getMessage());
1486
+ }
1487
+ }
1488
+
1489
+ @ReactMethod
1490
+ public void setTextBitmapUnderline(boolean haveUnderline, final Promise promise) {
1491
+ try {
1492
+ if (iminPrintUtils == null) {
1493
+ PrinterHelper.getInstance().setTextBitmapUnderline(haveUnderline);
1494
+ }
1495
+ promise.resolve(null);
1496
+ } catch (Exception e) {
1497
+ promise.reject("setTextBitmapUnderline_failed", e.getMessage());
1498
+ }
1499
+ }
1500
+
1501
+ @ReactMethod
1502
+ public void setTextBitmapLineSpacing(float lineHeight, final Promise promise) {
1503
+ try {
1504
+ if (iminPrintUtils == null) {
1505
+ PrinterHelper.getInstance().setTextBitmapLineSpacing(lineHeight);
1506
+ }
1507
+ promise.resolve(null);
1508
+ } catch (Exception e) {
1509
+ promise.reject("setTextBitmapLineSpacing_failed", e.getMessage());
1510
+ }
1511
+ }
1512
+
1513
+ @ReactMethod
1514
+ public void setTextBitmapLetterSpacing(float space, final Promise promise) {
1515
+ try {
1516
+ if (iminPrintUtils == null) {
1517
+ PrinterHelper.getInstance().setTextBitmapLetterSpacing(space);
1518
+ }
1519
+ promise.resolve(null);
1520
+ } catch (Exception e) {
1521
+ promise.reject("setTextBitmapLetterSpacing_failed", e.getMessage());
1522
+ }
1523
+ }
1524
+
1525
+ @ReactMethod
1526
+ public void setTextBitmapAntiWhite(boolean antiWhite, final Promise promise) {
1527
+ try {
1528
+ if (iminPrintUtils == null) {
1529
+ PrinterHelper.getInstance().setTextBitmapAntiWhite(antiWhite);
1530
+ }
1531
+ promise.resolve(null);
1532
+ } catch (Exception e) {
1533
+ promise.reject("setTextBitmapAntiWhite_failed", e.getMessage());
1534
+ }
1535
+ }
1536
+
1537
+ @ReactMethod
1538
+ public void printTextBitmap(ReadableMap config, final Promise promise) {
1539
+ try {
1540
+ if (iminPrintUtils == null) {
1541
+ String text = config.getString("text");
1542
+ if (config.hasKey("align")) {
1543
+ int align = config.getInt("align");
1544
+ PrinterHelper.getInstance().printTextBitmapWithAli(text + "\n", align, null);
1545
+ } else {
1546
+ PrinterHelper.getInstance().printTextBitmap(text + "\n", null);
1547
+ }
1548
+ }
1549
+ promise.resolve(null);
1550
+ } catch (Exception e) {
1551
+ promise.reject("printTextBitmap_failed", e.getMessage());
1552
+ }
1553
+ }
1554
+
1555
+ @ReactMethod
1556
+ public void enterPrinterBuffer(boolean isClean, final Promise promise) {
1557
+ try {
1558
+ if (iminPrintUtils == null) {
1559
+ PrinterHelper.getInstance().enterPrinterBuffer(isClean);
1560
+ }
1561
+ promise.resolve(null);
1562
+ } catch (Exception e) {
1563
+ promise.reject("enterPrinterBuffer_failed", e.getMessage());
1564
+ }
1565
+ }
1566
+
1567
+ @ReactMethod
1568
+ public void commitPrinterBuffer(final Promise promise) {
1569
+ try {
1570
+ if (iminPrintUtils == null) {
1571
+ PrinterHelper.getInstance().commitPrinterBuffer(null);
1572
+ }
1573
+ promise.resolve(null);
1574
+ } catch (Exception e) {
1575
+ promise.reject("commitPrinterBuffer_failed", e.getMessage());
1576
+ }
1577
+ }
1578
+
1579
+ @ReactMethod
1580
+ public void exitPrinterBuffer(boolean isCommit, final Promise promise) {
1581
+ try {
1582
+ if (iminPrintUtils == null) {
1583
+ PrinterHelper.getInstance().exitPrinterBuffer(isCommit);
1584
+ }
1585
+ promise.resolve(null);
1586
+ } catch (Exception e) {
1587
+ promise.reject("exitPrinterBuffer_failed", e.getMessage());
1588
+ }
1589
+ }
1590
+
1591
+ private BroadcastReceiver createChargingStateBroadcastReceiver() {
1592
+ return new BroadcastReceiver() {
1593
+ @Override
1594
+ public void onReceive(Context context, Intent intent) {
1595
+ int status = intent.getIntExtra(ACTION_PRITER_STATUS, -1);
1596
+ Log.d(TAG, "打印机状态:" + intent.getAction());
1597
+ // 发送事件到React Native
1598
+ if (intent.getAction().equals(ACTION_PRITER_STATUS_CHANGE)) {
1599
+ WritableMap result = Arguments.createMap();
1600
+ WritableMap payload = Arguments.createMap();
1601
+ payload.putString("message", Utils.getInstance().getPrinterStatusText(status));
1602
+ payload.putString("code", String.format("%d", status));
1603
+ result.putMap("eventData", payload);
1604
+ result.putString("eventName", "printer_status");
1605
+ sendEvent(reactContext, "eventBroadcast", result);
1606
+ }
1607
+ }
1608
+ };
1609
+ }
1610
+
1611
+ private void initializeBroadcastReceiver() {
1612
+ IntentFilter intentFilter = new IntentFilter();
1613
+ mBroadcastReceiver = createChargingStateBroadcastReceiver();
1614
+ intentFilter.addAction(ACTION_PRITER_STATUS_CHANGE);
1615
+ intentFilter.addAction(ACTION_POGOPIN_STATUS_CHANGE);
1616
+ getReactApplicationContext().registerReceiver(mBroadcastReceiver, intentFilter);
1617
+ }
1618
+
1619
+ @ReactMethod
1620
+ public void addListener(String eventName) {
1621
+ }
1622
+
1623
+ @ReactMethod
1624
+ public void removeListeners(Integer count) {
1625
+ }
1626
+
1627
+ @Override
1628
+ public Map<String, Object> getConstants() {
1629
+ final Map<String, Object> constants = new HashMap<>();
1630
+ constants.put("SDK_VERSION_IMIN", sdkVersion);
1631
+ return constants;
1632
+ }
1633
+
685
1634
  }