From 0c52ed44a017a85911c7436e4744af3eab2b5b85 Mon Sep 17 00:00:00 2001 From: Dave Johnson Date: Tue, 3 Aug 2010 15:10:56 -0700 Subject: [PATCH] changed FileUtils to public for testing purposes. added updategap that can updated a project with the latest phonegap jar and js --- framework/assets/js/phonegap.js.base | 4 +- framework/src/com/phonegap/FileUtils.java | 2 +- updategap | 85 +++++++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100755 updategap diff --git a/framework/assets/js/phonegap.js.base b/framework/assets/js/phonegap.js.base index 237a19ee..cdb4830c 100755 --- a/framework/assets/js/phonegap.js.base +++ b/framework/assets/js/phonegap.js.base @@ -164,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 diff --git a/framework/src/com/phonegap/FileUtils.java b/framework/src/com/phonegap/FileUtils.java index ab1a616c..420a1f0b 100644 --- a/framework/src/com/phonegap/FileUtils.java +++ b/framework/src/com/phonegap/FileUtils.java @@ -11,7 +11,7 @@ public class FileUtils { FileReader f_in; FileWriter f_out; - FileUtils(WebView view) + public FileUtils(WebView view) { mView = view; } diff --git a/updategap b/updategap new file mode 100755 index 00000000..8c79b2e2 --- /dev/null +++ b/updategap @@ -0,0 +1,85 @@ +#!/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_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 + + # 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", "js", "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 + + Params: + + android_sdk_path ... The path to your Android SDK install. + name ............... The name of your application. + package_name ....... The name of your package (For example: com.nitobi.demo) + www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.) + path ............... The path to generate the Android application. + + EOF +end \ No newline at end of file