forked from PoC-Consortium/burstcoin
-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
DeeplinkQRCodeGenerator.java
51 lines (39 loc) · 1.88 KB
/
DeeplinkQRCodeGenerator.java
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
package brs.deeplink;
import brs.feesuggestions.FeeSuggestionType;
import brs.util.StringUtils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageConfig;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.awt.image.BufferedImage;
import java.util.EnumMap;
import java.util.Map;
public class DeeplinkQRCodeGenerator {
private final QRCodeWriter qrCodeWriter = new QRCodeWriter();
private final Map<EncodeHintType, ErrorCorrectionLevel> hints = new EnumMap<>(EncodeHintType.class);
public DeeplinkQRCodeGenerator() {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
}
public BufferedImage generateRequestSignumDeepLinkQRCode(String receiverId, long amountNQT, FeeSuggestionType feeSuggestionType, Long feeNQT, String message, boolean immutable)
throws WriterException {
final StringBuilder deeplinkBuilder = new StringBuilder("burst://requestBurst");
deeplinkBuilder.append("&receiver=").append(receiverId);
deeplinkBuilder.append("&amountNQT=").append(amountNQT);
if (feeNQT != null) {
deeplinkBuilder.append("&feeNQT=").append(feeNQT);
} else {
deeplinkBuilder.append("&feeSuggestionType=").append(feeSuggestionType.getType());
}
if (!StringUtils.isEmpty(message)) {
deeplinkBuilder.append("&message=").append(message);
}
deeplinkBuilder.append("&immutable=").append(immutable);
return generateSignumQRCode(deeplinkBuilder.toString());
}
private BufferedImage generateSignumQRCode(String url) throws WriterException {
return MatrixToImageWriter.toBufferedImage(qrCodeWriter.encode(url, BarcodeFormat.QR_CODE, 350, 350, hints), new MatrixToImageConfig());
}
}