mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-03-04 23:27:09 -05:00
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.
This commit is contained in:
@@ -21,6 +21,7 @@ import java.lang.ref.WeakReference;
|
||||
class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
{
|
||||
private static final String TAG = "LoyaltyCardLocker";
|
||||
private static final int MAX_WIDTH = 600;
|
||||
|
||||
private final WeakReference<ImageView> imageViewReference;
|
||||
private final String cardId;
|
||||
@@ -37,7 +38,10 @@ class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user