react-native-printer-imin 0.4.2 → 0.6.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,852 @@ 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 openLogs(int open, final Promise promise) {
830
+ try {
831
+ if (iminPrintUtils != null) {
832
+ iminPrintUtils.setIsOpenLog(open);
833
+ }
834
+ promise.resolve(null);
835
+ } catch (Exception e) {
836
+ promise.reject("setIsOpenLog_failed", e.getMessage());
837
+ }
838
+ }
839
+
840
+ @ReactMethod
841
+ public void sendRAWDataHexStr(String byteStr, final Promise promise) {
842
+ try {
843
+ if (iminPrintUtils != null) {
844
+ iminPrintUtils.sendRAWData(byteStr);
845
+ }
846
+ promise.resolve(null);
847
+ } catch (Exception e) {
848
+ promise.reject("sendRAWDataHexStr_failed", e.getMessage());
849
+ }
850
+ }
851
+
852
+ @ReactMethod
853
+ public void printSingleBitmapColorChart(ReadableMap config, final Promise promise) {
854
+ try {
855
+ String url = config.getString("url");
856
+ if (config.hasKey("width") && config.hasKey("height")) {
857
+ int width = config.getInt("width");
858
+ int height = config.getInt("height");
859
+ Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
860
+ if (image.isRecycled()) {
861
+ return;
862
+ }
863
+ if (iminPrintUtils == null) {
864
+ if (config.hasKey("align")) {
865
+ int align = config.getInt("align");
866
+ PrinterHelper.getInstance().printBitmapColorChartWithAlign(image, align, null);
867
+ } else {
868
+ PrinterHelper.getInstance().printBitmapColorChart(image, null);
869
+ }
870
+ }
871
+ } else {
872
+ Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
873
+ if (image.isRecycled()) {
874
+ return;
875
+ }
876
+ if (iminPrintUtils == null) {
877
+ if (config.hasKey("align")) {
878
+ int align = config.getInt("align");
879
+ PrinterHelper.getInstance().printBitmapColorChartWithAlign(image, align, null);
880
+ } else {
881
+ PrinterHelper.getInstance().printBitmapColorChart(image, null);
882
+ }
883
+ }
884
+ }
885
+ promise.resolve(null);
886
+ } catch (Exception e) {
887
+ promise.reject("printSingleBitmap_failed", e.getMessage());
888
+ }
889
+ }
890
+
891
+
892
+ @ReactMethod
893
+ public void sendRAWData(ReadableArray bytes, final Promise promise) {
894
+ try {
895
+ // 处理接收到的 Uint8Array 数据
896
+ byte[] rawData = new byte[bytes.size()];
897
+ for (int i = 0; i < bytes.size(); i++) {
898
+ rawData[i] = (byte) bytes.getInt(i);
899
+ }
900
+ if (iminPrintUtils == null) {
901
+ PrinterHelper.getInstance().sendRAWData(rawData, null);
902
+ }
903
+ promise.resolve(null);
904
+ } catch (Exception e) {
905
+ promise.reject("sendRAWData_failed", e.getMessage());
906
+ }
907
+ }
908
+
909
+ @ReactMethod
910
+ public void printColumnsString(ReadableArray cols, final Promise promise) {
911
+ try {
912
+ String[] colsText = new String[cols.size()];
913
+ int[] colsWidth = new int[cols.size()];
914
+ int[] colsAlign = new int[cols.size()];
915
+ int[] colsFontSize = new int[cols.size()];
916
+ for (int i = 0; i < cols.size(); i++) {
917
+ ReadableMap col = cols.getMap(i);
918
+ String textColumn = col.getString("text");
919
+ int widthColumn = col.getInt("width");
920
+ int alignColumn = col.getInt("align");
921
+ int fontSizeColumn = col.getInt("fontSize");
922
+ colsText[i] = textColumn;
923
+ colsWidth[i] = widthColumn;
924
+ colsAlign[i] = alignColumn;
925
+ colsFontSize[i] = fontSizeColumn;
926
+ }
927
+ if (iminPrintUtils == null) {
928
+ PrinterHelper.getInstance().printColumnsString(colsText, colsWidth, colsAlign, colsFontSize, null);
929
+ }
930
+ promise.resolve(null);
931
+ } catch (Exception e) {
932
+ promise.reject("printColumnsString_failed", e.getMessage());
933
+ }
934
+ }
935
+
936
+ @ReactMethod
937
+ public void unBindService(final Promise promise) {
938
+ try {
939
+ if (iminPrintUtils == null) {
940
+ PrinterHelper.getInstance().deInitPrinterService(reactContext);
941
+ }
942
+ } catch (Exception e) {
943
+ promise.reject("unBindService_failed", e.getMessage());
944
+ }
945
+ }
946
+
947
+ @ReactMethod
948
+ public void initPrinterParams(final Promise promise) {
949
+ try {
950
+ if (iminPrintUtils == null) {
951
+ PrinterHelper.getInstance().initPrinterParams();
952
+ }
953
+ promise.resolve(null);
954
+ } catch (Exception e) {
955
+ promise.reject("initPrinterParams_failed", e.getMessage());
956
+ }
957
+ }
958
+
959
+ @ReactMethod
960
+ public void getFontCodepage(final Promise promise) {
961
+ try {
962
+ if (iminPrintUtils == null) {
963
+ List<String> fontCodepage = PrinterHelper.getInstance().getFontCodepage();
964
+ promise.resolve(fontCodepage);
965
+ } else {
966
+ promise.resolve(null);
967
+ }
968
+ } catch (Exception e) {
969
+ promise.reject("getFontCodepage_failed", e.getMessage());
970
+ }
971
+ }
972
+
973
+ @ReactMethod
974
+ public void setFontCodepage(int codepage, final Promise promise) {
975
+ try {
976
+ if (iminPrintUtils == null) {
977
+ PrinterHelper.getInstance().setFontCodepage(codepage);
978
+ }
979
+ promise.resolve(null);
980
+ } catch (Exception e) {
981
+ promise.reject("setFontCodepage_failed", e.getMessage());
982
+ }
983
+ }
984
+
985
+ @ReactMethod
986
+ public void getCurCodepage(final Promise promise) {
987
+ try {
988
+ if (iminPrintUtils == null) {
989
+ String curCodepage = PrinterHelper.getInstance().getCurCodepage();
990
+ promise.resolve(curCodepage);
991
+ } else {
992
+ promise.resolve(null);
993
+ }
994
+ } catch (Exception e) {
995
+ promise.reject("getCurCodepage_failed", e.getMessage());
996
+ }
997
+ }
998
+
999
+ @ReactMethod
1000
+ public void getEncodeList(final Promise promise) {
1001
+ try {
1002
+ if (iminPrintUtils == null) {
1003
+ List<String> encodeList = PrinterHelper.getInstance().getEncodeList();
1004
+ promise.resolve(encodeList);
1005
+ } else {
1006
+ promise.resolve(null);
1007
+ }
1008
+ } catch (Exception e) {
1009
+ promise.reject("getEncodeList_failed", e.getMessage());
683
1010
  }
684
1011
  }
1012
+
1013
+ @ReactMethod
1014
+ public void setPrinterEncode(int encode, final Promise promise) {
1015
+ try {
1016
+ if (iminPrintUtils == null) {
1017
+ PrinterHelper.getInstance().setPrinterEncode(encode);
1018
+ }
1019
+ promise.resolve(null);
1020
+ } catch (Exception e) {
1021
+ promise.reject("setPrinterEncode_failed", e.getMessage());
1022
+ }
1023
+ }
1024
+
1025
+ @ReactMethod
1026
+ public void getCurEncode(final Promise promise) {
1027
+ try {
1028
+ if (iminPrintUtils == null) {
1029
+ String curEncode = PrinterHelper.getInstance().getCurEncode();
1030
+ promise.resolve(curEncode);
1031
+ } else {
1032
+ promise.resolve(null);
1033
+ }
1034
+ } catch (Exception e) {
1035
+ promise.reject("getCurEncode_failed", e.getMessage());
1036
+ }
1037
+ }
1038
+
1039
+ @ReactMethod
1040
+ public void getPrinterDensityList(final Promise promise) {
1041
+ try {
1042
+ if (iminPrintUtils == null) {
1043
+ List<String> printerDensityList = PrinterHelper.getInstance().getPrinterDensityList();
1044
+ promise.resolve(printerDensityList);
1045
+ } else {
1046
+ promise.resolve(null);
1047
+ }
1048
+ } catch (Exception e) {
1049
+ promise.reject("getPrinterDensityList_failed", e.getMessage());
1050
+ }
1051
+ }
1052
+
1053
+ @ReactMethod
1054
+ public void setPrinterDensity(int density, final Promise promise) {
1055
+ try {
1056
+ if (iminPrintUtils == null) {
1057
+ PrinterHelper.getInstance().setPrinterDensity(density);
1058
+ }
1059
+ promise.resolve(null);
1060
+ } catch (Exception e) {
1061
+ promise.reject("setPrinterDensity_failed", e.getMessage());
1062
+ }
1063
+ }
1064
+
1065
+ @ReactMethod
1066
+ public void getPrinterDensity(final Promise promise) {
1067
+ try {
1068
+ if (iminPrintUtils == null) {
1069
+ promise.resolve(PrinterHelper.getInstance().getPrinterDensity());
1070
+ } else {
1071
+ promise.resolve(null);
1072
+ }
1073
+
1074
+ } catch (Exception e) {
1075
+ promise.reject("getPrinterDensity_failed", e.getMessage());
1076
+ }
1077
+ }
1078
+
1079
+ @ReactMethod
1080
+ public void getPrinterSpeedList(final Promise promise) {
1081
+ try {
1082
+ if (iminPrintUtils == null) {
1083
+ List<String> printerSpeedList = PrinterHelper.getInstance().getPrinterSpeedList();
1084
+ promise.resolve(printerSpeedList);
1085
+ } else {
1086
+ promise.resolve(null);
1087
+ }
1088
+
1089
+ } catch (Exception e) {
1090
+ promise.reject("getPrinterSpeedList_failed", e.getMessage());
1091
+ }
1092
+ }
1093
+
1094
+ @ReactMethod
1095
+ public void setPrinterSpeed(int speed, final Promise promise) {
1096
+ try {
1097
+ if (iminPrintUtils == null) {
1098
+ PrinterHelper.getInstance().setPrinterSpeed(speed);
1099
+ }
1100
+ promise.resolve(null);
1101
+ } catch (Exception e) {
1102
+ promise.reject("setPrinterSpeed_failed", e.getMessage());
1103
+ }
1104
+ }
1105
+
1106
+ @ReactMethod
1107
+ public void getPrinterSpeed(final Promise promise) {
1108
+ try {
1109
+ if (iminPrintUtils == null) {
1110
+ int printerSpeed = PrinterHelper.getInstance().getPrinterSpeed();
1111
+ promise.resolve(printerSpeed);
1112
+ } else {
1113
+ promise.resolve(null);
1114
+ }
1115
+ } catch (Exception e) {
1116
+ promise.reject("getPrinterSpeed_failed", e.getMessage());
1117
+ }
1118
+ }
1119
+
1120
+ @ReactMethod
1121
+ public void getPrinterPaperTypeList(final Promise promise) {
1122
+ try {
1123
+ if (iminPrintUtils == null) {
1124
+ List<String> printerPaperTypeList = PrinterHelper.getInstance().getPrinterPaperTypeList();
1125
+ promise.resolve(printerPaperTypeList);
1126
+ } else {
1127
+ promise.resolve(null);
1128
+ }
1129
+ } catch (Exception e) {
1130
+ promise.reject("getPrinterPaperTypeList_failed", e.getMessage());
1131
+ }
1132
+ }
1133
+
1134
+ @ReactMethod
1135
+ public void getPrinterPaperType(final Promise promise) {
1136
+ try {
1137
+ if (iminPrintUtils == null) {
1138
+ promise.resolve(PrinterHelper.getInstance().getPrinterPaperType());
1139
+ } else {
1140
+ promise.resolve(null);
1141
+ }
1142
+ } catch (Exception e) {
1143
+ promise.reject("getPrinterPaperType_failed", e.getMessage());
1144
+ }
1145
+ }
1146
+
1147
+ @ReactMethod
1148
+ public void getPrinterSerialNumber(final Promise promise) {
1149
+ try {
1150
+ if (iminPrintUtils == null) {
1151
+ PrinterHelper.getInstance().getPrinterSerialNumber(new INeoPrinterCallback() {
1152
+ @Override
1153
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1154
+ }
1155
+
1156
+ @Override
1157
+ public void onReturnString(String s) throws RemoteException {
1158
+ promise.resolve(s);
1159
+ }
1160
+
1161
+ @Override
1162
+ public void onRaiseException(int code, String msg) throws RemoteException {
1163
+ }
1164
+
1165
+ @Override
1166
+ public void onPrintResult(int code, String msg) throws RemoteException {
1167
+ }
1168
+ });
1169
+ } else {
1170
+ promise.resolve(null);
1171
+ }
1172
+ } catch (Exception e) {
1173
+ promise.reject("getPrinterSerialNumber_failed", e.getMessage());
1174
+ }
1175
+ }
1176
+
1177
+ @ReactMethod
1178
+ public void getPrinterModelName(final Promise promise) {
1179
+ try {
1180
+ if (iminPrintUtils == null) {
1181
+ PrinterHelper.getInstance().getPrinterModelName(new INeoPrinterCallback() {
1182
+ @Override
1183
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1184
+ }
1185
+
1186
+ @Override
1187
+ public void onReturnString(String s) throws RemoteException {
1188
+ promise.resolve(s);
1189
+ }
1190
+
1191
+ @Override
1192
+ public void onRaiseException(int code, String msg) throws RemoteException {
1193
+ }
1194
+
1195
+ @Override
1196
+ public void onPrintResult(int code, String msg) throws RemoteException {
1197
+ }
1198
+ });
1199
+ } else {
1200
+ promise.resolve(null);
1201
+ }
1202
+ } catch (Exception e) {
1203
+ promise.reject("getPrinterModelName_failed", e.getMessage());
1204
+ }
1205
+ }
1206
+
1207
+ @ReactMethod
1208
+ public void getPrinterThermalHead(final Promise promise) {
1209
+ try {
1210
+ if (iminPrintUtils == null) {
1211
+ PrinterHelper.getInstance().getPrinterThermalHead(new INeoPrinterCallback() {
1212
+ @Override
1213
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1214
+ }
1215
+
1216
+ @Override
1217
+ public void onReturnString(String s) throws RemoteException {
1218
+ promise.resolve(s);
1219
+ }
1220
+
1221
+ @Override
1222
+ public void onRaiseException(int code, String msg) throws RemoteException {
1223
+ }
1224
+
1225
+ @Override
1226
+ public void onPrintResult(int code, String msg) throws RemoteException {
1227
+ }
1228
+ });
1229
+ } else {
1230
+ promise.resolve(null);
1231
+ }
1232
+ } catch (Exception e) {
1233
+ promise.reject("getPrinterThermalHead_failed", e.getMessage());
1234
+ }
1235
+ }
1236
+
1237
+ @ReactMethod
1238
+ public void getPrinterFirmwareVersion(final Promise promise) {
1239
+ try {
1240
+ if (iminPrintUtils == null) {
1241
+ PrinterHelper.getInstance().getPrinterFirmwareVersion(new INeoPrinterCallback() {
1242
+ @Override
1243
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1244
+ }
1245
+
1246
+ @Override
1247
+ public void onReturnString(String s) throws RemoteException {
1248
+ promise.resolve(s);
1249
+ }
1250
+
1251
+ @Override
1252
+ public void onRaiseException(int code, String msg) throws RemoteException {
1253
+ }
1254
+
1255
+ @Override
1256
+ public void onPrintResult(int code, String msg) throws RemoteException {
1257
+ }
1258
+ });
1259
+ } else {
1260
+ promise.resolve(null);
1261
+ }
1262
+ } catch (Exception e) {
1263
+ promise.reject("getPrinterFirmwareVersion_failed", e.getMessage());
1264
+ }
1265
+ }
1266
+
1267
+ @ReactMethod
1268
+ public void getPrinterHardwareVersion(final Promise promise) {
1269
+ try {
1270
+ if (iminPrintUtils == null) {
1271
+ PrinterHelper.getInstance().getPrinterHardwareVersion(new INeoPrinterCallback() {
1272
+ @Override
1273
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1274
+ }
1275
+
1276
+ @Override
1277
+ public void onReturnString(String s) throws RemoteException {
1278
+ promise.resolve(s);
1279
+ }
1280
+
1281
+ @Override
1282
+ public void onRaiseException(int code, String msg) throws RemoteException {
1283
+ }
1284
+
1285
+ @Override
1286
+ public void onPrintResult(int code, String msg) throws RemoteException {
1287
+ }
1288
+ });
1289
+ } else {
1290
+ promise.resolve(null);
1291
+ }
1292
+ } catch (Exception e) {
1293
+ promise.reject("getPrinterHardwareVersion_failed", e.getMessage());
1294
+ }
1295
+ }
1296
+
1297
+ @ReactMethod
1298
+ public void getPrinterPaperDistance(final Promise promise) {
1299
+ try {
1300
+ if (iminPrintUtils == null) {
1301
+ PrinterHelper.getInstance().getPrinterPaperDistance(new INeoPrinterCallback() {
1302
+ @Override
1303
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1304
+ }
1305
+
1306
+ @Override
1307
+ public void onReturnString(String s) throws RemoteException {
1308
+ promise.resolve(s);
1309
+ }
1310
+
1311
+ @Override
1312
+ public void onRaiseException(int code, String msg) throws RemoteException {
1313
+ }
1314
+
1315
+ @Override
1316
+ public void onPrintResult(int code, String msg) throws RemoteException {
1317
+ }
1318
+ });
1319
+ } else {
1320
+ promise.resolve(null);
1321
+ }
1322
+ } catch (Exception e) {
1323
+ promise.reject("getPrinterPaperDistance_failed", e.getMessage());
1324
+ }
1325
+ }
1326
+
1327
+ @ReactMethod
1328
+ public void getPrinterCutTimes(final Promise promise) {
1329
+ try {
1330
+ if (iminPrintUtils == null) {
1331
+ PrinterHelper.getInstance().getPrinterCutTimes(new INeoPrinterCallback() {
1332
+ @Override
1333
+ public void onRunResult(boolean isSuccess) throws RemoteException {
1334
+ }
1335
+
1336
+ @Override
1337
+ public void onReturnString(String s) throws RemoteException {
1338
+ promise.resolve(s);
1339
+ }
1340
+
1341
+ @Override
1342
+ public void onRaiseException(int code, String msg) throws RemoteException {
1343
+ }
1344
+
1345
+ @Override
1346
+ public void onPrintResult(int code, String msg) throws RemoteException {
1347
+ }
1348
+ });
1349
+ } else {
1350
+ promise.resolve(null);
1351
+ }
1352
+ } catch (Exception e) {
1353
+ promise.reject("getPrinterCutTimes_failed", e.getMessage());
1354
+ }
1355
+ }
1356
+
1357
+
1358
+ @ReactMethod
1359
+ public void getPrinterMode(final Promise promise) {
1360
+ try {
1361
+ if (iminPrintUtils == null) {
1362
+ promise.resolve(PrinterHelper.getInstance().getPrinterMode());
1363
+ } else {
1364
+ promise.resolve(null);
1365
+ }
1366
+ } catch (Exception e) {
1367
+ promise.reject("getPrinterMode_failed", e.getMessage());
1368
+ }
1369
+ }
1370
+
1371
+ @ReactMethod
1372
+ public void getDrawerStatus(final Promise promise) {
1373
+ try {
1374
+ if (iminPrintUtils == null) {
1375
+ promise.resolve(PrinterHelper.getInstance().getDrawerStatus());
1376
+ } else {
1377
+ promise.resolve(null);
1378
+ }
1379
+ } catch (Exception e) {
1380
+ promise.reject("getDrawerStatus_failed", e.getMessage());
1381
+ }
1382
+ }
1383
+
1384
+ @ReactMethod
1385
+ public void getOpenDrawerTimes(final Promise promise) {
1386
+ try {
1387
+ if (iminPrintUtils == null) {
1388
+ promise.resolve(PrinterHelper.getInstance().getOpenDrawerTimes());
1389
+ } else {
1390
+ promise.resolve(null);
1391
+ }
1392
+ } catch (Exception e) {
1393
+ promise.reject("getOpenDrawerTimes_failed", e.getMessage());
1394
+ }
1395
+ }
1396
+
1397
+ @ReactMethod
1398
+ public void getServiceVersion(final Promise promise) {
1399
+ try {
1400
+ if (iminPrintUtils == null) {
1401
+ promise.resolve(PrinterHelper.getInstance().getServiceVersion());
1402
+ } else {
1403
+ promise.resolve(null);
1404
+ }
1405
+ } catch (Exception e) {
1406
+ promise.reject("getServiceVersion_failed", e.getMessage());
1407
+ }
1408
+ }
1409
+
1410
+ @ReactMethod
1411
+ public void getUsbPrinterVidPid(final Promise promise) {
1412
+ try {
1413
+ if (iminPrintUtils == null) {
1414
+ promise.resolve(PrinterHelper.getInstance().getUsbPrinterVidPid());
1415
+ } else {
1416
+ promise.resolve(null);
1417
+ }
1418
+ } catch (Exception e) {
1419
+ promise.reject("getUsbPrinterVidPid_failed", e.getMessage());
1420
+ }
1421
+ }
1422
+
1423
+ @ReactMethod
1424
+ public void getUsbDevicesName(final Promise promise) {
1425
+ try {
1426
+ if (iminPrintUtils == null) {
1427
+ promise.resolve(PrinterHelper.getInstance().getUsbDevicesName());
1428
+ } else {
1429
+ promise.resolve(null);
1430
+ }
1431
+ } catch (Exception e) {
1432
+ promise.reject("getUsbDevicesName_failed", e.getMessage());
1433
+ }
1434
+ }
1435
+
1436
+
1437
+ @ReactMethod
1438
+ public void setCodeAlignment(int align, final Promise promise) {
1439
+ try {
1440
+ if (iminPrintUtils == null) {
1441
+ PrinterHelper.getInstance().setCodeAlignment(align);
1442
+ }
1443
+ promise.resolve(null);
1444
+ } catch (Exception e) {
1445
+ promise.reject("setCodeAlignment_failed", e.getMessage());
1446
+ }
1447
+ }
1448
+
1449
+ @ReactMethod
1450
+ public void setTextBitmapTypeface(int typeface, final Promise promise) {
1451
+ try {
1452
+ if (iminPrintUtils == null) {
1453
+ switch (typeface) {
1454
+ case 1:
1455
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.MONOSPACE");
1456
+ break;
1457
+ case 2:
1458
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.DEFAULT_BOLD");
1459
+ break;
1460
+ case 3:
1461
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.SANS_SERIF");
1462
+ break;
1463
+ case 4:
1464
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.SERIF");
1465
+ break;
1466
+ default:
1467
+ PrinterHelper.getInstance().setTextBitmapTypeface("Typeface.DEFAULT");
1468
+ break;
1469
+ }
1470
+ }
1471
+ promise.resolve(null);
1472
+ } catch (Exception e) {
1473
+ promise.reject("setTextBitmapTypeface_failed", e.getMessage());
1474
+ }
1475
+ }
1476
+
1477
+ @ReactMethod
1478
+ public void setTextBitmapSize(int size, final Promise promise) {
1479
+ try {
1480
+ if (iminPrintUtils == null) {
1481
+ PrinterHelper.getInstance().setTextBitmapSize(size);
1482
+ }
1483
+ promise.resolve(null);
1484
+ } catch (Exception e) {
1485
+ promise.reject("setTextBitmapSize_failed", e.getMessage());
1486
+ }
1487
+ }
1488
+
1489
+ @ReactMethod
1490
+ public void setTextBitmapStyle(int style, final Promise promise) {
1491
+ try {
1492
+ if (iminPrintUtils == null) {
1493
+ PrinterHelper.getInstance().setTextBitmapStyle(style);
1494
+ }
1495
+ promise.resolve(null);
1496
+ } catch (Exception e) {
1497
+ promise.reject("setTextBitmapStyle_failed", e.getMessage());
1498
+ }
1499
+ }
1500
+
1501
+ @ReactMethod
1502
+ public void setTextBitmapStrikeThru(boolean strikeThru, final Promise promise) {
1503
+ try {
1504
+ if (iminPrintUtils == null) {
1505
+ PrinterHelper.getInstance().setTextBitmapStrikeThru(strikeThru);
1506
+ }
1507
+ promise.resolve(null);
1508
+ } catch (Exception e) {
1509
+ promise.reject("setTextBitmapStrikeThru_failed", e.getMessage());
1510
+ }
1511
+ }
1512
+
1513
+ @ReactMethod
1514
+ public void setTextBitmapUnderline(boolean haveUnderline, final Promise promise) {
1515
+ try {
1516
+ if (iminPrintUtils == null) {
1517
+ PrinterHelper.getInstance().setTextBitmapUnderline(haveUnderline);
1518
+ }
1519
+ promise.resolve(null);
1520
+ } catch (Exception e) {
1521
+ promise.reject("setTextBitmapUnderline_failed", e.getMessage());
1522
+ }
1523
+ }
1524
+
1525
+ @ReactMethod
1526
+ public void setTextBitmapLineSpacing(float lineHeight, final Promise promise) {
1527
+ try {
1528
+ if (iminPrintUtils == null) {
1529
+ PrinterHelper.getInstance().setTextBitmapLineSpacing(lineHeight);
1530
+ }
1531
+ promise.resolve(null);
1532
+ } catch (Exception e) {
1533
+ promise.reject("setTextBitmapLineSpacing_failed", e.getMessage());
1534
+ }
1535
+ }
1536
+
1537
+ @ReactMethod
1538
+ public void setTextBitmapLetterSpacing(float space, final Promise promise) {
1539
+ try {
1540
+ if (iminPrintUtils == null) {
1541
+ PrinterHelper.getInstance().setTextBitmapLetterSpacing(space);
1542
+ }
1543
+ promise.resolve(null);
1544
+ } catch (Exception e) {
1545
+ promise.reject("setTextBitmapLetterSpacing_failed", e.getMessage());
1546
+ }
1547
+ }
1548
+
1549
+ @ReactMethod
1550
+ public void setTextBitmapAntiWhite(boolean antiWhite, final Promise promise) {
1551
+ try {
1552
+ if (iminPrintUtils == null) {
1553
+ PrinterHelper.getInstance().setTextBitmapAntiWhite(antiWhite);
1554
+ }
1555
+ promise.resolve(null);
1556
+ } catch (Exception e) {
1557
+ promise.reject("setTextBitmapAntiWhite_failed", e.getMessage());
1558
+ }
1559
+ }
1560
+
1561
+ @ReactMethod
1562
+ public void printTextBitmap(ReadableMap config, final Promise promise) {
1563
+ try {
1564
+ if (iminPrintUtils == null) {
1565
+ String text = config.getString("text");
1566
+ if (config.hasKey("align")) {
1567
+ int align = config.getInt("align");
1568
+ PrinterHelper.getInstance().printTextBitmapWithAli(text + "\n", align, null);
1569
+ } else {
1570
+ PrinterHelper.getInstance().printTextBitmap(text + "\n", null);
1571
+ }
1572
+ }
1573
+ promise.resolve(null);
1574
+ } catch (Exception e) {
1575
+ promise.reject("printTextBitmap_failed", e.getMessage());
1576
+ }
1577
+ }
1578
+
1579
+ @ReactMethod
1580
+ public void enterPrinterBuffer(boolean isClean, final Promise promise) {
1581
+ try {
1582
+ if (iminPrintUtils == null) {
1583
+ PrinterHelper.getInstance().enterPrinterBuffer(isClean);
1584
+ }
1585
+ promise.resolve(null);
1586
+ } catch (Exception e) {
1587
+ promise.reject("enterPrinterBuffer_failed", e.getMessage());
1588
+ }
1589
+ }
1590
+
1591
+ @ReactMethod
1592
+ public void commitPrinterBuffer(final Promise promise) {
1593
+ try {
1594
+ if (iminPrintUtils == null) {
1595
+ PrinterHelper.getInstance().commitPrinterBuffer(null);
1596
+ }
1597
+ promise.resolve(null);
1598
+ } catch (Exception e) {
1599
+ promise.reject("commitPrinterBuffer_failed", e.getMessage());
1600
+ }
1601
+ }
1602
+
1603
+ @ReactMethod
1604
+ public void exitPrinterBuffer(boolean isCommit, final Promise promise) {
1605
+ try {
1606
+ if (iminPrintUtils == null) {
1607
+ PrinterHelper.getInstance().exitPrinterBuffer(isCommit);
1608
+ }
1609
+ promise.resolve(null);
1610
+ } catch (Exception e) {
1611
+ promise.reject("exitPrinterBuffer_failed", e.getMessage());
1612
+ }
1613
+ }
1614
+
1615
+ private BroadcastReceiver createChargingStateBroadcastReceiver() {
1616
+ return new BroadcastReceiver() {
1617
+ @Override
1618
+ public void onReceive(Context context, Intent intent) {
1619
+ int status = intent.getIntExtra(ACTION_PRITER_STATUS, -1);
1620
+ Log.d(TAG, "打印机状态:" + intent.getAction());
1621
+ // 发送事件到React Native
1622
+ if (intent.getAction().equals(ACTION_PRITER_STATUS_CHANGE)) {
1623
+ WritableMap result = Arguments.createMap();
1624
+ WritableMap payload = Arguments.createMap();
1625
+ payload.putString("message", Utils.getInstance().getPrinterStatusText(status));
1626
+ payload.putString("code", String.format("%d", status));
1627
+ result.putMap("eventData", payload);
1628
+ result.putString("eventName", "printer_status");
1629
+ sendEvent(reactContext, "eventBroadcast", result);
1630
+ }
1631
+ }
1632
+ };
1633
+ }
1634
+
1635
+ private void initializeBroadcastReceiver() {
1636
+ IntentFilter intentFilter = new IntentFilter();
1637
+ mBroadcastReceiver = createChargingStateBroadcastReceiver();
1638
+ intentFilter.addAction(ACTION_PRITER_STATUS_CHANGE);
1639
+ intentFilter.addAction(ACTION_POGOPIN_STATUS_CHANGE);
1640
+ getReactApplicationContext().registerReceiver(mBroadcastReceiver, intentFilter);
1641
+ }
1642
+
1643
+ @ReactMethod
1644
+ public void addListener(String eventName) {
1645
+ }
1646
+
1647
+ @ReactMethod
1648
+ public void removeListeners(Integer count) {
1649
+ }
1650
+
1651
+ @Override
1652
+ public Map<String, Object> getConstants() {
1653
+ final Map<String, Object> constants = new HashMap<>();
1654
+ constants.put("SDK_VERSION_IMIN", sdkVersion);
1655
+ return constants;
1656
+ }
1657
+
685
1658
  }