Search in sources :

Example 16 with QRCodeEncoder

use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.

the class OpenDimeActivity method generateQRCode.

private Bitmap generateQRCode(String uri) {
    Bitmap bitmap = null;
    QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
    try {
        bitmap = qrCodeEncoder.encodeAsBitmap();
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) WriterException(com.google.zxing.WriterException)

Example 17 with QRCodeEncoder

use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.

the class ManualCahootsActivity method shareCahootsPayload.

private void shareCahootsPayload() {
    String strCahoots = this.payload.toJSON().toString();
    // tx max size in bytes == 2148
    final int QR_ALPHANUM_CHAR_LIMIT = 4296;
    dialog = new AppCompatDialog(this, R.style.stowaway_dialog);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(true);
    dialog.setContentView(R.layout.cahoots_qr_dialog_layout);
    ImageView qrCode = dialog.findViewById(R.id.qr_code_imageview);
    Button copy = dialog.findViewById(R.id.cahoots_copy_btn);
    Button share = dialog.findViewById(R.id.cahoots_share);
    TextView qrErrorMessage = dialog.findViewById(R.id.qr_error_stowaway);
    if (strCahoots.length() <= QR_ALPHANUM_CHAR_LIMIT) {
        Display display = this.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int imgWidth = Math.max(size.x - 240, 150);
        Bitmap bitmap = null;
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(strCahoots, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
        try {
            bitmap = qrCodeEncoder.encodeAsBitmap();
        } catch (WriterException e) {
            qrErrorMessage.setVisibility(View.VISIBLE);
            e.printStackTrace();
        }
        qrCode.setImageBitmap(bitmap);
    } else {
        qrErrorMessage.setVisibility(View.VISIBLE);
        Toast.makeText(getApplicationContext(), R.string.tx_too_large_qr, Toast.LENGTH_SHORT).show();
    }
    share.setOnClickListener(v -> {
        if (!(strCahoots.length() <= QR_ALPHANUM_CHAR_LIMIT)) {
            Intent txtIntent = new Intent(android.content.Intent.ACTION_SEND);
            txtIntent.setType("text/plain");
            txtIntent.putExtra(android.content.Intent.EXTRA_TEXT, strCahoots);
            startActivity(Intent.createChooser(txtIntent, "Share"));
            return;
        }
        String strFileName = AppUtil.getInstance(getApplicationContext()).getReceiveQRFilename();
        File file = new File(strFileName);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
        file.setReadable(true, false);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
        } catch (FileNotFoundException fnfe) {
        }
        if (file != null && fos != null) {
            Bitmap bitmap1 = ((BitmapDrawable) qrCode.getDrawable()).getBitmap();
            bitmap1.compress(Bitmap.CompressFormat.PNG, 0, fos);
            try {
                fos.close();
            } catch (IOException ioe) {
                ;
            }
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("image/png");
            if (android.os.Build.VERSION.SDK_INT >= 24) {
                // From API 24 sending FIle on intent ,require custom file provider
                intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getApplicationContext().getPackageName() + ".provider", file));
            } else {
                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            }
            ManualCahootsActivity.this.startActivity(Intent.createChooser(intent, getApplicationContext().getText(R.string.send_tx)));
        }
    });
    copy.setOnClickListener(v -> {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getApplicationContext().getSystemService(android.content.Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = null;
        clip = android.content.ClipData.newPlainText("Cahoots", strCahoots);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getApplicationContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
    });
    dialog.show();
}
Also used : ClipboardManager(android.content.ClipboardManager) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) Point(android.graphics.Point) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) Point(android.graphics.Point) WriterException(com.google.zxing.WriterException) JSONException(org.json.JSONException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ClipData(android.content.ClipData) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) FileOutputStream(java.io.FileOutputStream) AppCompatDialog(android.support.v7.app.AppCompatDialog) ClipboardManager(android.content.ClipboardManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File) WriterException(com.google.zxing.WriterException) Display(android.view.Display)

Example 18 with QRCodeEncoder

use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.

the class BIP47ShowQR method generateQRCode.

private Bitmap generateQRCode(String uri) {
    Bitmap bitmap = null;
    QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
    try {
        bitmap = qrCodeEncoder.encodeAsBitmap();
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) WriterException(com.google.zxing.WriterException)

Aggregations

Bitmap (android.graphics.Bitmap)18 WriterException (com.google.zxing.WriterException)18 QRCodeEncoder (com.google.zxing.client.android.encode.QRCodeEncoder)18 ImageView (android.widget.ImageView)12 TextView (android.widget.TextView)12 LinearLayout (android.widget.LinearLayout)11 DialogInterface (android.content.DialogInterface)10 IOException (java.io.IOException)7 AlertDialog (android.app.AlertDialog)6 Intent (android.content.Intent)6 MnemonicException (org.bitcoinj.crypto.MnemonicException)6 JSONException (org.json.JSONException)6 Point (android.graphics.Point)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Display (android.view.Display)4 View (android.view.View)4 SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)4 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4