From 24578dcf88ff2a2001ba3e11b62b0829b09b0fbb Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 24 Oct 2023 17:12:41 +0200 Subject: [PATCH] enlarge qr display dialog and increase default qr code density --- .../sparrowwallet/sparrow/AppServices.java | 5 +++++ .../sparrow/control/QRDensity.java | 2 +- .../sparrow/control/QRDisplayDialog.java | 22 +++++++++++++------ .../sparrowwallet/sparrow/io/PdfUtils.java | 3 ++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 19a59387..7d33e0b6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -565,6 +565,11 @@ public class AppServices { return windowIcon; } + public static boolean isReducedWindowHeight() { + Window activeWindow = getActiveWindow(); + return (activeWindow != null && activeWindow.getHeight() < 768); + } + public static boolean isReducedWindowHeight(Node node) { return (node.getScene() != null && node.getScene().getWindow().getHeight() < 768); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRDensity.java b/src/main/java/com/sparrowwallet/sparrow/control/QRDensity.java index f74a5d09..a4b92dc3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRDensity.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRDensity.java @@ -1,7 +1,7 @@ package com.sparrowwallet.sparrow.control; public enum QRDensity { - NORMAL("Normal", 250), + NORMAL("Normal", 400), LOW("Low", 80); private final String name; diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java index e2f5c69f..ef00387c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java @@ -1,6 +1,7 @@ package com.sparrowwallet.sparrow.control; import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; import com.google.zxing.client.j2se.MatrixToImageConfig; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; @@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Locale; +import java.util.Map; import java.util.Optional; @SuppressWarnings("deprecation") @@ -39,8 +41,10 @@ public class QRDisplayDialog extends Dialog { private static final int ANIMATION_PERIOD_MILLIS = 200; - private static final int QR_WIDTH = 480; - private static final int QR_HEIGHT = 480; + private static final int DEFAULT_QR_SIZE = 580; + private static final int REDUCED_QR_SIZE = 520; + + private final int qrSize = getQRSize(); private final UR ur; private UREncoder encoder; @@ -103,8 +107,8 @@ public class QRDisplayDialog extends Dialog { dialogPane.getButtonTypes().add(scanButtonType); } - dialogPane.setPrefWidth(40 + QR_WIDTH + 40); - dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); + dialogPane.setPrefWidth(40 + qrSize + 40); + dialogPane.setPrefHeight(40 + qrSize + 85); AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton); @@ -137,13 +141,17 @@ public class QRDisplayDialog extends Dialog { dialogPane.getButtonTypes().add(scanButtonType); } - dialogPane.setPrefWidth(40 + QR_WIDTH + 40); - dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); + dialogPane.setPrefWidth(40 + qrSize + 40); + dialogPane.setPrefHeight(40 + qrSize + 85); AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton); } + private int getQRSize() { + return AppServices.isReducedWindowHeight() ? REDUCED_QR_SIZE : DEFAULT_QR_SIZE; + } + private void createAnimateQRService() { animateQRService = new AnimateQRService(); animateQRService.setPeriod(Duration.millis(ANIMATION_PERIOD_MILLIS)); @@ -169,7 +177,7 @@ public class QRDisplayDialog extends Dialog { protected Image getQrCode(String fragment) { try { QRCodeWriter qrCodeWriter = new QRCodeWriter(); - BitMatrix qrMatrix = qrCodeWriter.encode(fragment, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT); + BitMatrix qrMatrix = qrCodeWriter.encode(fragment, BarcodeFormat.QR_CODE, qrSize, qrSize, Map.of(EncodeHintType.MARGIN, "2")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); MatrixToImageWriter.writeToStream(qrMatrix, "PNG", baos, new MatrixToImageConfig()); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/PdfUtils.java b/src/main/java/com/sparrowwallet/sparrow/io/PdfUtils.java index ecdecdce..c833778f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/PdfUtils.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/PdfUtils.java @@ -1,6 +1,7 @@ package com.sparrowwallet.sparrow.io; 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; @@ -104,7 +105,7 @@ public class PdfUtils { private static javafx.scene.image.Image getQrCode(String fragment) throws IOException, WriterException { QRCodeWriter qrCodeWriter = new QRCodeWriter(); - BitMatrix qrMatrix = qrCodeWriter.encode(fragment.toUpperCase(Locale.ROOT), BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT); + BitMatrix qrMatrix = qrCodeWriter.encode(fragment.toUpperCase(Locale.ROOT), BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, Map.of(EncodeHintType.MARGIN, "2")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); MatrixToImageWriter.writeToStream(qrMatrix, "PNG", baos, new MatrixToImageConfig());