Compare commits

...

48 Commits

Author SHA1 Message Date
Joe Bowser
e01678da93 Dealing with the retagging of cordova.js 2013-06-19 15:03:11 -07:00
Joe Bowser
2b6a683198 CB-3902: Explicitly add market URIs to CordovaWebViewClient so this always works, not just sometimes 2013-06-18 16:19:27 -07:00
Benn Mapes
1f58d8ee27 [CB-3625] [CB-3338] updated windows cli scripts and added version option 2013-06-18 15:04:56 -07:00
Joe Bowser
fb4527d91b Updating Javascript 2013-06-18 13:24:53 -07:00
Andrew Grieve
a83bbcaf1d Set VERSION to 2.9.0rc1 2013-06-18 13:49:25 -04:00
Andrew Grieve
431f3337d9 Update JS snapshot to version 2.9.0rc1 2013-06-18 13:49:19 -04:00
Joe Bowser
c9b164b983 Removing bench from the README 2013-06-17 15:49:40 -07:00
Joe Bowser
54d32ad910 CB-3784: Nit-picking 2013-06-17 15:45:56 -07:00
Fil Maj
0efd9fcac0 [CB-3627] start-emulator now properly starts, waits for and unlocks an emulator, consumed by run as well. 2013-06-14 17:22:57 -07:00
Joe Bowser
c0a39570c9 CB-2391: False positive, this affects 4.2.2, not ICS. Bug breaks before we get to this point. :( 2013-06-14 17:03:40 -07:00
Joe Bowser
9ac4b570e6 CB-2391: Fix for colons crashing the WebView on ICS, tested on Samsung Galaxy S2 2013-06-14 16:55:47 -07:00
Joe Bowser
6689827278 Fixing the config.xml on tests to use the ActivityPlugin 2013-06-14 15:31:23 -07:00
Joe Bowser
86a24ebd0f Updating the JS used in the tests 2013-06-14 15:31:03 -07:00
Joe Bowser
d2a7d18067 Fixed bad comment, it's all dying at the same time 2013-06-14 15:30:24 -07:00
Joe Bowser
b679672c0e Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-android 2013-06-14 15:29:51 -07:00
Joe Bowser
90f83db9c9 CB-3504: Fixing issue with the use of WebResourceResponse on pre-Honeycomb devices. 2013-06-14 15:29:30 -07:00
Fil Maj
32d74f8623 correct refs to various lib scripts in run. 2013-06-14 14:48:23 -07:00
Fil Maj
53cc381c76 removing unused script anymore from create. 2013-06-14 14:44:26 -07:00
Fil Maj
add107583f Proper modularization of bash scripts for [CB-3627], but not solved yet. wait_for_emulator does not work atm 2013-06-13 16:46:21 -07:00
Fil Maj
e86d811fc0 [CB-3626] fix to start-emulator: if no id is provided, should start the first emulator 2013-06-13 12:44:43 -07:00
Ian Clelland
5cff144a22 [CB-2406] Add support for binary data in FileWriter.write() 2013-06-12 13:33:03 -04:00
Joe Bowser
a021adb7fd CB-3766: Javascript uses loadUrl, not loadUrlIntoView, which is only for documents 2013-06-12 09:33:52 -07:00
Joe Bowser
e2a090bbba Don't call loadUrlIntoView on the actvity 2013-06-12 09:18:10 -07:00
Joe Bowser
a70c8536f9 Re-adding the Plugin.java shim for now. This will remain a 2.x-only feature 2013-06-11 10:38:42 -07:00
Joe Bowser
e52d4fc003 CB-3736: Cleaning up code so that this makes more sense. Variables are OK 2013-06-07 16:43:53 -07:00
Joe Bowser
3753e3f353 Trying to get DataResource reverted so that we don't have to worry about this blowing up while we're breaking things out. DataResource should be on a branch until it's ready! 2013-06-06 14:35:12 -07:00
Andrew Grieve
979d8e66f2 Revert "Added "DataResource" - allows many plugins to intercept a single request"
This reverts commit 62c3e46529.
Reverting all DataResource changes for the 2.8.0 release.

Conflicts:

	framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
	framework/src/org/apache/cordova/api/DataResource.java
	framework/src/org/apache/cordova/api/DataResourceContext.java
2013-06-06 14:14:14 -07:00
Andrew Grieve
c5b37cc7e7 Revert "Changed all usages of FileHelper to use the new DataResource mechanism."
This reverts commit 867358ea81.
Reverting all DataResource changes for the 2.8.0 release.

Conflicts:

	framework/src/org/apache/cordova/FileUtils.java
2013-06-06 14:12:44 -07:00
Andrew Grieve
e3989bcc2b Revert "DataRequest code cleaned up."
This reverts commit a001d8cfb7.
Reverting all DataResource changes for the 2.8.0 release.

Conflicts:

	framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
2013-06-06 14:10:13 -07:00
Andrew Grieve
2f9c512b59 Revert "DataResource bugfix WebviewClient logs error for http urls."
This reverts commit 8f91ebf194.
Reverting all DataResource changes for the 2.8.0 release.

Conflicts:

	framework/src/org/apache/cordova/FileHelper.java
	framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
2013-06-06 14:08:52 -07:00
Andrew Grieve
43172cf530 Revert "CB-3496: Fixed streaming audio, this is pretty important for mobile spec"
This reverts commit aa81966e0b.

Going to revert all DataResource changes for on the 2.8.x branch.
2013-06-06 14:06:54 -07:00
Braden Shepherdson
e518eacbde Replace naive relative path in version script with proper one 2013-06-06 12:00:33 -04:00
David Kemp
c3b8b279b0 CB-3420: add hidden option to InAppBrowser 2013-06-05 10:19:56 -04:00
Joe Bowser
0dd4951be7 Forgot to update this so that it doesn't destroy someone's project, FAIL 2013-06-04 14:28:16 -07:00
Joe Bowser
12d06bd727 Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-android 2013-06-03 14:45:49 -07:00
Joe Bowser
bc52345f05 CB-3548: Throwing this one over the fence, but this change appears sane. We should just return false. 2013-06-03 14:45:27 -07:00
Ian Clelland
c28a313374 [CB-3569] Allow FileTransfer.upload to reference android_assets 2013-06-03 16:14:22 -04:00
Ian Clelland
c509c8e7e5 [CB-3563] Update references to DroidGap in code comments 2013-05-31 11:20:33 -04:00
Ian Clelland
fb89cef256 [CB-3563] Replace instances of DroidGap in log messages with more appropriate symbols 2013-05-31 11:16:09 -04:00
Ian Clelland
9ac9fd4fe9 [CB-3563] Change default logging tag from DroidGap to CordovaActivity 2013-05-31 10:54:40 -04:00
Ian Clelland
dfb89df4f1 [CB-3561] Update documentation comments to match implementation
Affects CordovaInterface and CordovaActivity. There should probably be a
concerted effort to update this across the entire project.
2013-05-31 10:54:40 -04:00
Andrew Grieve
0e572aea36 [CB-3340] Add copying of the version script to bin/create 2013-05-29 10:23:00 -04:00
Andrew Grieve
420cee4ee6 [CB-3468] Add missing license headers found by RAT 2013-05-28 16:43:38 -04:00
Ian Clelland
403297d967 CB-3523: Fix NPE on app restart with outstanding callback 2013-05-28 15:11:25 -04:00
Ian Clelland
abba254a38 CB-3358: Remove one more reference to commons-codec 2013-05-28 15:09:21 -04:00
Shravan Narayan
048107e378 CB-3384 Bugfix - Non null Mimetype is not required for WebResourceResponse 2013-05-28 13:58:39 -04:00
David Kemp
78efe2a960 CB-3358: Change Commons-codec:base64 to Android:Base64 2013-05-27 22:25:23 -04:00
Andrew Grieve
8077091b34 Update JS snapshot to version 2.8.0rc1 2013-05-27 22:15:49 -04:00
63 changed files with 2462 additions and 2048 deletions

View File

@@ -1,3 +1,23 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
Cordova Android
===
@@ -14,7 +34,6 @@ Requires
- Java JDK 1.5 or greater
- Apache ANT 1.8.0 or greater
- Android SDK [http://developer.android.com](http://developer.android.com)
- Apache Commons Codec [http://commons.apache.org/codec/](http://commons.apache.org/codec/)
Cordova Android Developer Tools
@@ -33,7 +52,6 @@ the dependencies:
General Commands
./bin/create [path package activity] ... create the ./example app or a cordova android project
./bin/bench ............................ generate a bench proj
./bin/autotest ......................... test the cli tools
./bin/test ............................. run mobile-spec
@@ -83,11 +101,7 @@ Note: The Developer Tools handle this. This is only to be done if the tooling f
you are developing directly against the framework.
To create your `cordova.jar` file, copy the commons codec:
mv commons-codec-1.7.jar framework/libs
then run in the framework directory:
To create your `cordova.jar` file, run in the framework directory:
android update project -p . -t android-17
ant jar

View File

@@ -1 +1 @@
dev
2.9.0rc1

View File

@@ -1,3 +1,20 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%check_reqs.js (
@@ -6,4 +23,4 @@ IF EXIST %full_path%check_reqs.js (
ECHO.
ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2
EXIT /B 1
)
)

View File

@@ -99,16 +99,6 @@ then
# update the cordova-android framework for the desired target
"$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then
# Use curl to get the jar (TODO: Support Apache Mirrors)
curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null
unzip commons-codec-1.7-bin.zip &> /dev/null
mkdir -p "$BUILD_PATH"/framework/libs
cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs
# cleanup yo
rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7
fi
# compile cordova.js and cordova.jar
pushd "$BUILD_PATH"/framework > /dev/null
ant jar > /dev/null
@@ -153,7 +143,7 @@ cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build
cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run
cp "$BUILD_PATH"/bin/templates/cordova/lib/cordova "$PROJECT_PATH"/cordova/lib/cordova
cp "$BUILD_PATH"/bin/templates/cordova/version "$PROJECT_PATH"/cordova/version
cp "$BUILD_PATH"/bin/templates/cordova/lib/install-device "$PROJECT_PATH"/cordova/lib/install-device
cp "$BUILD_PATH"/bin/templates/cordova/lib/install-emulator "$PROJECT_PATH"/cordova/lib/install-emulator
cp "$BUILD_PATH"/bin/templates/cordova/lib/list-devices "$PROJECT_PATH"/cordova/lib/list-devices

View File

@@ -106,60 +106,6 @@ function createAppInfoJar() {
}
}
function cleanup() {
// Cleanup
// if(fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.6.jar')) {
// fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.6.jar');
// fso.DeleteFolder(ROOT + '\\framework\\libs', true);
// }
if(fso.FileExists(ROOT + '\\framework\\cordova-'+VERSION+'.jar')) {
fso.DeleteFile(ROOT + '\\framework\\cordova-'+VERSION+'.jar');
}
if(fso.FileExists(ROOT + '\\framework\\assets\\www\\cordova-'+VERSION+'.js')) {
fso.DeleteFile(ROOT + '\\framework\\assets\\www\\cordova-'+VERSION+'.js');
}
}
function downloadCommonsCodec() {
if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) {
// We need the .jar
var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip';
var libsPath = ROOT + '\\framework\\libs';
var savePath = libsPath + '\\commons-codec-1.7-bin.zip';
if (!fso.FileExists(savePath)) {
if(!fso.FolderExists(ROOT + '\\framework\\libs')) {
fso.CreateFolder(libsPath);
}
// We need the zip to get the jar
var xhr = WScript.CreateObject('MSXML2.XMLHTTP');
xhr.open('GET', url, false);
xhr.send();
if (xhr.status == 200) {
var stream = WScript.CreateObject('ADODB.Stream');
stream.Open();
stream.Type = 1;
stream.Write(xhr.ResponseBody);
stream.Position = 0;
stream.SaveToFile(savePath);
stream.Close();
} else {
Log('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.');
}
}
var app = WScript.CreateObject('Shell.Application');
var source = app.NameSpace(savePath).Items();
var target = app.NameSpace(ROOT + '\\framework\\libs');
target.CopyHere(source, 256);
// Move the jar into libs
fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar');
// Clean up
fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip');
fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true);
}
}
// working dir
var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
if (args.Count() > 0) {
@@ -206,8 +152,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
Log("Building jar and js files...");
// update the cordova framework project to a target that exists on this machine
exec('android.bat update project --target "'+TARGET+'" --path "'+ROOT+'\\framework"');
// pull down commons codec if necessary
downloadCommonsCodec();
exec('ant.bat -f "'+ ROOT +'\\framework\\build.xml" jar');
}
@@ -254,6 +198,7 @@ exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\clean.bat" "' + PROJ
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\build.bat" "' + PROJECT_PATH + '\\cordova\\build.bat" /Y');
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\log.bat" "' + PROJECT_PATH + '\\cordova\\log.bat" /Y');
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\run.bat" "' + PROJECT_PATH + '\\cordova\\run.bat" /Y');
exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\version.bat" "' + PROJECT_PATH + '\\cordova\\version.bat" /Y');
// interpolate the activity name and package
Log("Updating AndroidManifest.xml and Main Activity...");
@@ -262,6 +207,4 @@ replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE);
replaceInFile(MANIFEST_PATH, /__ACTIVITY__/, ACTIVITY);
replaceInFile(MANIFEST_PATH, /__PACKAGE__/, PACKAGE);
replaceInFile(MANIFEST_PATH, /__APILEVEL__/, API_LEVEL);
cleanup();
replaceInFile(MANIFEST_PATH, /__APILEVEL__/, API_LEVEL);

View File

@@ -16,8 +16,24 @@
# specific language governing permissions and limitations
# under the License.
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/.." && pwd )
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_PATH"/lib/cordova build "$@"
if [[ "$#" -eq 1 ]] ; then
if [[ $1 == "--debug" ]] ; then
$DIR/clean
ant debug -f "$PROJECT_PATH"/build.xml
elif [[ $1 == "--release" ]] ; then
$DIR/clean
ant release -f "$PROJECT_PATH"/build.xml
elif [[ $1 == "--nobuild" ]] ; then
echo "Skipping build..."
else
echo "Error : Build command '$1' not recognized."
exit 2
fi
else
echo "Warning : [ --debug | --release | --nobuild ] not specified, defaulting to --debug"
$DIR/clean
ant debug -f "$PROJECT_PATH"/build.xml
fi

View File

@@ -1,2 +1,18 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
%~dp0\cordova.bat build %*
%~dp0\cordova.bat build %*

View File

@@ -16,8 +16,7 @@
# specific language governing permissions and limitations
# under the License.
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_PATH"/lib/cordova clean "$@"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/.." && pwd )
echo "Cleaning project..."
ant -f "$PROJECT_PATH/build.xml" clean

View File

@@ -1,2 +1,18 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
%~dp0\cordova.bat clean %*

View File

@@ -1,5 +1,3 @@
@ECHO OFF
GOTO BEGIN
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
@@ -16,7 +14,7 @@ GOTO BEGIN
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
:BEGIN
@ECHO OFF
IF NOT DEFINED JAVA_HOME GOTO MISSING
FOR %%X in (java.exe ant.bat android.bat) do (
SET FOUND=%%~$PATH:X

View File

@@ -1,386 +0,0 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd )
function list_devices {
IFS=$'\n'
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep -v 'emulator'`
device_list=($devices)
if [[ ${#device_list[@]} > 0 ]] ; then
for i in ${devices[@]}
do
# remove space and 'device'
echo ${i/[^a-zA-Z0-9._]device/}
done
else
echo "No devices found."
exit 2
fi
}
function list_started_emulators {
IFS=$'\n'
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep 'emulator'`
emulator_list=($devices)
if [[ ${#emulator_list[@]} > 0 ]] ; then
for i in ${emulator_list[@]}
do
# remove space and 'device'
echo ${i/[^a-zA-Z0-9._]device/}
done
else
echo "No started emulators found, you can start an emulator by using the command"
echo " 'cordova/lib/start-emulator'"
exit 2
fi
}
function list_emulator_images {
emulator_images=`android list avds | grep "Name:" | cut -f 2 -d ":"`
emulator_list=($emulator_images)
if [[ ${#emulator_list[@]} > 0 ]] ; then
for i in ${emulator_list[@]}
do
echo ${i/[^a-zA-Z0-9._]/}
done
else
echo "No emulators found, if you would like to create an emulator follow the instructions"
echo " provided here : http://developer.android.com/tools/devices/index.html"
echo " Or run 'android create avd --name <name> --target <targetID>' in on the command line."
exit 2
fi
}
function start_emulator {
emulator_images=`android list avds | grep "Name:" | cut -f 2 -d ":"`
# if target emulator is provided
if [[ "$#" -eq 1 ]] ; then
# check that it exists
if [[ $emulator_images =~ $1 ]] ; then
#xterm -e emulator -avd $1 &
emulator -avd $1 1> /dev/null 2>&1 &
else
echo "Could not find the provided emulator, make sure the emulator exists"
echo " by checking 'cordova/lib/list-emulator-images'"
exit 2
fi
else
# start first emulator
emulator_list=($emulator_images)
if [[ ${#emulator_list[@]} > 0 ]] ; then
#xterm -e emulator -avd ${emulator_list[0]} &
emulator -avd ${emulator_list[0]/[^a-zA-Z0-9._]/} 1> /dev/null 2>&1 &
else
echo "No emulators found, if you would like to create an emulator follow the instructions"
echo " provided here : http://developer.android.com/tools/devices/index.html"
echo " Or run 'android create avd --name <name> --target <targetID>' in on the command line."
exit 2
fi
fi
}
function install_device {
IFS=$'\n'
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep -v 'emulator'`
device_list=($devices)
if [[ ${#device_list[@]} > 0 ]] ; then
apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'`
apk_list=($apks)
if [[ ${#apk_list[@]} > 0 ]] ; then
local target
# handle target emulator
if [[ "$#" -eq 1 ]] ; then
# deploy to given target
target=${1/--target=/}
else
# delete trailing space and 'device' after device ID
target=${device_list[0]/[^a-zA-Z0-9._]device/}
fi
echo "Installing ${apk_list[0]} onto device $target..."
adb -s $target install -r ${apk_list[0]};
echo "Launching application..."
local launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml)
adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str
else
echo "Application package not found, could not install to device"
echo " make sure your application is built before deploying."
exit 2
fi
else
echo "No devices found to deploy to. Please make sure your device is connected"
echo " and you can view it using the 'cordova/lib/list-devices' command."
exit 2
fi
}
function install_emulator {
IFS=$'\n'
# check that there is an emulator to deploy to
emulator_string=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'emulator'`
emulator_list=($emulator_string)
if [[ ${#emulator_list[@]} > 0 ]] ; then
apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'`
apk_list=($apks)
if [[ ${#apk_list[@]} > 0 ]] ; then
local target
# handle target emulator
if [[ "$#" -eq 1 ]] ; then
# deploy to given target
target=${1/--target=/}
else
# delete trailing space and 'device' after emulator ID
target=${emulator_list[0]/[^a-zA-Z0-9._]device/}
fi
echo "Installing ${apk_list[0]} onto $target..."
adb -s $target install -r ${apk_list[0]};
echo "Launching application..."
local launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml)
adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str
else
echo "Application package not found, could not install to device"
echo " make sure your application is built before deploying."
exit 2
fi
else
echo "No emulators found to deploy to. Please make sure your emulator is started"
echo " and you can view it using the 'cordova/lib/list-started-emulators' command."
exit 2
fi
}
# cleans the project
function clean {
echo "Cleaning project..."
ant clean
}
# has to be used independently and not in conjunction with other commands
function log {
# filter out nativeGetEnabledTags spam from latest sdk bug.
adb logcat | grep -v nativeGetEnabledTags
}
function build {
if [[ "$#" -eq 1 ]] ; then
if [[ $1 == "--debug" ]] ; then
clean
ant debug -f "$PROJECT_PATH"/build.xml
elif [[ $1 == "--release" ]] ; then
clean
ant release -f "$PROJECT_PATH"/build.xml
elif [[ $1 == "--nobuild" ]] ; then
echo "Skipping build..."
else
echo "Error : Build command '$1' not recognized."
exit 2
fi
else
echo "Warning : [ --debug | --release | --nobuild ] not specified, defaulting to --debug"
clean
ant debug -f "$PROJECT_PATH"/build.xml
fi
}
function wait_for_emulator {
emulator_string=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep 'emulator'`
old_started=($emulator_string)
local new_started
local new_emulator_name
local i="0"
echo -n "Waiting for emulator..."
while [ $i -lt 300 ]
do
emulator_string=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep 'emulator'`
new_started=($emulator_string)
if [[ ${#new_started[@]} > ${#old_started[@]} && -z "$new_emulator_name" ]] ; then
# get the name of the started emulator
local count="0"
if [[ ${#old_started[@]} == 0 ]] ; then
new_emulator_name=${new_started[$count]/[^a-zA-Z0-9._]device/}
else
for count in {0...${#old_started[@]}}
do
if [[ ! ${new_started[$count]} == ${old_started[$count]} ]] ; then
new_emulator_name=${new_started[$count]/[^a-zA-Z0-9._]device/}
fi
done
if [[ -z "$new_emulator_name" ]] ; then
count=$[count+1]
new_emulator_name=${new_started[$count]/[^a-zA-Z0-9._]device/}
fi
fi
elif [[ "$new_emulator_name" ]] ; then
boot_anim=`adb -s $new_emulator_name shell getprop init.svc.bootanim`
if [[ $boot_anim =~ "stopped" ]] ; then
break
else
sleep 1
i=$[i+1]
echo -n "."
fi
else
sleep 1
i=$[i+1]
echo -n "."
fi
done
# Device timeout: emulator has not started in time
if [ $i -eq 300 ]
then
echo "emulator timeout!"
exit 69
else
echo "connected!"
fi
}
function run {
IFS=$'\n'
if [[ "$#" -eq 2 ]] ; then
build $2
if [[ $1 == "--device" ]] ; then
install_device
elif [[ $1 == "--emulator" ]] ; then
install_emulator
elif [[ $1 =~ "--target=" ]]; then
install_device $1
else
echo "Error : '$1' is not recognized as an install option"
fi
elif [[ "$#" -eq 1 ]] ; then
if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then
build $1
elif [[ $1 == "--device" ]] ; then
install_device
elif [[ $1 == "--emulator" ]] ; then
install_emulator
elif [[ $1 =~ "--target=" ]]; then
install_device $1
else
echo "Error : '$1' is not recognized as an install option"
fi
else
echo "Warning : [ --device | --emulate | --target=<targetID> ] not specified, using defaults."
build
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep -v 'emulator'`
device_list=($devices)
emulator_string=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep 'emulator'`
emulator_list=($emulator_string)
if [[ ${#device_list[@]} > 0 ]] ; then
install_device
elif [[ ${#emulator_list[@]} > 0 ]] ; then
install_emulator
else
emulator_images=`android list avds | grep "Name:" | cut -f 2 -d ":"`
echo $emulator_images
emulator_image_list=($emulator_images)
if [[ ${#emulator_image_list[@]} > 0 ]] ; then
echo "Starting emulator : ${emulator_image_list[0]}"
emulator -avd ${emulator_image_list[0]/[^.\w]/} 1> /dev/null 2>&1 &
wait_for_emulator
install_emulator
else
# TODO : look for emulator images and start one if it's availible
echo "Error : there are no availible devices or emulators to deploy to."
echo " create an emulator or connect your device to run this command."
echo "If you would like to create an emulator follow the instructions"
echo " provided here : http://developer.android.com/tools/devices/index.html"
echo " Or run 'android create avd --name <name> --target <targetID>' in on the command line."
exit 2
fi
fi
fi
}
# parse command line arguments
if [[ $# > 3 ]] ; then
echo "Error : too many arguments."
exit 2
elif [[ $# == 3 ]] ; then
if [[ $1 == "run" ]] ; then
run $2 $3
else
echo "Error : too many arguments for '$1'"
exit 2
fi
elif [[ $# == 2 ]] ; then
if [[ $1 == "run" ]] ; then
if [[ $2 == "--emulator" || $2 == "--device" || $2 =~ "--target=" ]] ; then
run $2 ''
elif [[ $2 == "--debug" || $2 == "--release" || $2 == "--nobuild" ]] ; then
run '' $2
else
echo "Error : '$2' is not recognized as a run option."
exit 2
fi
elif [[ $1 == "build" ]] ; then
build $2
elif [[ $1 == "start-emulator" ]] ; then
start_emulator $2
elif [[ $1 == "install-device" ]] ; then
if [[ $2 =~ "--target=" ]] ; then
install_device $2
else
echo "Error : '$2' is not recognized as an install option"
exit 2
fi
elif [[ $1 == "install-emulator" ]] ; then
if [[ $2 =~ "--target=" ]] ; then
install_emulator $2
else
echo "Error : '$2' is not recognized as an install option"
exit 2
fi
else
echo "Error : '$1' is not recognized as an option that takes arguments"
exit 2
fi
elif [[ $# == 1 ]] ; then
if [[ $1 == "run" ]] ; then
run
elif [[ $1 == "build" ]]; then
build
elif [[ $1 == "clean" ]]; then
clean
elif [[ $1 == "log" ]]; then
log
elif [[ $1 == "list-devices" ]]; then
list_devices
elif [[ $1 == "list-emulator-images" ]]; then
list_emulator_images
elif [[ $1 == "list-started-emulators" ]]; then
list_started_emulators
elif [[ $1 == "install-device" ]]; then
install_device
elif [[ $1 == "install-emulator" ]]; then
install_emulator
elif [[ $1 == "start-emulator" ]]; then
start_emulator
else
echo "Error : '$1' is not recognized as a tooling command."
exit 2
fi
else
echo "Error : No command recieved, exiting..."
exit 2
fi

View File

@@ -18,6 +18,21 @@
var ROOT = WScript.ScriptFullName.split('\\cordova\\lib\\cordova.js').join(''),
shell = WScript.CreateObject("WScript.Shell"),
fso = WScript.CreateObject('Scripting.FileSystemObject');
//device_id for targeting specific device
var device_id;
//build types
var NONE = 0,
DEBUG = '--debug',
RELEASE = '--release',
NO_BUILD = '--nobuild';
var build_type = NONE;
//deploy tpyes
var NONE = 0,
EMULATOR = 1,
DEVICE = 2,
TARGET = 3;
var deploy_type = NONE;
// log to stdout or stderr
@@ -86,6 +101,25 @@ function exec_verbose(command) {
}
}
function version(path) {
var cordovajs_path = path + "\\assets\\www\\cordova.js";
if(fso.FileExists(cordovajs_path)) {
var f = fso.OpenTextFile(cordovajs_path, 1,2);
var cordovajs = f.ReadAll();
f.Close();
var version_regex = /^.*CORDOVA_JS_BUILD_LABEL.*$/m;
var version_line = cordovajs.match(version_regex) + "";
var version = version_line.match(/(\d+)\.(\d+)\.(\d+)(rc\d)?/) + "";
// TODO : figure out why this isn't matching properly so we can remove this substring workaround.
Log(version.substr(0, ((version.length/2) -1)));
} else {
Log("Error : Could not find cordova js.", true);
Log("Expected Location : " + cordovajs_path, true);
WScript.Quit(2);
}
}
function get_devices() {
var device_list = []
var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll();
@@ -117,38 +151,18 @@ function list_devices() {
}
function get_emulator_images() {
// discription contains all data recieved squashed onto one line
var add_description = true;
var avd_list = [];
var local_emulators = shell.Exec("%comspec% /c android list avds").StdOut.ReadAll();
if (local_emulators.match(/Name\:/)) {
emulators = local_emulators.split('\n');
//format (ID DESCRIPTION)
var count = 0;
var output = '';
for (i in emulators) {
// Find the line with the emulator name.
if (emulators[i].match(/Name\:/)) {
// strip description
var emulator_name = emulators[i].replace(/\s*Name\:\s/, '') + ' ';
if (add_description) {
count = 1;
output += emulator_name
}
else {
avd_list.push(emulator_name);
}
}
// add description if indicated (all data squeezed onto one line)
if (count > 0) {
var emulator_description = emulators[i].replace(/\s*/g, '');
if (count > 4) {
avd_list.push(output + emulator_description);
count = 0;
output = '';
}
else {
count++;
output += emulator_description + ' '
}
avd_list.push(emulator_name);
}
}
}
@@ -192,8 +206,21 @@ function list_started_emulators() {
}
}
else {
Log('No started emulators found, if you would like to start an emulator call \'list-emulator-images\'');
Log(' to get the name of an emulator and then start the emulator with \'start-emulator <Name>\'');
Log('No started emulators found, if you would like to start an emulator call ');
Log('\'list-emulator-images\'');
Log(' to get the name of an emulator and then start the emulator with');
Log('\'start-emulator <Name>\'');
}
}
function create_emulator() {
//get targets
var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
if(targets) {
exec('%comspec% /c android create avd --name cordova_emulator --target ' + targets[targets.length - 1].replace(/id: /, ""));
} else {
Log("You do not have any android targets setup. Please create at least one target with the `android` command so that an emulator can be created.", true);
WScript.Quit(69);
}
}
@@ -207,14 +234,14 @@ function start_emulator(name) {
for (i in emulators) {
if (emulators[i].substr(0,name.length) == name) {
Log("Starting emulator : " + name);
shell.Run("%comspec% /c start cmd /c emulator -avd " + name);
shell.Exec("%comspec% /c emulator -avd " + name + " &");
//shell.Run("%comspec% /c start cmd /c emulator -cpu-delay 0 -no-boot-anim -cache %Temp%\cache -avd " + name);
started = true;
}
}
}
else {
if (emulators.length > 0 && started_emulators < 1) {
if (emulators.length > 0 && started_emulators.length == 0) {
emulator_name = emulators[0].split(' ', 1)[0];
start_emulator(emulator_name);
return;
@@ -230,15 +257,16 @@ function start_emulator(name) {
Log("Error : unable to start emulator, ensure you have emulators availible by checking \'list-emulator-images\'", true);
WScript.Quit(2);
}
else { // wait for emulator to boot before returning
WScript.Stdout.Write('Booting up emulator..');
else {
// wait for emulator to get the ID
Log('Waiting for emulator...');
var boot_anim = null;
var emulator_ID = null;
var new_started = get_started_emulators();
var new_started = null;
var i = 0;
// use boot animation property to tell when boot is complete.
while ((boot_anim == null || !boot_anim.output.match(/stopped/)) && i < 100) {
if (new_started.length > started_emulators.length && emulator_ID == null) {
while(emulator_ID == null && i < 10) {
new_started = get_started_emulators();
if(new_started.length > started_emulators.length) {
// find new emulator that was just started to get it's ID
for(var i = 0; i < new_started.length; i++) {
if (new_started[i] != started_emulators[i]) {
@@ -248,18 +276,25 @@ function start_emulator(name) {
}
}
}
else if (boot_anim == null) {
new_started = get_started_emulators();
}
else {
boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
}
}
if (i == 10) {
Log('\nEmulator start timed out.');
WScript.Quit(2);
}
i = 0;
WScript.Stdout.Write('Booting up emulator (this may take a while).');
// use boot animation property to tell when boot is complete.
while (!boot_anim.output.match(/stopped/) && i < 100) {
boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
i++;
WScript.Stdout.Write('.');
WScript.Sleep(2000);
}
if (i < 100) {
Log('\nBoot Complete!');
// Unlock the device
shell.Exec("%comspec% /c adb -s " + emulator_ID + " shell input keyevent 82");
} else {
Log('\nEmulator boot timed out. Failed to load emulator');
WScript.Quit(2);
@@ -267,34 +302,11 @@ function start_emulator(name) {
}
}
function install_device(target) {
var devices = get_devices();
var use_target = false;
if (devices.length < 1) {
Log("Error : No devices found to install to, make sure there are devices", true);
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-devices\'", true);
WScript.Quit(2);
}
if (target) {
var exists = false;
for (i in devices) {
if (devices[i].substr(0,target.length) == target)
{
exists = true;
break;
}
}
if (!exists) {
Log("Error : Unable to find target " + target, true);
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-devices'");
WScript.Quit(2);
}
use_target = true;
}
function get_apk(path) {
// check if file .apk has been created
if (fso.FolderExists(ROOT + '\\bin')) {
if (fso.FolderExists(path + '\\bin')) {
var path_to_apk;
var out_folder = fso.GetFolder(ROOT + '\\bin');
var out_folder = fso.GetFolder(path + '\\bin');
var out_files = new Enumerator(out_folder.Files);
for (;!out_files.atEnd(); out_files.moveNext()) {
var path = out_files.item() + '';
@@ -304,38 +316,7 @@ function install_device(target) {
}
}
if (path_to_apk) {
var launch_name = exec_out("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml");
if (launch_name.error) {
Log("Failed to get application name from appinfo.jar + AndroidManifest : ", true);
Log("Output : " + launch_name.output, true);
WScript.Quit(2);
}
// install on device (-d)
Log("Installing app on device...");
var cmd;
if (use_target) {
cmd = '%comspec% /c adb -s ' + target + ' install -r ' + path_to_apk;
} else {
cmd = '%comspec% /c adb -s ' + devices[0].split(' ', 1)[0] + ' install -r ' + path_to_apk;
}
var install = exec_out(cmd);
if ( install.error && install.output.match(/Failure/)) {
Log("Error : Could not install apk to device : ", true);
Log(install.output, true);
WScript.Quit(2);
}
else {
Log(install.output);
}
// run on device
Log("Launching application...");
cmd;
if (use_target) {
cmd = '%comspec% /c adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
} else {
cmd = '%comspec% /c adb -s ' + devices[0].split(' ', 1)[0] + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
}
exec_verbose(cmd);
return path_to_apk;
}
else {
Log('Failed to find apk, make sure you project is built and there is an ', true);
@@ -345,7 +326,18 @@ function install_device(target) {
}
}
function install_emulator(target) {
function install_device(path) {
var devices = get_devices();
var use_target = false;
if (devices.length < 1) {
Log("Error : No devices found to install to, make sure there are devices", true);
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-devices\'", true);
WScript.Quit(2);
}
launch(path, devices[0].split(' ', 1)[0], true);
}
function install_emulator(path) {
var emulators = get_started_emulators();
var use_target = false;
if (emulators.length < 1) {
@@ -353,46 +345,59 @@ function install_emulator(target) {
Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-started-emulators\'", true);
WScript.Quit(2);
}
if (target) {
launch(path, emulators[0].split(' ', 1)[0], false);
}
function install_target(path) {
if(device_id) {
var device = false;
var emulators = get_started_emulators();
var devices = get_devices();
var exists = false;
for (i in emulators) {
if (emulators[i].substr(0,target.length) == target)
{
if (emulators[i].substr(0,device_id.length) == device_id) {
exists = true;
break;
}
}
if (!exists) {
Log("Error : Unable to find target " + target, true);
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-started-emulators'")
}
use_target = true;
} else {
target = emulators[0].split(' ', 1)[0];
Log("Deploying to emulator : " + target);
}
// check if file .apk has been created
if (fso.FolderExists(ROOT + '\\bin')) {
var path_to_apk;
var out_folder = fso.GetFolder(ROOT + '\\bin');
var out_files = new Enumerator(out_folder.Files);
for (;!out_files.atEnd(); out_files.moveNext()) {
var path = out_files.item() + '';
if (fso.GetExtensionName(path) == 'apk' && !path.match(/unaligned/)) {
path_to_apk = out_files.item();
for (i in devices) {
if (devices[i].substr(0,device_id.length) == device_id) {
exists = true;
device = true
break;
}
}
if (!exists) {
Log("Error : Unable to find target " + device_id, true);
Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-started-emulators'");
Log(" Or \'<project>\\cordova\\lib\\list-devices'");
}
launch(path, device_id, device);
}
else {
Log("You cannot install to a target without providing a valid target ID.", true);
WScript.Quit(2);
}
}
function launch(path, id, device) {
if(id) {
var path_to_apk = get_apk(path);
if (path_to_apk) {
var launch_name = exec_out("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml");
var launch_name = exec_out("%comspec% /c java -jar "+path+"\\cordova\\appinfo.jar "+path+"\\AndroidManifest.xml");
if (launch_name.error) {
Log("Failed to get application name from appinfo.jar + AndroidManifest : ", true);
Log("Output : " + launch_name.output, true);
WScript.Quit(2);
}
// install on emulator (-e)
Log("Installing app on emulator...");
var cmd = '%comspec% /c adb -s ' + target + ' install -r ' + path_to_apk;
if (device) {
// install on device (-d)
Log("Installing app on device...");
} else {
// install on emulator (-e)
Log("Installing app on emulator...");
}
var cmd = '%comspec% /c adb -s ' + id + ' install -r ' + path_to_apk;
var install = exec_out(cmd);
if ( install.error && install.output.match(/Failure/)) {
Log("Error : Could not install apk to emulator : ", true);
@@ -402,14 +407,9 @@ function install_emulator(target) {
else {
Log(install.output);
}
// run on emulator
// launch the application
Log("Launching application...");
cmd;
if (use_target) {
cmd = '%comspec% /c adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
} else {
cmd = '%comspec% /c adb -s ' + emulators[0].split(' ', 1)[0] + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output
}
cmd = '%comspec% /c adb -s ' + id + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
exec_verbose(cmd);
}
else {
@@ -419,43 +419,14 @@ function install_emulator(target) {
}
}
else {
Log('Failed to find apk, make sure you project is built and there is an ', true);
Log(' apk in <project>\\bin\\. To build your project use \'<project>\\cordova\\build\'', true);
Log("You cannot install to a target without providing a valid target ID.", true);
WScript.Quit(2);
}
}
function clean() {
function clean(path) {
Log("Cleaning project...");
exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1");
}
function build(build_type) {
if (build_type) {
switch (build_type) {
case "--debug" :
clean();
Log("Building project...");
exec_verbose("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
break;
case "--release" :
clean();
Log("Building project...");
exec_verbose("%comspec% /c ant.bat release -f "+ROOT+"\\build.xml 2>&1");
break;
case "--nobuild" :
Log("Skipping build process.");
break;
default :
Log("Build option not recognized: " + build_type, true);
WScript.Quit(2);
break;
}
}
else {
Log("WARNING: [ --debug | --release | --nobuild ] not specified, defaulting to --debug.");
exec_verbose("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
}
exec("%comspec% /c ant.bat clean -f "+path+"\\build.xml 2>&1");
}
function log() {
@@ -463,131 +434,176 @@ function log() {
shell.Run("%comspec% /c adb logcat | grep -v nativeGetEnabledTags");
}
function run(target, build_type) {
var use_target = false;
if (!target) {
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, using defaults");
}
// build application
build(build_type);
// attempt to deploy to connected device
var devices = get_devices();
if (devices.length > 0 || target == "--device") {
if (target) {
if (target.substr(0,9) == "--target=") {
install_device(target.split('--target=').join(''))
} else if (target == "--device") {
install_device();
} else {
Log("Did not regognize " + target + " as a run option.", true);
WScript.Quit(2);
}
}
else {
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, using defaults");
install_device();
}
}
else {
var emulators = get_started_emulators();
if (emulators.length > 0) {
install_emulator();
}
else {
var emulator_images = get_emulator_images();
if (emulator_images.length < 1) {
Log('No emulators found, if you would like to create an emulator follow the instructions', true);
Log(' provided here : http://developer.android.com/tools/devices/index.html', true);
Log(' Or run \'android create avd --name <name> --target <targetID>\' in on the command line.', true);
WScript.Quit(2);
}
start_emulator(emulator_images[0].split(' ')[0]);
emulators = get_started_emulators();
if (emulators.length > 0) {
install_emulator();
}
else {
Log("Error : emulator failed to start.", true);
WScript.Quit(2);
}
}
function build(path) {
switch (build_type) {
case DEBUG :
clean(path);
Log("Building project...");
exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
break;
case RELEASE :
clean(path);
Log("Building project...");
exec_verbose("%comspec% /c ant.bat release -f "+path+"\\build.xml 2>&1");
break;
case NO_BUILD :
Log("Skipping build process.");
break;
case NONE :
clean(path);
Log("WARNING: [ --debug | --release | --nobuild ] not specified, defaulting to --debug.");
exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
break;
default :
Log("Build option not recognized: " + build_type, true);
WScript.Quit(2);
break;
}
}
function run(path) {
switch(deploy_type) {
case EMULATOR :
build(path);
if(get_started_emulators().length == 0) {
start_emulator();
}
//TODO : Start emulator if one isn't started, and create one if none exists.
install_emulator(path);
break;
case DEVICE :
build(path);
install_device(path);
break;
case TARGET :
build(path);
install_target(path);
break;
case NONE :
if (get_devices().length > 0) {
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --device");
deploy_type = DEVICE;
} else {
Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --emulator");
deploy_type = EMULATOR;
}
run(path);
break;
default :
Log("Deploy option not recognized: " + deploy_type, true);
WScript.Quit(2);
break;
}
}
var args = WScript.Arguments;
if (args.count() == 0) {
Log("Error: no args provided.");
WScript.Quit(2);
}
else {
if (args(0) == "build") {
if (args.Count() > 1) {
build(args(1))
} else {
build();
}
} else if (args(0) == "clean") {
clean();
} else if (args(0) == "list-devices") {
list_devices();
} else if (args(0) == "list-emulator-images") {
list_emulator_images();
} else if (args(0) == "list-started-emulators") {
list_started_emulators();
} else if (args(0) == "start-emulator") {
if (args.Count() > 1) {
start_emulator(args(1))
} else {
start_emulator();
}
} else if (args(0) == "log") {
log();
} else if (args(0) == "install-emulator") {
if (args.Count() == 2) {
if (args(1).substr(0,9) == "--target=") {
install_emulator(args(1).split('--target=').join(''));
} else {
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
WScript.Quit(2);
// parse command
switch(args(0)) {
case "version" :
version(ROOT);
break;
case "build" :
if(args.Count() > 1) {
if (args(1) == "--release") {
build_type = RELEASE;
}
else if (args(1) == "--debug") {
build_type = DEBUG;
}
else if (args(1) == "--nobuild") {
build_type = NO_BUILD;
}
else {
Log('Error: \"' + args(i) + '\" is not recognized as a build option', true);
WScript.Quit(2);
}
}
} else {
install_emulator();
}
} else if (args(0) == "install-device") {
if (args.Count() == 2) {
if (args(1).substr(0,9) == "--target=") {
install_device(args(1).split('--target=').join(''));
build(ROOT);
break;
case "clean" :
clean();
break;
case "list-devices" :
list_devices();
break;
case "list-emulator-images" :
list_emulator_images();
break;
case "list-started-emulators" :
list_started_emulators();
break;
case "start-emulator" :
if (args.Count() > 1) {
start_emulator(args(1))
} else {
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
WScript.Quit(2);
start_emulator();
}
} else {
install_device();
}
} else if (args(0) == "run") {
if (args.Count() == 3) {
run(args(1), args(2));
}
else if (args.Count() == 2) {
if (args(1).substr(0,9) == "--target=" ||
args(1) == "--emulator" ||
args(1) == "--device") {
run(args(1));
} else if (args(1) == "--debug" ||
args(1) == "--release" ||
args(1) == "--nobuild") {
run(null, args(1))
break;
case "install-emulator" :
if (args.Count() == 2) {
if (args(1).substr(0,9) == "--target=") {
device_id = args(1).split('--target=').join('');
install_emulator(ROOT);
} else {
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
WScript.Quit(2);
}
} else {
Log('Error: \"' + args(1) + '\" is not recognized as a run option', true);
WScript.Quit(2);
install_emulator(ROOT);
}
}
else {
run();
}
} else {
Log('Error: \"' + args(0) + '\" is not recognized as a tooling command', true);
WScript.Quit(2);
break;
case "install-device" :
if (args.Count() == 2) {
if (args(1).substr(0,9) == "--target=") {
device_id = args(1).split('--target=').join('');
install_target(ROOT);
} else {
Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
WScript.Quit(2);
}
} else {
install_device(ROOT);
}
break;
case "run" :
//parse args
for(var i = 1; i < args.Count(); i++) {
if (args(i) == "--release") {
build_type = RELEASE;
}
else if (args(i) == "--debug") {
build_type = DEBUG;
}
else if (args(i) == "--nobuild") {
build_type = NO_BUILD;
}
else if (args(i) == "--emulator" || args(i) == "-e") {
deploy_type = EMULATOR;
}
else if (args(i) == "--device" || args(i) == "-d") {
deploy_type = DEVICE;
}
else if (args(i).substr(0,9) == "--target=") {
device_id = args(i).split("--target=").join("");
deploy_type = TARGET;
}
else {
Log('Error: \"' + args(i) + '\" is not recognized as a run option', true);
WScript.Quit(2);
}
}
run(ROOT);
break;
default :
Log("Cordova does not regognize the command " + args(0), true);
WScript.Quit(2);
break;
}
}

View File

@@ -16,8 +16,34 @@
# specific language governing permissions and limitations
# under the License.
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/../.." && pwd )
device_list=$("$DIR/list-devices")
if [ $? != 0 ]; then
echo "No devices found to deploy to. Please make sure your device is connected"
echo " and you can view it using the 'cordova/lib/list-devices' command."
exit 2
fi
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_LIB_PATH"/cordova install-device "$@"
apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'`
apk_list=($apks)
if [[ ${#apk_list[@]} > 0 ]] ; then
# handle target
read -ra device_array <<< "$device_list"
if [[ "$#" -eq 1 ]] ; then
# deploy to given target
target=${1/--target=/}
else
# delete trailing space and 'device' after device ID
target=${device_array[0]}
fi
echo "Installing ${apk_list[0]} onto device $target..."
adb -s $target install -r ${apk_list[0]};
echo "Launching application..."
launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml)
adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str
else
echo "Application package not found, could not install to device"
echo " make sure your application is built before deploying."
exit 2
fi

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,35 @@
# specific language governing permissions and limitations
# under the License.
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/../.." && pwd )
emulator_list=$("$DIR/list-started-emulators")
if [ $? != 0 ]; then
echo "No emulators found to deploy to. Please make sure your emulator is started"
echo " You can view it using the 'cordova/lib/list-started-emulators' command."
echo " You can view created emulator images using the 'cordova/lib/list-emulator-images' command."
echo " You can start an emulator image using the 'cordova/lib/start-emulator' command."
exit 2
fi
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_LIB_PATH"/cordova install-emulator "$@"
apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'`
apk_list=($apks)
if [[ ${#apk_list[@]} > 0 ]] ; then
# handle target emulator
if [[ "$#" -eq 1 ]] ; then
# deploy to given target
target=${1/--target=/}
else
# delete trailing space and 'device' after emulator ID
target=${emulator_list[0]}
fi
echo "Installing ${apk_list[0]} onto emulator $target..."
adb -s $target install -r ${apk_list[0]};
echo "Launching application..."
launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml)
adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str
else
echo "Application package not found, could not install to device"
echo " make sure your application is built before deploying."
exit 2
fi

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,15 @@
# specific language governing permissions and limitations
# under the License.
set -e
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_LIB_PATH"/cordova list-devices
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep -v 'emulator' | awk '{ print $1; }'`
device_list=($devices)
if [[ ${#device_list[@]} > 0 ]] ; then
for i in ${devices[@]}
do
echo $i
done
exit 0
else
echo "No devices found."
exit 2
fi

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,17 @@
# specific language governing permissions and limitations
# under the License.
set -e
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_LIB_PATH"/cordova list-emulator-images
emulator_images=`android list avds | grep "Name:" | cut -f 2 -d ":"`
emulator_list=($emulator_images)
if [[ ${#emulator_list[@]} > 0 ]] ; then
for i in ${emulator_list[@]}
do
echo $i
done
exit 0
else
echo "No emulators found, if you would like to create an emulator follow the instructions"
echo " provided here : http://developer.android.com/tools/devices/index.html"
echo " Or run 'android create avd --name <name> --target <targetID>' in on the command line."
exit 2
fi

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,17 @@
# specific language governing permissions and limitations
# under the License.
set -e
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
bash "$CORDOVA_LIB_PATH"/cordova list-started-emulators
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print $1;}}' | grep 'emulator' | grep -v 'offline'`
read -ra emulator_list <<< "$devices"
if [[ ${#emulator_list[@]} > 0 ]] ; then
for i in ${emulator_list[@]}
do
# remove space and 'device'
echo $i
done
exit 0
else
echo "No started emulators found (it may still be booting up), you can start an emulator by using the command"
echo " 'cordova/lib/start-emulator'"
exit 2
fi

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,76 @@
# specific language governing permissions and limitations
# under the License.
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd )
CORDOVA_LIB_PATH=$( cd "$( dirname "$0" )" && pwd )
function dot {
sleep 1
echo -n "."
}
bash "$CORDOVA_LIB_PATH"/cordova start-emulator "$@"
function wait_for_emulator {
local i="0"
echo -n "Waiting for emulator"
emulator_string=$($DIR/list-started-emulators)
while [ $? != 0 ]
do
dot
i=$[i+1]
emulator_string=$($DIR/list-started-emulators)
done
read -ra target <<< "$emulator_string"
echo ""
echo -n "Waiting for it to boot up (this can take a while)"
while [ $i -lt 300 ]
do
boot_anim=$(adb -s $target shell getprop init.svc.bootanim 2>&1)
if [[ "$boot_anim" =~ "stopped" ]] ; then
break
else
i=$[i+1]
dot
fi
done
# Device timeout: emulator has not started in time
if [ $i -eq 300 ]
then
echo ""
echo "Emulator timeout!"
exit 69
else
echo ""
echo "Connected!"
fi
# Unlock the device
adb -s $target shell input keyevent 82
exit 0
}
emulator_images=$("$DIR/list-emulator-images")
if [ $? != 0 ]; then
echo "No emulators found, if you would like to create an emulator follow the instructions"
echo " provided here : http://developer.android.com/tools/devices/index.html"
echo " Or run 'android create avd --name <name> --target <targetID>' in on the command line."
exit 2
fi
# if target emulator is provided
if [[ "$#" -eq 1 ]] ; then
# check that it exists
if [[ $emulator_images =~ $1 ]] ; then
#xterm -e emulator -avd $1 &
emulator -avd $1 1> /dev/null 2>&1 &
else
echo "Could not find the provided emulator '$1', make sure the emulator exists"
echo " by checking 'cordova/lib/list-emulator-images'"
exit 2
fi
else
# start first emulator
read -ra emulator_list <<< "$emulator_images"
#xterm -e emulator -avd ${emulator_list[0]} &
emulator -avd ${emulator_list[0]} 1> /dev/null 2>&1 &
fi
wait_for_emulator

View File

@@ -1,3 +1,19 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
SET full_path=%~dp0
IF EXIST %full_path%cordova.js (
@@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
ECHO.
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
EXIT /B 1
)
)

View File

@@ -16,8 +16,5 @@
# specific language governing permissions and limitations
# under the License.
set -e
CORDOVA_PATH=$( cd "$( dirname "$0" )/.." && pwd )
bash "$CORDOVA_PATH"/cordova/lib/cordova log "$@"
# filter out nativeGetEnabledTags spam from latest sdk bug.
adb logcat | grep -v nativeGetEnabledTags

View File

@@ -1,2 +1,18 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
%~dp0\cordova.bat log %*

View File

@@ -16,8 +16,66 @@
# specific language governing permissions and limitations
# under the License.
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/.." && pwd )
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd )
function run_on_device_or_emulator {
devices=`$DIR/lib/list-devices`
if [ $? = 0 ]; then
$DIR/lib/install-device
else
run_on_emulator
fi
}
bash "$CORDOVA_PATH"/lib/cordova run "$@"
function run_on_emulator {
emulators=`$DIR/lib/list-started-emulators`
if [ $? = 0 ] ; then
$DIR/lib/install-emulator
else
images=`$DIR/lib/list-emulator-images`
if [ $? = 0 ] ; then
$DIR/lib/start-emulator
$DIR/lib/install-emulator
else
echo "No devices/emulators started nor images available to start. How are we supposed to do this, then?"
exit 2
fi
fi
}
if [[ "$#" -eq 2 ]] ; then
# TODO: the order of arguments here may be reversed from the assumption below
$DIR/build $2
if [[ $1 == "--device" ]] ; then
$DIR/lib/install-device
elif [[ $1 == "--emulator" ]] ; then
run_on_emulator
elif [[ $1 =~ "--target=" ]]; then
$DIR/lib/install-device $1
else
echo "Error : '$1' is not recognized as an install option"
fi
elif [[ "$#" -eq 1 ]] ; then
if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then
$DIR/build $1
run_on_device_or_emulator
elif [[ $1 == "--device" ]] ; then
$DIR/build
$DIR/lib/install-device
elif [[ $1 == "--emulator" ]] ; then
#$DIR/build
run_on_emulator
elif [[ $1 =~ "--target=" ]]; then
$DIR/build
$DIR/lib/install-device $1
else
echo "Error : '$1' is not recognized as an install option"
fi
else
echo "Warning : [ --device | --emulate | --target=<targetID> ] not specified, using defaults."
$DIR/build
run_on_device_or_emulator
fi

View File

@@ -1,2 +1,18 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
%~dp0\cordova.bat run %*
%~dp0\cordova.bat run %*

View File

@@ -24,7 +24,7 @@ PROJECT_PATH="$(dirname "$CORDOVA_PATH")"
VERSION_FILE_PATH="$PROJECT_PATH/assets/www/cordova.js"
if [ -f "$VERSION_FILE_PATH" ]; then
JSVersion=$(sed -n '2,2p' assets/www/cordova.js)
JSVersion=$(sed -n '2,2p' $VERSION_FILE_PATH)
echo $JSVersion | sed -e 's/\/\/ //'| cut -f 1 -d '-'
else
echo "The file \"$VERSION_FILE_PATH\" does not exist."

View File

@@ -0,0 +1,18 @@
:: Licensed to the Apache Software Foundation (ASF) under one
:: or more contributor license agreements. See the NOTICE file
:: distributed with this work for additional information
:: regarding copyright ownership. The ASF licenses this file
:: to you under the Apache License, Version 2.0 (the
:: "License"); you may not use this file except in compliance
:: with the License. You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing,
:: software distributed under the License is distributed on an
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
:: KIND, either express or implied. See the License for the
:: specific language governing permissions and limitations
:: under the License.
@ECHO OFF
%~dp0\cordova.bat version %*

View File

@@ -64,8 +64,6 @@ function createAppInfoJar {
function on_error {
echo "An unexpected error occurred: $previous_command exited with $?"
echo "Deleting project..."
[ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH"
exit 1
}

View File

@@ -96,46 +96,6 @@ function cleanup() {
}
}
function downloadCommonsCodec() {
if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) {
// We need the .jar
var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip';
var libsPath = ROOT + '\\framework\\libs';
var savePath = libsPath + '\\commons-codec-1.7-bin.zip';
if (!fso.FileExists(savePath)) {
if(!fso.FolderExists(ROOT + '\\framework\\libs')) {
fso.CreateFolder(libsPath);
}
// We need the zip to get the jar
var xhr = WScript.CreateObject('MSXML2.XMLHTTP');
xhr.open('GET', url, false);
xhr.send();
if (xhr.status == 200) {
var stream = WScript.CreateObject('ADODB.Stream');
stream.Open();
stream.Type = 1;
stream.Write(xhr.ResponseBody);
stream.Position = 0;
stream.SaveToFile(savePath);
stream.Close();
} else {
WScript.Echo('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.');
}
}
var app = WScript.CreateObject('Shell.Application');
var source = app.NameSpace(savePath).Items();
var target = app.NameSpace(ROOT + '\\framework\\libs');
target.CopyHere(source, 256);
// Move the jar into libs
fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar');
// Clean up
fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip');
fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true);
}
}
var args = WScript.Arguments, PROJECT_PATH="example",
shell=WScript.CreateObject("WScript.Shell");
@@ -161,8 +121,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
WScript.Echo("Building jar and js files...");
// update the cordova framework project to a target that exists on this machine
exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
// pull down commons codec if necessary
downloadCommonsCodec();
exec('ant.bat -f \"'+ ROOT +'\\framework\\build.xml\" jar');
}

View File

@@ -3,7 +3,6 @@
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="libs/commons-codec-1.7.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@@ -1,9 +1,5 @@
// Platform: android
// commit d0ffb852378ff018bac2f3b12c38098a19b8ce00
// File generated at :: Thu Apr 18 2013 15:10:54 GMT-0400 (EDT)
// 2.9.0rc1-0-g002f33d
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -22,26 +18,36 @@
specific language governing permissions and limitations
under the License.
*/
;(function() {
var CORDOVA_JS_BUILD_LABEL = '2.9.0rc1-0-g002f33d';
// file: lib/scripts/require.js
var require,
define;
(function () {
var modules = {};
var modules = {},
// Stack of moduleIds currently being built.
var requireStack = [];
requireStack = [],
// Map of module ID -> index into requireStack of modules currently being built.
var inProgressModules = {};
inProgressModules = {},
SEPERATOR = ".";
function build(module) {
var factory = module.factory;
var factory = module.factory,
localRequire = function (id) {
var resultantId = id;
//Its a relative path, so lop off the last portion and add the id (minus "./")
if (id.charAt(0) === ".") {
resultantId = module.id.slice(0, module.id.lastIndexOf(SEPERATOR)) + SEPERATOR + id.slice(2);
}
return require(resultantId);
};
module.exports = {};
delete module.factory;
factory(require, module.exports, module);
factory(localRequire, module.exports, module);
return module.exports;
}
@@ -1314,8 +1320,6 @@ var CaptureAudioOptions = function(){
this.limit = 1;
// Maximum duration of a single sound clip in seconds.
this.duration = 0;
// The selected audio mode. Must match with one of the elements in supportedAudioModes array.
this.mode = null;
};
module.exports = CaptureAudioOptions;
@@ -1356,8 +1360,6 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module)
var CaptureImageOptions = function(){
// Upper limit of images user can take. Value must be equal or greater than 1.
this.limit = 1;
// The selected image mode. Must match with one of the elements in supportedImageModes array.
this.mode = null;
};
module.exports = CaptureImageOptions;
@@ -1375,8 +1377,6 @@ var CaptureVideoOptions = function(){
this.limit = 1;
// Maximum duration of a single video clip in seconds.
this.duration = 0;
// The selected video mode. Must match with one of the elements in supportedVideoModes array.
this.mode = null;
};
module.exports = CaptureVideoOptions;
@@ -2396,11 +2396,7 @@ function initRead(reader, file) {
reader._error = null;
reader._readyState = FileReader.LOADING;
if (typeof file == 'string') {
// Deprecated in Cordova 2.4.
console.warn('Using a string argument with FileReader.readAs functions is deprecated.');
reader._fileName = file;
} else if (typeof file.fullPath == 'string') {
if (typeof file.fullPath == 'string') {
reader._fileName = file.fullPath;
} else {
reader._fileName = '';
@@ -3063,9 +3059,31 @@ FileWriter.prototype.abort = function() {
/**
* Writes data to the file
*
* @param text to be written
* @param data text or blob to be written
*/
FileWriter.prototype.write = function(text) {
FileWriter.prototype.write = function(data) {
var isBinary = false;
// If we don't have Blob or ArrayBuffer support, don't bother.
if (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined') {
// Check to see if the incoming data is a blob
if (data instanceof Blob) {
var that=this;
var fileReader = new FileReader();
fileReader.onload = function() {
// Call this method again, with the arraybuffer as argument
FileWriter.prototype.write.call(that, this.result);
};
fileReader.readAsArrayBuffer(data);
return;
}
// Mark data type for safer transport over the binary bridge
isBinary = (data instanceof ArrayBuffer);
}
// Throw an exception if we are already writing a file
if (this.readyState === FileWriter.WRITING) {
throw new FileError(FileError.INVALID_STATE_ERR);
@@ -3131,7 +3149,7 @@ FileWriter.prototype.write = function(text) {
if (typeof me.onwriteend === "function") {
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
}
}, "File", "write", [this.fileName, text, this.position]);
}, "File", "write", [this.fileName, data, this.position, isBinary]);
};
/**
@@ -3317,6 +3335,9 @@ InAppBrowser.prototype = {
close: function (eventname) {
exec(null, null, "InAppBrowser", "close", []);
},
show: function (eventname) {
exec(null, null, "InAppBrowser", "show", []);
},
addEventListener: function (eventname,f) {
if (eventname in this.channels) {
this.channels[eventname].subscribe(f);
@@ -4071,6 +4092,10 @@ module.exports = {
// file: lib/android/plugin/android/nativeapiprovider.js
define("cordova/plugin/android/nativeapiprovider", function(require, exports, module) {
/**
* Exports the ExposedJsApi.java object if available, otherwise exports the PromptBasedNativeApi.
*/
var nativeApi = this._cordovaNative || require('cordova/plugin/android/promptbasednativeapi');
var currentApi = nativeApi;
@@ -4149,6 +4174,11 @@ module.exports = {
// file: lib/android/plugin/android/promptbasednativeapi.js
define("cordova/plugin/android/promptbasednativeapi", function(require, exports, module) {
/**
* Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
* This is used only on the 2.3 simulator, where addJavascriptInterface() is broken.
*/
module.exports = {
exec: function(service, action, callbackId, argsJson) {
return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
@@ -5072,7 +5102,6 @@ function Device() {
this.available = false;
this.platform = null;
this.version = null;
this.name = null;
this.uuid = null;
this.cordova = null;
this.model = null;
@@ -5081,12 +5110,15 @@ function Device() {
channel.onCordovaReady.subscribe(function() {
me.getInfo(function(info) {
var buildLabel = info.cordova;
if (buildLabel != CORDOVA_JS_BUILD_LABEL) {
buildLabel += ' JS=' + CORDOVA_JS_BUILD_LABEL;
}
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.name = info.name;
me.uuid = info.uuid;
me.cordova = info.cordova;
me.cordova = buildLabel;
me.model = info.model;
channel.onCordovaInfoReady.fire();
},function(e) {
@@ -5843,10 +5875,13 @@ var exec = require('cordova/exec');
var utils = require('cordova/utils');
var UseConsole = true;
var UseLogger = true;
var Queued = [];
var DeviceReady = false;
var CurrentLevel;
var originalConsole = console;
/**
* Logging levels
*/
@@ -5907,8 +5942,7 @@ logger.level = function (value) {
* Getter/Setter for the useConsole functionality
*
* When useConsole is true, the logger will log via the
* browser 'console' object. Otherwise, it will use the
* native Logger plugin.
* browser 'console' object.
*/
logger.useConsole = function (value) {
if (arguments.length) UseConsole = !!value;
@@ -5932,6 +5966,18 @@ logger.useConsole = function (value) {
return UseConsole;
};
/**
* Getter/Setter for the useLogger functionality
*
* When useLogger is true, the logger will log via the
* native Logger plugin.
*/
logger.useLogger = function (value) {
// Enforce boolean
if (arguments.length) UseLogger = !!value;
return UseLogger;
};
/**
* Logs a message at the LOG level.
*
@@ -6001,24 +6047,26 @@ logger.logLevel = function(level /* , ... */) {
return;
}
// if not using the console, use the native logger
if (!UseConsole) {
// Log using the native logger if that is enabled
if (UseLogger) {
exec(null, null, "Logger", "logLevel", [level, message]);
return;
}
// make sure console is not using logger
if (console.__usingCordovaLogger) {
throw new Error("console and logger are too intertwingly");
}
// Log using the console if that is enabled
if (UseConsole) {
// make sure console is not using logger
if (console.__usingCordovaLogger) {
throw new Error("console and logger are too intertwingly");
}
// log to the console
switch (level) {
case logger.LOG: console.log(message); break;
case logger.ERROR: console.log("ERROR: " + message); break;
case logger.WARN: console.log("WARN: " + message); break;
case logger.INFO: console.log("INFO: " + message); break;
case logger.DEBUG: console.log("DEBUG: " + message); break;
// log to the console
switch (level) {
case logger.LOG: originalConsole.log(message); break;
case logger.ERROR: originalConsole.log("ERROR: " + message); break;
case logger.WARN: originalConsole.log("WARN: " + message); break;
case logger.INFO: originalConsole.log("INFO: " + message); break;
case logger.DEBUG: originalConsole.log("DEBUG: " + message); break;
}
}
};
@@ -6279,7 +6327,7 @@ module.exports = {
// Some platforms take an array of button label names.
// Other platforms take a comma separated list.
// For compatibility, we convert to the desired type based on the platform.
if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone") {
if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone" || platform.id == "blackberry10") {
if (typeof _buttonLabels === 'string') {
var buttonLabelString = _buttonLabels;
_buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here
@@ -6303,12 +6351,14 @@ module.exports = {
* @param {Function} resultCallback The callback that is called when user clicks on a button.
* @param {String} title Title of the dialog (default: "Prompt")
* @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
* @param {String} defaultText Textbox input value (default: "Default text")
*/
prompt: function(message, resultCallback, title, buttonLabels) {
prompt: function(message, resultCallback, title, buttonLabels, defaultText) {
var _message = (message || "Prompt message");
var _title = (title || "Prompt");
var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]);
var _defaultText = (defaultText || "Default text");
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]);
},
/**
@@ -6650,12 +6700,15 @@ function UUIDcreatePart(length) {
});
window.cordova = require('cordova');
// file: lib/scripts/bootstrap.js
(function (context) {
if (context._cordovaJsLoaded) {
throw new Error('cordova.js included multiple times.');
}
context._cordovaJsLoaded = true;
var channel = require('cordova/channel');
var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
@@ -6748,11 +6801,21 @@ require('cordova/channel').onNativeReady.fire();
}
}
function scriptErrorCallback(err) {
// Open Question: If a script path specified in cordova_plugins.js does not exist, do we fail for all?
// this is currently just continuing.
scriptCounter--;
if (scriptCounter === 0) {
onScriptLoadingComplete && onScriptLoadingComplete();
}
}
// Helper function to inject a <script> tag.
function injectScript(path) {
scriptCounter++;
var script = document.createElement("script");
script.onload = scriptLoadedCallback;
script.onerror = scriptErrorCallback;
script.src = path;
document.head.appendChild(script);
}
@@ -6764,37 +6827,42 @@ require('cordova/channel').onNativeReady.fire();
context.cordova.require('cordova/channel').onPluginsReady.fire();
}
// Handler for the cordova_plugins.json content.
// Handler for the cordova_plugins.js content.
// See plugman's plugin_loader.js for the details of this object.
// This function is only called if the really is a plugins array that isn't empty.
// Otherwise the XHR response handler will just call finishPluginLoading().
function handlePluginsObject(modules) {
// Otherwise the onerror response handler will just call finishPluginLoading().
function handlePluginsObject(modules, path) {
// First create the callback for when all plugins are loaded.
var mapper = context.cordova.require('cordova/modulemapper');
onScriptLoadingComplete = function() {
// Loop through all the plugins and then through their clobbers and merges.
for (var i = 0; i < modules.length; i++) {
var module = modules[i];
if (!module) continue;
if (module) {
try {
if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) {
mapper.clobbers(module.id, module.clobbers[j]);
}
}
if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) {
mapper.clobbers(module.id, module.clobbers[j]);
if (module.merges && module.merges.length) {
for (var k = 0; k < module.merges.length; k++) {
mapper.merges(module.id, module.merges[k]);
}
}
// Finally, if runs is truthy we want to simply require() the module.
// This can be skipped if it had any merges or clobbers, though,
// since the mapper will already have required the module.
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
context.cordova.require(module.id);
}
}
}
if (module.merges && module.merges.length) {
for (var k = 0; k < module.merges.length; k++) {
mapper.merges(module.id, module.merges[k]);
catch(err) {
// error with module, most likely clobbers, should we continue?
}
}
// Finally, if runs is truthy we want to simply require() the module.
// This can be skipped if it had any merges or clobbers, though,
// since the mapper will already have required the module.
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
context.cordova.require(module.id);
}
}
finishPluginLoading();
@@ -6802,35 +6870,78 @@ require('cordova/channel').onNativeReady.fire();
// Now inject the scripts.
for (var i = 0; i < modules.length; i++) {
injectScript(modules[i].file);
injectScript(path + modules[i].file);
}
}
// Find the root of the app
var path = '';
var scripts = document.getElementsByTagName('script');
var term = 'cordova.js';
for (var n = scripts.length-1; n>-1; n--) {
var src = scripts[n].src;
if (src.indexOf(term) == (src.length - term.length)) {
path = src.substring(0, src.length - term.length);
break;
}
}
var plugins_json = path + 'cordova_plugins.json';
var plugins_js = path + 'cordova_plugins.js';
// One some phones (Windows) this xhr.open throws an Access Denied exception
// So lets keep trying, but with a script tag injection technique instead of XHR
var injectPluginScript = function injectPluginScript() {
try {
var script = document.createElement("script");
script.onload = function(){
var list = cordova.require("cordova/plugin_list");
handlePluginsObject(list,path);
};
script.onerror = function() {
// Error loading cordova_plugins.js, file not found or something
// this is an acceptable error, pre-3.0.0, so we just move on.
finishPluginLoading();
};
script.src = plugins_js;
document.head.appendChild(script);
} catch(err){
finishPluginLoading();
}
}
// Try to XHR the cordova_plugins.json file asynchronously.
try { // we commented we were going to try, so let us actually try and catch
var xhr = new context.XMLHttpRequest();
xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
var obj = JSON.parse(this.responseText);
if (obj && obj instanceof Array && obj.length > 0) {
handlePluginsObject(obj);
} else {
finishPluginLoading();
}
};
xhr.onerror = function() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
var obj;
try {
obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
} catch (err) {
// obj will be undefined.
}
if (Array.isArray(obj) && obj.length > 0) {
handlePluginsObject(obj, path);
} else {
finishPluginLoading();
};
xhr.open('GET', 'cordova_plugins.json', true); // Async
}
};
xhr.onerror = function() {
// In this case, the json file was not present, but XHR was allowed,
// so we should still try the script injection technique with the js file
// in case that is there.
injectPluginScript();
};
try { // we commented we were going to try, so let us actually try and catch
xhr.open('GET', plugins_json, true); // Async
xhr.send();
}
catch(err){
finishPluginLoading();
} catch(err){
injectPluginScript();
}
}(window));
})();

View File

@@ -31,22 +31,6 @@
<fail message="The required minimum version of ant is 1.8.0, you have ${ant.version}"
unless="thisantversion" />
<!-- check that commons codec is available. You should copy the codec jar to
framework/libs, as it is not included in the Cordova distribution.
The name of the jar file in framework/libs does not matter. -->
<available classname="org.apache.commons.codec.binary.Base64"
property="exists.base64"
ignoresystemclasses="true">
<classpath>
<pathelement path="${classpath}" />
<fileset dir="libs">
<include name="*.jar" />
</fileset>
</classpath>
</available>
<fail message="You need to put a copy of Apache Commons Codec jar in the framework/libs directory"
unless="exists.base64" />
<!-- The local.properties file is created and updated by the 'android'
tool. (For example "sdkdir/tools/android update project -p ." inside
of this directory where the AndroidManifest.xml file exists. This

View File

@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<widget xmlns = "http://www.w3.org/ns/widgets"
id = "io.cordova.helloCordova"

View File

@@ -30,7 +30,7 @@ import org.json.JSONObject;
import java.util.HashMap;
/**
* This class exposes methods in DroidGap that can be called from JavaScript.
* This class exposes methods in Cordova that can be called from JavaScript.
*/
public class App extends CordovaPlugin {
@@ -104,7 +104,7 @@ public class App extends CordovaPlugin {
* Load the url into the webview.
*
* @param url
* @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
* @param props Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
* @throws JSONException
*/
public void loadUrl(String url, JSONObject props) throws JSONException {
@@ -198,7 +198,7 @@ public class App extends CordovaPlugin {
* @param override T=override, F=cancel override
*/
public void overrideButton(String button, boolean override) {
LOG.i("DroidGap", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!");
LOG.i("App", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!");
webView.bindButton(button, override);
}

View File

@@ -20,7 +20,7 @@ package org.apache.cordova;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.DataResource;
import android.content.Context;
import android.media.AudioManager;
@@ -56,14 +56,6 @@ public class AudioHandler extends CordovaPlugin {
this.pausedForPhone = new ArrayList<AudioPlayer>();
}
public String getFilePath(String url, String source){
DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source);
if(dataResource.getUri().getScheme().equals("http") || dataResource.getUri().getScheme().equals("https"))
return dataResource.getUri().toString();
else
return dataResource.getRealFile().getPath();
}
/**
* Executes the request and returns PluginResult.
* @param action The action to execute.
@@ -76,13 +68,13 @@ public class AudioHandler extends CordovaPlugin {
String result = "";
if (action.equals("startRecordingAudio")) {
this.startRecordingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startRecordingAudio"));
this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
}
else if (action.equals("stopRecordingAudio")) {
this.stopRecordingAudio(args.getString(0));
}
else if (action.equals("startPlayingAudio")) {
this.startPlayingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startPlayingAudio"));
this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
}
else if (action.equals("seekToAudio")) {
this.seekToAudio(args.getString(0), args.getInt(1));
@@ -110,7 +102,7 @@ public class AudioHandler extends CordovaPlugin {
}
else if (action.equals("create")) {
String id = args.getString(0);
String src = getFilePath(args.getString(1), "AudioHandler.create");
String src = FileHelper.stripFileProtocol(args.getString(1));
AudioPlayer audio = new AudioPlayer(this, id, src);
this.players.put(id, audio);
}

View File

@@ -20,16 +20,14 @@ package org.apache.cordova;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.codec.binary.Base64;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.DataResource;
import org.apache.cordova.api.LOG;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
@@ -43,11 +41,13 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Rect;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
/**
@@ -290,7 +290,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// If sending base64 image back
if (destType == DATA_URL) {
bitmap = getScaledBitmap(imageUri.toString());
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
if (bitmap == null) {
// Try to get the bitmap from intent.
bitmap = (Bitmap)intent.getExtras().get("data");
@@ -316,9 +316,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
if (this.saveToPhotoAlbum) {
Uri inputUri = getUriFromMediaStore();
//Just because we have a media URI doesn't mean we have a real file, we need to make it
DataResource dataResource = DataResource.initiateNewDataRequestForUri(inputUri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
File file = dataResource.getRealFile();
uri = Uri.fromFile(file);
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
} else {
uri = Uri.fromFile(new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg"));
}
@@ -334,15 +332,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.callbackContext.success(uri.toString());
} else {
bitmap = getScaledBitmap(imageUri.toString());
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
if (rotate != 0 && this.correctOrientation) {
bitmap = getRotatedBitmap(rotate, bitmap, exif);
}
// Add compressed version of captured image to returned media store Uri
DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
OutputStream os = dataResource.getOutputStream();
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
os.close();
@@ -350,7 +347,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
if (this.encodingType == JPEG) {
String exifPath;
if (this.saveToPhotoAlbum) {
exifPath = dataResource.getRealFile().getPath();
exifPath = FileHelper.getRealPath(uri, this.cordova);
} else {
exifPath = uri.getPath();
}
@@ -401,9 +398,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.callbackContext.success(uri.toString());
} else {
String uriString = uri.toString();
DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
// Get the path to the image. Makes loading so much easier.
String mimeType = dataResource.getMimeType();
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
// If we don't have a valid image so quit.
if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
Log.d(LOG_TAG, "I either have a null image path or bitmap");
@@ -444,8 +440,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Create an ExifHelper to save the exif data that is lost during compression
String resizePath = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
// Some content: URIs do not map to file paths (e.g. picasa).
File realFile = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent").getRealFile();
String realPath = realFile != null? realFile.getPath() : null;
String realPath = FileHelper.getRealPath(uri, this.cordova);
ExifHelper exif = new ExifHelper();
if (realPath != null && this.encodingType == JPEG) {
try {
@@ -539,15 +534,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
*/
private void writeUncompressedImage(Uri uri) throws FileNotFoundException,
IOException {
DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
InputStream fis = inputDataResource.getInputStream();
DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
OutputStream os = outDataResource.getOutputStream();
if(fis == null) {
throw new FileNotFoundException("Could not get the input file");
} else if(os == null) {
throw new FileNotFoundException("Could not get the output file");
}
FileInputStream fis = new FileInputStream(FileHelper.stripFileProtocol(imageUri.toString()));
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
byte[] buffer = new byte[4096];
int len;
while ((len = fis.read(buffer)) != -1) {
@@ -590,15 +578,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
*/
private Bitmap getScaledBitmap(String imageUrl) throws IOException {
// If no new width or height were specified return the original bitmap
DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap");
if (this.targetWidth <= 0 && this.targetHeight <= 0) {
return BitmapFactory.decodeStream(dataResource.getInputStream());
return BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova));
}
// figure out the original width and height of the image
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
//CB-2292: WTF? Why is the width null?
if(options.outWidth == 0 || options.outHeight == 0)
@@ -612,7 +599,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Load in the smallest bitmap possible that is closest to the size we want
options.inJustDecodeBounds = false;
options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight);
Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
Bitmap unscaledBitmap = BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
if (unscaledBitmap == null) {
return null;
}
@@ -711,20 +698,16 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
bitmap.recycle();
}
DataResource dataResource = DataResource.initiateNewDataRequestForUri(oldImage, webView.pluginManager, cordova, "CameraLauncher.cleanup");
File file = dataResource.getRealFile();
if(file != null) {
// Clean up initial camera-written image file.
file.delete();
// Clean up initial camera-written image file.
(new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete();
checkForDuplicateImage(imageType);
// Scan for the gallery to update pic refs in gallery
if (this.saveToPhotoAlbum && newImage != null) {
this.scanForGallery(newImage);
}
System.gc();
checkForDuplicateImage(imageType);
// Scan for the gallery to update pic refs in gallery
if (this.saveToPhotoAlbum && newImage != null) {
this.scanForGallery(newImage);
}
System.gc();
}
/**
@@ -778,7 +761,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
try {
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encodeBase64(code);
byte[] output = Base64.encode(code, Base64.DEFAULT);
String js_out = new String(output);
this.callbackContext.success(js_out);
js_out = null;

View File

@@ -26,7 +26,6 @@ import java.io.OutputStream;
import android.os.Build;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.DataResource;
import org.apache.cordova.api.LOG;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
@@ -130,8 +129,7 @@ public class Capture extends CordovaPlugin {
// If the mimeType isn't set the rest will fail
// so let's see if we can determine it.
if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.dataResource");
mimeType = dataResource.getMimeType();
mimeType = FileHelper.getMimeType(filePath, cordova);
}
Log.d(LOG_TAG, "Mime type = " + mimeType);
@@ -158,8 +156,7 @@ public class Capture extends CordovaPlugin {
private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.getImageData");
BitmapFactory.decodeFile(dataResource.getRealFile().getPath(), options);
BitmapFactory.decodeFile(FileHelper.stripFileProtocol(filePath), options);
obj.put("height", options.outHeight);
obj.put("width", options.outWidth);
return obj;
@@ -351,8 +348,7 @@ public class Capture extends CordovaPlugin {
* @throws IOException
*/
private JSONObject createMediaFile(Uri data) {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(data, webView.pluginManager, cordova, "Capture.createMediaFile");
File fp = dataResource.getRealFile();
File fp = new File(FileHelper.getRealPath(data, this.cordova));
JSONObject obj = new JSONObject();
try {
@@ -362,7 +358,6 @@ public class Capture extends CordovaPlugin {
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
// is stored in the audio or video content store.
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
if (data.toString().contains("/audio/")) {
obj.put("type", AUDIO_3GPP);
@@ -370,7 +365,7 @@ public class Capture extends CordovaPlugin {
obj.put("type", VIDEO_3GPP);
}
} else {
obj.put("type", dataResource.getMimeType());
obj.put("type", FileHelper.getMimeType(fp.getAbsolutePath(), cordova));
}
obj.put("lastModifiedDate", fp.lastModified());

View File

@@ -64,11 +64,10 @@ import android.widget.LinearLayout;
* As an example:
*
* package org.apache.cordova.examples;
* import android.app.Activity;
* import android.os.Bundle;
* import org.apache.cordova.*;
*
* public class Examples extends DroidGap {
* public class Example extends CordovaActivity {
* @Override
* public void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState);
@@ -77,9 +76,6 @@ import android.widget.LinearLayout;
* super.setStringProperty("loadingDialog", "Title,Message"); // show loading dialog
* super.setStringProperty("errorUrl", "file:///android_asset/www/error.html"); // if error loading file in super.loadUrl().
*
* // Initialize activity
* super.init();
*
* // Clear cache if you want
* super.appView.clearCache(true);
*
@@ -121,7 +117,7 @@ import android.widget.LinearLayout;
* Cordova.xml configuration:
* Cordova uses a configuration file at res/xml/cordova.xml to specify the following settings.
*
* Approved list of URLs that can be loaded into DroidGap
* Approved list of URLs that can be loaded into Cordova
* <access origin="http://server regexp" subdomains="true" />
* Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR)
* <log level="DEBUG" />
@@ -138,7 +134,7 @@ import android.widget.LinearLayout;
* </plugins>
*/
public class CordovaActivity extends Activity implements CordovaInterface {
public static String TAG = "DroidGap";
public static String TAG = "CordovaActivity";
// The webview for our app
protected CordovaWebView appView;
@@ -263,7 +259,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
@Override
public void onCreate(Bundle savedInstanceState) {
Config.init(this);
LOG.d(TAG, "DroidGap.onCreate()");
LOG.d(TAG, "CordovaActivity.onCreate()");
super.onCreate(savedInstanceState);
if(savedInstanceState != null)
@@ -336,7 +332,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
*/
@SuppressLint("NewApi")
public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) {
LOG.d(TAG, "DroidGap.init()");
LOG.d(TAG, "CordovaActivity.init()");
// Set up web container
this.appView = webView;
@@ -599,7 +595,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* @param value
*/
public void setBooleanProperty(String name, boolean value) {
Log.d(TAG, "Setting boolean properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml");
Log.d(TAG, "Setting boolean properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
this.getIntent().putExtra(name, value);
}
@@ -610,7 +606,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* @param value
*/
public void setIntegerProperty(String name, int value) {
Log.d(TAG, "Setting integer properties in DroidGap will be deprecated in 3.1 on August 2013, please use config.xml");
Log.d(TAG, "Setting integer properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
this.getIntent().putExtra(name, value);
}
@@ -621,7 +617,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* @param value
*/
public void setStringProperty(String name, String value) {
Log.d(TAG, "Setting string properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml");
Log.d(TAG, "Setting string properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
this.getIntent().putExtra(name, value);
}
@@ -632,7 +628,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* @param value
*/
public void setDoubleProperty(String name, double value) {
Log.d(TAG, "Setting double properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml");
Log.d(TAG, "Setting double properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
this.getIntent().putExtra(name, value);
}
@@ -716,7 +712,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* The final call you receive before your activity is destroyed.
*/
public void onDestroy() {
LOG.d(TAG, "onDestroy()");
LOG.d(TAG, "CordovaActivity.onDestroy()");
super.onDestroy();
// hide the splash screen to avoid leaking a window
@@ -856,18 +852,13 @@ public class CordovaActivity extends Activity implements CordovaInterface {
mUploadMessage = null;
}
CordovaPlugin callback = this.activityResultCallback;
if(callback == null)
{
if(initCallbackClass != null)
{
this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
callback = activityResultCallback;
LOG.d(TAG, "We have a callback to send this result to");
callback.onActivityResult(requestCode, resultCode, intent);
}
if(callback == null && initCallbackClass != null) {
// The application was restarted, but had defined an initial callback
// before being shut down.
this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
callback = this.activityResultCallback;
}
else
{
if(callback != null) {
LOG.d(TAG, "We have a callback to send this result to");
callback.onActivityResult(requestCode, resultCode, intent);
}
@@ -961,7 +952,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
}
/*
* Hook in DroidGap for menu plugins
* Hook in Cordova for menu plugins
*
*/
@Override
@@ -1000,7 +991,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
* @param url The url to load.
* @param openExternal Load url in browser instead of Cordova webview.
* @param clearHistory Clear the history stack, so new page becomes top of history
* @param params DroidGap parameters for new app
* @param params Parameters for new app
*/
public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) {
if (this.appView != null) {

View File

@@ -222,6 +222,7 @@ public class CordovaChromeClient extends WebChromeClient {
result.confirm(r == null ? "" : r);
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}
@@ -286,7 +287,7 @@ public class CordovaChromeClient extends WebChromeClient {
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
{
LOG.d(TAG, "DroidGap: onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
LOG.d(TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
if (estimatedSize < MAX_QUOTA)
{

View File

@@ -485,7 +485,7 @@ public class CordovaWebView extends WebView {
// If first page, then show splashscreen
else {
LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time);
LOG.d(TAG, "loadUrlIntoView(%s, %d)", url, time);
// Send message to show splashscreen now if desired
this.postMessage("splashscreen", "show");
@@ -555,7 +555,7 @@ public class CordovaWebView extends WebView {
* @param url The url to load.
* @param openExternal Load url in browser instead of Cordova webview.
* @param clearHistory Clear the history stack, so new page becomes top of history
* @param params DroidGap parameters for new app
* @param params Parameters for new app
*/
public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) {
LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);
@@ -601,7 +601,7 @@ public class CordovaWebView extends WebView {
/**
* Check configuration parameters from Config.
* Approved list of URLs that can be loaded into DroidGap
* Approved list of URLs that can be loaded into Cordova
* <access origin="http://server regexp" subdomains="true" />
* Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR)
* <log level="DEBUG" />
@@ -806,7 +806,7 @@ public class CordovaWebView extends WebView {
{
// Send destroy event to JavaScript
// Since baseUrl is set in loadUrlIntoView, if user hit Back button before loadUrl was called, we'll get an NPE on baseUrl (CB-2458)
this.loadUrlIntoView("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
// Load blank page so that JavaScript onunload is called
this.loadUrl("about:blank");

View File

@@ -188,6 +188,17 @@ public class CordovaWebViewClient extends WebViewClient {
LOG.e(TAG, "Error sending sms " + url + ":" + e.toString());
}
}
//Android Market
else if(url.startsWith("market:")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading Google Play Store: " + url, e);
}
}
// All else
else {
@@ -211,35 +222,7 @@ public class CordovaWebViewClient extends WebViewClient {
}
return true;
}
/**
* Check for intercepting any requests for resources.
* This includes images and scripts and so on, not just top-level pages.
* @param view The WebView.
* @param url The URL to be loaded.
* @return Either null to proceed as normal, or a WebResourceResponse.
*/
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
//If something isn't whitelisted, just send a blank response
if(!Config.isUrlWhiteListed(url) && (url.startsWith("http://") || url.startsWith("https://")))
{
return getWhitelistResponse();
}
if (this.appView.pluginManager != null) {
return this.appView.pluginManager.shouldInterceptRequest(url);
}
return null;
}
private WebResourceResponse getWhitelistResponse()
{
WebResourceResponse emptyResponse;
String empty = "";
ByteArrayInputStream data = new ByteArrayInputStream(empty.getBytes());
return new WebResourceResponse("text/plain", "UTF-8", data);
}
/**
* On received http auth request.
* The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination

View File

@@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
public class Device extends CordovaPlugin {
public static final String TAG = "Device";
public static String cordovaVersion = "dev"; // Cordova version
public static String cordovaVersion = "2.9.0rc1"; // Cordova version
public static String platform = "Android"; // Device OS
public static String uuid; // Device UUID
@@ -101,7 +101,7 @@ public class Device extends CordovaPlugin {
/**
* Listen for telephony events: RINGING, OFFHOOK and IDLE
* Send these events to all plugins using
* DroidGap.onMessage("telephone", "ringing" | "offhook" | "idle")
* CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
*/
private void initTelephonyReceiver() {
IntentFilter intentFilter = new IntentFilter();

View File

@@ -26,11 +26,10 @@ import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.LOG;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLConnection;
import java.util.Locale;
public class FileHelper {
private static final String LOG_TAG = "FileUtils";
@@ -91,63 +90,24 @@ public class FileHelper {
* @throws IOException
*/
public static InputStream getInputStreamFromUriString(String uriString, CordovaInterface cordova) throws IOException {
if (uriString.startsWith("content:")) {
if (uriString.startsWith("content")) {
Uri uri = Uri.parse(uriString);
return cordova.getActivity().getContentResolver().openInputStream(uri);
} else if (uriString.startsWith("file:///android_asset/")) {
Uri uri = Uri.parse(uriString);
String relativePath = uri.getPath().substring(15);
return cordova.getActivity().getAssets().open(relativePath);
} else if (uriString.startsWith("file://")) {
return new FileInputStream(getRealPath(uriString, cordova));
} else {
return null;
}
}
public static OutputStream getOutputStreamFromUriString(String uriString, CordovaInterface cordova) throws FileNotFoundException{
if (uriString.startsWith("content:")) {
Uri uri = Uri.parse(uriString);
return cordova.getActivity().getContentResolver().openOutputStream(uri);
} else if (uriString.startsWith("file:") && !uriString.startsWith("file:///android_asset/")) {
String realPath = uriString.substring(7);
return new FileOutputStream(realPath);
} else {
return null;
}
}
/**
* Returns whether the uri can be written to by openeing a File to that uri
*
* @param the URI to test
* @return boolean indicating whether the uri is writable
*/
public static boolean isUriWritable(String uriString) {
String scheme = uriString.split(":")[0];
if(scheme.equals("file")){
// special case file
return !uriString.startsWith("file:///android_asset/");
}
return "content".equals(scheme);
}
/**
* Ensures the "file://" prefix exists for the given string
* If the given URI string already has a scheme, it is returned unchanged
*
* @param path - the path string to operate on
* @return a String with the "file://" scheme set
*/
public static String insertFileProtocol(String path) {
if(!path.matches("^[a-z0-9+.-]+:.*")){
//Ensure it is not a relative path
if(!path.startsWith("/")){
throw new IllegalArgumentException("Relative paths" + path + "are not allowed.");
int question = uriString.indexOf("?");
if (question > -1) {
uriString = uriString.substring(0,question);
}
path = "file://" + path;
if (uriString.startsWith("file:///android_asset/")) {
Uri uri = Uri.parse(uriString);
String relativePath = uri.getPath().substring(15);
return cordova.getActivity().getAssets().open(relativePath);
} else {
return new FileInputStream(getRealPath(uriString, cordova));
}
} else {
return new FileInputStream(getRealPath(uriString, cordova));
}
return path;
}
/**

View File

@@ -855,20 +855,15 @@ public class FileTransfer extends CordovaPlugin {
* @throws FileNotFoundException
*/
private InputStream getPathFromUri(String path) throws FileNotFoundException {
if (path.startsWith("content:")) {
Uri uri = Uri.parse(path);
return cordova.getActivity().getContentResolver().openInputStream(uri);
}
else if (path.startsWith("file://")) {
int question = path.indexOf("?");
if (question == -1) {
return new FileInputStream(path.substring(7));
try {
InputStream stream = FileHelper.getInputStreamFromUriString(path, cordova);
if (stream == null) {
return new FileInputStream(path);
} else {
return new FileInputStream(path.substring(7, question));
return stream;
}
}
else {
return new FileInputStream(path);
} catch (IOException e) {
throw new FileNotFoundException();
}
}

View File

@@ -18,14 +18,15 @@
*/
package org.apache.cordova;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import org.apache.commons.codec.binary.Base64;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.DataResource;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.file.EncodingException;
import org.apache.cordova.file.FileExistsException;
@@ -45,6 +46,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.channels.FileChannel;
/**
@@ -131,7 +134,7 @@ public class FileUtils extends CordovaPlugin {
this.readFileAs(args.getString(0), start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_BINARYSTRING);
}
else if (action.equals("write")) {
long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2));
long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2), args.getBoolean(3));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileSize));
}
else if (action.equals("truncate")) {
@@ -231,7 +234,7 @@ public class FileUtils extends CordovaPlugin {
* @param filePath the path to check
*/
private void notifyDelete(String filePath) {
String newFilePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.notifyDelete").getRealFile().getPath();
String newFilePath = FileHelper.getRealPath(filePath, cordova);
try {
this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
MediaStore.Images.Media.DATA + " = ?",
@@ -253,10 +256,37 @@ public class FileUtils extends CordovaPlugin {
* @throws IOException if the user can't read the file
* @throws JSONException
*/
@SuppressWarnings("deprecation")
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
File fp = DataResource.initiateNewDataRequestForUri(url, webView.pluginManager, cordova, "FileUtils.resolveLocalFileSystemURI").getRealFile();
String decoded = URLDecoder.decode(url, "UTF-8");
if (fp == null || !fp.exists()) {
File fp = null;
// Handle the special case where you get an Android content:// uri.
if (decoded.startsWith("content:")) {
Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
// Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
fp = new File(cursor.getString(column_index));
} else {
// Test to see if this is a valid URL first
@SuppressWarnings("unused")
URL testUrl = new URL(decoded);
if (decoded.startsWith("file://")) {
int questionMark = decoded.indexOf("?");
if (questionMark < 0) {
fp = new File(decoded.substring(7, decoded.length()));
} else {
fp = new File(decoded.substring(7, questionMark));
}
} else {
fp = new File(decoded);
}
}
if (!fp.exists()) {
throw new FileNotFoundException();
}
if (!fp.canRead()) {
@@ -274,9 +304,9 @@ public class FileUtils extends CordovaPlugin {
* @throws JSONException
*/
private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException {
File fp = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
File fp = createFileObject(fileName);
if (fp == null || !fp.exists()) {
if (!fp.exists()) {
// The directory we are listing doesn't exist so we should fail.
throw new FileNotFoundException();
}
@@ -311,10 +341,8 @@ public class FileUtils extends CordovaPlugin {
* @throws FileExistsException
*/
private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
DataResource dataResourceFrom = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.transferTo");
String newFileName = dataResourceFrom.getRealFile().getPath();
DataResource dataResourceTo = DataResource.initiateNewDataRequestForUri(newParent, webView.pluginManager, cordova, "FileUtils.transferTo");
newParent = dataResourceTo.getRealFile().getPath();
String newFileName = FileHelper.getRealPath(fileName, cordova);
newParent = FileHelper.getRealPath(newParent, cordova);
// Check for invalid file name
if (newName != null && newName.contains(":")) {
@@ -585,7 +613,7 @@ public class FileUtils extends CordovaPlugin {
* @throws FileExistsException
*/
private boolean removeRecursively(String filePath) throws FileExistsException {
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
File fp = createFileObject(filePath);
// You can't delete the root directory.
if (atRootDirectory(filePath)) {
@@ -626,7 +654,7 @@ public class FileUtils extends CordovaPlugin {
* @throws InvalidModificationException
*/
private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException {
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
File fp = createFileObject(filePath);
// You can't delete the root directory.
if (atRootDirectory(filePath)) {
@@ -670,8 +698,7 @@ public class FileUtils extends CordovaPlugin {
throw new EncodingException("This file has a : in it's name");
}
String filePath = getFullFilePath(dirPath, fileName);
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getFile").getRealFile();
File fp = createFileObject(dirPath, fileName);
if (create) {
if (exclusive && fp.exists()) {
@@ -713,14 +740,15 @@ public class FileUtils extends CordovaPlugin {
* @param fileName new file name
* @return
*/
private String getFullFilePath(String dirPath, String fileName) {
private File createFileObject(String dirPath, String fileName) {
File fp = null;
if (fileName.startsWith("/")) {
return fileName;
fp = new File(fileName);
} else {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(dirPath, webView.pluginManager, cordova, "FileUtils.getFullFilePath");
dirPath = dataResource.getRealFile().getPath();
return dirPath + File.separator + fileName;
dirPath = FileHelper.getRealPath(dirPath, cordova);
fp = new File(dirPath + File.separator + fileName);
}
return fp;
}
/**
@@ -732,13 +760,12 @@ public class FileUtils extends CordovaPlugin {
* @throws JSONException
*/
private JSONObject getParent(String filePath) throws JSONException {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getParent");
filePath = dataResource.getRealFile().getPath();
filePath = FileHelper.getRealPath(filePath, cordova);
if (atRootDirectory(filePath)) {
return getEntry(filePath);
}
return getEntry(dataResource.getRealFile().getParent());
return getEntry(new File(filePath).getParent());
}
/**
@@ -749,7 +776,7 @@ public class FileUtils extends CordovaPlugin {
* @return true if we are at the root, false otherwise.
*/
private boolean atRootDirectory(String filePath) {
filePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.atRootDirectory").getRealFile().getPath();
filePath = FileHelper.getRealPath(filePath, cordova);
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
@@ -759,6 +786,19 @@ public class FileUtils extends CordovaPlugin {
return false;
}
/**
* Create a File object from the passed in path
*
* @param filePath
* @return
*/
private File createFileObject(String filePath) {
filePath = FileHelper.getRealPath(filePath, cordova);
File file = new File(filePath);
return file;
}
/**
* Look up metadata about this entry.
*
@@ -767,9 +807,9 @@ public class FileUtils extends CordovaPlugin {
* @throws FileNotFoundException
*/
private long getMetadata(String filePath) throws FileNotFoundException {
File file = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata").getRealFile();
File file = createFileObject(filePath);
if (file == null || !file.exists()) {
if (!file.exists()) {
throw new FileNotFoundException("Failed to find file in getMetadata");
}
@@ -785,16 +825,15 @@ public class FileUtils extends CordovaPlugin {
* @throws JSONException
*/
private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata");
File file = dataResource.getRealFile();
File file = createFileObject(filePath);
if (file == null || !file.exists()) {
if (!file.exists()) {
throw new FileNotFoundException("File: " + filePath + " does not exist.");
}
JSONObject metadata = new JSONObject();
metadata.put("size", file.length());
metadata.put("type", dataResource.getMimeType());
metadata.put("type", FileHelper.getMimeType(filePath, cordova));
metadata.put("name", file.getName());
metadata.put("fullPath", filePath);
metadata.put("lastModifiedDate", file.lastModified());
@@ -896,8 +935,7 @@ public class FileUtils extends CordovaPlugin {
this.cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs");
byte[] bytes = readAsBinaryHelper(dataResource.getInputStream(), start, end);
byte[] bytes = readAsBinaryHelper(filename, start, end);
PluginResult result;
switch (resultType) {
@@ -911,8 +949,8 @@ public class FileUtils extends CordovaPlugin {
result = new PluginResult(PluginResult.Status.OK, bytes, true);
break;
default: // Base64.
String contentType = dataResource.getMimeType();
byte[] base64 = Base64.encodeBase64(bytes);
String contentType = FileHelper.getMimeType(filename, cordova);
byte[] base64 = Base64.encode(bytes, Base64.DEFAULT);
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
result = new PluginResult(PluginResult.Status.OK, s);
}
@@ -938,9 +976,10 @@ public class FileUtils extends CordovaPlugin {
* @return Contents of the file as a byte[].
* @throws IOException
*/
private byte[] readAsBinaryHelper(InputStream inputStream, int start, int end) throws IOException {
private byte[] readAsBinaryHelper(String filename, int start, int end) throws IOException {
int numBytesToRead = end - start;
byte[] bytes = new byte[numBytesToRead];
InputStream inputStream = FileHelper.getInputStreamFromUriString(filename, cordova);
int numBytesRead = 0;
if (start > 0) {
@@ -960,17 +999,17 @@ public class FileUtils extends CordovaPlugin {
* @param filename The name of the file.
* @param data The contents of the file.
* @param offset The position to begin writing the file.
* @param isBinary True if the file contents are base64-encoded binary data
* @throws FileNotFoundException, IOException
* @throws NoModificationAllowedException
*/
/**/
public long write(String filename, String data, int offset) throws FileNotFoundException, IOException, NoModificationAllowedException {
public long write(String filename, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException {
if (filename.startsWith("content://")) {
throw new NoModificationAllowedException("Couldn't write to file given its content URI");
}
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.write");
filename = dataResource.getRealFile().getPath();
filename = FileHelper.getRealPath(filename, cordova);
boolean append = false;
if (offset > 0) {
@@ -978,7 +1017,12 @@ public class FileUtils extends CordovaPlugin {
append = true;
}
byte[] rawData = data.getBytes();
byte[] rawData;
if (isBinary) {
rawData = Base64.decode(data, Base64.DEFAULT);
} else {
rawData = data.getBytes();
}
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
FileOutputStream out = new FileOutputStream(filename, append);
byte buff[] = new byte[rawData.length];
@@ -999,16 +1043,13 @@ public class FileUtils extends CordovaPlugin {
* @throws NoModificationAllowedException
*/
private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.truncateFile");
if(!dataResource.isWritable()) {
throw new NoModificationAllowedException("Couldn't truncate file as it is not writable");
}
File file = dataResource.getRealFile();
if(file == null) {
throw new FileNotFoundException("Couldn't get the file");
if (filename.startsWith("content://")) {
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
}
RandomAccessFile raf = new RandomAccessFile(file, "rw");
filename = FileHelper.getRealPath(filename, cordova);
RandomAccessFile raf = new RandomAccessFile(filename, "rw");
try {
if (raf.length() >= size) {
FileChannel channel = raf.getChannel();

View File

@@ -260,12 +260,13 @@ public class Globalization extends CordovaPlugin {
String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a
//get Date value + options (if available)
if (options.getJSONObject(0).length() > 1){
boolean test = options.getJSONObject(0).has(OPTIONS);
if (options.getJSONObject(0).has(OPTIONS)){
//options were included
JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS);
//get formatLength option
if (!((JSONObject)options.getJSONObject(0).get(OPTIONS)).isNull(FORMATLENGTH)){
String fmtOpt = (String)((JSONObject)options.getJSONObject(0).get(OPTIONS)).get(FORMATLENGTH);
if (!innerOptions.isNull(FORMATLENGTH)){
String fmtOpt = innerOptions.getString(FORMATLENGTH);
if (fmtOpt.equalsIgnoreCase(MEDIUM)){//medium
fmtDate = (SimpleDateFormat)android.text.format.DateFormat.getMediumDateFormat(this.cordova.getActivity());
}else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)){ //long/full
@@ -275,8 +276,8 @@ public class Globalization extends CordovaPlugin {
//return pattern type
fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern();
if (!((JSONObject)options.getJSONObject(0).get(OPTIONS)).isNull(SELECTOR)){
String selOpt = (String)((JSONObject)options.getJSONObject(0).get(OPTIONS)).get(SELECTOR);
if (!innerOptions.isNull(SELECTOR)){
String selOpt = innerOptions.getString(SELECTOR);
if (selOpt.equalsIgnoreCase(DATE)){
fmt = fmtDate.toLocalizedPattern();
}else if (selOpt.equalsIgnoreCase(TIME)){

View File

@@ -18,12 +18,11 @@
*/
package org.apache.cordova;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.DataResource;
import org.apache.cordova.api.DataResourceContext;
import org.apache.cordova.api.LOG;
import android.annotation.TargetApi;
@@ -45,27 +44,57 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism.
DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova,
"WebViewClient.shouldInterceptRequest");
url = dataResource.getUri().toString();
// This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it.
//Check if plugins intercept the request
WebResourceResponse ret = super.shouldInterceptRequest(view, url);
if(ret == null) {
try {
InputStream is;
String mimeType;
if((is = dataResource.getInputStream()) != null && (mimeType = dataResource.getMimeType()) != null) {
// If we don't know how to open this file, let the browser continue loading
ret = new WebResourceResponse(mimeType, "UTF-8", is);
}
} catch(IOException e) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e);
}
if(!Config.isUrlWhiteListed(url) && (url.startsWith("http://") || url.startsWith("https://")))
{
ret = getWhitelistResponse();
}
else if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpecialsInAssetUrlFix(url))){
ret = generateWebResourceResponse(url);
}
else if (ret == null && this.appView.pluginManager != null) {
ret = this.appView.pluginManager.shouldInterceptRequest(url);
}
return ret;
}
private WebResourceResponse getWhitelistResponse()
{
WebResourceResponse emptyResponse;
String empty = "";
ByteArrayInputStream data = new ByteArrayInputStream(empty.getBytes());
return new WebResourceResponse("text/plain", "UTF-8", data);
}
private WebResourceResponse generateWebResourceResponse(String url) {
if (url.startsWith("file:///android_asset/")) {
String mimetype = FileHelper.getMimeType(url, cordova);
try {
InputStream stream = FileHelper.getInputStreamFromUriString(url, cordova);
WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8", stream);
return response;
} catch (IOException e) {
LOG.e("generateWebResourceResponse", e.getMessage(), e);
}
}
return null;
}
private static boolean needsIceCreamSpecialsInAssetUrlFix(String url) {
if (!url.contains("%20")){
return false;
}
switch(android.os.Build.VERSION.SDK_INT){
case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
return true;
default:
return false;
}
}
}

View File

@@ -69,8 +69,9 @@ public class InAppBrowser extends CordovaPlugin {
private static final String SELF = "_self";
private static final String SYSTEM = "_system";
// private static final String BLANK = "_blank";
private static final String LOCATION = "location";
private static final String EXIT_EVENT = "exit";
private static final String LOCATION = "location";
private static final String HIDDEN = "hidden";
private static final String LOAD_START_EVENT = "loadstart";
private static final String LOAD_STOP_EVENT = "loadstop";
private static final String LOAD_ERROR_EVENT = "loaderror";
@@ -80,8 +81,9 @@ public class InAppBrowser extends CordovaPlugin {
private Dialog dialog;
private WebView inAppWebView;
private EditText edittext;
private boolean showLocationBar = true;
private CallbackContext callbackContext;
private boolean showLocationBar = true;
private boolean openWindowHidden = false;
private String buttonLabel = "Done";
/**
@@ -185,6 +187,16 @@ public class InAppBrowser extends CordovaPlugin {
}
injectDeferredObject(args.getString(0), jsWrapper);
}
else if (action.equals("show")) {
Runnable runnable = new Runnable() {
@Override
public void run() {
dialog.show();
}
};
this.cordova.getActivity().runOnUiThread(runnable);
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
}
else {
return false;
}
@@ -361,11 +373,16 @@ public class InAppBrowser extends CordovaPlugin {
public String showWebPage(final String url, HashMap<String, Boolean> features) {
// Determine if we should hide the location bar.
showLocationBar = true;
openWindowHidden = false;
if (features != null) {
Boolean show = features.get(LOCATION);
if (show != null) {
showLocationBar = show.booleanValue();
}
Boolean hidden = features.get(HIDDEN);
if(hidden != null) {
openWindowHidden = hidden.booleanValue();
}
}
final CordovaWebView thatWebView = this.webView;
@@ -549,6 +566,11 @@ public class InAppBrowser extends CordovaPlugin {
dialog.setContentView(main);
dialog.show();
dialog.getWindow().setAttributes(lp);
// the goal of openhidden is to load the url and not display it
// Show() needs to be called to cause the URL to be loaded
if(openWindowHidden) {
dialog.hide();
}
}
};
this.cordova.getActivity().runOnUiThread(runnable);

View File

@@ -1,3 +1,21 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova;
import java.util.ArrayList;

View File

@@ -1,3 +1,21 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova.api;
import org.json.JSONArray;

View File

@@ -24,7 +24,7 @@ import android.content.Intent;
import java.util.concurrent.ExecutorService;
/**
* The Cordova activity abstract class that is extended by DroidGap.
* The Activity interface that is implemented by CordovaActivity.
* It is used to isolate plugin development, and remove dependency on entire Cordova library.
*/
public interface CordovaInterface {

View File

@@ -175,20 +175,6 @@ public class CordovaPlugin {
return null;
}
/**
* All plugins can now choose if they want to modify any uri requests. This includes all webview requests, opening of files, content uri's etc.
* This mechanism allows several plugins to modify the same request
* @param requestSource The source of the incoming request
*
* @param dataResource The resource to be loaded.
* @param dataResourceContext Context associated with the resource load
* @return Return a new DataResource if the plugin wants to assist in loading the request or null if it doesn't.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public DataResource handleDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) {
return null;
}
/**
* Called when the WebView does a top-level navigation or refreshes.
*

View File

@@ -1,141 +0,0 @@
package org.apache.cordova.api;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.cordova.FileHelper;
import android.net.Uri;
/*
* All requests to access files, browser network requests etc have to go through this class.
*/
public class DataResource {
private CordovaInterface cordova;
// Uri of the request. Always required.
private Uri uri;
// Remaining fields may or may not be null
private InputStream is;
private OutputStream os;
private String mimeType;
private Boolean writable;
private File realFile;
private boolean retryIsLoad = true;
private boolean retryOsLoad = true;
private boolean retryMimeTypeLoad = true;
private boolean retryWritableLoad = true;
private boolean retryRealFileLoad = true;
public DataResource(CordovaInterface cordova, Uri uri) {
this.cordova = cordova;
this.uri = uri;
}
public DataResource(CordovaInterface cordova, Uri uri, InputStream is,
OutputStream os, String mimeType, boolean writable, File realFile) {
this(cordova, uri);
this.is = is;
this.mimeType = mimeType;
this.writable = Boolean.valueOf(writable);
this.realFile = realFile;
}
public Uri getUri() {
// Uri is always provided
return uri;
}
public InputStream getInputStream() throws IOException {
if(is == null && retryIsLoad) {
try {
is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova);
} finally {
// We failed loading once, don't try loading anymore
if(is == null) {
retryIsLoad = false;
}
}
}
return is;
}
public OutputStream getOutputStream() throws FileNotFoundException {
if(os == null && retryOsLoad) {
try {
os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova);
} finally {
// We failed loading once, don't try loading anymore
if(os == null) {
retryOsLoad = false;
}
}
}
return os;
}
public String getMimeType() {
if(mimeType == null && retryMimeTypeLoad) {
try {
mimeType = FileHelper.getMimeType(uri.toString(), cordova);
} finally {
// We failed loading once, don't try loading anymore
if(mimeType == null) {
retryMimeTypeLoad = false;
}
}
}
return mimeType;
}
public boolean isWritable() {
if(writable == null && retryWritableLoad) {
try {
writable = FileHelper.isUriWritable(uri.toString());
} finally {
// We failed loading once, don't try loading anymore
if(writable == null) {
retryWritableLoad = false;
}
}
}
// default to false
return writable != null && writable.booleanValue();
}
public File getRealFile() {
if(realFile == null && retryRealFileLoad) {
try {
String realPath = FileHelper.getRealPath(uri, cordova);
if(realPath != null) {
realFile = new File(realPath);
}
} finally {
// We failed loading once, don't try loading anymore
if(realFile == null) {
retryRealFileLoad = false;
}
}
}
return realFile;
}
// static instantiation methods
public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
// if no protocol is specified, assume its file:
uriString = FileHelper.insertFileProtocol(uriString);
return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag);
}
public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag));
}
public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
// if no protocol is specified, assume its file:
uriString = FileHelper.insertFileProtocol(uriString);
return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, dataResourceContext);
}
public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
DataResource dataResource = new DataResource(cordova, uri);
if (pluginManager != null) {
// get the resource as returned by plugins
dataResource = pluginManager.handleDataResourceRequestWithPlugins(dataResource, dataResourceContext);
}
return dataResource;
}
}

View File

@@ -1,31 +0,0 @@
package org.apache.cordova.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/*
* Some context information associated with a DataRequest.
*/
public class DataResourceContext {
// A random id that is unique for a particular request.
private int requestId;
// A tag associated with the source of this dataResourceContext
private String source;
// If needed, any data associated with core plugins can be a part of the context object
// If needed, any data associated with non core plugins should store data in a Map so as to not clutter the context object
private Map<String, Object> dataMap;
public DataResourceContext(String source) {
this.requestId = new Random().nextInt();
this.source = source;
this.dataMap = new HashMap<String, Object>();
}
public int getRequestId() {
return requestId;
}
public String getSource() {
return source;
}
public Map<String, Object> getDataMap() {
return dataMap;
}
}

View File

@@ -0,0 +1,177 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova.api;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Legacy Plugin class. This acts as a shim to support the old execute() signature.
* New plugins should extend CordovaPlugin directly.
*/
@Deprecated
public abstract class Plugin extends CordovaPlugin {
public LegacyContext ctx; // LegacyContext object
public abstract PluginResult execute(String action, JSONArray args, String callbackId);
public boolean isSynch(String action) {
return false;
}
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.setContext(cordova);
this.setView(webView);
}
/**
* Sets the context of the Plugin. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(CordovaInterface ctx) {
this.cordova = ctx;
this.ctx = new LegacyContext(cordova);
}
/**
* Sets the main View of the application, this is the WebView within which
* a Cordova app runs.
*
* @param webView The Cordova WebView
*/
public void setView(CordovaWebView webView) {
this.webView = webView;
}
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
final String callbackId = callbackContext.getCallbackId();
boolean runAsync = !isSynch(action);
if (runAsync) {
// Run this on a different thread so that this one can return back to JS
cordova.getThreadPool().execute(new Runnable() {
public void run() {
PluginResult cr;
try {
cr = execute(action, args, callbackId);
} catch (Throwable e) {
cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
}
sendPluginResult(cr, callbackId);
}
});
} else {
PluginResult cr = execute(action, args, callbackId);
// Interpret a null response as NO_RESULT, which *does* clear the callbacks on the JS side.
if (cr == null) {
cr = new PluginResult(PluginResult.Status.NO_RESULT);
}
callbackContext.sendPluginResult(cr);
}
return true;
}
/**
* Send generic JavaScript statement back to JavaScript.
* sendPluginResult() should be used instead where possible.
*/
public void sendJavascript(String statement) {
this.webView.sendJavascript(statement);
}
/**
* Send generic JavaScript statement back to JavaScript.
*/
public void sendPluginResult(PluginResult pluginResult, String callbackId) {
this.webView.sendPluginResult(pluginResult, callbackId);
}
/**
* Call the JavaScript success callback for this plugin.
*
* This can be used if the execute code for the plugin is asynchronous meaning
* that execute should return null and the callback from the async operation can
* call success(...) or error(...)
*
* @param pluginResult The result to return.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void success(PluginResult pluginResult, String callbackId) {
this.webView.sendPluginResult(pluginResult, callbackId);
}
/**
* Helper for success callbacks that just returns the Status.OK by default
*
* @param message The message to add to the success result.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void success(JSONObject message, String callbackId) {
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.OK, message), callbackId);
}
/**
* Helper for success callbacks that just returns the Status.OK by default
*
* @param message The message to add to the success result.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void success(String message, String callbackId) {
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.OK, message), callbackId);
}
/**
* Call the JavaScript error callback for this plugin.
*
* @param pluginResult The result to return.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void error(PluginResult pluginResult, String callbackId) {
this.webView.sendPluginResult(pluginResult, callbackId);
}
/**
* Helper for error callbacks that just returns the Status.ERROR by default
*
* @param message The message to add to the error result.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void error(JSONObject message, String callbackId) {
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message), callbackId);
}
/**
* Helper for error callbacks that just returns the Status.ERROR by default
*
* @param message The message to add to the error result.
* @param callbackId The callback id used when calling back into JavaScript.
*/
public void error(String message, String callbackId) {
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message), callbackId);
}
}

View File

@@ -54,7 +54,6 @@ public class PluginManager {
// Map URL schemes like foo: to plugins that want to handle those schemes
// This would allow how all URLs are handled to be offloaded to a plugin
protected HashMap<String, String> urlMap = new HashMap<String, String>();
private int MAX_REPITIONS = 1000;
/**
* Constructor.
@@ -74,7 +73,7 @@ public class PluginManager {
public void init() {
LOG.d(TAG, "init()");
// If first time, then load plugins from plugins.xml file
// If first time, then load plugins from config.xml file
if (this.firstRun) {
this.loadPlugins();
this.firstRun = false;
@@ -92,7 +91,7 @@ public class PluginManager {
}
/**
* Load plugins from res/xml/plugins.xml
* Load plugins from res/xml/config.xml
*/
public void loadPlugins() {
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
@@ -397,36 +396,8 @@ public class PluginManager {
private void pluginConfigurationMissing() {
LOG.e(TAG, "=====================================================================================");
LOG.e(TAG, "ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.");
LOG.e(TAG, "ERROR: config.xml is missing. Add res/xml/plugins.xml to your project.");
LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml");
LOG.e(TAG, "=====================================================================================");
}
/**
* Called when the any resource is going to be loaded - either from the webview, files or any other resource
*
*
* @param dataResource The resource request to be loaded.
* @param dataResourceContext The context of the dataResource request
* @return Return the resource request that will be loaded. The returned request may be modified or unchanged.
*/
public DataResource handleDataResourceRequestWithPlugins(DataResource dataResource, DataResourceContext dataResourceContext){
int repetitions = 0;
boolean requestModified = true;
while(requestModified && repetitions < MAX_REPITIONS) {
requestModified = false;
repetitions ++;
for (PluginEntry entry : this.entries.values()) {
if (entry.plugin != null) {
DataResource ret = entry.plugin.handleDataResourceRequest(dataResource, dataResourceContext);
if(ret != null) {
dataResource = ret;
requestModified = true;
break;
}
}
}
}
return dataResource;
}
}

View File

@@ -1,3 +1,23 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# Android Native Tests #
These tests are designed to verify Android native features and other Android specific features.

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<widget xmlns = "http://www.w3.org/ns/widgets"
id = "io.cordova.helloCordova"
version = "2.0.0">
@@ -12,8 +30,7 @@
Apache Cordova Team
</author>
<access origin="*"/>
<access origin="*.apache.org"/>
<!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
<content src="index.html" />
@@ -24,6 +41,9 @@
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<feature name="Activity">
<param name="android-package" value="org.apache.cordova.test.ActivityPlugin" />
</feature>
<feature name="App">
<param name="android-package" value="org.apache.cordova.App"/>
</feature>

View File

@@ -97,7 +97,6 @@ public class CordovaWebViewTestActivity extends Activity implements CordovaInter
super.onDestroy();
if (cordovaWebView != null) {
// Send destroy event to JavaScript
cordovaWebView.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
cordovaWebView.handleDestroy();
}
}