diff options
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java | 30 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/QrCodeUtils.java | 5 |
2 files changed, 17 insertions, 18 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java index 0f9a52be6..1efd2c935 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java @@ -21,11 +21,6 @@ import android.annotation.TargetApi; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.TransitionDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -37,6 +32,7 @@ import android.support.v4.content.Loader; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AlphaAnimation; import android.widget.ImageView; import android.widget.TextView; @@ -404,21 +400,25 @@ public class ViewKeyShareFragment extends LoaderFragment implements new AsyncTask<Void, Void, Bitmap>() { protected Bitmap doInBackground(Void... unused) { String qrCodeContent = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; - return QrCodeUtils.getQRCodeBitmap(qrCodeContent, QR_CODE_SIZE); + // render with minimal size + return QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0); } protected void onPostExecute(Bitmap qrCode) { // only change view, if fragment is attached to activity if (ViewKeyShareFragment.this.isAdded()) { - // Transition drawable with a transparent drawable and the final bitmap - final TransitionDrawable td = - new TransitionDrawable(new Drawable[]{ - new ColorDrawable(Color.TRANSPARENT), - new BitmapDrawable(getResources(), qrCode) - }); - - mFingerprintQrCode.setImageDrawable(td); - td.startTransition(200); + + // scale the image up to our actual size. we do this in code rather + // than let the ImageView do this because we don't require filtering. + Bitmap scaled = Bitmap.createScaledBitmap(qrCode, + mFingerprintQrCode.getHeight(), mFingerprintQrCode.getHeight(), + false); + mFingerprintQrCode.setImageBitmap(scaled); + + // simple fade-in animation + AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f); + anim.setDuration(200); + mFingerprintQrCode.startAnimation(anim); } } }; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/QrCodeUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/QrCodeUtils.java index dd07a16b0..36f38045f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/QrCodeUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/QrCodeUtils.java @@ -37,7 +37,6 @@ import java.util.Hashtable; * Copied from Bitcoin Wallet */ public class QrCodeUtils { - public static final QRCodeWriter QR_CODE_WRITER = new QRCodeWriter(); /** * Generate Bitmap with QR Code based on input. @@ -50,7 +49,7 @@ public class QrCodeUtils { try { final Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); - final BitMatrix result = QR_CODE_WRITER.encode(input, BarcodeFormat.QR_CODE, size, + final BitMatrix result = new QRCodeWriter().encode(input, BarcodeFormat.QR_CODE, size, size, hints); final int width = result.getWidth(); @@ -60,7 +59,7 @@ public class QrCodeUtils { for (int y = 0; y < height; y++) { final int offset = y * width; for (int x = 0; x < width; x++) { - pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.TRANSPARENT; + pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } |