capacitor-plugin-gpos700 0.1.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.

Potentially problematic release.


This version of capacitor-plugin-gpos700 might be problematic. Click here for more details.

package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # capacitor-plugin-gpos700
2
+
3
+ Plugin for GPOS700
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install capacitor-plugin-gpos700
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`imprimirTexto(...)`](#imprimirtexto)
17
+ * [`statusImpressora()`](#statusimpressora)
18
+
19
+ </docgen-index>
20
+
21
+ <docgen-api>
22
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
23
+
24
+ ### imprimirTexto(...)
25
+
26
+ ```typescript
27
+ imprimirTexto(options: { mensagem: string; alinhar?: string; size?: number; font?: string; }) => Promise<void>
28
+ ```
29
+
30
+ | Param | Type |
31
+ | ------------- | ---------------------------------------------------------------------------------- |
32
+ | **`options`** | <code>{ mensagem: string; alinhar?: string; size?: number; font?: string; }</code> |
33
+
34
+ --------------------
35
+
36
+
37
+ ### statusImpressora()
38
+
39
+ ```typescript
40
+ statusImpressora() => Promise<{ status: string; }>
41
+ ```
42
+
43
+ **Returns:** <code>Promise&lt;{ status: string; }&gt;</code>
44
+
45
+ --------------------
46
+
47
+ </docgen-api>
@@ -0,0 +1,61 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "com.galago.plugins.gpos"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError = false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ flatDir {
49
+ dirs 'libs'
50
+ }
51
+ }
52
+
53
+
54
+ dependencies {
55
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
56
+ implementation project(':capacitor-android')
57
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
58
+ testImplementation "junit:junit:$junitVersion"
59
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
60
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
61
+ }
@@ -0,0 +1,6 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.galago.plugins.gpos">
3
+ <uses-permission android:name="android.permission.CAMERA" />
4
+ <uses-feature android:name="android.hardware.camera" />
5
+ <uses-feature android:name="android.hardware.camera.autofocus" />
6
+ </manifest>
@@ -0,0 +1,152 @@
1
+ package com.galago.plugins.gpos;
2
+
3
+ public class ConfigPrint {
4
+
5
+ private String fonte = "NORMAL";
6
+ private String alinhamento;
7
+ private int tamanho;
8
+ private int offSet;
9
+ private int iHeight;
10
+ private int iWidth;
11
+ private int lineSpace;
12
+ private boolean negrito;
13
+ private boolean italico;
14
+ private boolean sublinhado;
15
+ private int avancaLinhas;
16
+
17
+ public ConfigPrint() {
18
+ this.fonte = "NORMAL";
19
+ this.alinhamento = "CENTER";
20
+ this.tamanho = 20;
21
+ this.offSet = 0;
22
+ this.iHeight = 700;
23
+ this.iWidth = 430;
24
+ this.lineSpace = 0;
25
+ this.negrito = true;
26
+ this.italico = true;
27
+ this.sublinhado = false;
28
+ this.avancaLinhas = 0;
29
+ }
30
+
31
+ public ConfigPrint(String fonte, String alinhamento, int tamanho, int offSet, int lineSpace, boolean negrito, boolean italico, boolean sublinhado) {
32
+ this.fonte = fonte;
33
+ this.alinhamento = alinhamento;
34
+ this.tamanho = tamanho;
35
+ this.offSet = offSet;
36
+ this.lineSpace = lineSpace;
37
+ this.negrito = negrito;
38
+ this.italico = italico;
39
+ this.sublinhado = sublinhado;
40
+ }
41
+
42
+ public ConfigPrint(String fonte, String alinhamento, int tamanho, int offSet, int iHeight, int iWidth, int lineSpace, boolean negrito, boolean italico, boolean sublinhado) {
43
+ this.fonte = fonte;
44
+ this.alinhamento = alinhamento;
45
+ this.tamanho = tamanho;
46
+ this.offSet = offSet;
47
+ this.iHeight = iHeight;
48
+ this.iWidth = iWidth;
49
+ this.lineSpace = lineSpace;
50
+ this.negrito = negrito;
51
+ this.italico = italico;
52
+ this.sublinhado = sublinhado;
53
+ }
54
+
55
+ public String getFonte() {
56
+ return fonte;
57
+ }
58
+
59
+ public void setFonte(String fonte) {
60
+ this.fonte = fonte;
61
+ switch (fonte) {
62
+ case "NORMAL", "DEFAULT", "DEFAULT BOLD", "MONOSPACE", "SANS SERIF", "SERIF" -> {
63
+ }
64
+ default ->
65
+ setFont(fonte);
66
+ }
67
+ }
68
+
69
+ public String getAlinhamento() {
70
+ return alinhamento;
71
+ }
72
+
73
+ public void setAlinhamento(String alinhamento) {
74
+ this.alinhamento = alinhamento;
75
+ }
76
+
77
+ public int getTamanho() {
78
+ return tamanho;
79
+ }
80
+
81
+ public void setTamanho(int tamanho) {
82
+ this.tamanho = tamanho;
83
+ }
84
+
85
+ public int getOffSet() {
86
+ return offSet;
87
+ }
88
+
89
+ public void setOffSet(int offSet) {
90
+ this.offSet = offSet;
91
+ }
92
+
93
+ public int getLineSpace() {
94
+ return lineSpace;
95
+ }
96
+
97
+ public void setLineSpace(int lineSpace) {
98
+ this.lineSpace = lineSpace;
99
+ }
100
+
101
+ private void setFont(String fonte) {
102
+ this.fonte = "fonts/" + fonte;
103
+ }
104
+
105
+ public int getiHeight() {
106
+ return iHeight;
107
+ }
108
+
109
+ public void setiHeight(int iHeight) {
110
+ this.iHeight = iHeight;
111
+ }
112
+
113
+ public int getiWidth() {
114
+ return iWidth;
115
+ }
116
+
117
+ public void setiWidth(int iWidth) {
118
+ this.iWidth = iWidth;
119
+ }
120
+
121
+ public boolean isNegrito() {
122
+ return negrito;
123
+ }
124
+
125
+ public void setNegrito(boolean negrito) {
126
+ this.negrito = negrito;
127
+ }
128
+
129
+ public boolean isItalico() {
130
+ return italico;
131
+ }
132
+
133
+ public void setItalico(boolean italico) {
134
+ this.italico = italico;
135
+ }
136
+
137
+ public boolean isSublinhado() {
138
+ return sublinhado;
139
+ }
140
+
141
+ public void setSublinhado(boolean sublinhado) {
142
+ this.sublinhado = sublinhado;
143
+ }
144
+
145
+ public int getAvancaLinhas() {
146
+ return avancaLinhas;
147
+ }
148
+
149
+ public void setAvancaLinhas(int avancaLinhas) {
150
+ this.avancaLinhas = avancaLinhas;
151
+ }
152
+ }
@@ -0,0 +1,509 @@
1
+ package com.galago.plugins.gpos;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Context;
5
+ import android.graphics.Bitmap;
6
+ import android.graphics.BitmapFactory;
7
+ import android.graphics.Paint;
8
+ import android.graphics.Typeface;
9
+
10
+ import br.com.gertec.gedi.GEDI;
11
+ import br.com.gertec.gedi.enums.GEDI_PRNTR_e_Alignment;
12
+ import br.com.gertec.gedi.enums.GEDI_PRNTR_e_BarCodeType;
13
+ import br.com.gertec.gedi.enums.GEDI_PRNTR_e_Status;
14
+ import br.com.gertec.gedi.exceptions.GediException;
15
+ import br.com.gertec.gedi.interfaces.IGEDI;
16
+ import br.com.gertec.gedi.interfaces.IPRNTR;
17
+ import br.com.gertec.gedi.structs.GEDI_PRNTR_st_BarCodeConfig;
18
+ import br.com.gertec.gedi.structs.GEDI_PRNTR_st_PictureConfig;
19
+ import br.com.gertec.gedi.structs.GEDI_PRNTR_st_StringConfig;
20
+
21
+ public class GertecPrinter {
22
+
23
+ // Definições
24
+ private final String IMPRESSORA_ERRO = "Impressora com erro.";
25
+
26
+ // Statics
27
+ private static boolean isPrintInit = false;
28
+
29
+ // Vaviáveis iniciais
30
+ private Activity activity;
31
+ private Context context;
32
+
33
+ // Classe de impressão
34
+ private IGEDI iGedi = null;
35
+ private IPRNTR iPrint = null;
36
+ private GEDI_PRNTR_st_StringConfig stringConfig;
37
+ private GEDI_PRNTR_st_PictureConfig pictureConfig;
38
+ private GEDI_PRNTR_e_Status status;
39
+
40
+ // Classe de configuração da impressão
41
+ private ConfigPrint configPrint;
42
+ private Typeface typeface;
43
+
44
+ /**
45
+ * Método construtor da classe usando o GPOS 700
46
+ *
47
+ * @param c = Context atual que esta sendo inicializada a class
48
+ *
49
+ */
50
+ public GertecPrinter(Context c) {
51
+ this.context = c;
52
+ startIGEDI();
53
+ }
54
+
55
+ /**
56
+ * Método que instância a classe GEDI da lib deve ser usado apenas para o
57
+ * GPOS 700
58
+ *
59
+ * @apiNote = Este mátodo faz a instância da classe GEDI através de uma
60
+ * Thread. Será sempre chamado na construção da classe. Não alterar...
61
+ *
62
+ */
63
+ private void startIGEDI() {
64
+ new Thread(() -> {
65
+ GEDI.init(this.context);
66
+ this.iGedi = GEDI.getInstance(this.context);
67
+ this.iPrint = this.iGedi.getPRNTR();
68
+ try {
69
+ new Thread().sleep(250);
70
+ } catch (InterruptedException e) {
71
+ e.printStackTrace();
72
+ }
73
+ }).start();
74
+ }
75
+
76
+ /**
77
+ * Método que recebe a configuração para ser usada na impressão
78
+ *
79
+ * @param config = Classe {@link ConfigPrint} que contém toda a configuração
80
+ * para a impressão
81
+ *
82
+ */
83
+ public void setConfigImpressao(ConfigPrint config) {
84
+
85
+ this.configPrint = config;
86
+
87
+ this.stringConfig = new GEDI_PRNTR_st_StringConfig(new Paint());
88
+ this.stringConfig.paint.setTextSize(configPrint.getTamanho());
89
+ this.stringConfig.paint.setTextAlign(Paint.Align.valueOf(configPrint.getAlinhamento()));
90
+ this.stringConfig.offset = configPrint.getOffSet();
91
+ this.stringConfig.lineSpace = configPrint.getLineSpace();
92
+
93
+ switch (configPrint.getFonte()) {
94
+ case "NORMAL":
95
+ this.typeface = Typeface.create(configPrint.getFonte(), Typeface.NORMAL);
96
+ break;
97
+ case "DEFAULT":
98
+ this.typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
99
+ break;
100
+ case "DEFAULT BOLD":
101
+ this.typeface = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL);
102
+ break;
103
+ case "MONOSPACE":
104
+ this.typeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL);
105
+ break;
106
+ case "SANS SERIF":
107
+ this.typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
108
+ break;
109
+ case "SERIF":
110
+ this.typeface = Typeface.create(Typeface.SERIF, Typeface.NORMAL);
111
+ break;
112
+ default:
113
+ this.typeface = Typeface.createFromAsset(this.context.getAssets(), configPrint.getFonte());
114
+ }
115
+
116
+ if (this.configPrint.isNegrito() && this.configPrint.isItalico()) {
117
+ typeface = Typeface.create(typeface, Typeface.BOLD_ITALIC);
118
+ } else if (this.configPrint.isNegrito()) {
119
+ typeface = Typeface.create(typeface, Typeface.BOLD);
120
+ } else if (this.configPrint.isItalico()) {
121
+ typeface = Typeface.create(typeface, Typeface.ITALIC);
122
+ }
123
+
124
+ if (this.configPrint.isSublinhado()) {
125
+ this.stringConfig.paint.setFlags(Paint.UNDERLINE_TEXT_FLAG);
126
+ }
127
+
128
+ this.stringConfig.paint.setTypeface(this.typeface);
129
+ }
130
+
131
+ /**
132
+ * Método que retorna o atual estado da impressora
133
+ *
134
+ * @throws GediException = vai retorno o código do erro.
135
+ *
136
+ * @return String = traduzStatusImpressora()
137
+ *
138
+ *
139
+ */
140
+ public String getStatusImpressora() throws GediException {
141
+ try {
142
+ ImpressoraInit();
143
+ this.status = this.iPrint.Status();
144
+ } catch (GediException e) {
145
+ throw new GediException(e.getErrorCode());
146
+ }
147
+
148
+ return traduzStatusImpressora(this.status);
149
+ }
150
+
151
+ /**
152
+ * Método que recebe o atual texto a ser impresso
153
+ *
154
+ * @param texto = Texto que será impresso.
155
+ *
156
+ * @throws Exception = caso a impressora esteja com erro.
157
+ *
158
+ *
159
+ */
160
+ public void imprimeTexto(String texto) throws Exception {
161
+
162
+ //this.getStatusImpressora();
163
+ try {
164
+ if (!isImpressoraOK()) {
165
+ throw new Exception(IMPRESSORA_ERRO);
166
+ }
167
+ sPrintLine(texto);
168
+ } catch (Exception e) {
169
+ throw new Exception(e.getMessage());
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Método que recebe o atual texto e o tamanho da fonte que deve ser usado
175
+ * na impressão.
176
+ *
177
+ * @param texto = Texto que será impresso.
178
+ * @param tamanho = Tamanho da fonte que será usada
179
+ *
180
+ * @throws Exception = caso a impressora esteja com erro.
181
+ *
182
+ * @apiNote = Esse mátodo só altera o tamanho do texto na impressão que for
183
+ * chamado a classe {@link ConfigPrint} não será alterada para continuar
184
+ * sendo usado na impressão da proxíma linha
185
+ *
186
+ *
187
+ */
188
+ public void imprimeTexto(String texto, int tamanho) throws Exception {
189
+
190
+ int tamanhoOld;
191
+
192
+ //this.getStatusImpressora();
193
+ try {
194
+ if (!isImpressoraOK()) {
195
+ throw new Exception(IMPRESSORA_ERRO);
196
+ }
197
+ tamanhoOld = this.configPrint.getTamanho();
198
+ this.configPrint.setTamanho(tamanho);
199
+ this.setConfigImpressao(this.configPrint);
200
+ sPrintLine(texto);
201
+ this.configPrint.setTamanho(tamanhoOld);
202
+ this.setConfigImpressao(this.configPrint);
203
+ } catch (Exception e) {
204
+ throw new Exception(e.getMessage());
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Método que recebe o atual texto e ser o mesmo será impresso em negrito.
210
+ *
211
+ * @param texto = Texto que será impresso.
212
+ * @param negrito = Caso o texto deva ser impresso em negrito
213
+ *
214
+ * @throws Exception = caso a impressora esteja com erro.
215
+ *
216
+ * @apiNote = Esse mátodo só altera o tamanho do texto na impressão que for
217
+ * chamado * a classe {@link ConfigPrint} não será alterada para continuar
218
+ * sendo usado na impressão da * proxíma linha
219
+ *
220
+ *
221
+ */
222
+ public void imprimeTexto(String texto, boolean negrito) throws Exception {
223
+
224
+ boolean negritoOld = false;
225
+
226
+ //this.getStatusImpressora();
227
+ try {
228
+ if (!isImpressoraOK()) {
229
+ throw new Exception(IMPRESSORA_ERRO);
230
+ }
231
+ negritoOld = this.configPrint.isNegrito();
232
+ this.configPrint.setNegrito(negrito);
233
+ this.setConfigImpressao(this.configPrint);
234
+ sPrintLine(texto);
235
+
236
+ this.configPrint.setNegrito(negritoOld);
237
+ this.setConfigImpressao(this.configPrint);
238
+
239
+ } catch (Exception e) {
240
+ throw new Exception(e.getMessage());
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Método que recebe o atual texto e ser o mesmo será impresso em negrito
246
+ * e/ou itálico.
247
+ *
248
+ * @param texto = Texto que será impresso.
249
+ * @param negrito = Caso o texto deva ser impresso em negrito
250
+ * @param italico = Caso o texto deva ser impresso em itálico
251
+ *
252
+ * @throws Exception = caso a impressora esteja com erro.
253
+ *
254
+ * @apiNote = Esse mátodo só altera o tamanho do texto na impressão que for
255
+ * chamado * a classe {@link ConfigPrint} não será alterada para continuar
256
+ * sendo usado na impressão da * proxíma linha
257
+ *
258
+ *
259
+ */
260
+ public void imprimeTexto(String texto, boolean negrito, boolean italico) throws Exception {
261
+
262
+ boolean negritoOld = false;
263
+ boolean italicoOld = false;
264
+
265
+ try {
266
+ if (!isImpressoraOK()) {
267
+ throw new Exception(IMPRESSORA_ERRO);
268
+ }
269
+ negritoOld = this.configPrint.isNegrito();
270
+ italicoOld = this.configPrint.isItalico();
271
+ this.configPrint.setNegrito(negrito);
272
+ this.configPrint.setItalico(italico);
273
+ this.setConfigImpressao(this.configPrint);
274
+ sPrintLine(texto);
275
+
276
+ this.configPrint.setNegrito(negritoOld);
277
+ this.configPrint.setItalico(italicoOld);
278
+ this.setConfigImpressao(this.configPrint);
279
+
280
+ } catch (Exception e) {
281
+ throw new Exception(e.getMessage());
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Método que recebe o atual texto e ser o mesmo será impresso em negrito,
287
+ * itálico e/ou sublinhado.
288
+ *
289
+ * @param texto = Texto que será impresso.
290
+ * @param negrito = Caso o texto deva ser impresso em negrito
291
+ * @param italico = Caso o texto deva ser impresso em itálico
292
+ * @param sublinhado = Caso o texto deva ser impresso em itálico.
293
+ *
294
+ * @throws Exception = caso a impressora esteja com erro.
295
+ *
296
+ * @apiNote = Esse mátodo só altera o tamanho do texto na impressão que for
297
+ * chamado * a classe {@link ConfigPrint} não será alterada para continuar
298
+ * sendo usado na impressão da * proxíma linha
299
+ *
300
+ *
301
+ */
302
+ public void imprimeTexto(String texto, boolean negrito, boolean italico, boolean sublinhado) throws Exception {
303
+
304
+ boolean negritoOld = false;
305
+ boolean italicoOld = false;
306
+ boolean sublinhadoOld = false;
307
+
308
+ try {
309
+ if (!isImpressoraOK()) {
310
+ throw new Exception(IMPRESSORA_ERRO);
311
+ }
312
+ negritoOld = this.configPrint.isNegrito();
313
+ italicoOld = this.configPrint.isItalico();
314
+ sublinhadoOld = this.configPrint.isSublinhado();
315
+
316
+ this.configPrint.setNegrito(negrito);
317
+ this.configPrint.setItalico(italico);
318
+ this.configPrint.setSublinhado(sublinhado);
319
+ this.setConfigImpressao(this.configPrint);
320
+ sPrintLine(texto);
321
+
322
+ this.configPrint.setNegrito(negritoOld);
323
+ this.configPrint.setItalico(italicoOld);
324
+ this.configPrint.setSublinhado(sublinhadoOld);
325
+ this.setConfigImpressao(this.configPrint);
326
+
327
+ } catch (Exception e) {
328
+ throw new Exception(e.getMessage());
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Método privado que faz a impressão do texto.
334
+ *
335
+ * @param texto = Texto que será impresso
336
+ *
337
+ * @throws GediException = retorna o código do erro
338
+ *
339
+ *
340
+ */
341
+ private boolean sPrintLine(String texto) throws Exception {
342
+ //Print Data
343
+ try {
344
+ ImpressoraInit();
345
+ this.iPrint.DrawStringExt(this.stringConfig, texto);
346
+ this.avancaLinha(configPrint.getAvancaLinhas());
347
+ //ImpressoraOutput();
348
+ return true;
349
+ } catch (GediException e) {
350
+ throw new GediException(e.getErrorCode());
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Método que faz a impressão de imagens
356
+ *
357
+ * @param imagem = Nome da imagem que deve estar na pasta drawable
358
+ *
359
+ * @throws IllegalArgumentException = Argumento passado ilegal
360
+ * @throws GediException = retorna o código do erro.
361
+ *
362
+ *
363
+ */
364
+ public boolean imprimeImagem(String imagem) throws GediException {
365
+
366
+ int id = 0;
367
+ Bitmap bmp;
368
+ try {
369
+
370
+ pictureConfig = new GEDI_PRNTR_st_PictureConfig();
371
+
372
+ // Align
373
+ pictureConfig.alignment = GEDI_PRNTR_e_Alignment.valueOf(configPrint.getAlinhamento());
374
+ // Height
375
+ pictureConfig.height = this.configPrint.getiHeight();
376
+ // Width
377
+ pictureConfig.width = this.configPrint.getiWidth();
378
+
379
+ if (android.os.Build.MODEL.equals("GPOS700")) {
380
+ id = context.getResources().getIdentifier(imagem, "drawable",
381
+ context.getPackageName());
382
+ bmp = BitmapFactory.decodeResource(context.getResources(), id);
383
+ } else {
384
+ id = this.activity.getApplicationContext().getResources().getIdentifier(
385
+ imagem, "drawable",
386
+ this.activity.getApplicationContext().getPackageName());
387
+ bmp = BitmapFactory.decodeResource(this.activity.getApplicationContext().getResources(), id);
388
+ }
389
+
390
+ ImpressoraInit();
391
+ this.iPrint.DrawPictureExt(pictureConfig, bmp);
392
+ this.avancaLinha(configPrint.getAvancaLinhas());
393
+
394
+ return true;
395
+ } catch (IllegalArgumentException e) {
396
+ throw new IllegalArgumentException(e);
397
+ } catch (GediException e) {
398
+ throw new GediException(e.getErrorCode());
399
+ }
400
+
401
+ }
402
+
403
+ /**
404
+ * Método que faz o avanço de linhas após uma impressão.
405
+ *
406
+ * @param linhas = Número de linhas que dever ser pulado após a impressão.
407
+ *
408
+ * @throws GediException = retorna o código do erro.
409
+ *
410
+ * @apiNote = Esse método não deve ser chamado dentro de um FOR ou WHILE, o
411
+ * número de linhas deve ser sempre passado no atributo do método.
412
+ *
413
+ *
414
+ */
415
+ public void avancaLinha(int linhas) throws GediException {
416
+ try {
417
+ if (linhas > 0) {
418
+ this.iPrint.DrawBlankLine(linhas);
419
+ }
420
+ } catch (GediException e) {
421
+ throw new GediException(e.getErrorCode());
422
+ }
423
+ }
424
+
425
+ /**
426
+ * Método que retorno se a impressora está apta a fazer impressões
427
+ *
428
+ * @return true = quando estiver tudo ok.
429
+ *
430
+ *
431
+ */
432
+ public boolean isImpressoraOK() {
433
+
434
+ if (status.getValue() == 0) {
435
+ return true;
436
+ }
437
+ return false;
438
+ }
439
+
440
+ /**
441
+ * Método que faz a inicialização da impressao
442
+ *
443
+ * @throws GediException = retorno o código do erro.
444
+ *
445
+ *
446
+ */
447
+ public void ImpressoraInit() throws GediException {
448
+ try {
449
+ if (this.iPrint != null && !isPrintInit) {
450
+ this.iPrint.Init();
451
+ isPrintInit = true;
452
+ }
453
+ } catch (GediException e) {
454
+ e.printStackTrace();
455
+ throw new GediException(e.getErrorCode());
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Método que faz a finalizacao do objeto iPrint
461
+ *
462
+ * @throws GediException = retorno o código do erro.
463
+ *
464
+ *
465
+ */
466
+ public void ImpressoraOutput() throws GediException {
467
+ try {
468
+ if (this.iPrint != null) {
469
+ this.iPrint.Output();
470
+ isPrintInit = false;
471
+ }
472
+ } catch (GediException e) {
473
+ e.printStackTrace();
474
+ throw new GediException(e.getErrorCode());
475
+ }
476
+ }
477
+
478
+ /**
479
+ * Método que faz a tradução do status atual da impressora.
480
+ *
481
+ * @param status = Recebe o {@link GEDI_PRNTR_e_Status} como atributo
482
+ *
483
+ * @return String = Retorno o atual status da impressora
484
+ *
485
+ *
486
+ */
487
+ private String traduzStatusImpressora(GEDI_PRNTR_e_Status status) {
488
+ String retorno;
489
+ switch (status) {
490
+ case OK:
491
+ retorno = "IMPRESSORA OK";
492
+ break;
493
+
494
+ case OUT_OF_PAPER:
495
+ retorno = "SEM PAPEL";
496
+ break;
497
+
498
+ case OVERHEAT:
499
+ retorno = "SUPER AQUECIMENTO";
500
+ break;
501
+
502
+ default:
503
+ retorno = "ERRO DESCONHECIDO";
504
+ break;
505
+ }
506
+
507
+ return retorno;
508
+ }
509
+ }
@@ -0,0 +1,60 @@
1
+ package com.galago.plugins.gpos;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.Plugin;
5
+ import com.getcapacitor.PluginCall;
6
+ import com.getcapacitor.PluginMethod;
7
+ import com.getcapacitor.annotation.CapacitorPlugin;
8
+
9
+ @CapacitorPlugin(name = "Gpos")
10
+ public class GposPlugin extends Plugin {
11
+
12
+ private GertecPrinter gertecPrinter;
13
+ private ConfigPrint configPrint = new ConfigPrint();
14
+
15
+ @Override
16
+ public void load() {
17
+ // Inicializa a impressora usando o contexto do Capacitor
18
+ gertecPrinter = new GertecPrinter(getContext());
19
+ gertecPrinter.setConfigImpressao(configPrint);
20
+ }
21
+
22
+ @PluginMethod
23
+ public void imprimirTexto(PluginCall call) {
24
+ String mensagem = call.getString("mensagem");
25
+ String alinhar = call.getString("alinhar", "CENTER");
26
+ int size = call.getInt("size", 20);
27
+ String fonte = call.getString("font", "NORMAL"); // Captura a fonte enviada
28
+
29
+ try {
30
+ if (gertecPrinter.isImpressoraOK()) {
31
+ configPrint.setAlinhamento(alinhar);
32
+ configPrint.setTamanho(size);
33
+ configPrint.setFonte(fonte); // Define a fonte na configuração
34
+ configPrint.setAvancaLinhas(2);
35
+
36
+ gertecPrinter.setConfigImpressao(configPrint);
37
+ gertecPrinter.imprimeTexto(mensagem);
38
+
39
+ gertecPrinter.ImpressoraOutput();
40
+ call.resolve();
41
+ } else {
42
+ call.reject("Impressora não está pronta ou sem papel.");
43
+ }
44
+ } catch (Exception e) {
45
+ call.reject("Erro na impressão: " + e.getMessage());
46
+ }
47
+ }
48
+
49
+ @PluginMethod
50
+ public void statusImpressora(PluginCall call) {
51
+ try {
52
+ String status = gertecPrinter.getStatusImpressora();
53
+ JSObject ret = new JSObject();
54
+ ret.put("status", status);
55
+ call.resolve(ret);
56
+ } catch (Exception e) {
57
+ call.reject(e.getMessage());
58
+ }
59
+ }
60
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "api": {
3
+ "name": "GposPlugin",
4
+ "slug": "gposplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "imprimirTexto",
10
+ "signature": "(options: { mensagem: string; alinhar?: string; size?: number; font?: string; }) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "{ mensagem: string; alinhar?: string | undefined; size?: number | undefined; font?: string | undefined; }"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [],
20
+ "docs": "",
21
+ "complexTypes": [],
22
+ "slug": "imprimirtexto"
23
+ },
24
+ {
25
+ "name": "statusImpressora",
26
+ "signature": "() => Promise<{ status: string; }>",
27
+ "parameters": [],
28
+ "returns": "Promise<{ status: string; }>",
29
+ "tags": [],
30
+ "docs": "",
31
+ "complexTypes": [],
32
+ "slug": "statusimpressora"
33
+ }
34
+ ],
35
+ "properties": []
36
+ },
37
+ "interfaces": [],
38
+ "enums": [],
39
+ "typeAliases": [],
40
+ "pluginConfigs": []
41
+ }
@@ -0,0 +1,11 @@
1
+ export interface GposPlugin {
2
+ imprimirTexto(options: {
3
+ mensagem: string;
4
+ alinhar?: string;
5
+ size?: number;
6
+ font?: string;
7
+ }): Promise<void>;
8
+ statusImpressora(): Promise<{
9
+ status: string;
10
+ }>;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface GposPlugin {\n imprimirTexto(options: {\n mensagem: string;\n alinhar?: string;\n size?: number;\n font?: string; // Adicionado para suportar VECTRA.otf\n }): Promise<void>;\n\n statusImpressora(): Promise<{ status: string }>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { GposPlugin } from './definitions';
2
+ declare const Gpos: GposPlugin;
3
+ export * from './definitions';
4
+ export { Gpos };
@@ -0,0 +1,5 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const Gpos = registerPlugin('Gpos');
3
+ export * from './definitions';
4
+ export { Gpos };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,IAAI,GAAG,cAAc,CAAa,MAAM,CAAC,CAAC;AAEhD,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { GposPlugin } from './definitions';\n\nconst Gpos = registerPlugin<GposPlugin>('Gpos');\n\nexport * from './definitions';\nexport { Gpos };\n"]}
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const Gpos = core.registerPlugin('Gpos');
6
+
7
+ exports.Gpos = Gpos;
8
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gpos = registerPlugin('Gpos');\nexport * from './definitions';\nexport { Gpos };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;;AACK,MAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,11 @@
1
+ var capacitorPluginGpos700 = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const Gpos = core.registerPlugin('Gpos');
5
+
6
+ exports.Gpos = Gpos;
7
+
8
+ return exports;
9
+
10
+ })({}, capacitorExports);
11
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Gpos = registerPlugin('Gpos');\nexport * from './definitions';\nexport { Gpos };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;AACK,OAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM;;;;;;;;;;"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "capacitor-plugin-gpos700",
3
+ "version": "0.1.0",
4
+ "description": "Capacitor plugin for GPOS700 and similar Gertec GPOS devices",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "README.md"
14
+ ],
15
+ "author": "Igor Gomes",
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/roginaldosemog/capacitor-plugin-gpos700"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/roginaldosemog/capacitor-plugin-gpos700/issues"
23
+ },
24
+ "keywords": [
25
+ "capacitor",
26
+ "plugin",
27
+ "native"
28
+ ],
29
+ "scripts": {
30
+ "verify": "npm run verify:android",
31
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
32
+ "lint": "npm run eslint && npm run prettier -- --check",
33
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write",
34
+ "eslint": "eslint . --ext ts",
35
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
36
+ "docgen": "docgen --api GposPlugin --output-readme README.md --output-json dist/docs.json",
37
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
38
+ "clean": "rimraf ./dist",
39
+ "watch": "tsc --watch",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "devDependencies": {
43
+ "@capacitor/android": "^8.0.0",
44
+ "@capacitor/core": "^8.0.0",
45
+ "@capacitor/docgen": "^0.3.1",
46
+ "@ionic/eslint-config": "^0.4.0",
47
+ "@ionic/prettier-config": "^4.0.0",
48
+ "eslint": "^8.57.1",
49
+ "prettier": "^3.8.1",
50
+ "rimraf": "^6.1.0",
51
+ "rollup": "^4.53.2",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "peerDependencies": {
55
+ "@capacitor/core": ">=7.0.0"
56
+ },
57
+ "prettier": "@ionic/prettier-config",
58
+ "eslintConfig": {
59
+ "extends": "@ionic/eslint-config/recommended"
60
+ },
61
+ "capacitor": {
62
+ "android": {
63
+ "src": "android"
64
+ }
65
+ }
66
+ }