This repository was archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathBarcodeConverter.java
More file actions
242 lines (178 loc) · 7.69 KB
/
BarcodeConverter.java
File metadata and controls
242 lines (178 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package com.visioncameracodescanner;
import android.graphics.Point;
import android.graphics.Rect;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.google.mlkit.vision.barcode.common.Barcode;
import java.util.List;
/**
* Converter util class used to convert Barcode related variables to either WritableNativeArray or
* WritableNativeMap
*/
public class BarcodeConverter {
public static WritableNativeArray convertToArray(@NonNull Point[] points) {
WritableNativeArray array = new WritableNativeArray();
for (Point point: points) {
array.pushMap(convertToMap(point));
}
return array;
}
public static WritableNativeArray convertToArray(@NonNull String[] elements) {
WritableNativeArray array = new WritableNativeArray();
for (String elem: elements) {
array.pushString(elem);
}
return array;
}
public static WritableNativeArray convertStringList(@NonNull List<String> elements) {
WritableNativeArray array = new WritableNativeArray();
for (String elem: elements) {
array.pushString(elem);
}
return array;
}
public static WritableNativeArray convertAddressList(@NonNull List<Barcode.Address> addresses) {
WritableNativeArray array = new WritableNativeArray();
for (Barcode.Address address: addresses) {
array.pushMap(convertToMap(address));
}
return array;
}
public static WritableNativeArray convertPhoneList(@NonNull List<Barcode.Phone> phones) {
WritableNativeArray array = new WritableNativeArray();
for (Barcode.Phone phone: phones) {
array.pushMap(convertToMap(phone));
}
return array;
}
public static WritableNativeArray convertEmailList(@NonNull List<Barcode.Email> emails) {
WritableNativeArray array = new WritableNativeArray();
for (Barcode.Email email: emails) {
array.pushMap(convertToMap(email));
}
return array;
}
public static WritableNativeMap convertToMap(@NonNull Point point) {
WritableNativeMap map = new WritableNativeMap();
map.putInt("x", point.x);
map.putInt("y", point.y);
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.Address address) {
WritableNativeMap map = new WritableNativeMap();
map.putArray("addressLines", convertToArray(address.getAddressLines()));
map.putInt("type", address.getType());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Rect rect) {
WritableNativeMap map = new WritableNativeMap();
map.putInt("bottom", rect.bottom);
map.putInt("left", rect.left);
map.putInt("right", rect.right);
map.putInt("top", rect.top);
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.ContactInfo contactInfo) {
WritableNativeMap map = new WritableNativeMap();
map.putArray("addresses", convertAddressList(contactInfo.getAddresses()));
map.putArray("emails", convertEmailList(contactInfo.getEmails()));
map.putMap("name", convertToMap(contactInfo.getName()));
map.putString("organization", contactInfo.getOrganization());
map.putArray("phones", convertPhoneList(contactInfo.getPhones()));
map.putString("title", contactInfo.getTitle());
map.putArray("urls", convertStringList(contactInfo.getUrls()));
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.PersonName name) {
WritableNativeMap map = new WritableNativeMap();
map.putString("first", name.getFirst());
map.putString("formattedName", name.getFormattedName());
map.putString("last", name.getLast());
map.putString("middle", name.getMiddle());
map.putString("prefix", name.getPrefix());
map.putString("pronunciation", name.getPronunciation());
map.putString("suffix", name.getSuffix());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.UrlBookmark url) {
WritableNativeMap map = new WritableNativeMap();
map.putString("title", url.getTitle());
map.putString("url", url.getUrl());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.Email email) {
WritableNativeMap map = new WritableNativeMap();
map.putString("address", email.getAddress());
map.putString("body", email.getBody());
map.putString("subject", email.getSubject());
map.putInt("type", email.getType());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.Phone phone) {
WritableNativeMap map = new WritableNativeMap();
map.putString("number", phone.getNumber());
map.putInt("type", phone.getType());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.Sms sms) {
WritableNativeMap map = new WritableNativeMap();
map.putString("message", sms.getMessage());
map.putString("phoneNumber", sms.getPhoneNumber());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.WiFi wifi) {
WritableNativeMap map = new WritableNativeMap();
map.putInt("encryptionType", wifi.getEncryptionType());
map.putString("password", wifi.getPassword());
map.putString("ssid", wifi.getSsid());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.GeoPoint geoPoint) {
WritableNativeMap map = new WritableNativeMap();
map.putDouble("lat", geoPoint.getLat());
map.putDouble("lng", geoPoint.getLng());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.CalendarDateTime calendarDateTime) {
WritableNativeMap map = new WritableNativeMap();
map.putInt("day", calendarDateTime.getDay());
map.putInt("hours", calendarDateTime.getHours());
map.putInt("minutes", calendarDateTime.getMinutes());
map.putInt("month", calendarDateTime.getMonth());
map.putString("rawValue", calendarDateTime.getRawValue());
map.putInt("year", calendarDateTime.getYear());
map.putInt("seconds", calendarDateTime.getSeconds());
map.putBoolean("isUtc", calendarDateTime.isUtc());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.CalendarEvent calendarEvent) {
WritableNativeMap map = new WritableNativeMap();
map.putString("description", calendarEvent.getDescription());
map.putMap("end", convertToMap(calendarEvent.getEnd()));
map.putString("location", calendarEvent.getLocation());
map.putString("organizer", calendarEvent.getOrganizer());
map.putMap("start", convertToMap(calendarEvent.getStart()));
map.putString("status", calendarEvent.getStatus());
map.putString("summary", calendarEvent.getSummary());
return map;
}
public static WritableNativeMap convertToMap(@NonNull Barcode.DriverLicense driverLicense) {
WritableNativeMap map = new WritableNativeMap();
map.putString("addressCity", driverLicense.getAddressCity());
map.putString("addressState", driverLicense.getAddressState());
map.putString("addressStreet", driverLicense.getAddressStreet());
map.putString("addressZip", driverLicense.getAddressZip());
map.putString("birthDate", driverLicense.getBirthDate());
map.putString("documentType", driverLicense.getDocumentType());
map.putString("expiryDate", driverLicense.getExpiryDate());
map.putString("firstName", driverLicense.getFirstName());
map.putString("gender", driverLicense.getGender());
map.putString("issueDate", driverLicense.getIssueDate());
map.putString("issuingCountry", driverLicense.getIssuingCountry());
map.putString("lastName", driverLicense.getLastName());
map.putString("licenseNumber", driverLicense.getLicenseNumber());
map.putString("middleName", driverLicense.getMiddleName());
return map;
}
}