forked from github/cordova-android
no more ruby dependency
This commit is contained in:
parent
7e2044c5b4
commit
65cf68b5d2
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,9 +3,10 @@ default.properties
|
||||
gen
|
||||
assets/www/phonegap.js
|
||||
local.properties
|
||||
framework/proguard.cfg
|
||||
framework/phonegap.jar
|
||||
framework/phonegap-*.jar
|
||||
framework/bin
|
||||
framework/assets/www/.DS_Store
|
||||
framework/assets/www/phonegap-*.js
|
||||
.DS_Store
|
||||
example
|
||||
|
83
README.md
83
README.md
@ -1,59 +1,27 @@
|
||||
PhoneGap/Android
|
||||
================
|
||||
===
|
||||
|
||||
PhoneGap/Android is an Android application library that allows for PhoneGap based projects to be built for the Android Platform. PhoneGap based applications are, at the core, an application written with web technology: HTML, CSS and JavaScript.
|
||||
|
||||
Pre Requisites
|
||||
--------------
|
||||
---
|
||||
|
||||
- Java JDK 1.5
|
||||
- Android SDK [http://developer.android.com](http://developer.android.com)
|
||||
- Apache ANT
|
||||
- Ruby (Optional, see section: DroidGap with JRuby)
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
On any POSIX machine add PhoneGap/Android to your PATH variable like so:
|
||||
|
||||
export PATH=$PATH:~/phonegap-android/bin
|
||||
|
||||
On Windows add the phonegap-android/bin to your PATH as normal.
|
||||
|
||||
DroidGap: PhoneGap/Android Dev Script
|
||||
-------------------------------------
|
||||
PhoneGap/Android Developer Tools
|
||||
---
|
||||
|
||||
Tools for developers building mobile apps using PhoneGap for Android.
|
||||
|
||||
Usage:
|
||||
|
||||
<pre>droidgap [command] [parameters]</pre>
|
||||
|
||||
Commands:
|
||||
|
||||
<pre>
|
||||
help ...... See this message. Type help [command name] to see specific help topics.
|
||||
gen ....... Generate the example PhoneGap application to current directory (or optionally provide an output directory as parameter).
|
||||
create .... Creates an Android compatible project from a WWW folder.
|
||||
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
||||
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
||||
test ...... Gets edge copy of mobile-spec and runs in first device or emulator attached.
|
||||
</pre>
|
||||
./bin/create [path package activity]
|
||||
./bin/debug [path]
|
||||
./bin/emulate
|
||||
./bin/log
|
||||
|
||||
Quickstart:
|
||||
|
||||
<pre>
|
||||
$ droidgap gen exampleapp
|
||||
$ cd exampleapp
|
||||
$ ant debug install && adb logcat
|
||||
</pre>
|
||||
|
||||
DroidGap with JRuby
|
||||
-------------------
|
||||
|
||||
If you want to use the droidgap command but do not want to install Ruby then you can call it using jruby jar included in the lib folder. All the options are the same and a call looks like this:
|
||||
|
||||
java -jar jruby-complete-1.4.0RC1.jar ../bin/droidgap help run
|
||||
|
||||
Keep in mind this will be slower due to JVM warmup.
|
||||
|
||||
Importing a PhoneGap/Android app into Eclipse
|
||||
---------------------------------------------
|
||||
@ -66,40 +34,13 @@ Importing a PhoneGap/Android app into Eclipse
|
||||
6. Click on the Target tab and select Manual (this way you can choose the emulator or device to build to)
|
||||
|
||||
|
||||
Common Command Line Tasks
|
||||
=========================
|
||||
|
||||
Running Mobile Spec
|
||||
---
|
||||
|
||||
droidgap test
|
||||
|
||||
Compile an APK
|
||||
---
|
||||
|
||||
Make sure you have a device plugged in (with debugging enabled) or a running emulator. Then:
|
||||
|
||||
ant debug install
|
||||
|
||||
or
|
||||
|
||||
droidgap run
|
||||
|
||||
Converting a W3C Widget into a an APK
|
||||
---
|
||||
|
||||
Given a Widget called FooBar with an index.html file in it. You navigate to its folder and run:
|
||||
|
||||
droidgap create
|
||||
cd ../FooBar_android
|
||||
ant debug install
|
||||
Common Commandline Tools
|
||||
===
|
||||
|
||||
List devices attached
|
||||
---
|
||||
|
||||
adb devices
|
||||
List of devices attached
|
||||
0123456789012 device
|
||||
|
||||
Install APK onto device
|
||||
---
|
||||
|
@ -1,2 +0,0 @@
|
||||
@ECHO OFF
|
||||
echo %~dp$PATH:1
|
50
bin/create
Executable file
50
bin/create
Executable file
@ -0,0 +1,50 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# create a phonegap/android project
|
||||
#
|
||||
# USAGE
|
||||
# ./create [path package activity]
|
||||
#
|
||||
PROJECT_PATH=${1:-"./example"}
|
||||
PACKAGE=${2:-"com.phonegap.example"}
|
||||
ACTIVITY=${3:-"PhoneGapExample"}
|
||||
ACTIVITY_PATH=./Example/src/com/phonegap/example/$ACTIVITY.java
|
||||
TARGET=$(android list targets | grep 'id: ' | sed 's/id: \([0-9]\).*/\1/g' | tail -1)
|
||||
VERSION=$(cat ./VERSION)
|
||||
|
||||
# clobber any existing example
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
rm -rf $PROJECT_PATH
|
||||
fi
|
||||
|
||||
# compile phonegap.js and phonegap.jar
|
||||
cd ./framework && ant jar && cd ../
|
||||
|
||||
# create the project
|
||||
android create project --target $TARGET --path $PROJECT_PATH --package $PACKAGE --activity $ACTIVITY
|
||||
|
||||
# copy in www
|
||||
mkdir -p ./Example/assets && cp -r ./bin/templates/www ./Example/assets/www
|
||||
|
||||
# copy in phonegap.js
|
||||
cp ./framework/assets/www/phonegap-$VERSION.js ./Example/assets/www/phonegap-$VERSION.js
|
||||
|
||||
# copy in phonegap.jar
|
||||
mkdir -p ./Example/libs && cp ./framework/phonegap-$VERSION.jar ./Example/libs/phonegap-$VERSION.jar
|
||||
|
||||
# copy in default activity
|
||||
cat ./bin/templates/Activity.java > $ACTIVITY_PATH
|
||||
|
||||
# interpolate the acivity name and package
|
||||
find "$ACTIVITY_PATH" | xargs grep '__ACTIVITY__' -sl | xargs -L1 sed -i "" "s/__ACTIVITY__/${ACTIVITY}/g"
|
||||
find "$ACTIVITY_PATH" | xargs grep '__ID__' -sl | xargs -L1 sed -i "" "s/__ID__/${PACKAGE}/g"
|
||||
|
||||
# copy in uses-permission elements
|
||||
sed '$d' < $PROJECT_PATH/AndroidManifest.xml > tmpFile ; mv tmpFile $PROJECT_PATH/AndroidManifest.xml
|
||||
cat ./bin/templates/uses-permission-elements >> $PROJECT_PATH/AndroidManifest.xml
|
||||
echo '</manifest>' >> $PROJECT_PATH/AndroidManifest.xml
|
||||
|
||||
# copy in plugins.xml
|
||||
mkdir -p $PROJECT_PATH/res/xml
|
||||
cp ./bin/templates/plugins.xml $PROJECT_PATH/res/xml/plugins.xml
|
173
bin/droidgap
173
bin/droidgap
@ -1,173 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
ROOT = File.expand_path(File.dirname(__FILE__).gsub(/bin$/,''))
|
||||
require 'fileutils'
|
||||
require File.join(ROOT, "lib", "generate.rb")
|
||||
require File.join(ROOT, "lib", "classic.rb")
|
||||
require File.join(ROOT, "lib", "create.rb")
|
||||
require File.join(ROOT, "lib", "run.rb")
|
||||
require File.join(ROOT, "lib", "update.rb")
|
||||
require File.join(ROOT, "lib", "test.rb")
|
||||
|
||||
# ---------------------------------------------------------- #
|
||||
# #
|
||||
# command line interface #
|
||||
# #
|
||||
# ---------------------------------------------------------- #
|
||||
|
||||
# droidgap gen [app name]
|
||||
Generate.new(ARGV[1]) if ARGV.first == 'gen'
|
||||
|
||||
# droidgap classic (for windows users mostly)
|
||||
Classic.new(ARGV[1..-1]) if ARGV.first == 'classic'
|
||||
|
||||
# droidgap create [path to phonegap project]
|
||||
Create.new(ARGV[1]) if ARGV.first == 'create'
|
||||
|
||||
# droidgap run [optional directory]
|
||||
Run.new if ARGV.first == 'run'
|
||||
|
||||
# droidgap update [params]
|
||||
Update.new if ARGV.first == 'update'
|
||||
|
||||
# droidgap log
|
||||
if ARGV.first == 'log'
|
||||
$stdout.sync = true
|
||||
IO.popen('adb logcat') do |f|
|
||||
until f.eof?
|
||||
puts f.gets
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# droidgap test
|
||||
Test.new if ARGV.first == 'test'
|
||||
|
||||
# TODO implement these!
|
||||
puts "droidgap ship not implemented" if ARGV.first == 'ship'
|
||||
|
||||
if ARGV.first.nil? || ARGV.first == 'help'
|
||||
help = <<-EOF
|
||||
|
||||
DroidGap: PhoneGap/Android Dev Script
|
||||
-------------------------------------
|
||||
|
||||
Useful utilities for devlopers building mobile apps using PhoneGap for Android.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap <command> <parameters>
|
||||
|
||||
Commands:
|
||||
|
||||
help ...... See this message. Type help [command name] to see specific help topics.
|
||||
gen ....... Generate the example PhoneGap application to current directory (or optionally provide an output directory as parameter).
|
||||
create .... Creates an Android compatible project from a WWW folder.
|
||||
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
||||
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
||||
ship ...... Build and sign an APK suitable for submission to an Android Marketplace.
|
||||
|
||||
Quickstart:
|
||||
|
||||
$ droidgap gen exampleapp
|
||||
$ cd exampleapp
|
||||
$ ant debug install && adb logcat
|
||||
|
||||
EOF
|
||||
|
||||
gen = <<-EOF
|
||||
|
||||
DroidGap Generate
|
||||
-----------------
|
||||
|
||||
Generate the example PhoneGap application to path supplied or current working directory if none is supplied.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap gen [path]
|
||||
|
||||
NOTE: Do *not* run "droidgap gen example" - you will end up with a recursive directory problem.
|
||||
|
||||
EOF
|
||||
|
||||
run = <<-EOF
|
||||
|
||||
DroidGap Run
|
||||
------------
|
||||
|
||||
Launches PhoneGap project to first device found and attaches a logger that listens for console.log statements.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap run <path>
|
||||
|
||||
EOF
|
||||
|
||||
ship = <<-EOF
|
||||
|
||||
DroidGap Ship
|
||||
-------------
|
||||
|
||||
Build and sign an APK suitable for submission to an Android Marketplace.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap ship <path>
|
||||
|
||||
EOF
|
||||
|
||||
log = <<-EOF
|
||||
|
||||
DroidGap Log
|
||||
-------------
|
||||
|
||||
Launches LogCat
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap log
|
||||
|
||||
EOF
|
||||
|
||||
create = <<-EOF
|
||||
|
||||
DroidGap Create
|
||||
----------------
|
||||
|
||||
Creates an Android compatable project from a PhoneGap project. For example, if you have MyProject with index.html this command will create MyProject_android.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap create <path>
|
||||
|
||||
EOF
|
||||
|
||||
update = <<-EOF
|
||||
|
||||
DroidGap Update
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Builds the JS and PhoneGap Android jar file and copies them to your project.
|
||||
|
||||
EOF
|
||||
|
||||
classic = <<-EOF
|
||||
|
||||
DroidGap Classic
|
||||
~~~~~~~~~~~~-~~~
|
||||
|
||||
Compatability for older droidgap scripts.
|
||||
|
||||
Usage:
|
||||
|
||||
droidgap classic [android_sdk_path] [name] [package_name] [www] [path]
|
||||
|
||||
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 application.
|
||||
|
||||
EOF
|
||||
|
||||
puts ARGV[1].nil? ? help : eval(ARGV[1])
|
||||
end
|
@ -1 +0,0 @@
|
||||
ruby %~dp0droidgap %1 %2
|
3
bin/emulate
Executable file
3
bin/emulate
Executable file
@ -0,0 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
emulator -cpu-delay 0 -no-boot-anim -cache ./tmp/cache -avd default > /dev/null 2>&1 & # put the avd's chatty ass in the background
|
16
bin/templates/Activity.java
Normal file
16
bin/templates/Activity.java
Normal file
@ -0,0 +1,16 @@
|
||||
package __ID__;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import com.phonegap.*;
|
||||
|
||||
public class __ACTIVITY__ extends DroidGap
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
super.loadUrl("file:///android_asset/www/index.html");
|
||||
}
|
||||
}
|
||||
|
19
bin/templates/plugins.xml
Executable file
19
bin/templates/plugins.xml
Executable file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<plugins>
|
||||
<plugin name="App" value="com.phonegap.App"/>
|
||||
<plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
|
||||
<plugin name="Device" value="com.phonegap.Device"/>
|
||||
<plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
|
||||
<plugin name="Compass" value="com.phonegap.CompassListener"/>
|
||||
<plugin name="Media" value="com.phonegap.AudioHandler"/>
|
||||
<plugin name="Camera" value="com.phonegap.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="com.phonegap.ContactManager"/>
|
||||
<plugin name="Crypto" value="com.phonegap.CryptoHandler"/>
|
||||
<plugin name="File" value="com.phonegap.FileUtils"/>
|
||||
<plugin name="Network Status" value="com.phonegap.NetworkManager"/>
|
||||
<plugin name="Notification" value="com.phonegap.Notification"/>
|
||||
<plugin name="Storage" value="com.phonegap.Storage"/>
|
||||
<plugin name="Temperature" value="com.phonegap.TempListener"/>
|
||||
<plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
|
||||
<plugin name="Capture" value="com.phonegap.Capture"/>
|
||||
</plugins>
|
14
bin/templates/uses-permission-elements
Normal file
14
bin/templates/uses-permission-elements
Normal file
@ -0,0 +1,14 @@
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
3
bin/test
Executable file
3
bin/test
Executable file
@ -0,0 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
echo 'TODO download mobile-spec, generate a project, copy it in, build it'
|
@ -119,8 +119,8 @@
|
||||
|
||||
<!-- update project files to reference phonegap-x.x.x.min.js -->
|
||||
<replaceregexp match="phonegap(.*)\.js" replace="phonegap-${version}.js" byline="true">
|
||||
<fileset file="assets/www/index.html" />
|
||||
<fileset file="../example/index.html" />
|
||||
<fileset file="assets/www/index.html" />
|
||||
<fileset file="../bin/templates/www/index.html" />
|
||||
</replaceregexp>
|
||||
<replaceregexp match="phonegapVersion = [\u0022].*[\u0022];" replace="phonegapVersion = ${dblQuote}${version}${dblQuote};" byline="true">
|
||||
<fileset file="src/com/phonegap/Device.java" />
|
||||
|
175
lib/classic.rb
175
lib/classic.rb
@ -1,175 +0,0 @@
|
||||
class Classic
|
||||
attr_reader :android_sdk_path, :name, :pkg, :www, :path
|
||||
|
||||
def initialize(a)
|
||||
@android_sdk_path, @name, @pkg, @www, @path = a
|
||||
build
|
||||
end
|
||||
|
||||
def build
|
||||
setup
|
||||
clobber
|
||||
build_jar
|
||||
create_android
|
||||
include_www
|
||||
generate_manifest
|
||||
copy_libs
|
||||
add_name_to_strings
|
||||
write_java
|
||||
end
|
||||
|
||||
def setup
|
||||
@android_dir = File.expand_path(File.dirname(__FILE__).gsub(/lib$/,''))
|
||||
@framework_dir = File.join(@android_dir, "framework")
|
||||
@icon = File.join(@www, 'icon.png') unless !@icon.nil? && File.exists?(@icon)
|
||||
# Hash that stores the location of icons for each resolution type. Uses the default icon for all resolutions as a baseline.
|
||||
@icons = {
|
||||
:"drawable-ldpi" => @icon,
|
||||
:"drawable-mdpi" => @icon,
|
||||
:"drawable-hdpi" => @icon
|
||||
} if @icons.nil?
|
||||
@app_js_dir = ''
|
||||
@content = 'index.html'
|
||||
end
|
||||
|
||||
# replaces @path with new android project
|
||||
def clobber
|
||||
FileUtils.rm_r(@path) if File.exists? @path
|
||||
FileUtils.mkdir_p @path
|
||||
end
|
||||
|
||||
# removes local.properties and recreates based on android_sdk_path
|
||||
# then generates framework/phonegap.jar
|
||||
def build_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
|
||||
|
||||
# runs android create project
|
||||
# TODO need to allow more flexible SDK targetting via config.xml
|
||||
def create_android
|
||||
IO.popen("android list targets") { |f|
|
||||
targets = f.readlines(nil)[0].scan(/id\:.*$/)
|
||||
if (targets.length > 0)
|
||||
target_id = targets.last.match(/\d+/).to_a.first
|
||||
`android create project -t #{ target_id } -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
|
||||
else
|
||||
puts "No Android targets found. Please run 'android' and install at least one SDK package."
|
||||
puts "If that makes no sense then you need to go read the Android SDK documentation."
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# copies the project/www folder into tmp/android/www
|
||||
def include_www
|
||||
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
||||
FileUtils.cp_r File.join(@www, "."), File.join(@path, "assets", "www")
|
||||
end
|
||||
|
||||
# creates an AndroidManifest.xml for the project
|
||||
def generate_manifest
|
||||
manifest = ""
|
||||
open(File.join(@framework_dir, "AndroidManifest.xml"), 'r') do |old|
|
||||
manifest = old.read
|
||||
manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"'
|
||||
manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\""
|
||||
manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name.gsub(' ','') }\""
|
||||
manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"'
|
||||
end
|
||||
open(File.join(@path, "AndroidManifest.xml"), 'w') { |x| x.puts manifest }
|
||||
end
|
||||
|
||||
# copies stuff from src directory into the android project directory (@path)
|
||||
def copy_libs
|
||||
version = IO.read(File.join(@framework_dir, '../VERSION')).lstrip.rstrip
|
||||
framework_res_dir = File.join(@framework_dir, "res")
|
||||
app_res_dir = File.join(@path, "res")
|
||||
# copies in the jar
|
||||
FileUtils.mkdir_p File.join(@path, "libs")
|
||||
FileUtils.cp File.join(@framework_dir, "phonegap-#{ version }.jar"), File.join(@path, "libs")
|
||||
# copies in the strings.xml
|
||||
FileUtils.mkdir_p File.join(app_res_dir, "values")
|
||||
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
|
||||
# copies in plugins.xml
|
||||
FileUtils.mkdir_p File.join(app_res_dir, "xml")
|
||||
FileUtils.cp File.join(framework_res_dir, "xml","plugins.xml"), File.join(app_res_dir, "xml", "plugins.xml")
|
||||
# drops in the layout files: main.xml and preview.xml
|
||||
FileUtils.mkdir_p File.join(app_res_dir, "layout")
|
||||
%w(main.xml).each do |f|
|
||||
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
|
||||
end
|
||||
# icon file copy
|
||||
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
||||
# if specific resolution icons are specified, use those. if not, see if a general purpose icon was defined.
|
||||
# finally, fall back to using the default PhoneGap one.
|
||||
currentIcon = ""
|
||||
if !@icons[e.to_sym].nil? && File.exists?(File.join(@www, @icons[e.to_sym]))
|
||||
currentIcon = File.join(@www, @icons[e.to_sym])
|
||||
elsif File.exists?(@icon)
|
||||
currentIcon = @icon
|
||||
else
|
||||
currentIcon = File.join(framework_res_dir, "drawable", "icon.png")
|
||||
end
|
||||
FileUtils.mkdir_p(File.join(app_res_dir, e))
|
||||
FileUtils.cp(currentIcon, File.join(app_res_dir, e, "icon.png"))
|
||||
end
|
||||
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
|
||||
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", @app_js_dir, "phonegap-#{ version }.js"), 'w') {|f| f.write(phonegapjs) }
|
||||
end
|
||||
|
||||
# puts app name in strings
|
||||
def add_name_to_strings
|
||||
x = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||
<resources>
|
||||
<string name=\"app_name\">#{ @name }</string>
|
||||
<string name=\"go\">Snap</string>
|
||||
</resources>
|
||||
"
|
||||
open(File.join(@path, "res", "values", "strings.xml"), 'w') do |f|
|
||||
f.puts x.gsub(' ','')
|
||||
end
|
||||
end
|
||||
|
||||
# create java source file
|
||||
def write_java
|
||||
j = "
|
||||
package #{ @pkg };
|
||||
|
||||
import android.os.Bundle;
|
||||
import com.phonegap.*;
|
||||
|
||||
public class #{ @name.gsub(' ','') } extends DroidGap
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
super.loadUrl(\"file:///android_asset/www/#{ @content }\");
|
||||
}
|
||||
}
|
||||
"
|
||||
code_dir = File.join(@path, "src", @pkg.gsub('.', File::SEPARATOR))
|
||||
FileUtils.mkdir_p(code_dir)
|
||||
open(File.join(code_dir, "#{ @name }.java"),'w') { |f| f.puts j }
|
||||
end
|
||||
|
||||
# friendly output for now
|
||||
def msg
|
||||
puts "Created #{ @path }"
|
||||
end
|
||||
#
|
||||
end
|
@ -1,97 +0,0 @@
|
||||
# Create
|
||||
#
|
||||
# Generates an Android project from a valid WWW directory and puts it in ../[PROJECT NAME]_android
|
||||
#
|
||||
class Create < Classic
|
||||
def initialize(path)
|
||||
guess_paths(path)
|
||||
read_config
|
||||
build
|
||||
end
|
||||
|
||||
def guess_paths(path)
|
||||
# if no path is supplied uses current directory for project
|
||||
path = FileUtils.pwd if path.nil?
|
||||
|
||||
# if a www is found use it for the project
|
||||
path = File.join(path, 'www') if File.exists? File.join(path, 'www')
|
||||
|
||||
# defaults
|
||||
@name = path.split("/").last.gsub('-','').gsub(' ','') # no dashses nor spaces
|
||||
@path = File.join(path, '..', "#{ @name }_android")
|
||||
@www = path
|
||||
@pkg = "com.phonegap.#{ @name }"
|
||||
@android_sdk_path = Dir.getwd[0,1] != "/" ? `android-sdk-path.bat android.bat`.gsub('\\tools','').gsub('\\', '\\\\\\\\') : `which android`.gsub(/\/tools\/android$/,'').chomp
|
||||
@android_dir = File.expand_path(File.dirname(__FILE__).gsub('lib',''))
|
||||
@framework_dir = File.join(@android_dir, "framework")
|
||||
@icon = File.join(@www, 'icon.png')
|
||||
@app_js_dir = ''
|
||||
@content = 'index.html'
|
||||
|
||||
# stop executation on errors
|
||||
raise "Expected index.html in the following folder #{ path }.\nThe path is expected to be the directory droidgap create is run from or specified as a command line arg like droidgap create my_path." unless File.exists? File.join(path, 'index.html')
|
||||
raise 'Could not find android in your PATH!' if @android_sdk_path.empty?
|
||||
end
|
||||
|
||||
# reads in a config.xml file
|
||||
def read_config
|
||||
config_file = File.join(@www, 'config.xml')
|
||||
|
||||
if File.exists?(config_file)
|
||||
require 'rexml/document'
|
||||
f = File.new config_file
|
||||
doc = REXML::Document.new(f)
|
||||
@config = {}
|
||||
@config[:id] = doc.root.attributes["id"]
|
||||
@config[:version] = doc.root.attributes["version"]
|
||||
@config[:icons] = {}
|
||||
defaultIconSize = 0
|
||||
doc.root.elements.each do |n|
|
||||
@config[:name] = n.text.gsub('-','').gsub(' ','') if n.name == 'name'
|
||||
@config[:description] = n.text if n.name == 'description'
|
||||
@config[:content] = n.attributes["src"] if n.name == 'content'
|
||||
if n.name == 'icon'
|
||||
if n.attributes["width"] == '72' && n.attributes["height"] == '72'
|
||||
@config[:icons]["drawable-hdpi".to_sym] = n.attributes["src"]
|
||||
if 72 > defaultIconSize
|
||||
@config[:icon] = n.attributes["src"]
|
||||
defaultIconSize = 72
|
||||
end
|
||||
elsif n.attributes["width"] == '48' && n.attributes["height"] == '48'
|
||||
@config[:icons]["drawable-mdpi".to_sym] = n.attributes["src"]
|
||||
if 48 > defaultIconSize
|
||||
@config[:icon] = n.attributes["src"]
|
||||
defaultIconSize = 48
|
||||
end
|
||||
elsif n.attributes["width"] == '36' && n.attributes["height"] == '36'
|
||||
@config[:icons]["drawable-ldpi".to_sym] = n.attributes["src"]
|
||||
if 36 > defaultIconSize
|
||||
@config[:icon] = n.attributes["src"]
|
||||
defaultIconSize = 36
|
||||
end
|
||||
else
|
||||
@config[:icon] = n.attributes["src"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if n.name == "preference" && n.attributes["name"] == 'javascript_folder'
|
||||
@config[:js_dir] = n.attributes["value"]
|
||||
end
|
||||
end
|
||||
|
||||
# extract android specific stuff
|
||||
@config[:versionCode] = doc.elements["//android:versionCode"] ? doc.elements["//android:versionCode"].text : 3
|
||||
@config[:minSdkVersion] = doc.elements["//android:minSdkVersion"] ? doc.elements["//android:minSdkVersion"].text : 1
|
||||
# will change the name from the directory to the name element text
|
||||
@name = @config[:name] if @config[:name]
|
||||
# set the icon from the config
|
||||
@icon = File.join(@www, @config[:icon]) if @config[:icon]
|
||||
@icons = @config[:icons] if @config[:icons].length > 0
|
||||
# sets the app js dir where phonegap.js gets copied
|
||||
@app_js_dir = @config[:js_dir] ? @config[:js_dir] : ''
|
||||
# sets the start page
|
||||
@content = @config[:content] ? @config[:content] : 'index.html'
|
||||
end
|
||||
end
|
||||
end
|
@ -1,15 +0,0 @@
|
||||
# Creates a new PhoneGap/Android project from ./example
|
||||
class Generate
|
||||
def initialize(name)
|
||||
if name.nil?
|
||||
puts "You need to supply a name to generate a project. Try this:\n\ndroidgap gen MyApp\n\n"
|
||||
return
|
||||
end
|
||||
from = File.join ROOT, "example"
|
||||
to = File.join FileUtils.pwd, name
|
||||
FileUtils.cp_r from, to
|
||||
Create.new(to)
|
||||
FileUtils.rm_rf to
|
||||
FileUtils.mv "#{ to }_android", to
|
||||
end
|
||||
end
|
Binary file not shown.
68
lib/run.rb
68
lib/run.rb
@ -1,68 +0,0 @@
|
||||
#
|
||||
# Run
|
||||
# ---
|
||||
#
|
||||
# A handy machine that does the following:
|
||||
#
|
||||
# - runs ant_debug
|
||||
# - if there is no device attached it will start an emulator with the first avd found
|
||||
# - runs ant_install
|
||||
#
|
||||
class Run
|
||||
# if no path is supplied uses current directory for project
|
||||
def initialize
|
||||
@path = FileUtils.pwd
|
||||
build
|
||||
start_emulator if first_device.nil?
|
||||
install
|
||||
end
|
||||
|
||||
def build
|
||||
Dir.chdir(@path)
|
||||
`ant debug`
|
||||
end
|
||||
|
||||
def install
|
||||
Dir.chdir(@path)
|
||||
`ant install`
|
||||
end
|
||||
|
||||
def start_emulator
|
||||
puts "No devices attached. Starting emulator w/ first avd...\n"
|
||||
$stdout.sync = true
|
||||
avd = first_avd
|
||||
if (avd.nil? || avd == "")
|
||||
puts "No Android Virtual Device (AVD) could be found. Please create one with the Android SDK."
|
||||
return
|
||||
end
|
||||
IO.popen("emulator -avd #{ avd } -logcat all") do |f|
|
||||
until f.eof?
|
||||
puts f.gets
|
||||
if f.gets.include? 'Boot is finished'
|
||||
#IO.popen("cd #{ @pkg.path }; ant install;") do |f|
|
||||
# puts f.gets
|
||||
#end
|
||||
puts "\n\nEMULATOR IS NOW RUNNING!\n\n"
|
||||
puts "install your app by running: "
|
||||
puts "cd #{ @pkg.path }; ant install;"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# helpers
|
||||
def first_device
|
||||
fd = `adb devices`.split("\n").pop()
|
||||
if fd == 'List of devices attached '
|
||||
nil
|
||||
else
|
||||
fd.gsub('device','')
|
||||
end
|
||||
end
|
||||
|
||||
def first_avd
|
||||
`android list avd | grep "Name: "`.gsub('Name: ','').strip
|
||||
end
|
||||
|
||||
#
|
||||
end
|
@ -1,6 +0,0 @@
|
||||
# this is for implementors mostly
|
||||
class Test
|
||||
def initialize
|
||||
`git clone git@github.com:phonegap/mobile-spec.git && cd mobile-spec && droidgap create && cd ../mobilespec_android && ant debug install`
|
||||
end
|
||||
end
|
@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'fileutils'
|
||||
|
||||
class Update
|
||||
attr_reader :android_sdk_path, :path
|
||||
|
||||
def initialize
|
||||
@path = FileUtils.pwd
|
||||
@android_sdk_path = Dir.getwd[0,1] != "/" ? `android-sdk-path.bat android.bat`.gsub('\\tools','').gsub('\\', '\\\\\\\\') : `which android`.gsub('/tools/android','')
|
||||
@android_dir = File.expand_path(File.dirname(__FILE__))
|
||||
@framework_dir = File.join(@android_dir, "..", "framework")
|
||||
# puts "updating #{ @path } with phonegap from #{ @android_dir }"
|
||||
build_jar
|
||||
copy_libs
|
||||
end
|
||||
|
||||
# removes local.properties and recreates based on android_sdk_path
|
||||
# then generates framework/phonegap.jar & framework/assets/www/phonegap.js
|
||||
def build_jar
|
||||
puts "Building the JAR and combining JS files..."
|
||||
%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..."
|
||||
version = IO.read(File.join(@framework_dir, '../VERSION'))
|
||||
|
||||
FileUtils.cp File.join(@framework_dir, "phonegap-#{ version }.jar"), File.join(@path, "libs")
|
||||
|
||||
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
|
||||
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-#{ version }.js"), 'w') {|f| f.write(phonegapjs) }
|
||||
end
|
||||
#
|
||||
end
|
BIN
util/js.jar
BIN
util/js.jar
Binary file not shown.
5544
util/jslint.js
5544
util/jslint.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user