Skip to content
Browse files

hacked together working app

  • Loading branch information...
1 parent 50b618b commit 5b526bfed5433b856328ae63255aadc3a9705f53 @benfoxall committed May 20, 2012
Showing with 3,330 additions and 4 deletions.
  1. +87 −4 assets/www/index.html
  2. +3,242 −0 assets/www/socket.io.js
  3. +1 −0 src/com/bfoxall/ExposeActivity.java
View
91 assets/www/index.html
@@ -2,24 +2,107 @@
<html>
<head>
<title>Cordova</title>
+<!-- <script src="http://debug.phonegap.com/target/target-script-min.js#helllooooo"></script> -->
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8" src="barcodescanner.js"></script>
+<script type="text/javascript" charset="utf-8" src="socket.io.js"></script>
</head>
<body>
<h1>Expose</h1>
+ <button id="b">Link up</button>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
+
+// returns a cloned object with any functions replaced with '__fn__'
+function augment(obj){
+ // var newobj = {};
+ var maxdepth = 5;
+
+ return (function recurse(obj, depth){
+ if(!depth){
+ return "max depth reached";
+
+ } else if(typeof(obj) === 'function'){
+ return '__fn__';
+
+ } else if(obj === new Object(obj)){
+ var newobj = {};
+ for(var i in obj){
+ // if(obj.hasOwnProperty(i)){
+ newobj[i] = recurse(obj[i], depth - 1);
+ // }
+ }
+ return newobj;
+
+ } else {
+ return obj;
+ }
+ })(obj, maxdepth);
+}
+
function onDeviceReady() {
// Now safe to use the Cordova API
+ document.getElementById('b').addEventListener("click", function(){
+ alert("Clicked");
+ }, false);
window.plugins.barcodeScanner.scan( function(result) {
- alert("We got a barcode\n" +
- "Result: " + result.text + "\n" +
- "Format: " + result.format + "\n" +
- "Cancelled: " + result.cancelled);
+ if(result.text){
+ var toks = result.text.split('?');
+
+ var exposedObj = {
+ barcodeScanner:window.plugins.barcodeScanner,
+ camera:navigator.camera,
+ compass:navigator.compass,
+ test:'OK'
+ };
+
+ // multiple args aren't supported yet
+ exposedObj.captureHack = function(fn){
+ navigator.camera.getPicture(fn, function(){
+ alert('failed to get picture')
+ }, {
+ quality: 50,
+ destinationType: navigator.camera.DestinationType.DATA_URL
+ });
+ }
+
+ var socket = io.connect(toks[0]);
+
+ socket.emit('expose', toks[1], augment(exposedObj));
+
+
+ socket.on('request', function(rID,what){
+ var target = exposedObj;
+
+ var parts = what.split('.');
+ for(i in parts){
+ if(parts[i]){
+ target = target[parts[i]];
+ }
+ }
+ target(function(){
+ var args = Array.prototype.slice.call(arguments)
+ socket.emit('response', rID, args);
+ });
+ });
+
+
+
+
+
+
+
+ }
+ // alert("We got a barcode\n" +
+ // "Result: " + result.text + "\n" +
+ // "Format: " + result.format + "\n" +
+ // "Cancelled: " + result.cancelled);
+
+
}, function(error) {
alert("Scanning failed: " + error);
}
View
3,242 assets/www/socket.io.js
3,242 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
1 src/com/bfoxall/ExposeActivity.java
@@ -8,6 +8,7 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+// System.out.println("Yuup, this works");
super.loadUrl("file:///android_asset/www/index.html");
}
}

0 comments on commit 5b526bf

Please sign in to comment.
Something went wrong with that request. Please try again.