diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-03-17 20:53:28 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-03-17 20:53:28 +0100 |
commit | 31411b788a28b5a2a3bc5de9aa8691b4389d83ff (patch) | |
tree | 2a9254aa8174b0c44b09120c3b8dcfda7f44f49f /src/main/java | |
parent | 95c8a6d304ebd57a141d30b3ecad2dc5c03e00e8 (diff) |
use qr codes instead of aztec. Barcode Scanner is terrible at reading aztec
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/BarcodeProvider.java | 14 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/XmppActivity.java | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/services/BarcodeProvider.java b/src/main/java/de/pixart/messenger/services/BarcodeProvider.java index cd28cb74d..f32082e1a 100644 --- a/src/main/java/de/pixart/messenger/services/BarcodeProvider.java +++ b/src/main/java/de/pixart/messenger/services/BarcodeProvider.java @@ -18,8 +18,9 @@ import android.util.Log; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; -import com.google.zxing.aztec.AztecWriter; import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import java.io.File; import java.io.FileNotFoundException; @@ -105,7 +106,7 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); - Bitmap bitmap = createAztecBitmap(account.getShareableUri(), 1024); + Bitmap bitmap = create2dBarcodeBitmap(account.getShareableUri(), 1024); OutputStream outputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); outputStream.close(); @@ -168,12 +169,12 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio return Uri.parse("content://" + packageId + AUTHORITY + "/" + account.getJid().toBareJid() + ".png"); } - public static Bitmap createAztecBitmap(String input, int size) { + public static Bitmap create2dBarcodeBitmap(String input, int size) { try { - final AztecWriter AZTEC_WRITER = new AztecWriter(); + final QRCodeWriter barcodeWriter = new QRCodeWriter(); final Hashtable<EncodeHintType, Object> hints = new Hashtable<>(); - hints.put(EncodeHintType.ERROR_CORRECTION, 10); - final BitMatrix result = AZTEC_WRITER.encode(input, BarcodeFormat.AZTEC, size, size, hints); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); + final BitMatrix result = barcodeWriter.encode(input, BarcodeFormat.QR_CODE, size, size, hints); final int width = result.getWidth(); final int height = result.getHeight(); final int[] pixels = new int[width * height]; @@ -187,6 +188,7 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } catch (final Exception e) { + e.printStackTrace(); return null; } } diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 4835ab03e..d7467b7a4 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -1095,7 +1095,7 @@ public abstract class XmppActivity extends Activity { Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (size.x < size.y ? size.x : size.y); - Bitmap bitmap = BarcodeProvider.createAztecBitmap(uri, width); + Bitmap bitmap = BarcodeProvider.create2dBarcodeBitmap(uri, width); ImageView view = new ImageView(this); view.setBackgroundColor(Color.WHITE); view.setImageBitmap(bitmap); |