From 32911858122379aa6daa576f4a16736c60eac8a6 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sun, 18 Feb 2018 23:14:37 -0500 Subject: [PATCH] Render 1D barcodes with a larger width For some reason when 1D barcodes are rendered in a smaller width, they end up scrunched up and not using all available space. As a result, they do not scale to the entire width of the screen. In many cases the barcode is not scannable even in landscape. To resolve this, render the 1D barcodes in a larger space. The space is still bounded, to prevent OOMs on tablets or really wide screen devices. --- .../card_locker/BarcodeImageWriterTask.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java index 474dc0298..ac885de43 100644 --- a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java +++ b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java @@ -21,7 +21,11 @@ import java.lang.ref.WeakReference; class BarcodeImageWriterTask extends AsyncTask { private static final String TAG = "LoyaltyCardLocker"; - private static final int MAX_WIDTH = 500; + + // When drawn in a smaller window 1D barcodes for some reason end up + // squished, whereas 2D barcodes look fine. + private static final int MAX_WIDTH_1D = 1500; + private static final int MAX_WIDTH_2D = 500; private final WeakReference imageViewReference; private final String cardId; @@ -38,6 +42,8 @@ class BarcodeImageWriterTask extends AsyncTask cardId = cardIdString; format = barcodeFormat; + final int MAX_WIDTH = getMaxWidth(format); + if(imageView.getWidth() < MAX_WIDTH) { imageHeight = imageView.getHeight(); @@ -52,6 +58,36 @@ class BarcodeImageWriterTask extends AsyncTask } } + private int getMaxWidth(BarcodeFormat format) + { + switch(format) + { + // 2D barcodes + case AZTEC: + case DATA_MATRIX: + case MAXICODE: + case PDF_417: + case QR_CODE: + return MAX_WIDTH_2D; + + // 1D barcodes: + case CODABAR: + case CODE_39: + case CODE_93: + case CODE_128: + case EAN_8: + case EAN_13: + case ITF: + case UPC_A: + case UPC_E: + case RSS_14: + case RSS_EXPANDED: + case UPC_EAN_EXTENSION: + default: + return MAX_WIDTH_1D; + } + } + public Bitmap doInBackground(Void... params) { MultiFormatWriter writer = new MultiFormatWriter();