diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
3 files changed, 33 insertions, 21 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java index 6193be297..cc66a33a3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeActivity.java @@ -17,10 +17,12 @@ package org.sufficientlysecure.keychain.ui; +import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; @@ -38,8 +40,6 @@ public class QrCodeActivity extends ActionBarActivity { private ImageView mFingerprintQrCode; - private static final int QR_CODE_SIZE = 1000; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -87,7 +87,20 @@ public class QrCodeActivity extends ActionBarActivity { String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); String qrCodeContent = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; - mFingerprintQrCode.setImageBitmap(QrCodeUtils.getQRCodeBitmap(qrCodeContent, QR_CODE_SIZE)); + + // create a minimal size qr code, we can keep this in ram no problem + final Bitmap qrCode = QrCodeUtils.getQRCodeBitmap(qrCodeContent, 0); + + mFingerprintQrCode.getViewTreeObserver().addOnGlobalLayoutListener( + new OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + // create actual bitmap in display dimensions + Bitmap scaled = Bitmap.createScaledBitmap(qrCode, + mFingerprintQrCode.getWidth(), mFingerprintQrCode.getWidth(), false); + mFingerprintQrCode.setImageBitmap(scaled); + } + }); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.showNotify(this, R.string.error_key_not_found, Style.ERROR); 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; } } |