From e92cd6076e1a231af91648a98260d23414cdc662 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Sun, 18 Dec 2011 18:45:49 -0800 Subject: [PATCH] Fixed app loading on android, updates to readme, split out app js from helpers --- README.md | 27 +++++++++++-------- ext/android/AppLoader.java | 47 +++++++-------------------------- index.html | 2 +- js/helpers.js | 51 ++++++++++++++++++++++++++++++++++++ js/hydra.js | 53 -------------------------------------- 5 files changed, 77 insertions(+), 103 deletions(-) create mode 100644 js/helpers.js diff --git a/README.md b/README.md index f05c2a7..361ff1a 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,20 @@ Hydra ==== -![Hydra!](http://github.com/filmaj/hydra/raw/master/img/icon128.png) +![Hydra!](http://github.com/filmaj/hydra/raw/master/img/icon-big.png) -A beast with many heads. Keep one or more [PhoneGap](http://www.phonegap.com) app assets "in the cloud" on -[build.phonegap.com](http://build.phonegap.com), and use this shell to -store different apps and keep each app up-to-date with the latest -assets. +A beast with many heads. Keep one or more [PhoneGap](http://www.phonegap.com) app assets "in the cloud" on [build.phonegap.com](http://build.phonegap.com), and use this shell to store different apps and keep each app up-to-date with the latest assets. -#### iOS #### +# Getting Started + +1. Edit the `CALLBACK_ANDROID` and other platform paths at the top of + the `makefile`. +2. Run `make ` to generate the PhoneGap/Callback/Cordova + project under `dist/`. +3. `cd dist/` and then run the platform-specific tools to + debug/test/deploy/sign/etc. + +## iOS' Special Needs 1. Include libz.dylib in your project - Xcode 4 @@ -24,20 +30,18 @@ assets. 2. For the key, add "com.nitobi.BinaryDownloader", and for the value, add "BinaryDownloader" 3. For the key, add "com.nitobi.ZipUtil", and for the value, add "ZipUtil" -3. For PhoneGap 1.1, In PhoneGap.plist, under "ExternalHosts", add these new entries: +3. For PhoneGap 1.1, In PhoneGap.plist, under "ExternalHosts", add these new entries: * build.phonegap.com * s3.amazonaws.com * (any other hosts that your downloaded app needs to connect to - of course you need to know this in advance - or you can use "*" to allow everything) -Why? ----- +# Why? * Easier to manage application updates; a poor man's TestFlight. * Theoretically more secure. However: be warned I don't know shit about security. -Contributors ----- +# Contributors * [Fil Maj](http://www.github.com/filmaj) * [Michael Brooks](http://www.github.com/mwbrooks) @@ -45,3 +49,4 @@ Contributors * [Joe Bowser](http://www.github.com/infil00p) * [Shazron Abdullah](http://www.github.com/shazron) * [Brett Rudd](http://www.github.com/goya) + diff --git a/ext/android/AppLoader.java b/ext/android/AppLoader.java index 7578b7c..1cd7cd1 100644 --- a/ext/android/AppLoader.java +++ b/ext/android/AppLoader.java @@ -1,42 +1,13 @@ package com.phonegap.remote; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.util.Scanner; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.HttpVersion; -import org.apache.http.ProtocolVersion; -import org.apache.http.StatusLine; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ClientConnectionManager; -import org.apache.http.conn.params.ConnManagerPNames; -import org.apache.http.conn.params.ConnPerRouteBean; -import org.apache.http.conn.scheme.PlainSocketFactory; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.conn.SingleClientConnManager; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.HttpParams; -import org.apache.http.params.HttpProtocolParams; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import android.util.Base64; +import java.io.*; +import java.util.*; +import org.apache.http.*; +import org.json.*; import com.byarger.exchangeit.EasySSLSocketFactory; -import com.phonegap.api.Plugin; -import com.phonegap.api.PluginResult; +import com.phonegap.api.*; public class AppLoader extends Plugin { @@ -77,10 +48,10 @@ private void fetch(JSONArray args) { String password; String id; try { - id = args.getString(1); - url = args.getString(2); - username = args.getString(3); - password = args.getString(4); + id = args.getString(0); + url = args.getString(1); + username = args.getString(2); + password = args.getString(3); // Create directory for app. local_path = "/data/data/" + ctx.getPackageName() + "/remote_app/" + id + "/"; diff --git a/index.html b/index.html index b15e007..5a308b3 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - + diff --git a/js/helpers.js b/js/helpers.js new file mode 100644 index 0000000..ab6d852 --- /dev/null +++ b/js/helpers.js @@ -0,0 +1,51 @@ +// constants +var BUILD_URL = 'https://build.phonegap.com'; + +// Dom helpers +function $(s) { return document.getElementById(s); } + +// Extend the String object for simple templating +String.prototype.format = function(){ + var args = arguments; + obj = (args.length == 1 && (typeof args[0] == 'object')) ? args[0] : args; + return this.replace(/\{(\w+)\}/g, function(m, i){ + return obj[i]; + }); +} + + // helper for XHR +function xhr(url, options) { + var xhr = new XMLHttpRequest(); + + if (options && options.username && typeof options.password != 'undefined') { + var schemeSeparator = "://"; + var extractToIndex = url.indexOf(schemeSeparator) + schemeSeparator.length; + var scheme = url.substring(0, extractToIndex); + var rhs = url.substring(extractToIndex); + url = scheme + encodeURIComponent(options.username) + ':' + encodeURIComponent(options.password) + '@' + rhs; + } + + xhr.open('GET', url, (options && typeof options.async != 'undefined'?options.async:true)); + + if (options && options.headers) { + // Lifted from xui source; github.com/xui/xui/blob/master/src/js/xhr.js + for (var key in options.headers) { + if (options.headers.hasOwnProperty(key)) { + xhr.setRequestHeader(key, options.headers[key]); + } + } + } + + xhr.setRequestHeader("Accept", "application/json"); + + xhr.onreadystatechange = function(){ + if ( xhr.readyState == 4 ) { + if ( xhr.status == 200 || xhr.status == 0) { + options.callback.call(xhr); + } else { + alert('XHR error, status: ' + xhr.status); + } + } + }; + xhr.send((options && options.data? options.data : null)); +} diff --git a/js/hydra.js b/js/hydra.js index a808da0..41c0e73 100644 --- a/js/hydra.js +++ b/js/hydra.js @@ -1,12 +1,6 @@ (function() { if (!('localStorage' in window && window['localStorage'] !== null)) alert("No support for localStorage."); - // constants - var BUILD_URL = 'https://build.phonegap.com'; - - // Dom helpers - function $(s) { return document.getElementById(s); } - function showModal(txt) { var wrap = $('modal-wrap'); var msg = $('modal-msg'); @@ -29,52 +23,6 @@ hideModal(); } - // Extend the String object for simple templating - String.prototype.format = function(){ - var args = arguments; - obj = (args.length == 1 && (typeof args[0] == 'object')) ? args[0] : args; - return this.replace(/\{(\w+)\}/g, function(m, i){ - return obj[i]; - }); - } - - // helper for XHR - function xhr(url, options) { - var xhr = new XMLHttpRequest(); - - if (options && options.username && typeof options.password != 'undefined') { - var schemeSeparator = "://"; - var extractToIndex = url.indexOf(schemeSeparator) + schemeSeparator.length; - var scheme = url.substring(0, extractToIndex); - var rhs = url.substring(extractToIndex); - url = scheme + encodeURIComponent(options.username) + ':' + encodeURIComponent(options.password) + '@' + rhs; - } - - xhr.open('GET', url, (options && typeof options.async != 'undefined'?options.async:true)); - - if (options && options.headers) { - // Lifted from xui source; github.com/xui/xui/blob/master/src/js/xhr.js - for (var key in options.headers) { - if (options.headers.hasOwnProperty(key)) { - xhr.setRequestHeader(key, options.headers[key]); - } - } - } - - xhr.setRequestHeader("Accept", "application/json"); - - xhr.onreadystatechange = function(){ - if ( xhr.readyState == 4 ) { - if ( xhr.status == 200 || xhr.status == 0) { - options.callback.call(xhr); - } else { - alert('XHR error, status: ' + xhr.status); - } - } - }; - xhr.send((options && options.data? options.data : null)); - } - // plugin error handler function pluginError(msg) { alert('Hydration plugin error!' + msg); @@ -273,7 +221,6 @@ // Do nothing; show the login form. } } - hideModal(); }, false); })();