package com.jaiswallab.lab.inventory;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Calendar;
+
import com.google.zxing.*;
import com.google.zxing.integration.android.*;
import com.google.zxing.qrcode.QRCodeWriter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
+import android.media.MediaScannerConnection;
+import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
import android.provider.MediaStore;
+import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
}
// This method is called at click of the scan new QR button
- public void printQRClick(View view) {
+ public void printQRClick(View view) throws Exception {
printingNewQR = true;
recognizingQR = false;
addNewQR();
//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() {
+ public void addNewQR() throws Exception {
int rand1 = (int) (100*Math.random());
int rand2 = (int) (100*Math.random());
Bitmap barcode_bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- for (int y = 0; y < barcode_matrix.length; ++y) //TODO possibly reverse x&y mapping here?
- {
- for (int x = 0; x < barcode_matrix[y].length; ++x)
- {
- if (barcode_matrix[y][x] == -1)
- {
- barcode_bitmap.setPixel(x, y, Color.WHITE);
- }
- else
- {
- barcode_bitmap.setPixel(x, y, Color.BLACK);
- }
- }
- }
+ for (int y = 0; y < barcode_matrix.length; ++y) // TODO possibly reverse x&y mapping here?
+ {
+ for (int x = 0; x < barcode_matrix[y].length; ++x) {
+ if (barcode_matrix[y][x] == -1) {
+ barcode_bitmap.setPixel(x, y, Color.WHITE);
+ } else {
+ barcode_bitmap.setPixel(x, y, Color.BLACK);
+ }
+ }
+ }
//imageView.SetImageBitmap(img);
if(barcode_bitmap != null) text3.setText("BARCODE EXISTS");
else text3.setText("barcode null :(");
- String barcodeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), barcode_bitmap, "NEW QR", "A newly created QR code");
- text2.setText(barcodeUrl);
+ //String barcodeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), barcode_bitmap, "NEW QR", "A newly created QR code");
+ savePhoto(barcode_bitmap);
+ //text2.setText(barcodeUrl);
/*
Uri barcodeUri = Uri.parse(barcodeUrl);
} catch (WriterException e) { //eek }
}
-
-
return;
+
}
return;
}
+ public void savePhoto(Bitmap bmp) throws Exception {
+ File imageFileFolder = new File(Environment.getExternalStorageDirectory(),
+ "Rotate");
+ imageFileFolder.mkdir();
+ FileOutputStream out = null;
+ Calendar c = Calendar.getInstance();
+ String date = fromInt(c.get(Calendar.MONTH))
+ + fromInt(c.get(Calendar.DAY_OF_MONTH))
+ + fromInt(c.get(Calendar.YEAR))
+ + fromInt(c.get(Calendar.HOUR_OF_DAY))
+ + fromInt(c.get(Calendar.MINUTE))
+ + fromInt(c.get(Calendar.SECOND));
+ text2.setText(date);
+ File imageFileName = new File(imageFileFolder, date.toString() + ".jpg");
+ if(imageFileName!=null) text4.setText("file seems to be created?");
+ try {
+ out = new FileOutputStream(imageFileName);
+ bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
+ out.flush();
+ out.close();
+ scanPhoto(imageFileName.toString());
+ text4.setText(imageFileName.toString());
+ out = null;
+ } catch (Exception e) {
+ System.out.println("unable to save photo");
+ e.printStackTrace();
+ }
+ }
+
+ public String fromInt(int val) {
+ return String.valueOf(val);
+ }
+
+ public void scanPhoto(final String imageFileName) throws Exception {
+ MediaScannerConnection msConn = new MediaScannerConnection(this,
+ new MediaScannerConnectionClient() {
+ public void onMediaScannerConnected() {
+ try {
+ scanPhoto(imageFileName);
+ } catch (Exception e) {
+ System.out.println("unable to scan photo!");
+ e.printStackTrace();
+ }
+ Log.i("msClient obj in Photo Utility",
+ "connection established");
+ }
+
+ public void onScanCompleted(String path, Uri uri) {
+ finish();
+ Log.i("msClient obj in Photo Utility", "scan completed");
+ }
+ });
+ msConn.connect();
+ }
+
}
\ No newline at end of file