From: miles Date: Tue, 24 Sep 2013 20:25:52 +0000 (+0000) Subject: scan initiates using webcam, but even though the scan appears to be successful, rathe... X-Git-Url: http://gitweb.planteome.org/?a=commitdiff_plain;h=c12e2714e2e793a1ef020bdbbc0564ce908da830;p=old-jaiswallab-svn%2F.git scan initiates using webcam, but even though the scan appears to be successful, rather than returning to the main activity and parsing the results the webcam continues to scan indefinitely. svn path=/; revision=511 --- diff --git a/Personnel/justin/lab inventory/bin/classes.dex b/Personnel/justin/lab inventory/bin/classes.dex index d18e7d0..3d32b17 100644 Binary files a/Personnel/justin/lab inventory/bin/classes.dex and b/Personnel/justin/lab inventory/bin/classes.dex differ diff --git a/Personnel/justin/lab inventory/bin/lab inventory.apk b/Personnel/justin/lab inventory/bin/lab inventory.apk index c6c2e9a..4e27faf 100644 Binary files a/Personnel/justin/lab inventory/bin/lab inventory.apk and b/Personnel/justin/lab inventory/bin/lab inventory.apk differ diff --git a/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/MainActivity.java b/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/MainActivity.java index d79a97c..7298762 100644 --- a/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/MainActivity.java +++ b/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/MainActivity.java @@ -2,6 +2,7 @@ package com.jaiswallab.lab.inventory; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.util.Calendar; import com.google.zxing.*; @@ -62,9 +63,10 @@ public class MainActivity extends Activity { 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 @@ -74,20 +76,26 @@ public class MainActivity extends Activity { 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 + /* +*/ } @@ -135,18 +143,17 @@ public class MainActivity extends Activity { 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 } } @@ -158,13 +165,14 @@ public class MainActivity extends Activity { //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(); @@ -179,15 +187,24 @@ public class MainActivity extends Activity { 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) {