mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 12:55:08 -05:00
Use Mode.ALPHANUMERIC for QR codes to save space
This commit is contained in:
parent
0f520975e4
commit
c8266203f8
@ -85,11 +85,12 @@ public class QrCodeViewActivity extends BaseActivity {
|
||||
ActivityCompat.finishAfterTransition(QrCodeViewActivity.this);
|
||||
}
|
||||
|
||||
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
|
||||
String qrCodeContent = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
|
||||
|
||||
Uri uri = new Uri.Builder()
|
||||
.scheme(Constants.FINGERPRINT_SCHEME)
|
||||
.opaquePart(KeyFormattingUtils.convertFingerprintToHex(blob))
|
||||
.build();
|
||||
// create a minimal size qr code, we can keep this in ram no problem
|
||||
final Bitmap qrCode = QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0);
|
||||
final Bitmap qrCode = QrCodeUtils.getQRCodeBitmap(uri, 0);
|
||||
|
||||
mQrCode.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new OnGlobalLayoutListener() {
|
||||
|
@ -731,9 +731,12 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
AsyncTask<Void, Void, Bitmap> loadTask =
|
||||
new AsyncTask<Void, Void, Bitmap>() {
|
||||
protected Bitmap doInBackground(Void... unused) {
|
||||
String qrCodeContent = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
|
||||
Uri uri = new Uri.Builder()
|
||||
.scheme(Constants.FINGERPRINT_SCHEME)
|
||||
.opaquePart(fingerprint)
|
||||
.build();
|
||||
// render with minimal size
|
||||
return QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0);
|
||||
return QrCodeUtils.getQRCodeBitmap(uri, 0);
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap qrCode) {
|
||||
|
@ -386,9 +386,12 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
||||
AsyncTask<Void, Void, Bitmap> loadTask =
|
||||
new AsyncTask<Void, Void, Bitmap>() {
|
||||
protected Bitmap doInBackground(Void... unused) {
|
||||
String qrCodeContent = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
|
||||
Uri uri = new Uri.Builder()
|
||||
.scheme(Constants.FINGERPRINT_SCHEME)
|
||||
.opaquePart(fingerprint)
|
||||
.build();
|
||||
// render with minimal size
|
||||
return QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0);
|
||||
return QrCodeUtils.getQRCodeBitmap(uri, 0);
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap qrCode) {
|
||||
|
@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
@ -33,17 +34,24 @@ import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Copied from Bitcoin Wallet
|
||||
*/
|
||||
public class QrCodeUtils {
|
||||
|
||||
public static Bitmap getQRCodeBitmap(final Uri uri, final int size) {
|
||||
// for URIs we want alphanumeric encoding to save space, thus make everything upper case!
|
||||
// zxing will then select Mode.ALPHANUMERIC internally
|
||||
return getQRCodeBitmap(uri.toString().toUpperCase(Locale.ENGLISH), size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Bitmap with QR Code based on input.
|
||||
* @return QR Code as Bitmap
|
||||
*/
|
||||
public static Bitmap getQRCodeBitmap(final String input, final int size) {
|
||||
private static Bitmap getQRCodeBitmap(final String input, final int size) {
|
||||
|
||||
try {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user