package com.jaiswallab.lab.inventory;
+import com.google.zxing.*;
import com.google.zxing.integration.android.*;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+import com.google.zxing.qrcode.encoder.ByteMatrix;
+import com.google.zxing.qrcode.encoder.Encoder;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
public void printQRClick(View view) {
printingNewQR = true;
recognizingQR = false;
- text1.setText("Print QR button clicked");
- //IntentIntegrator intentIntegrator = new IntentIntegrator(this);
- //intentIntegrator.initiateScan();
+ addNewQR();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (scanResult != null) {
String contents = scanResult.getContents();
if(printingNewQR) {
- // addNewQR(contents);
+ return;
} else if(recognizingQR){
displayQRInfo(contents);
}
text1.setText(contents);
// handle scan result
}
+
// else continue with any other code you need in the method
}
//this will use the information passed to it to create a new ID in the database
//it will also use any input from a variety of text edits in order to populate the database entry
//can we store pictures in the database if desired?
-/* public void addNewQR(String id) {
- return;
+ public void addNewQR() {
+
int rand1 = (int) (100*Math.random());
int rand2 = (int) (100*Math.random());
int rand3 = (int) (100*Math.random());
int rand4 = (int) (100*Math.random());
- String barcode_content = text1.getText().toString() + Integer.toString(rand1)
- + text2.getText().toString() + Integer.toString(rand2)
- + text3.getText().toString() + Integer.toString(rand3)
- + text4.getText().toString() + Integer.toString(rand4);
+ String barcode_content = text1.getText().toString() + Integer.toString(rand1) + text2.getText().toString() + Integer.toString(rand2) + text3.getText().toString() + Integer.toString(rand3) + text4.getText().toString() + Integer.toString(rand4);
+ text1.setText(barcode_content);
+ return;
+ /*
try {
// generate a 150x150 QR code
- Bitmap barcode_bitmap = encodeAsBitmap(barcode_content, BarcodeFormat.QR_CODE, 150, 150);
+ ByteMatrix barcode_matrix = Encoder.encode(barcode_content, ErrorCorrectionLevel.L).getMatrix();
+// Bitmap barcode_bitmap = BitmapFactory.decodeByteArray(barcode_matrix, 0, barcode_matrix.length);
+
+ Bitmap barcode_bitmap = ByteMatrix2Bitmap(barcode_matrix);
+
String barcodeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), barcode_bitmap, "NEW QR", "A newly created QR code");
- Uri barcodeUri = Uri.parse(imgUrl);
+ Uri barcodeUri = Uri.parse(barcodeUrl);
Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(barcodeUri, "image/bmp"); //TODO make sure image/bmp is correct.
} catch (WriterException e) { //eek }
}
+ */
+
+ }
+
+ private static Bitmap ByteMatrix2Bitmap(ByteMatrix matrix){
+ int width = matrix.getWidth();
+ int height = matrix.getHeight();
+ byte[][] array = matrix.getArray();
+
+ byte[] imgdata = new byte[width * height];
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ if (array[y][x]==0)
+ imgdata[y * width + x] = 0;
+ else
+ imgdata[y * width + x] = 1;
+ }
+ }
+
+ Bitmap bitmap = BitmapFactory.decodeByteArray(imgdata,0,imgdata.length);
+ return bitmap;
}
- */
//this will use the information passed to it to reference an existing ID in the database
return;
}
-}
-
-
-/* public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- if (requestCode == 0) {
- if (resultCode == RESULT_OK) {
- // contents contains whatever was encoded
- String contents = intent.getStringExtra("SCAN_RESULT");
- text.setText(contents);
- // Format contains the type of code i.e. UPC, EAN, QRCode etc...
- String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
-
-
- }
- }
-
- }
-*/
\ No newline at end of file
+}
\ No newline at end of file