aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/ui
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2018-02-26 21:07:26 +0100
committersteckbrief <steckbrief@chefmail.de>2018-02-26 21:07:26 +0100
commitfb9817091a8722782801a34b40e5baaceb777521 (patch)
tree8ee6fed344addc8c3303e82b50468c6a931d2894 /src/main/java/de/thedevstack/conversationsplus/utils/ui
parent010eb44ad971ad9e77b555179d70b6e43d1dec80 (diff)
improves remote file status display and loading of remote files
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/ui')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ui/QrCodeUtil.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/QrCodeUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/QrCodeUtil.java
new file mode 100644
index 00000000..1c342290
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/QrCodeUtil.java
@@ -0,0 +1,68 @@
+package de.thedevstack.conversationsplus.utils.ui;
+
+import android.app.AlertDialog;
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.Point;
+import android.widget.ImageView;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+import java.util.Hashtable;
+
+import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ui.XmppActivity;
+
+/**
+ */
+public final class QrCodeUtil {
+
+ public static void showQrCode(XmppActivity activity) {
+ String uri = activity.getShareableUri();
+ if (uri != null) {
+ Point size = new Point();
+ activity.getWindowManager().getDefaultDisplay().getSize(size);
+ final int width = (size.x < size.y ? size.x : size.y);
+
+ Bitmap bitmap = QrCodeUtil.createQrCodeBitmap(uri, width);
+ ImageView view = new ImageView(activity);
+ view.setImageBitmap(bitmap);
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setView(view);
+ builder.create().show();
+ }
+ }
+
+ public static Bitmap createQrCodeBitmap(String input, int size) {
+ Logging.d(Config.LOGTAG,"qr code requested size: "+size);
+ try {
+ final QRCodeWriter QR_CODE_WRITER = new QRCodeWriter();
+ final Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
+ hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
+ final BitMatrix result = QR_CODE_WRITER.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];
+ 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;
+ }
+ }
+ final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ Logging.d(Config.LOGTAG,"output size: "+width+"x"+height);
+ bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
+ return bitmap;
+ } catch (final WriterException e) {
+ return null;
+ }
+ }
+
+ private QrCodeUtil() {}
+}