package com.dspread.pos.utils;

import android.graphics.Bitmap;
import android.graphics.Color;
//import com.google.zxing.BarcodeFormat;
//import com.google.zxing.MultiFormatWriter;
//import com.google.zxing.WriterException;
//import com.google.zxing.common.BitMatrix;
import com.dspread.print.zxing.BarcodeFormat;
import com.dspread.print.zxing.EncodeHintType;
import com.dspread.print.zxing.MultiFormatWriter;
import com.dspread.print.zxing.WriterException;
import com.dspread.print.zxing.common.BitMatrix;
import com.dspread.print.zxing.qrcode.decoder.ErrorCorrectionLevel;


public class QRCodeGenerator {
    public static Bitmap generateQRCode(String text, int width, int height) {
        try {
            BitMatrix bitMatrix = new MultiFormatWriter().encode(
                    text,
                    BarcodeFormat.QR_CODE,
                    width,
                    height
            );

            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    bitmap.setPixel(x, y, bitMatrix.get(x, y) ? Color.WHITE : Color.rgb(140, 16 , 132));
                }
            }
            return bitmap;
        } catch (WriterException e) {
            e.printStackTrace();
            return null;
        }
    }
}