Merged in latest.

This commit is contained in:
filmaj 2010-08-25 22:32:31 -07:00
commit 764c9191b7
17 changed files with 570 additions and 1681 deletions

View File

@ -7,6 +7,7 @@ class Build
def initialize(*a)
@android_sdk_path, @name, @pkg, @www, @path = a
@android_sdk_path = "/Users/davejohnson/Sdk/android-sdk-mac_86"
@android_dir = File.expand_path(File.dirname(__FILE__))
@framework_dir = File.join(@android_dir, "framework")
end
@ -85,7 +86,7 @@ class Build
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
FileUtils.mkdir_p File.join(app_res_dir, "layout")
%w(main.xml preview.xml).each do |f|
%w(main.xml).each do |f|
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
PhoneGap.Channel = function(type)
{
this.type = type;
this.handlers = {};
this.guid = 0;
this.fired = false;
this.enabled = true;
};
PhoneGap.Channel.prototype.sub = function(f, c, g)
{
// need a function to call
if (f == null)
return;
var func = f;
if (typeof c == "object" && f instanceof Function)
func = PhoneGap.close(c, f);
g = g || func.observer_guid || f.observer_guid || this.guid++;
func.observer_guid = g;
f.observer_guid = g;
this.handlers[g] = func;
return g;
};
PhoneGap.Channel.prototype.sob = function(f, c)
{
var g = null;
var _this = this;
var m = function() {
f.apply(c || null, arguments);
_this.dub(g);
}
if (this.fired) {
if (typeof c == "object" && f instanceof Function)
f = PhoneGap.close(c, f);
f.apply(this, this.fireArgs);
} else {
g = this.sub(m);
}
return g;
};
PhoneGap.Channel.prototype.dub = function(g)
{
if (g instanceof Function)
g = g.observer_guid;
this.handlers[g] = null;
delete this.handlers[g];
};
PhoneGap.Channel.prototype.fire = function(e)
{
if (this.enabled)
{
var fail = false;
for (var item in this.handlers) {
var handler = this.handlers[item];
if (handler instanceof Function) {
var rv = (handler.apply(this, arguments)==false);
fail = fail || rv;
}
}
this.fired = true;
this.fireArgs = arguments;
return !fail;
}
return true;
};
PhoneGap.Channel.merge = function(h, e) {
var i = e.length;
var f = function() {
if (!(--i)) h();
}
for (var j=0; j<i; j++) {
(!e[j].fired?e[j].sob(f):i--);
}
if (!i) h();
}

View File

@ -6,7 +6,7 @@ if (typeof(DeviceInfo) != 'object')
* information about the state of PhoneGap.
* @class
*/
PhoneGap = {
var PhoneGap = {
queue: {
ready: true,
commands: [],
@ -112,7 +112,6 @@ PhoneGap.Channel.join = function(h, c) {
if (!i) h();
};
/**
* Boolean flag indicating if the PhoneGap API is available and initialized.
*/ // TODO: Remove this, it is unused here ... -jm
@ -137,6 +136,19 @@ PhoneGap.addConstructor = function(func) {
});
};
/**
* Adds a plugin object to window.plugins
*/
PhoneGap.addPlugin = function(name, obj) {
if ( !window.plugins ) {
window.plugins = {};
}
if ( !window.plugins[name] ) {
window.plugins[name] = obj;
}
}
/**
* onDOMContentLoaded channel is fired when the DOM content
* of the page has been parsed.
@ -152,9 +164,7 @@ PhoneGap.onNativeReady = new PhoneGap.Channel();
// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since
// it may be called before any PhoneGap JS is ready.
try {
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
} catch (e) { }
if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
/**
* onDeviceReady is fired only after both onDOMContentLoaded and
@ -193,7 +203,21 @@ document.addEventListener = function(evt, handler, capture) {
}
};
// Intercept calls to document.addEventListener and watch for deviceready
PhoneGap._document_addEventListener = document.addEventListener;
document.addEventListener = function(evt, handler, capture) {
if (evt.toLowerCase() == 'deviceready') {
PhoneGap.onDeviceReady.subscribeOnce(handler);
} else {
PhoneGap._document_addEventListener.call(document, evt, handler);
}
};
PhoneGap.callbackId = 0;
PhoneGap.callbacks = {};
/**
* Execute a PhoneGap command in a queued fashion, to ensure commands do not
@ -202,12 +226,27 @@ document.addEventListener = function(evt, handler, capture) {
* @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
* @param {String[]} [args] Zero or more arguments to pass to the method
*/
PhoneGap.exec = function() {
PhoneGap.queue.commands.push(arguments);
if (PhoneGap.queue.timer == null)
PhoneGap.queue.timer = setInterval(PhoneGap.run_command, 10);
PhoneGap.exec = function(clazz, action, args) {
return CommandManager.exec(clazz, action, callbackId, JSON.stringify(args), false);
};
PhoneGap.execAsync = function(success, fail, clazz, action, args) {
var callbackId = clazz + PhoneGap.callbackId++;
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
return CommandManager.exec(clazz, action, callbackId, JSON.stringify(args), true);
};
PhoneGap.callbackSuccess = function(callbackId, args) {
PhoneGap.callbacks[callbackId].success(args);
delete PhoneGap.callbacks[callbackId];
};
PhoneGap.callbackError = function(callbackId, args) {
PhoneGap.callbacks[callbackId].fail(args);
delete PhoneGap.callbacks[callbackId];
};
/**
* Internal function used to dispatch the request to PhoneGap. It processes the
* command queue and executes the next command on the list. If one of the
@ -324,7 +363,7 @@ PhoneGap.UUIDcreatePart = function(length) {
};
PhoneGap.close = function(context, func, params) {
if (null == params) {
if (typeof params === 'undefined') {
return function() {
return func.apply(context, arguments);
}

View File

@ -0,0 +1,5 @@
PhoneGap.addConstructor(function() {
if (typeof navigator.splashScreen == "undefined") {
navigator.splashScreen = SplashScreen; // SplashScreen object come from native side through addJavaScriptInterface
}
});

View File

@ -64,21 +64,53 @@
-->
<setup />
<target name="move_files">
<concat destfile="../example/phonegap.js">
<target name="check-javascript" depends="build-javascript">
<delete dir="assets/lib"/>
<mkdir dir="assets/lib"/>
<echo file="assets/lib/lint.js">var alert=function(){},device={},Element={},debug={};</echo>
<concat destfile="assets/lib/phonegap-lint.js" append="true">
<fileset dir="assets/lib">
<include name="lint.js" />
</fileset>
<fileset dir="assets/www">
<include name="phonegap.js" />
</fileset>
</concat>
<exec executable="cmd" os="Windows 7">
<arg value="/c"/>
<arg value="java"/>
<arg value="-cp"/>
<arg value="${basedir}/util/js.jar"/>
<arg value="org.mozilla.javascript.tools.shell.Main"/>
<arg value="${basedir}/util/jslint.js"/>
<arg value="${basedir}/js/lib/phonegap-lint.js"/>
</exec>
<exec executable="java" os="Mac OS X">
<arg value="-cp"/>
<arg value="../util/js.jar"/>
<arg value="org.mozilla.javascript.tools.shell.Main"/>
<arg value="../util/jslint.js"/>
<arg value="assets/lib/phonegap-lint.js"/>
</exec>
</target>
<target name="build-javascript">
<delete file="assets/www/phonegap.js"/>
<concat destfile="assets/www/phonegap.js">
<fileset dir="assets/js" includes="phonegap.js.base" />
<fileset dir="assets/js" includes="*.js" />
</concat>
</target>
<target name="jar" depends="move_files, compile">
<target name="jar" depends="build-javascript, compile">
<jar jarfile="phonegap.jar" basedir="bin/classes" excludes="**/R*.class" />
</target>
<target name="phonegap_debug" depends="move_files, debug">
<target name="phonegap_debug" depends="build-javascript, debug">
</target>
<target name="phonegap_release" depends="move_files, release">
<target name="phonegap_release" depends="build-javascript, release">
</target>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="PhoneGap/PhoneGap.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/PhoneGap/export-phonegap.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=PhoneGap/src"/>
<javaElement handleIdentifier="=PhoneGap/gen"/>
</selectedElements>
</jardesc>

View File

@ -12,15 +12,13 @@ public final class R {
}
public static final class drawable {
public static final int icon=0x7f020000;
public static final int splash=0x7f020001;
}
public static final class id {
public static final int appView=0x7f050000;
public static final int go=0x7f050002;
public static final int surface=0x7f050001;
}
public static final class layout {
public static final int main=0x7f030000;
public static final int preview=0x7f030001;
}
public static final class string {
public static final int app_name=0x7f040000;

BIN
framework/res/drawable/splash.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,23 +0,0 @@
<?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"
android:orientation="horizontal">
<SurfaceView android:id="@+id/surface"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
</SurfaceView>
<Button
android:id="@+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/go"
android:minWidth="50dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
/>
</RelativeLayout>

View File

@ -25,6 +25,9 @@ package com.phonegap;
import java.io.File;
import com.phonegap.api.Command;
import com.phonegap.api.CommandManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
@ -35,6 +38,7 @@ import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
@ -50,6 +54,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.GeolocationPermissions.Callback;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.os.Build.*;
import android.provider.MediaStore;
@ -58,6 +63,7 @@ public class DroidGap extends Activity {
private static final String LOG_TAG = "DroidGap";
protected WebView appView;
protected ImageView splashScreen;
private LinearLayout root;
private Device gap;
@ -73,46 +79,64 @@ public class DroidGap extends Activity {
private BrowserKey mKey;
private AudioHandler audio;
private CallbackServer callbackServer;
private CommandManager commandManager;
private Uri imageUri;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket!
LinearLayout.LayoutParams containerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0F);
LinearLayout.LayoutParams webviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 1.0F);
root = new LinearLayout(this);
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(Color.BLACK);
root.setLayoutParams(containerParams);
appView = new WebView(this);
appView.setLayoutParams(webviewParams);
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
splashScreen = new ImageView(this);
splashScreen.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT,
1.0F));
splashScreen.setImageResource(R.drawable.splash);
// root.addView(splashScreen);
initWebView();
root.addView(appView);
setContentView(root);
}
private void initWebView() {
appView = new WebView(DroidGap.this);
appView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT,
1.0F));
WebViewReflect.checkCompatibility();
if (android.os.Build.VERSION.RELEASE.startsWith("2."))
appView.setWebChromeClient(new EclairClient(this));
else
{
appView.setWebChromeClient(new GapClient(this));
if (android.os.Build.VERSION.RELEASE.startsWith("2.")) {
appView.setWebChromeClient(new EclairClient(DroidGap.this));
} else {
appView.setWebChromeClient(new GapClient(DroidGap.this));
}
appView.setWebViewClient(new GapViewClient(this));
appView.setInitialScale(100);
appView.setVerticalScrollBarEnabled(false);
appView.requestFocusFromTouch();
WebSettings settings = appView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
@ -127,18 +151,15 @@ public class DroidGap extends Activity {
WebViewReflect.setDomStorage(settings);
// Turn off native geolocation object in browser - we use our own :)
WebViewReflect.setGeolocationEnabled(settings, true);
/* Bind the appView object to the gap class methods */
// Bind the appView object to the gap class methods
bindBrowser(appView);
if(cupcakeStorage != null)
cupcakeStorage.setStorage(appPackage);
root.addView(appView);
setContentView(root);
}
public void invoke(String origin, boolean allow, boolean remember) {
// Try firing the onNativeReady event in JS. If it fails because the JS is
// not loaded yet then just set a flag so that the onNativeReady can be fired
// from the JS side when the JS gets to that code.
appView.loadUrl("javascript:try{PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
}
@Override
@ -226,6 +247,7 @@ public class DroidGap extends Activity {
private void bindBrowser(WebView appView)
{
callbackServer = new CallbackServer();
commandManager = new CommandManager(appView, this);
gap = new Device(appView, this);
accel = new AccelListener(appView, this);
launcher = new CameraLauncher(appView, this);
@ -238,6 +260,7 @@ public class DroidGap extends Activity {
audio = new AudioHandler(appView, this);
// This creates the new javascript interfaces for PhoneGap
appView.addJavascriptInterface(commandManager, "CommandManager");
appView.addJavascriptInterface(gap, "DroidGap");
appView.addJavascriptInterface(accel, "Accel");
appView.addJavascriptInterface(launcher, "GapCam");
@ -249,6 +272,7 @@ public class DroidGap extends Activity {
appView.addJavascriptInterface(mKey, "BackButton");
appView.addJavascriptInterface(audio, "GapAudio");
appView.addJavascriptInterface(callbackServer, "CallbackServer");
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
{
@ -258,11 +282,14 @@ public class DroidGap extends Activity {
appView.addJavascriptInterface(geo, "Geo");
}
}
public void loadUrl(String url)
public void loadUrl(final String url)
{
appView.loadUrl(url);
this.runOnUiThread(new Runnable() {
public void run() {
DroidGap.this.appView.loadUrl(url);
}
});
}
/**
@ -283,7 +310,6 @@ public class DroidGap extends Activity {
return this.callbackServer.getPort();
}
/**
* Provides a hook for calling "alert" from javascript. Useful for
* debugging your javascript.
@ -401,8 +427,7 @@ public class DroidGap extends Activity {
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
{
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mKey.isBound())
{
@ -428,10 +453,17 @@ public class DroidGap extends Activity {
// This is where we launch the menu
appView.loadUrl("javascript:keyEvent.menuTrigger()");
}
return false;
}
/**
* Removes the splash screen from root view and adds the WebView
*/
public void hideSplashScreen() {
root.removeView(splashScreen);
root.addView(appView);
}
// This is required to start the camera activity! It has to come from the previous activity
public void startCamera()
{
@ -463,11 +495,5 @@ public class DroidGap extends Activity {
{
launcher.failPicture("Did not complete!");
}
}
public WebView getView()
{
return this.appView;
}
}
}

View File

@ -11,7 +11,7 @@ public class FileUtils {
FileReader f_in;
FileWriter f_out;
FileUtils(WebView view)
public FileUtils(WebView view)
{
mView = view;
}

View File

@ -0,0 +1,15 @@
package com.phonegap;
public class SplashScreen {
private final DroidGap gap;
public SplashScreen(DroidGap gap) {
this.gap = gap;
}
public void hide() {
gap.runOnUiThread(new Runnable() {
public void run() {
gap.hideSplashScreen();
}
});
}
}

View File

@ -0,0 +1,41 @@
package com.phonegap.api;
import org.json.JSONArray;
import android.content.Context;
import android.webkit.WebView;
/**
* Command interface must be implemented by any plugin classes.
*
* The execute method is called by the CommandManager.
*
* @author davejohnson
*
*/
public interface Command {
/**
* Executes the request and returns CommandResult.
*
* @param action The command to execute.
* @param args JSONArry of arguments for the command.
* @return A CommandResult object with a status and message.
*/
CommandResult execute(String action, JSONArray args);
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
void setContext(Context ctx);
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
void setView(WebView webView);
}

View File

@ -0,0 +1,130 @@
package com.phonegap.api;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.webkit.WebView;
import com.phonegap.DroidGap;
/**
* CommandManager is exposed to JavaScript in the PhoneGap WebView.
*
* Calling native plugin code can be done by calling CommandManager.exec(...)
* from JavaScript.
*
* @author davejohnson
*
*/
public final class CommandManager {
private Command[] commands;
private final Context ctx;
private final WebView app;
public CommandManager(WebView app, Context ctx) {
this.ctx = ctx;
this.app = app;
}
/**
* Receives a request for execution and fulfills it by finding the appropriate
* Java class and calling it's execute method.
*
* CommandManager.exec can be used either synchronously or async. In either case, a JSON encoded
* string is returned that will indicate if any errors have occurred when trying to find
* or execute the class denoted by the clazz argument.
*
* @param clazz String containing the fully qualified class name. e.g. com.phonegap.FooBar
* @param action String containt the action that the class is supposed to perform. This is
* passed to the plugin execute method and it is up to the plugin developer
* how to deal with it.
* @param callbackId String containing the id of the callback that is execute in JavaScript if
* this is an async plugin call.
* @param args An Array literal string containing any arguments needed in the
* plugin execute method.
* @param async Boolean indicating whether the calling JavaScript code is expecting an
* immediate return value. If true, either PhoneGap.callbackSuccess(...) or PhoneGap.callbackError(...)
* is called once the plugin code has executed.
* @return JSON encoded string with a response message and status.
*/
public String exec(final String clazz, final String action, final String callbackId,
final String jsonArgs, final boolean async) {
CommandResult cr = null;
try {
final JSONArray args = new JSONArray(jsonArgs);
Class c = getClassByName(clazz);
if (isPhoneGapCommand(c)) {
// Create a new instance of the plugin and set the context and webview
final Command plugin = (Command)c.newInstance();
plugin.setContext(this.ctx);
plugin.setView(this.app);
if (async) {
// Run this on a different thread so that this one can return back to JS
Thread thread = new Thread(new Runnable() {
public void run() {
// Call execute on the plugin so that it can do it's thing
CommandResult cr = plugin.execute(action, args);
// Check the status for 0 (success) or otherwise
if (cr.getStatus() == 0) {
app.loadUrl(cr.toSuccessCallbackString(callbackId));
} else {
app.loadUrl(cr.toErrorCallbackString(callbackId));
}
}
});
thread.start();
return "";
} else {
// Call execute on the plugin so that it can do it's thing
cr = plugin.execute(action, args);
}
}
} catch (ClassNotFoundException e) {
cr = new CommandResult(CommandResult.Status.CLASS_NOT_FOUND_EXCEPTION);
} catch (IllegalAccessException e) {
cr = new CommandResult(CommandResult.Status.ILLEGAL_ACCESS_EXCEPTION);
} catch (InstantiationException e) {
cr = new CommandResult(CommandResult.Status.INSTANTIATION_EXCEPTION);
} catch (JSONException e) {
cr = new CommandResult(CommandResult.Status.JSON_EXCEPTION);
}
// if async we have already returned at this point unless there was an error...
if (async) {
app.loadUrl(cr.toErrorCallbackString(callbackId));
}
return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
}
/**
*
*
* @param clazz
* @return
* @throws ClassNotFoundException
*/
private Class getClassByName(final String clazz) throws ClassNotFoundException {
return Class.forName(clazz);
}
/**
* Get the interfaces that a class implements and see if it implements the
* com.phonegap.api.Command interface.
*
* @param c The class to check the interfaces of.
* @return Boolean indicating if the class implements com.phonegap.api.Command
*/
private boolean isPhoneGapCommand(Class c) {
boolean isCommand = false;
Class[] interfaces = c.getInterfaces();
for (int j=0; j<interfaces.length; j++) {
if (interfaces[j].getName().equals("com.phonegap.api.Command")) {
isCommand = true;
break;
}
}
return isCommand;
}
}

View File

@ -0,0 +1,60 @@
package com.phonegap.api;
import java.net.URLEncoder;
public class CommandResult {
private final int status;
private final String message;
public CommandResult(Status status) {
this.status = status.ordinal();
this.message = CommandResult.StatusMessages[this.status];
}
public CommandResult(Status status, String message) {
this.status = status.ordinal();
this.message = message;
}
public int getStatus() {
return status;
}
public String getMessage() {
return message;
}
public String getJSONString() {
return "{ status: " + this.getStatus() + ", message: '" + URLEncoder.encode(this.getMessage()) + "' }";
}
public String toSuccessCallbackString(String callbackId) {
return "javascript:PhoneGap.callbackSuccess('"+callbackId+"', " + this.getJSONString() + " );";
}
public String toErrorCallbackString(String callbackId) {
return "javascript:PhoneGap.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
}
public static String[] StatusMessages = new String[] {
"OK",
"Class not found",
"Illegal access",
"Instantiation error",
"Malformed url",
"IO error",
"Invalid action",
"JSON error"
};
public enum Status {
OK,
CLASS_NOT_FOUND_EXCEPTION,
ILLEGAL_ACCESS_EXCEPTION,
INSTANTIATION_EXCEPTION,
MALFORMED_URL_EXCEPTION,
IO_EXCEPTION,
INVALID_ACTION,
JSON_EXCEPTION
}
}

81
updategap Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env ruby
require 'fileutils'
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
class Build
attr_reader :android_sdk_path, :path
def initialize(*a)
@android_sdk_path, @path = a
@android_dir = File.expand_path(File.dirname(__FILE__))
@framework_dir = File.join(@android_dir, "framework")
end
# runs the build script
def run
build_jar
copy_libs
puts "Complete!"
end
# removes local.properties and recreates based on android_sdk_path
# then generates framework/phonegap.jar
def build_jar
puts "Building the JAR..."
%w(local.properties phonegap.js phonegap.jar).each do |f|
FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
end
open(File.join(@framework_dir, "local.properties"), 'w') do |f|
f.puts "sdk.dir=#{ @android_sdk_path }"
end
Dir.chdir(@framework_dir)
`ant jar`
Dir.chdir(@android_dir)
end
# copies stuff from framework into the project
# TODO need to allow for www import inc icon
def copy_libs
puts "Copying over libraries and assets and creating phonegap.js..."
FileUtils.mkdir_p File.join(@path, "libs")
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
# concat JS and put into www folder.
js_dir = File.join(@framework_dir, "assets", "js")
phonegapjs = IO.read(File.join(js_dir, 'phonegap.js.base'))
Dir.new(js_dir).entries.each do |script|
next if script[0].chr == "." or script == "phonegap.js.base"
phonegapjs << IO.read(File.join(js_dir, script))
phonegapjs << "\n\n"
end
File.open(File.join(@path, "assets", "www", "phonegap.js"), 'w') {|f| f.write(phonegapjs) }
end
#
end
if ARGV.length == 2
Build.new(*ARGV).run
else
puts <<-EOF
TestGap: Builds the JS and PhoneGap Android jar file and copies them to your project.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Creates a fresh app for hybrid mobile web hacking. Delicious robot!
Usage:
./testgap <android_sdk_path> <path>
Params:
android_sdk_path ... The path to your Android SDK install.
path ............... The path to generate the Android application.
EOF
end