mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
Fixing the build process, found Android 2.0 bugs
This commit is contained in:
parent
c794756f70
commit
2c11550b30
80
build.rb
Normal file
80
build.rb
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
require 'rubygems'
|
||||||
|
require 'nokogiri'
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
class Build
|
||||||
|
attr_reader :path
|
||||||
|
attr_reader :name
|
||||||
|
attr_reader :package_name
|
||||||
|
attr_reader :www_dir
|
||||||
|
|
||||||
|
def start(name, pkg_name, www, path)
|
||||||
|
create_android(name, pkg_name, path)
|
||||||
|
@www_dir = www
|
||||||
|
generate_manifest
|
||||||
|
copy_libs
|
||||||
|
write_java
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_android(name, pkg_name, path)
|
||||||
|
@name = name
|
||||||
|
@pkg_name = pkg_name
|
||||||
|
@path = path
|
||||||
|
`android create project -t 5 -k #{pkg_name} -a #{name} -n #{name} -p #{path}`
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_manifest
|
||||||
|
f = File.open('framework/AndroidManifest.xml', 'r')
|
||||||
|
doc = Nokogiri::XML(f.read)
|
||||||
|
manifest = doc.search('//manifest')
|
||||||
|
manifest[0]['package'] = @pkg_name
|
||||||
|
actions = doc.search('//activity')
|
||||||
|
actions[0]['android:name'] = ".#{@name}"
|
||||||
|
actions[1]['android:name'] = "com.phonegap.CameraPreview"
|
||||||
|
f = File.open("#{@path}/AndroidManifest.xml", 'w')
|
||||||
|
f.write(doc.to_xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
def copy_libs
|
||||||
|
FileUtils.cp('framework/phonegap.jar', "#{@path}/libs")
|
||||||
|
FileUtils.cp('framework/res/values/strings.xml', "#{@path}/res/values/strings.xml")
|
||||||
|
FileUtils.mkdir_p("#{@path}/res/drawable/")
|
||||||
|
FileUtils.mkdir_p("#{@path}/assets")
|
||||||
|
FileUtils.cp_r("#{@www_dir}/", "#{@path}/assets/www")
|
||||||
|
FileUtils.cp("#{@www_dir}/icon.png", "#{@path}/res/drawable/icon.png")
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_java
|
||||||
|
package_path = "#{@path}/src/" + @pkg_name.gsub('.', '/')
|
||||||
|
doc = File.open("#{package_path}/#{@name}.java", 'r')
|
||||||
|
data = doc.read.split(/\n/)
|
||||||
|
result = ""
|
||||||
|
data.each do |line|
|
||||||
|
if line.include? "android.os.Bundle"
|
||||||
|
line += "\n\nimport com.phonegap.*;"
|
||||||
|
end
|
||||||
|
if line.include? "extends Activity"
|
||||||
|
line = "public class #{@name} extends DroidGap"
|
||||||
|
end
|
||||||
|
if line.include? "setContentView"
|
||||||
|
line = " super.loadUrl(\"file:///android_asset/www/index.html\");"
|
||||||
|
end
|
||||||
|
result += line + "\n"
|
||||||
|
end
|
||||||
|
doc.close
|
||||||
|
package_path = "#{@path}/src/" + @pkg_name.gsub('.', '/')
|
||||||
|
target = File.open(package_path + "/#{@name}.java", 'w')
|
||||||
|
target.write(result);
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
b = Build.new
|
||||||
|
|
||||||
|
if(ARGV.length >= 3)
|
||||||
|
b.start(ARGV[0], ARGV[1], ARGV[2], ARGV[3])
|
||||||
|
else
|
||||||
|
str = "Android PhoneGap Build Tool \n Usage: build <name> <package_name> <wwwdir> <path> \n name: The name of your application \n package_name: The name of your package: i.e. com.nitobi.demo \n wwwdir: The name of your Web App \n path: Location of where you want to work on your application"
|
||||||
|
puts str
|
||||||
|
end
|
@ -71,7 +71,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar" depends="move_files, compile">
|
<target name="jar" depends="move_files, compile">
|
||||||
<jar jarfile="phonegap.jar" basedir="bin/classes"/>
|
<jar jarfile="phonegap.jar" basedir="bin/classes" excludes="**/R*.class" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="phonegap_debug" depends="move_files, debug">
|
<target name="phonegap_debug" depends="move_files, debug">
|
||||||
|
@ -86,7 +86,11 @@ public class DroidGap extends Activity {
|
|||||||
WebViewReflect.checkCompatibility();
|
WebViewReflect.checkCompatibility();
|
||||||
|
|
||||||
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
|
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
|
||||||
appView.setWebChromeClient(new PhoneGapClient(this));
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ECLAIR)
|
||||||
|
appView.setWebChromeClient(new EclairClient(this));
|
||||||
|
else
|
||||||
|
appView.setWebChromeClient(new GapClient(this));
|
||||||
|
|
||||||
appView.setInitialScale(100);
|
appView.setInitialScale(100);
|
||||||
|
|
||||||
WebSettings settings = appView.getSettings();
|
WebSettings settings = appView.getSettings();
|
||||||
@ -145,13 +149,57 @@ public class DroidGap extends Activity {
|
|||||||
* Provides a hook for calling "alert" from javascript. Useful for
|
* Provides a hook for calling "alert" from javascript. Useful for
|
||||||
* debugging your javascript.
|
* debugging your javascript.
|
||||||
*/
|
*/
|
||||||
final class PhoneGapClient extends GapClient {
|
public class GapClient extends WebChromeClient {
|
||||||
|
|
||||||
PhoneGapClient(Context ctx){
|
Context mCtx;
|
||||||
|
public GapClient(Context ctx)
|
||||||
|
{
|
||||||
|
mCtx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
||||||
|
Log.d(LOG_TAG, message);
|
||||||
|
// This shows the dialog box. This can be commented out for dev
|
||||||
|
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx);
|
||||||
|
alertBldr.setMessage(message);
|
||||||
|
alertBldr.setTitle("Alert");
|
||||||
|
alertBldr.show();
|
||||||
|
result.confirm();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class EclairClient extends GapClient
|
||||||
|
{
|
||||||
|
private long MAX_QUOTA = 2000000;
|
||||||
|
|
||||||
|
public EclairClient(Context ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
||||||
|
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
||||||
|
{
|
||||||
|
|
||||||
|
if( estimatedSize < MAX_QUOTA)
|
||||||
|
{
|
||||||
|
long newQuota = estimatedSize;
|
||||||
|
quotaUpdater.updateQuota(newQuota);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set the quota to whatever it is and force an error
|
||||||
|
// TODO: get docs on how to handle this properly
|
||||||
|
quotaUpdater.updateQuota(currentQuota);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is required to start the camera activity! It has to come from the previous activity
|
// This is required to start the camera activity! It has to come from the previous activity
|
||||||
public void startCamera(int quality)
|
public void startCamera(int quality)
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package com.phonegap;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.webkit.JsResult;
|
|
||||||
import android.webkit.WebChromeClient;
|
|
||||||
import android.webkit.WebStorage;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
|
|
||||||
public class GapClient extends WebChromeClient {
|
|
||||||
|
|
||||||
private static final String LOG_TAG = "DroidGap";
|
|
||||||
private long MAX_QUOTA = 2000000;
|
|
||||||
private WebChromeClient mInstance;
|
|
||||||
|
|
||||||
/* class initialization fails when this throws an exception */
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Context mCtx;
|
|
||||||
GapClient(Context ctx)
|
|
||||||
{
|
|
||||||
mCtx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
|
||||||
Log.d(LOG_TAG, message);
|
|
||||||
// This shows the dialog box. This can be commented out for dev
|
|
||||||
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx);
|
|
||||||
alertBldr.setMessage(message);
|
|
||||||
alertBldr.setTitle("Alert");
|
|
||||||
alertBldr.show();
|
|
||||||
result.confirm();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
|
||||||
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
|
||||||
{
|
|
||||||
|
|
||||||
if( estimatedSize < MAX_QUOTA)
|
|
||||||
{
|
|
||||||
long newQuota = estimatedSize;
|
|
||||||
quotaUpdater.updateQuota(newQuota);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Set the quota to whatever it is and force an error
|
|
||||||
// TODO: get docs on how to handle this properly
|
|
||||||
quotaUpdater.updateQuota(currentQuota);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user