import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Calendar;
import com.google.zxing.*;
printingNewQR = false;
recognizingQR = true;
text1.setText("Recognize QR button clicked");
+
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
intentIntegrator.initiateScan();
- //startActivityForResult(intentIntegrator, 0);
+ return;
}
// This method is called at click of the scan new QR button
addNewQR();
}
- public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
- if (scanResult != null) {
- String contents = scanResult.getContents();
- if(printingNewQR) {
- return;
- } else if(recognizingQR){
- displayQRInfo(contents);
- }
- text1.setText(contents);
- // handle scan result
+ public void onActivityResult (int requestCode, int resultCode, Intent intent) {
+ switch (requestCode) {
+ case IntentIntegrator.REQUEST_CODE:
+ IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
+ if (scanResult != null) {
+ String contents = scanResult.getContents();
+ if(printingNewQR) {
+ return;
+ } else if(recognizingQR){
+ displayQRInfo(contents);
+ }
+ text1.setText(contents);
+ }
+ break;
}
+
+
- // else continue with any other code you need in the method
+ /*
+*/
}
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");
- savePhoto(barcode_bitmap);
- //text2.setText(barcodeUrl);
+ String filepath = savePhoto(barcode_bitmap);
-/*
- Uri barcodeUri = Uri.parse(barcodeUrl);
+
+ Uri barcodeUri = Uri.parse(filepath);
+
Intent printIntent = new Intent(this, PrintDialogActivity.class);
- printIntent.setDataAndType(barcodeUri, "image/bmp"); //TODO make sure image/bmp is correct.
+ printIntent.setDataAndType(barcodeUri, "image/bmp"); //TODO make sure image/bmp is correct.0
printIntent.putExtra("title", "NEW QR");
startActivity(printIntent);
- */
+
} catch (WriterException e) { //eek }
}
//this will use the information passed to it to reference an existing ID in the database
//it will display the database information in a useful format
public void displayQRInfo(String id) {
+ setContentView(R.layout.activity_main);
+ text1.setText(id);
return;
}
- public void savePhoto(Bitmap bmp) throws Exception {
+ public String savePhoto(Bitmap bmp) throws Exception {
File root = android.os.Environment.getExternalStorageDirectory();
- File dir = new File (root.getAbsolutePath() + "/foldername");
- dir.mkdirs();
+ File dir = new File (root.getAbsolutePath() + "/Pictures");
FileOutputStream out = null;
Calendar c = Calendar.getInstance();
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();
+ if (bmp.compress(Bitmap.CompressFormat.JPEG, 100, out)) text1.setText("bitmap successfully compressed");
+ try {
+ out.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
text4.setText(imageFileName.toString());
out = null;
} catch (Exception e) {
System.out.println("unable to save photo");
e.printStackTrace();
}
+ return imageFileName.toString();
}
public String fromInt(int val) {