From 64db9e593d9e4bde7613f5ab18dd59921ce79c34 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sun, 11 Jun 2017 14:56:17 -0400 Subject: [PATCH] Limit width of barcodes To reduce the amount of memory used in generating barcodes, limit the width of the barcodes to no more than 3x the height. This should be plenty sufficient to generate a usable barcode. On devices with a really long width generating a barcode of 200x2560 is not useful and can result in an OutOfMemoryError. --- .../java/protect/card_locker/BarcodeImageWriterTask.java | 6 +++++- 1 file changed, 5 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 b7e5642e9..1e8e5736f 100644 --- a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java +++ b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java @@ -21,6 +21,7 @@ import java.lang.ref.WeakReference; class BarcodeImageWriterTask extends AsyncTask { private static final String TAG = "LoyaltyCardLocker"; + private static final int MAX_WIDTH = 600; private final WeakReference imageViewReference; private final String cardId; @@ -37,7 +38,10 @@ class BarcodeImageWriterTask extends AsyncTask cardId = cardIdString; format = barcodeFormat; imageHeight = imageView.getHeight(); - imageWidth = imageView.getWidth(); + + // No matter how long the window is, there is only so much space + // needed for the barcode. Put a limit on it to reduce memory usage + imageWidth = Math.min(imageView.getWidth(), MAX_WIDTH); } public Bitmap doInBackground(Void... params)