react-native-printer-imin 0.2.2 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +11 -2
- package/android/libs/iminPrinterSDK-10_V1.0.9_2306201823.jar +0 -0
- package/android/src/main/AndroidManifest.xml +3 -1
- package/android/src/main/AndroidManifestNew.xml +3 -4
- package/android/src/main/java/com/printerimin/PrinterIminModule.java +582 -24
- package/lib/commonjs/index.js +253 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/typing.js +61 -45
- package/lib/commonjs/typing.js.map +1 -1
- package/lib/module/index.js +190 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/typing.js +59 -47
- package/lib/module/typing.js.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/typing.d.ts +125 -1
- package/lib/typescript/src/typing.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +247 -4
- package/src/typing.ts +152 -47
- package/android/libs/iminPrinterSDK.jar +0 -0
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
package com.printerimin;
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
import com.bumptech.glide.Glide;
|
|
5
|
+
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
6
|
+
|
|
3
7
|
import android.graphics.Bitmap;
|
|
4
8
|
import android.graphics.Typeface;
|
|
9
|
+
import android.graphics.BitmapFactory;
|
|
5
10
|
import android.os.Build;
|
|
6
11
|
import android.util.Log;
|
|
7
12
|
|
|
8
13
|
import androidx.annotation.NonNull;
|
|
9
14
|
|
|
15
|
+
|
|
10
16
|
import com.facebook.react.bridge.Arguments;
|
|
11
17
|
import com.facebook.react.bridge.Promise;
|
|
12
18
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -16,24 +22,28 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
16
22
|
import com.facebook.react.bridge.ReadableArray;
|
|
17
23
|
import com.facebook.react.bridge.ReadableMap;
|
|
18
24
|
import com.facebook.react.bridge.WritableMap;
|
|
25
|
+
|
|
19
26
|
import com.facebook.react.module.annotations.ReactModule;
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
|
|
22
29
|
import com.imin.library.SystemPropManager;
|
|
30
|
+
import com.imin.printer.PrinterHelper;
|
|
23
31
|
import com.imin.printerlib.Callback;
|
|
24
32
|
import com.imin.printerlib.IminPrintUtils;
|
|
25
|
-
import com.imin.printerlib.print.PrintUtils;
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
import java.util.ArrayList;
|
|
36
|
+
import java.util.Arrays;
|
|
37
|
+
|
|
29
38
|
import java.util.HashMap;
|
|
30
39
|
import java.util.List;
|
|
31
40
|
import java.util.Map;
|
|
32
41
|
|
|
33
42
|
import org.json.JSONArray;
|
|
34
|
-
import org.json.JSONException;
|
|
35
43
|
import org.json.JSONObject;
|
|
36
44
|
|
|
45
|
+
import org.json.JSONException;
|
|
46
|
+
|
|
37
47
|
@ReactModule(name = PrinterIminModule.NAME)
|
|
38
48
|
public class PrinterIminModule extends ReactContextBaseJavaModule {
|
|
39
49
|
private final ReactApplicationContext reactContext;
|
|
@@ -44,14 +54,20 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
|
|
|
44
54
|
public PrinterIminModule(ReactApplicationContext reactContext) {
|
|
45
55
|
super(reactContext);
|
|
46
56
|
this.reactContext = reactContext;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
connectType = IminPrintUtils.PrintConnectType.SPI;
|
|
57
|
+
if (Build.MODEL.equals("W27_Pro") || Build.MODEL.equals("I23D01") || Build.MODEL.equals("I23M01") || Build.MODEL.equals("I23M02")) {
|
|
58
|
+
//初始化 2.0 的 SDK。
|
|
59
|
+
PrinterHelper.getInstance().initPrinterService(reactContext);
|
|
51
60
|
} else {
|
|
52
|
-
|
|
61
|
+
//初始化 1.0 SDK
|
|
62
|
+
iminPrintUtils = IminPrintUtils.getInstance(reactContext);
|
|
63
|
+
String deviceModel = SystemPropManager.getModel();
|
|
64
|
+
if (deviceModel.contains("M2-203") || deviceModel.contains("M2-202") || deviceModel.contains("M2-Pro")) {
|
|
65
|
+
connectType = IminPrintUtils.PrintConnectType.SPI;
|
|
66
|
+
} else {
|
|
67
|
+
connectType = IminPrintUtils.PrintConnectType.USB;
|
|
68
|
+
}
|
|
69
|
+
iminPrintUtils.resetDevice();
|
|
53
70
|
}
|
|
54
|
-
iminPrintUtils.resetDevice();
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
@Override
|
|
@@ -64,7 +80,9 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
|
|
|
64
80
|
@ReactMethod
|
|
65
81
|
public void initPrinter(final Promise promise) {
|
|
66
82
|
try {
|
|
67
|
-
iminPrintUtils
|
|
83
|
+
if (iminPrintUtils != null) {
|
|
84
|
+
iminPrintUtils.initPrinter(connectType);
|
|
85
|
+
}
|
|
68
86
|
promise.resolve(true);
|
|
69
87
|
} catch (Exception e) {
|
|
70
88
|
promise.reject("ININTPRINTER_FAILED", e.getMessage());
|
|
@@ -74,33 +92,573 @@ public class PrinterIminModule extends ReactContextBaseJavaModule {
|
|
|
74
92
|
@ReactMethod
|
|
75
93
|
public void getPrinterStatus(final Promise promise) {
|
|
76
94
|
WritableMap payload = Arguments.createMap();
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
int status = iminPrintUtils.getPrinterStatus(connectType);
|
|
107
|
+
payload.putString("message", getPrinterStatusText(status));
|
|
108
|
+
payload.putString("code", String.format("%d", status));
|
|
109
|
+
promise.resolve(payload);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
public void setTextSize(int size, final Promise promise) {
|
|
116
|
+
try {
|
|
117
|
+
if (iminPrintUtils != null) {
|
|
118
|
+
iminPrintUtils.setTextSize(size);
|
|
119
|
+
}
|
|
120
|
+
promise.resolve(null);
|
|
121
|
+
} catch (Exception e) {
|
|
122
|
+
promise.reject("setTextSize_failed", e.getMessage());
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
public void setTextTypeface(int font, final Promise promise) {
|
|
128
|
+
try {
|
|
129
|
+
if (iminPrintUtils != null) {
|
|
130
|
+
switch (font) {
|
|
131
|
+
case 1:
|
|
132
|
+
iminPrintUtils.setTextTypeface(Typeface.MONOSPACE);
|
|
133
|
+
break;
|
|
134
|
+
case 2:
|
|
135
|
+
iminPrintUtils.setTextTypeface(Typeface.DEFAULT_BOLD);
|
|
136
|
+
break;
|
|
137
|
+
case 3:
|
|
138
|
+
iminPrintUtils.setTextTypeface(Typeface.SANS_SERIF);
|
|
139
|
+
break;
|
|
140
|
+
case 4:
|
|
141
|
+
iminPrintUtils.setTextTypeface(Typeface.SERIF);
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
iminPrintUtils.setTextTypeface(Typeface.DEFAULT);
|
|
145
|
+
break;
|
|
84
146
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
147
|
+
}
|
|
148
|
+
promise.resolve(null);
|
|
149
|
+
} catch (Exception e) {
|
|
150
|
+
promise.reject("setTextTypeface_failed", e.getMessage());
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@ReactMethod
|
|
155
|
+
public void setTextStyle(int style, final Promise promise) {
|
|
156
|
+
try {
|
|
157
|
+
if (iminPrintUtils != null) {
|
|
158
|
+
iminPrintUtils.setTextStyle(style);
|
|
159
|
+
}
|
|
160
|
+
promise.resolve(null);
|
|
161
|
+
} catch (Exception e) {
|
|
162
|
+
promise.reject("setTextStyle_failed", e.getMessage());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@ReactMethod
|
|
167
|
+
public void setAlignment(int alignment, final Promise promise) {
|
|
168
|
+
try {
|
|
169
|
+
if (iminPrintUtils != null) {
|
|
170
|
+
iminPrintUtils.setAlignment(alignment);
|
|
171
|
+
}
|
|
172
|
+
promise.resolve(null);
|
|
173
|
+
} catch (Exception e) {
|
|
174
|
+
promise.reject("setAlignment_failed", e.getMessage());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@ReactMethod
|
|
179
|
+
public void setTextLineSpacing(float space, final Promise promise) {
|
|
180
|
+
try {
|
|
181
|
+
if (iminPrintUtils != null) {
|
|
182
|
+
iminPrintUtils.setTextLineSpacing(space);
|
|
183
|
+
}
|
|
184
|
+
promise.resolve(null);
|
|
185
|
+
} catch (Exception e) {
|
|
186
|
+
promise.reject("setTextLineSpacing_failed", e.getMessage());
|
|
91
187
|
}
|
|
92
188
|
}
|
|
93
189
|
|
|
94
190
|
@ReactMethod
|
|
95
191
|
public void printText(String text, final Promise promise) {
|
|
96
192
|
try {
|
|
97
|
-
iminPrintUtils
|
|
193
|
+
if (iminPrintUtils != null) {
|
|
194
|
+
iminPrintUtils.printText(text);
|
|
195
|
+
}
|
|
98
196
|
promise.resolve(null);
|
|
99
197
|
} catch (Exception e) {
|
|
100
198
|
promise.reject("printText_failed", e.getMessage());
|
|
101
199
|
}
|
|
102
200
|
}
|
|
103
201
|
|
|
202
|
+
@ReactMethod
|
|
203
|
+
public void printAntiWhiteText(String text, final Promise promise) {
|
|
204
|
+
try {
|
|
205
|
+
if (iminPrintUtils != null) {
|
|
206
|
+
iminPrintUtils.printAntiWhiteText(text);
|
|
207
|
+
}
|
|
208
|
+
promise.resolve(null);
|
|
209
|
+
} catch (Exception e) {
|
|
210
|
+
promise.reject("printAntiWhiteText_failed", e.getMessage());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@ReactMethod
|
|
215
|
+
public void setTextWidth(int width, final Promise promise) {
|
|
216
|
+
try {
|
|
217
|
+
if (iminPrintUtils != null) {
|
|
218
|
+
iminPrintUtils.setTextWidth(width);
|
|
219
|
+
}
|
|
220
|
+
promise.resolve(null);
|
|
221
|
+
} catch (Exception e) {
|
|
222
|
+
promise.reject("setTextWidth_failed", e.getMessage());
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@ReactMethod
|
|
227
|
+
public void printAndLineFeed(final Promise promise) {
|
|
228
|
+
try {
|
|
229
|
+
if (iminPrintUtils != null) {
|
|
230
|
+
iminPrintUtils.printAndLineFeed();
|
|
231
|
+
}
|
|
232
|
+
promise.resolve(null);
|
|
233
|
+
} catch (Exception e) {
|
|
234
|
+
promise.reject("printAndLineFeed_failed", e.getMessage());
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@ReactMethod
|
|
239
|
+
public void printAndFeedPaper(int height, final Promise promise) {
|
|
240
|
+
try {
|
|
241
|
+
if (iminPrintUtils != null) {
|
|
242
|
+
iminPrintUtils.printAndFeedPaper(height);
|
|
243
|
+
}
|
|
244
|
+
promise.resolve(null);
|
|
245
|
+
} catch (Exception e) {
|
|
246
|
+
promise.reject("printAndLineFeed_failed", e.getMessage());
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@ReactMethod
|
|
251
|
+
public void printColumnsText(ReadableArray cols, final Promise promise) {
|
|
252
|
+
try {
|
|
253
|
+
String[] colsText = new String[cols.size()];
|
|
254
|
+
int[] colsWidth = new int[cols.size()];
|
|
255
|
+
int[] colsAlign = new int[cols.size()];
|
|
256
|
+
int[] colsFontSize = new int[cols.size()];
|
|
257
|
+
for (int i = 0; i < cols.size(); i++) {
|
|
258
|
+
ReadableMap col = cols.getMap(i);
|
|
259
|
+
String textColumn = col.getString("text");
|
|
260
|
+
int widthColumn = col.getInt("width");
|
|
261
|
+
int alignColumn = col.getInt("align");
|
|
262
|
+
int fontSizeColumn = col.getInt("fontSize");
|
|
263
|
+
colsText[i] = textColumn;
|
|
264
|
+
colsWidth[i] = widthColumn;
|
|
265
|
+
colsAlign[i] = alignColumn;
|
|
266
|
+
colsFontSize[i] = fontSizeColumn;
|
|
267
|
+
}
|
|
268
|
+
if (iminPrintUtils != null) {
|
|
269
|
+
iminPrintUtils.printColumnsText(colsText, colsWidth, colsAlign, colsFontSize);
|
|
270
|
+
}
|
|
271
|
+
promise.resolve(null);
|
|
272
|
+
} catch (Exception e) {
|
|
273
|
+
promise.reject("printColumnsText_failed", e.getMessage());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@ReactMethod
|
|
278
|
+
public void setPageFormat(int style, final Promise promise) {
|
|
279
|
+
try {
|
|
280
|
+
if (iminPrintUtils != null) {
|
|
281
|
+
iminPrintUtils.setPageFormat(style);
|
|
282
|
+
}
|
|
283
|
+
promise.resolve(null);
|
|
284
|
+
} catch (Exception e) {
|
|
285
|
+
promise.reject("setPageFormat_failed", e.getMessage());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@ReactMethod
|
|
290
|
+
public void partialCut(final Promise promise) {
|
|
291
|
+
try {
|
|
292
|
+
if (iminPrintUtils != null) {
|
|
293
|
+
iminPrintUtils.partialCut();
|
|
294
|
+
}
|
|
295
|
+
promise.resolve(null);
|
|
296
|
+
} catch (Exception e) {
|
|
297
|
+
promise.reject("partialCut_failed", e.getMessage());
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@ReactMethod
|
|
302
|
+
public void printSingleBitmap(ReadableMap config, final Promise promise) {
|
|
303
|
+
try {
|
|
304
|
+
String url = config.getString("url");
|
|
305
|
+
if (config.hasKey("width") && config.hasKey("height")) {
|
|
306
|
+
int width = config.getInt("width");
|
|
307
|
+
int height = config.getInt("height");
|
|
308
|
+
Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
|
|
309
|
+
Log.d("printSingleBitmap", "image:" + image);
|
|
310
|
+
if (image.isRecycled()) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (iminPrintUtils != null) {
|
|
314
|
+
if (config.hasKey("align")) {
|
|
315
|
+
int align = config.getInt("align");
|
|
316
|
+
iminPrintUtils.printSingleBitmap(image, align);
|
|
317
|
+
} else {
|
|
318
|
+
iminPrintUtils.printSingleBitmap(image);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
|
|
323
|
+
Log.d("printSingleBitmap", "image:" + image);
|
|
324
|
+
if (image.isRecycled()) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (iminPrintUtils != null) {
|
|
328
|
+
if (config.hasKey("align")) {
|
|
329
|
+
int align = config.getInt("align");
|
|
330
|
+
iminPrintUtils.printSingleBitmap(image, align);
|
|
331
|
+
} else {
|
|
332
|
+
iminPrintUtils.printSingleBitmap(image);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
promise.resolve(null);
|
|
339
|
+
} catch (Exception e) {
|
|
340
|
+
promise.reject("printSingleBitmap_failed", e.getMessage());
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
@ReactMethod
|
|
345
|
+
public void printMultiBitmap(ReadableMap config, final Promise promise) {
|
|
346
|
+
try {
|
|
347
|
+
Log.d("printMultiBitmap", "config:" + config.getArray("urls"));
|
|
348
|
+
ReadableArray urls = config.getArray("urls");
|
|
349
|
+
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
|
|
350
|
+
if (config.hasKey("width") && config.hasKey("height")) {
|
|
351
|
+
int width = config.getInt("width");
|
|
352
|
+
int height = config.getInt("height");
|
|
353
|
+
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());
|
|
355
|
+
}
|
|
356
|
+
if (iminPrintUtils != null) {
|
|
357
|
+
if (config.hasKey("align")) {
|
|
358
|
+
int align = config.getInt("align");
|
|
359
|
+
iminPrintUtils.printMultiBitmap(bitmaps, align);
|
|
360
|
+
} else {
|
|
361
|
+
iminPrintUtils.printMultiBitmap(bitmaps, 0);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
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());
|
|
367
|
+
}
|
|
368
|
+
if (iminPrintUtils != null) {
|
|
369
|
+
if (config.hasKey("align")) {
|
|
370
|
+
int align = config.getInt("align");
|
|
371
|
+
iminPrintUtils.printMultiBitmap(bitmaps, align);
|
|
372
|
+
} else {
|
|
373
|
+
iminPrintUtils.printMultiBitmap(bitmaps, 0);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// // if (image.isRecycled()) {
|
|
378
|
+
// // return;
|
|
379
|
+
// // }
|
|
380
|
+
promise.resolve(null);
|
|
381
|
+
} catch (Exception e) {
|
|
382
|
+
promise.reject("printMultiBitmap_failed", e.getMessage());
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
@ReactMethod
|
|
387
|
+
public void printSingleBitmapBlackWhite(ReadableMap config, final Promise promise) {
|
|
388
|
+
try {
|
|
389
|
+
String url = config.getString("url");
|
|
390
|
+
if (config.hasKey("width") && config.hasKey("height")) {
|
|
391
|
+
int width = config.getInt("width");
|
|
392
|
+
int height = config.getInt("height");
|
|
393
|
+
Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit(width, height).get();
|
|
394
|
+
if (image.isRecycled()) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
Log.d("printSingleBitmap", "image:" + image);
|
|
398
|
+
if (iminPrintUtils != null) {
|
|
399
|
+
iminPrintUtils.printSingleBitmapBlackWhite(image);
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
Bitmap image = Glide.with(reactContext).asBitmap().load(url).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).submit().get();
|
|
403
|
+
if (image.isRecycled()) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
Log.d("printSingleBitmap", "image:" + image);
|
|
407
|
+
|
|
408
|
+
if (iminPrintUtils != null) {
|
|
409
|
+
iminPrintUtils.printSingleBitmapBlackWhite(image);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
promise.resolve(null);
|
|
413
|
+
} catch (Exception e) {
|
|
414
|
+
promise.reject("printSingleBitmapBlackWhite_failed", e.getMessage());
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
@ReactMethod
|
|
419
|
+
public void setQrCodeSize(int qrSize, final Promise promise) {
|
|
420
|
+
try {
|
|
421
|
+
if (iminPrintUtils != null) {
|
|
422
|
+
iminPrintUtils.setQrCodeSize(qrSize);
|
|
423
|
+
}
|
|
424
|
+
promise.resolve(null);
|
|
425
|
+
} catch (Exception e) {
|
|
426
|
+
promise.reject("setQrCodeSize_failed", e.getMessage());
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
@ReactMethod
|
|
431
|
+
public void setLeftMargin(int margin, final Promise promise) {
|
|
432
|
+
try {
|
|
433
|
+
if (iminPrintUtils != null) {
|
|
434
|
+
iminPrintUtils.setLeftMargin(margin);
|
|
435
|
+
}
|
|
436
|
+
promise.resolve(null);
|
|
437
|
+
} catch (Exception e) {
|
|
438
|
+
promise.reject("setLeftMargin_failed", e.getMessage());
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
@ReactMethod
|
|
443
|
+
public void setBarCodeWidth(int width, final Promise promise) {
|
|
444
|
+
try {
|
|
445
|
+
if (iminPrintUtils != null) {
|
|
446
|
+
iminPrintUtils.setBarCodeWidth(width);
|
|
447
|
+
}
|
|
448
|
+
promise.resolve(null);
|
|
449
|
+
} catch (Exception e) {
|
|
450
|
+
promise.reject("setBarCodeWidth_failed", e.getMessage());
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
@ReactMethod
|
|
455
|
+
public void setBarCodeHeight(int height, final Promise promise) {
|
|
456
|
+
try {
|
|
457
|
+
if (iminPrintUtils != null) {
|
|
458
|
+
iminPrintUtils.setBarCodeHeight(height);
|
|
459
|
+
}
|
|
460
|
+
promise.resolve(null);
|
|
461
|
+
} catch (Exception e) {
|
|
462
|
+
promise.reject("setBarCodeHeight_failed", e.getMessage());
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
@ReactMethod
|
|
467
|
+
public void setBarCodeContentPrintPos(int position, final Promise promise) {
|
|
468
|
+
try {
|
|
469
|
+
if (iminPrintUtils != null) {
|
|
470
|
+
iminPrintUtils.setBarCodeContentPrintPos(position);
|
|
471
|
+
}
|
|
472
|
+
promise.resolve(null);
|
|
473
|
+
} catch (Exception e) {
|
|
474
|
+
promise.reject("setBarCodeContentPrintPos_failed", e.getMessage());
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
@ReactMethod
|
|
479
|
+
public void printBarCode(ReadableMap config, final Promise promise) {
|
|
480
|
+
try {
|
|
481
|
+
String barCodeContent = config.getString("data");
|
|
482
|
+
int barCodeType = config.getInt("type");
|
|
483
|
+
if (iminPrintUtils != null) {
|
|
484
|
+
if (config.hasKey("align")) {
|
|
485
|
+
int barCodeAlign = config.getInt("align");
|
|
486
|
+
iminPrintUtils.printBarCode(barCodeType, barCodeContent, barCodeAlign);
|
|
487
|
+
} else {
|
|
488
|
+
iminPrintUtils.printBarCode(barCodeType, barCodeContent);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
promise.resolve(null);
|
|
492
|
+
} catch (Exception e) {
|
|
493
|
+
promise.reject("printBarCode_failed", e.getMessage());
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
@ReactMethod
|
|
499
|
+
public void setDoubleQRSize(int size, final Promise promise) {
|
|
500
|
+
try {
|
|
501
|
+
if (iminPrintUtils != null) {
|
|
502
|
+
iminPrintUtils.setDoubleQRSize(size);
|
|
503
|
+
}
|
|
504
|
+
promise.resolve(null);
|
|
505
|
+
} catch (Exception e) {
|
|
506
|
+
promise.reject("setDoubleQRSize_failed", e.getMessage());
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
@ReactMethod
|
|
511
|
+
public void setDoubleQR1Level(int level, final Promise promise) {
|
|
512
|
+
try {
|
|
513
|
+
if (iminPrintUtils != null) {
|
|
514
|
+
iminPrintUtils.setDoubleQR1Level(level);
|
|
515
|
+
}
|
|
516
|
+
promise.resolve(null);
|
|
517
|
+
} catch (Exception e) {
|
|
518
|
+
promise.reject("setDoubleQR1Level_failed", e.getMessage());
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
@ReactMethod
|
|
523
|
+
public void setDoubleQR2Level(int level, final Promise promise) {
|
|
524
|
+
try {
|
|
525
|
+
if (iminPrintUtils != null) {
|
|
526
|
+
iminPrintUtils.setDoubleQR2Level(level);
|
|
527
|
+
}
|
|
528
|
+
promise.resolve(null);
|
|
529
|
+
} catch (Exception e) {
|
|
530
|
+
promise.reject("setDoubleQR2Level_failed", e.getMessage());
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
@ReactMethod
|
|
535
|
+
public void setDoubleQR1MarginLeft(int leftMargin, final Promise promise) {
|
|
536
|
+
try {
|
|
537
|
+
if (iminPrintUtils != null) {
|
|
538
|
+
iminPrintUtils.setDoubleQR1MarginLeft(leftMargin);
|
|
539
|
+
}
|
|
540
|
+
promise.resolve(null);
|
|
541
|
+
} catch (Exception e) {
|
|
542
|
+
promise.reject("setDoubleQR1MarginLeft_failed", e.getMessage());
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
@ReactMethod
|
|
547
|
+
public void setDoubleQR2MarginLeft(int leftMargin, final Promise promise) {
|
|
548
|
+
try {
|
|
549
|
+
if (iminPrintUtils != null) {
|
|
550
|
+
iminPrintUtils.setDoubleQR2MarginLeft(leftMargin);
|
|
551
|
+
}
|
|
552
|
+
promise.resolve(null);
|
|
553
|
+
} catch (Exception e) {
|
|
554
|
+
promise.reject("setDoubleQR2MarginLeft_failed", e.getMessage());
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
@ReactMethod
|
|
559
|
+
public void setQrCodeErrorCorrectionLev(int level, final Promise promise) {
|
|
560
|
+
try {
|
|
561
|
+
if (iminPrintUtils != null) {
|
|
562
|
+
iminPrintUtils.setQrCodeErrorCorrectionLev(level);
|
|
563
|
+
}
|
|
564
|
+
promise.resolve(null);
|
|
565
|
+
} catch (Exception e) {
|
|
566
|
+
promise.reject("setQrCodeErrorCorrectionLev_failed", e.getMessage());
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
@ReactMethod
|
|
571
|
+
public void setDoubleQR1Version(int version, final Promise promise) {
|
|
572
|
+
try {
|
|
573
|
+
if (iminPrintUtils != null) {
|
|
574
|
+
iminPrintUtils.setDoubleQR1Version(version);
|
|
575
|
+
}
|
|
576
|
+
promise.resolve(null);
|
|
577
|
+
} catch (Exception e) {
|
|
578
|
+
promise.reject("setDoubleQR1Version_failed", e.getMessage());
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
@ReactMethod
|
|
583
|
+
public void setDoubleQR2Version(int version, final Promise promise) {
|
|
584
|
+
try {
|
|
585
|
+
if (iminPrintUtils != null) {
|
|
586
|
+
iminPrintUtils.setDoubleQR2Version(version);
|
|
587
|
+
}
|
|
588
|
+
promise.resolve(null);
|
|
589
|
+
} catch (Exception e) {
|
|
590
|
+
promise.reject("setDoubleQR2Version_failed", e.getMessage());
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
@ReactMethod
|
|
595
|
+
public void printQrCode(ReadableMap config, final Promise promise) {
|
|
596
|
+
try {
|
|
597
|
+
String qrStr = config.getString("data");
|
|
598
|
+
if (iminPrintUtils != null) {
|
|
599
|
+
if (config.hasKey("align")) {
|
|
600
|
+
int align = config.getInt("align");
|
|
601
|
+
iminPrintUtils.printQrCode(qrStr, align);
|
|
602
|
+
} else {
|
|
603
|
+
iminPrintUtils.printQrCode(qrStr);
|
|
604
|
+
}
|
|
605
|
+
promise.resolve(null);
|
|
606
|
+
}
|
|
607
|
+
} catch (Exception e) {
|
|
608
|
+
promise.reject("printQrCode_failed", e.getMessage());
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
@ReactMethod
|
|
613
|
+
public void printDoubleQR(ReadableMap config, final Promise promise) {
|
|
614
|
+
try {
|
|
615
|
+
String qrCode1Text = config.getString("qrCode1Text");
|
|
616
|
+
String qrCode2Text = config.getString("qrCode2Text");
|
|
617
|
+
if (iminPrintUtils != null) {
|
|
618
|
+
iminPrintUtils.printDoubleQR(qrCode1Text, qrCode2Text);
|
|
619
|
+
}
|
|
620
|
+
promise.resolve(null);
|
|
621
|
+
} catch (Exception e) {
|
|
622
|
+
promise.reject("printDoubleQR_failed", e.getMessage());
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
@ReactMethod
|
|
627
|
+
public void openCashBox(final Promise promise) {
|
|
628
|
+
try {
|
|
629
|
+
if (iminPrintUtils != null) {
|
|
630
|
+
iminPrintUtils.openCashBox();
|
|
631
|
+
}
|
|
632
|
+
promise.resolve(null);
|
|
633
|
+
} catch (Exception e) {
|
|
634
|
+
promise.reject("openCashBox_failed", e.getMessage());
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
@ReactMethod
|
|
640
|
+
public void setInitIminPrinter(boolean isDefault, final Promise promise) {
|
|
641
|
+
try {
|
|
642
|
+
if (iminPrintUtils != null) {
|
|
643
|
+
iminPrintUtils.setInitIminPrinter(isDefault);
|
|
644
|
+
}
|
|
645
|
+
promise.resolve(null);
|
|
646
|
+
} catch (Exception e) {
|
|
647
|
+
promise.reject("setInitIminPrinter_failed", e.getMessage());
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
@ReactMethod
|
|
652
|
+
public void resetDevice(final Promise promise) {
|
|
653
|
+
try {
|
|
654
|
+
if (iminPrintUtils != null) {
|
|
655
|
+
iminPrintUtils.resetDevice();
|
|
656
|
+
}
|
|
657
|
+
} catch (Exception e) {
|
|
658
|
+
promise.reject("resetDevice_failed", e.getMessage());
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
104
662
|
private String getPrinterStatusText(int code) {
|
|
105
663
|
if (code == 0) {
|
|
106
664
|
return "Printer is normal!";
|