Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
*HAS ERROS*
authormiles <miles@localhost>
Fri, 20 Sep 2013 20:54:27 +0000 (20:54 +0000)
committermiles <miles@localhost>
Fri, 20 Sep 2013 20:54:27 +0000 (20:54 +0000)
Added PrintDialogActivity.java, and print_dialog.xml, implemented code to print qr codes via cloud print

svn path=/; revision=504

Personnel/justin/lab inventory/bin/classes.dex
Personnel/justin/lab inventory/bin/lab inventory.apk
Personnel/justin/lab inventory/bin/resources.ap_
Personnel/justin/lab inventory/lint.xml [new file with mode: 0644]
Personnel/justin/lab inventory/res/layout/activity_main.xml
Personnel/justin/lab inventory/res/layout/print_dialog.xml [new file with mode: 0644]
Personnel/justin/lab inventory/res/values/strings.xml
Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/MainActivity.java
Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/PrintDialogActivity.java [new file with mode: 0644]

index f0f7b113fc69f77886d50b77285c4697e10f4de2..f5f0a2e509fe9aca5ce03632b7dbbcb3e114bd9c 100644 (file)
Binary files a/Personnel/justin/lab inventory/bin/classes.dex and b/Personnel/justin/lab inventory/bin/classes.dex differ
index 575a65beb59a7284d339975f8fbebafada0b292e..3d7e8f7c61e163ec66f40e53b9a069028a8ba06e 100644 (file)
Binary files a/Personnel/justin/lab inventory/bin/lab inventory.apk and b/Personnel/justin/lab inventory/bin/lab inventory.apk differ
index 626024f929011dc8650cd881bb97f22a59b867bc..54fcb86ec033c78196cffb996760adf4562146f1 100644 (file)
Binary files a/Personnel/justin/lab inventory/bin/resources.ap_ and b/Personnel/justin/lab inventory/bin/resources.ap_ differ
diff --git a/Personnel/justin/lab inventory/lint.xml b/Personnel/justin/lab inventory/lint.xml
new file mode 100644 (file)
index 0000000..1928f48
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+    <issue id="JavascriptInterface" severity="ignore" />
+</lint>
\ No newline at end of file
index d41352c3754e38d678bf85b4ba79f13cd2511138..9cbc67b14c73bde97ae03ef2a6eb56461b0f70b5 100644 (file)
@@ -3,50 +3,61 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
 
+    <Button
+        android:id="@+id/button1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignBaseline="@+id/button2"
+        android:layout_alignBottom="@+id/button2"
+        android:layout_alignParentLeft="true"
+        android:onClick="recognizeQRClick"
+        android:text="@string/recognize_qr_button" />
+
     <EditText
         android:id="@+id/editText1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignParentBottom="true"
-        android:layout_alignParentLeft="true"
-        android:layout_marginBottom="26dp"
-        android:layout_marginLeft="24dp"
+        android:layout_alignParentRight="true"
+        android:layout_centerVertical="true"
         android:ems="10"
-        android:text="@string/hello_world" >
-    </EditText>
+        android:text="Data 1" />
 
     <EditText
-        android:id="@+id/editText2"
+        android:id="@+id/EditText01"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignLeft="@+id/button2"
         android:layout_alignParentRight="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginTop="154dp"
+        android:layout_below="@+id/editText1"
         android:ems="10"
-        android:hint="new data:" >
+        android:text="Data 2" />
 
-        <requestFocus />
-    </EditText>
+    <EditText
+        android:id="@+id/EditText02"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_below="@+id/EditText01"
+        android:ems="10"
+        android:text="Data 3" />
 
-    <Button
-        android:id="@+id/button2"
+    <EditText
+        android:id="@+id/EditText03"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignBottom="@+id/editText2"
         android:layout_alignParentRight="true"
-        android:layout_marginBottom="66dp"
-        android:onClick="scanQRClick"
-        android:text="@string/scan_qr_button" />
+        android:layout_below="@+id/EditText02"
+        android:ems="10"
+        android:text="Data 4" />
 
-    <Button
-        android:id="@+id/button1"
+    <Print
+        android:id="@+id/print"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignBaseline="@+id/button2"
-        android:layout_alignBottom="@+id/button2"
-        android:layout_alignParentLeft="true"
-        android:onClick="recognizeQRClick"
-        android:text="@string/recognize_qr_button" />
+        android:layout_above="@+id/editText1"
+        android:layout_alignParentRight="true"
+        android:layout_marginBottom="80dp"
+        android:onClick="printQRClick"
+        android:text="@string/print_qr_button" />
+    
 
 </RelativeLayout>
\ No newline at end of file
diff --git a/Personnel/justin/lab inventory/res/layout/print_dialog.xml b/Personnel/justin/lab inventory/res/layout/print_dialog.xml
new file mode 100644 (file)
index 0000000..12dad46
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?> 
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:layout_width="fill_parent"
+                android:layout_height="fill_parent"> 
+  <WebView android:id="@+id/webview"
+           android:layout_width="fill_parent" 
+           android:layout_height="fill_parent"/> 
+</RelativeLayout>
\ No newline at end of file
index 5011e9938661f41ac5bc68f106a1a64243197c97..e4d2d245947f3929728dbc591a13a84cea3c7136 100644 (file)
@@ -7,6 +7,6 @@
     <string name="qr_button">Start QR code scanner</string>
     <string name="inventory_button">Check inventory</string>
     <string name="recognize_qr_button">Recognize QR</string>
-    <string name="scan_qr_button">Scan in QR</string>
+    <string name="print_qr_button">Print new QR</string>
     
 </resources>
\ No newline at end of file
index 2fbb3be0ba842b7d507a45018c7638177a3af2ff..65fa0b110396cb460bf2749433009e184590c0f8 100644 (file)
@@ -1,11 +1,13 @@
 package com.jaiswallab.lab.inventory;
 
-import com.google.zxing.integration.android.IntentIntegrator;
-import com.google.zxing.integration.android.IntentResult;
+import com.google.zxing.integration.android.*;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
 import android.os.Bundle;
+import android.provider.MediaStore;
 import android.view.Menu;
 import android.view.View;
 import android.widget.EditText;
@@ -16,15 +18,18 @@ import android.widget.EditText;
 
 public class MainActivity extends Activity {
 
-       boolean scanningNewQR = false;
+       boolean printingNewQR = false;
        boolean recognizingQR = false;
-       private EditText text;
-
+       private EditText text1;
+       private EditText text2;
+       private EditText text3;
+       private EditText text4;
+       
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
-        text = (EditText) findViewById(R.id.editText1);
+        text1 = (EditText) findViewById(R.id.editText1);
     }
 
     @Override
@@ -35,45 +40,73 @@ public class MainActivity extends Activity {
     
     // This method is called at click of the QR code button
     public void recognizeQRClick(View view) { 
-       scanningNewQR = false;
+       printingNewQR = false;
        recognizingQR = true;
-       text.setText("Recognize QR button clicked");
+       text1.setText("Recognize QR button clicked");
        IntentIntegrator intentIntegrator = new IntentIntegrator(this);
        intentIntegrator.initiateScan();
        //startActivityForResult(intentIntegrator, 0);
     }
     
+    // This method is called at click of the scan new QR button
+    public void printQRClick(View view) {
+       printingNewQR = true;
+       recognizingQR = false;
+       text1.setText("Print QR button clicked");
+       IntentIntegrator intentIntegrator = new IntentIntegrator(this);
+       intentIntegrator.initiateScan();
+    }
+    
     public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null) {
                String contents = scanResult.getContents();
-               if(scanningNewQR) {
+               if(printingNewQR) {
                        addNewQR(contents);
                } else if(recognizingQR){
                        displayQRInfo(contents);
                }
-               text.setText(contents);
+               text1.setText(contents);
                // handle scan result
        }
          // else continue with any other code you need in the method
        }
     
-    // This method is called at click of the check inventory button
-    public void scanQRClick(View view) {
-       scanningNewQR = true;
-       recognizingQR = false;
-       text.setText("Scan QR button clicked");
-       IntentIntegrator intentIntegrator = new IntentIntegrator(this);
-       intentIntegrator.initiateScan();
-    }
     
-    //this will use the information passed to it to create a new ID in the databse
+    
+    //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;
+       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);
+       try {
+           // generate a 150x150 QR code
+           Bitmap barcode_bitmap = encodeAsBitmap(barcode_content, BarcodeFormat.QR_CODE, 150, 150);
+
+           String barcodeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), barcode_bitmap, "NEW QR", "A newly created QR code");
+           
+           Uri barcodeUri = Uri.parse(imgUrl);
+           
+               Intent printIntent = new Intent(this, PrintDialogActivity.class);
+               printIntent.setDataAndType(barcodeUri, "image/bmp"); //TODO make sure image/bmp is correct.
+               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) {
diff --git a/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/PrintDialogActivity.java b/Personnel/justin/lab inventory/src/com/jaiswallab/lab/inventory/PrintDialogActivity.java
new file mode 100644 (file)
index 0000000..7e296c8
--- /dev/null
@@ -0,0 +1,142 @@
+package com.jaiswallab.lab.inventory;
+
+import android.app.Activity;
+import android.content.ActivityNotFoundException;
+import android.content.ContentResolver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Base64;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class PrintDialogActivity extends Activity {
+  private static final String PRINT_DIALOG_URL = "https://www.google.com/cloudprint/dialog.html";
+  private static final String JS_INTERFACE = "AndroidPrintDialog";
+  private static final String CONTENT_TRANSFER_ENCODING = "base64";
+
+  private static final String ZXING_URL = "http://zxing.appspot.com";
+  private static final int ZXING_SCAN_REQUEST = 65743;
+
+  /**
+   * Post message that is sent by Print Dialog web page when the printing dialog
+   * needs to be closed.
+   */
+  private static final String CLOSE_POST_MESSAGE_NAME = "cp-dialog-on-close";
+
+  /**
+   * Web view element to show the printing dialog in.
+   */
+  private WebView dialogWebView;
+
+  /**
+   * Intent that started the action.
+   */
+  Intent cloudPrintIntent;
+
+  @Override
+  public void onCreate(Bundle icicle) {
+    super.onCreate(icicle);
+
+    setContentView(R.layout.print_dialog);
+    dialogWebView = (WebView) findViewById(R.id.webview);
+    cloudPrintIntent = this.getIntent();
+
+    WebSettings settings = dialogWebView.getSettings();
+    settings.setJavaScriptEnabled(true);
+
+    dialogWebView.setWebViewClient(new PrintDialogWebClient());
+    dialogWebView.addJavascriptInterface(
+      new PrintDialogJavaScriptInterface(), JS_INTERFACE);
+
+    dialogWebView.loadUrl(PRINT_DIALOG_URL);
+  }
+
+  @Override
+  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+    if (requestCode == ZXING_SCAN_REQUEST && resultCode == RESULT_OK) {
+      dialogWebView.loadUrl(intent.getStringExtra("SCAN_RESULT"));
+    }
+  }
+
+  final class PrintDialogJavaScriptInterface {
+    public String getType() {
+      return cloudPrintIntent.getType();
+    }
+
+    public String getTitle() {
+      return cloudPrintIntent.getExtras().getString("title");
+    }
+
+    public String getContent() {
+      try {
+        ContentResolver contentResolver = getContentResolver();
+        InputStream is = contentResolver.openInputStream(cloudPrintIntent.getData());
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        byte[] buffer = new byte[4096];
+        int n = is.read(buffer);
+        while (n >= 0) {
+          baos.write(buffer, 0, n);
+          n = is.read(buffer);
+        }
+        is.close();
+        baos.flush();
+
+        return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
+      } catch (FileNotFoundException e) {
+        e.printStackTrace();
+      } catch (IOException e) {
+        e.printStackTrace();
+      }
+      return "";
+    }
+
+    public String getEncoding() {
+      return CONTENT_TRANSFER_ENCODING;
+    }
+
+    public void onPostMessage(String message) {
+      if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) {
+        finish();
+      }
+    }
+  }
+
+  private final class PrintDialogWebClient extends WebViewClient {
+    @Override
+    public boolean shouldOverrideUrlLoading(WebView view, String url) {
+      if (url.startsWith(ZXING_URL)) {
+        Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
+        intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
+        try {
+          startActivityForResult(intentScan, ZXING_SCAN_REQUEST);
+        } catch (ActivityNotFoundException error) {
+          view.loadUrl(url);
+        }
+      } else {
+        view.loadUrl(url);
+      }
+      return false;
+    }
+
+    @Override
+    public void onPageFinished(WebView view, String url) {
+      if (PRINT_DIALOG_URL.equals(url)) {
+        // Submit print document.
+        view.loadUrl("javascript:printDialog.setPrintDocument(printDialog.createPrintDocument("
+          + "window." + JS_INTERFACE + ".getType(),window." + JS_INTERFACE + ".getTitle(),"
+          + "window." + JS_INTERFACE + ".getContent(),window." + JS_INTERFACE + ".getEncoding()))");
+
+        // Add post messages listener.
+        view.loadUrl("javascript:window.addEventListener('message',"
+            + "function(evt){window." + JS_INTERFACE + ".onPostMessage(evt.data)}, false)");
+      }
+    }
+  }
+}
\ No newline at end of file