use qr codes instead of aztec. Barcode Scanner is terrible at reading aztec. fixes #2375

This commit is contained in:
Daniel Gultsch 2017-03-17 12:56:55 +01:00
parent 935ac25cbd
commit 91a69d7d85
3 changed files with 17 additions and 13 deletions

View file

@ -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;
@ -106,7 +107,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();
@ -181,12 +182,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];
@ -200,6 +201,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;
}
}

View file

@ -52,18 +52,12 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.aztec.AztecWriter;
import com.google.zxing.common.BitMatrix;
import net.java.otr4j.session.SessionID;
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
@ -1059,7 +1053,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);

View file

@ -176,6 +176,7 @@
<string name="mgmt_account_delete_confirm_text">Zure kontua ezabatzen baduzu zure elkarrizketa historia guztia galduko da</string>
<string name="attach_record_voice">Ahotsa grabatu</string>
<string name="account_settings_jabber_id">Jabber IDa</string>
<string name="block_jabber_id">Jabber IDa blokeatu</string>
<string name="account_settings_password">Pasahitza</string>
<string name="account_settings_example_jabber_id">erabiltzailea@adibidea.com</string>
<string name="account_settings_confirm_password">Pasahitza berretsi</string>
@ -470,6 +471,8 @@
<string name="disable_account">Kontua ezgaitu</string>
<string name="contact_is_typing">%s idazten ari da...</string>
<string name="contact_has_stopped_typing">%s(e)k idazteari utzi dio</string>
<string name="contacts_are_typing">%s idazten ari dira…</string>
<string name="contacts_have_stopped_typing">%s idazteari utzi diote</string>
<string name="pref_chat_states">Idazketa jakinarazpenak</string>
<string name="pref_chat_states_summary">Zure kontaktuak mezu berri bat noiz idazten ari zaren jakin dezaten baimendu</string>
<string name="send_location">Kokapena partekatu</string>
@ -700,4 +703,9 @@
<string name="encrypting_message">Mezua enkriptatzen</string>
<string name="not_fetching_history_retention_period">Mezurik ez eskuratzen gelditze tarte lokalarengatik.</string>
<string name="transcoding_video_progress">Bideoa konprimatzen (%s%% osatua)</string>
<string name="corresponding_conversations_closed">Dagokion elkarrizketa itxi egin da.</string>
<string name="contact_blocked_past_tense">Kontaktua blokeatu da.</string>
<string name="pref_notifications_from_strangers">Ezezagunen jakinarazpenak</string>
<string name="pref_notifications_from_strangers_summary">Ezezagunen mezuak jasotzerakoan jakinarazi.</string>
<string name="received_message_from_stranger">Ezezagun baten mezu bat jaso duzu</string>
</resources>