mirror of
https://github.com/apache/cordova-android.git
synced 2026-01-30 00:05:28 +08:00
Compare commits
148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8923e52a5e | ||
|
|
aa4f2cc4d9 | ||
|
|
4a23f86411 | ||
|
|
a69bd65152 | ||
|
|
7392b63b99 | ||
|
|
73aa5cc7c3 | ||
|
|
7bf35e9c83 | ||
|
|
adb871f9e1 | ||
|
|
21b7346277 | ||
|
|
79935d31ef | ||
|
|
d2fc08959a | ||
|
|
3ebc1d71df | ||
|
|
f6503f8476 | ||
|
|
d593448182 | ||
|
|
403b87b68b | ||
|
|
bf69362709 | ||
|
|
c00fb987f6 | ||
|
|
7c6450de50 | ||
|
|
10cbcd7f5a | ||
|
|
e918ffd751 | ||
|
|
3ed41597d2 | ||
|
|
5722d976ce | ||
|
|
8555c42196 | ||
|
|
e85394dd99 | ||
|
|
cc5cfad58d | ||
|
|
363b1429e3 | ||
|
|
900ff9ed2c | ||
|
|
c9d4276207 | ||
|
|
fef0e429db | ||
|
|
26044ad662 | ||
|
|
42430d5d11 | ||
|
|
770a257ed3 | ||
|
|
9fe1f21c9f | ||
|
|
49d8d22d7f | ||
|
|
d274891c2c | ||
|
|
c099c65365 | ||
|
|
79ba28d6c4 | ||
|
|
b4d1ca6181 | ||
|
|
657faaff7f | ||
|
|
a43e80ae1d | ||
|
|
5253b5fb31 | ||
|
|
8b12bf79e4 | ||
|
|
45d75524c9 | ||
|
|
8a137395ae | ||
|
|
390fe537f8 | ||
|
|
40cd71484c | ||
|
|
9188773152 | ||
|
|
cc8edea065 | ||
|
|
14b368e731 | ||
|
|
4d03577220 | ||
|
|
040619cd61 | ||
|
|
d6fef8d6e3 | ||
|
|
7c1eb7da9b | ||
|
|
d87ee719a3 | ||
|
|
a52ba37cf7 | ||
|
|
cd667d6af5 | ||
|
|
7e4158ce94 | ||
|
|
0ba803ff46 | ||
|
|
6c48c6a3a1 | ||
|
|
7ee135e516 | ||
|
|
fd69095d3d | ||
|
|
357c0ee1ca | ||
|
|
40637c1486 | ||
|
|
a84d2eab02 | ||
|
|
52213541a3 | ||
|
|
c7d4d83476 | ||
|
|
003e3d4d85 | ||
|
|
95b9cd0229 | ||
|
|
044a61d881 | ||
|
|
9aa1cd756a | ||
|
|
ee4c91539a | ||
|
|
77547f8826 | ||
|
|
52a3a919f9 | ||
|
|
1293d64589 | ||
|
|
54968b755b | ||
|
|
d8d7c29afe | ||
|
|
1c7626aba2 | ||
|
|
e0fea2c352 | ||
|
|
210cc2bd5e | ||
|
|
664a061d10 | ||
|
|
fa4d6d369a | ||
|
|
3bff8aec88 | ||
|
|
e64cb2fc4f | ||
|
|
c5ada0f09f | ||
|
|
44edcbb3cf | ||
|
|
3fd2f590fd | ||
|
|
4f61531422 | ||
|
|
6e82ec4152 | ||
|
|
9206dca741 | ||
|
|
503640f6b5 | ||
|
|
e1e04f859c | ||
|
|
e30896155c | ||
|
|
282f59cd99 | ||
|
|
89e260a5a1 | ||
|
|
20891aee1a | ||
|
|
6e5ef1e819 | ||
|
|
e8544d30d1 | ||
|
|
f9af33b750 | ||
|
|
d28a60ed97 | ||
|
|
0890be5815 | ||
|
|
308a5f1509 | ||
|
|
7904bcc054 | ||
|
|
c7e3b46e2e | ||
|
|
490a13d3c4 | ||
|
|
1dfe7e59a7 | ||
|
|
a2cdcd47be | ||
|
|
a42451969f | ||
|
|
7955c6dd02 | ||
|
|
56096ad00e | ||
|
|
faacdd6b02 | ||
|
|
bdd7449af3 | ||
|
|
64c462c8ad | ||
|
|
cb0b054079 | ||
|
|
41b49df944 | ||
|
|
ffa76246e3 | ||
|
|
3af4d6b139 | ||
|
|
752b1b0e30 | ||
|
|
d91beb5ad9 | ||
|
|
8db5e06c62 | ||
|
|
bc309c9f00 | ||
|
|
9078fe17b5 | ||
|
|
3172ae4525 | ||
|
|
58774addad | ||
|
|
8c191331ae | ||
|
|
7f7c211769 | ||
|
|
51bf8c39af | ||
|
|
4bba9ac5a0 | ||
|
|
e9eb08486a | ||
|
|
3466ef6dfd | ||
|
|
36bca7d609 | ||
|
|
cc04b54adf | ||
|
|
e96ae91800 | ||
|
|
1d5af102c7 | ||
|
|
b106d2cae8 | ||
|
|
c66142d6b8 | ||
|
|
5fac30ea34 | ||
|
|
fae551f0ce | ||
|
|
65e3a8a453 | ||
|
|
1511183dfd | ||
|
|
2094854588 | ||
|
|
feff655530 | ||
|
|
71ea25f40a | ||
|
|
7840448133 | ||
|
|
e77e552293 | ||
|
|
5ceb6e2cfa | ||
|
|
035ad08c69 | ||
|
|
80d0a0cb4c | ||
|
|
05e233bf1d |
11
.gitignore
vendored
11
.gitignore
vendored
@@ -1,15 +1,18 @@
|
||||
.DS_Store
|
||||
default.properties
|
||||
gen
|
||||
assets/www/phonegap.js
|
||||
assets/www/cordova.js
|
||||
local.properties
|
||||
framework/proguard.cfg
|
||||
framework/phonegap.jar
|
||||
framework/cordova.jar
|
||||
framework/cordova-*.jar
|
||||
framework/phonegap-*.jar
|
||||
framework/bin
|
||||
framework/test/org/apache/cordova/*.class
|
||||
framework/assets/www/.DS_Store
|
||||
framework/assets/www/cordova-*.js
|
||||
framework/assets/www/phonegap-*.js
|
||||
example
|
||||
test
|
||||
./test
|
||||
tmp
|
||||
*.tmp
|
||||
*.tmp
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -199,4 +199,4 @@
|
||||
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.
|
||||
limitations under the License.
|
||||
1
NOTICE
1
NOTICE
@@ -3,4 +3,3 @@ Copyright 2011 The Apache Software Foundation
|
||||
|
||||
This product includes software developed by
|
||||
The Apache Software Foundation (http://www.apache.org)
|
||||
|
||||
|
||||
47
README.md
47
README.md
@@ -1,7 +1,16 @@
|
||||
PhoneGap Android
|
||||
Cordova Android
|
||||
===
|
||||
|
||||
PhoneGap Android is an Android application library that allows for PhoneGap based projects to be built for the Android Platform. PhoneGap based applications are, at the core, an application written with web technology: HTML, CSS and JavaScript.
|
||||
Cordova Android is an Android application library that allows for Cordova based projects to be built for the Android Platform. Cordova based applications are, at the core, an application written with web technology: HTML, CSS and JavaScript.
|
||||
|
||||
Apache Cordova is an effort undergoing incubation at The Apache
|
||||
Software Foundation (ASF), sponsored by the Apache Incubator project.
|
||||
Incubation is required of all newly accepted projects until a further
|
||||
review indicates that the infrastructure, communications, and decision
|
||||
making process have stabilized in a manner consistent with other
|
||||
successful ASF projects. While incubation status is not necessarily
|
||||
a reflection of the completeness or stability of the code, it does
|
||||
indicate that the project has yet to be fully endorsed by the ASF.
|
||||
|
||||
Requires
|
||||
---
|
||||
@@ -10,25 +19,35 @@ Requires
|
||||
- Apache ANT
|
||||
- Android SDK [http://developer.android.com](http://developer.android.com)
|
||||
|
||||
PhoneGap Android Developer Tools
|
||||
|
||||
Building
|
||||
---
|
||||
|
||||
The PhoneGap developer tooling is split between general tooling and project level tooling.
|
||||
To create your cordova.jar, run in the framework directory:
|
||||
|
||||
android update project -p . -t android-15
|
||||
ant jar
|
||||
|
||||
|
||||
Cordova Android Developer Tools
|
||||
---
|
||||
|
||||
The Cordova developer tooling is split between general tooling and project level tooling.
|
||||
|
||||
General Commands
|
||||
|
||||
./bin/create [path package activity] ... create the ./example app or a phonegap android project
|
||||
./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
|
||||
|
||||
Project Commands
|
||||
|
||||
These commands live in a generated PhoneGap Android project.
|
||||
These commands live in a generated Cordova Android project.
|
||||
|
||||
./phonegap/debug [path] ..................... install to first device
|
||||
./phonegap/emulate .......................... start avd (emulator) named default
|
||||
./phonegap/log .............................. starts logcat
|
||||
./cordovap/debug [path] ..................... install to first device
|
||||
./cordova/emulate .......................... start avd (emulator) named default
|
||||
./cordova/log .............................. starts logcat
|
||||
|
||||
Running the Example Project
|
||||
---
|
||||
@@ -41,29 +60,29 @@ Create the example project and build it to the first device:
|
||||
|
||||
./bin/create
|
||||
cd example
|
||||
./phonegap/debug
|
||||
./cordova/debug
|
||||
|
||||
Start adb logcat (console.log calls output here):
|
||||
|
||||
./phonegap/log
|
||||
./cordova/log
|
||||
|
||||
Running the [callback/callback-test](http://github.com/callback/callback-test) tests:
|
||||
---
|
||||
|
||||
./bin/test
|
||||
|
||||
Creating a new PhoneGap Android Project
|
||||
Creating a new Cordova Android Project
|
||||
---
|
||||
|
||||
./bin/create ~/Desktop/myapp com.phonegap.special MyApp
|
||||
|
||||
Importing a PhoneGap Android Project into Eclipse
|
||||
Importing a Cordova Android Project into Eclipse
|
||||
----
|
||||
|
||||
1. File > New > Project...
|
||||
2. Android > Android Project
|
||||
3. Create project from existing source (point to the generated app found in tmp/android)
|
||||
4. Right click on libs/phonegap.jar and add to build path
|
||||
4. Right click on libs/cordova.jar and add to build path
|
||||
5. Right click on the project root: Run as > Run Configurations
|
||||
6. Click on the Target tab and select Manual (this way you can choose the emulator or device to build to)
|
||||
|
||||
|
||||
2
bin/BOOM
2
bin/BOOM
@@ -1,4 +1,4 @@
|
||||
#! /bin/sh
|
||||
|
||||
./bin/create
|
||||
cd ./example && ./phonegap/debug && ./phonegap/log
|
||||
cd ./example && ./cordova/debug && ./cordova/log
|
||||
|
||||
12
bin/bench
12
bin/bench
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# Creates an app in `./bench` that posts results to http://phonegap-bench.heroku.com with current PhoneGap/Android sha.
|
||||
# Creates an app in `./bench` that posts results to http://cordova-bench.heroku.com with current cordova/Android sha.
|
||||
#
|
||||
# USAGE
|
||||
# ./bin/bench
|
||||
@@ -13,17 +13,17 @@ then
|
||||
fi
|
||||
|
||||
# create a benching app
|
||||
./bin/create ./bench com.phonegap.bench PhoneGapBench
|
||||
./bin/create ./bench org.apache.cordova.bench cordovaBench
|
||||
|
||||
# grab the latest bench www code
|
||||
git clone git@github.com:brianleroux/phonegap-bench.git
|
||||
git clone git@github.com:brianleroux/cordova-bench.git
|
||||
|
||||
# copy it into the app
|
||||
cat ./phonegap-bench/www/index.html > ./bench/assets/www/index.html
|
||||
#cat ~/Desktop/phonegap-bench/www/index.html > ./bench/assets/www/index.html
|
||||
cat ./cordova-bench/www/index.html > ./bench/assets/www/index.html
|
||||
#cat ~/Desktop/cordova-bench/www/index.html > ./bench/assets/www/index.html
|
||||
|
||||
# clean up
|
||||
rm -rf ./phonegap-bench
|
||||
rm -rf ./cordova-bench
|
||||
|
||||
# launch to the first device found
|
||||
./bin/debug ./bench
|
||||
|
||||
22
bin/create
22
bin/create
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# create a phonegap/android project
|
||||
# create a cordova/android project
|
||||
#
|
||||
# USAGE
|
||||
# ./create [path package activity]
|
||||
@@ -8,8 +8,8 @@
|
||||
set -e
|
||||
|
||||
PROJECT_PATH=${1:-"./example"}
|
||||
PACKAGE=${2:-"com.phonegap.example"}
|
||||
ACTIVITY=${3:-"PhoneGapExample"}
|
||||
PACKAGE=${2:-"org.apache.cordova.example"}
|
||||
ACTIVITY=${3:-"cordovaExample"}
|
||||
TARGET=$(android list targets | grep 'id: ' | sed 's/id: \([0-9]*\).*/\1/g' | tail -1)
|
||||
VERSION=$(cat ./VERSION)
|
||||
|
||||
@@ -19,23 +19,23 @@ then
|
||||
rm -rf $PROJECT_PATH
|
||||
fi
|
||||
|
||||
# update the phonegap-android framework for the desired target
|
||||
# update the cordova-android framework for the desired target
|
||||
android update project --target $TARGET --path ./framework
|
||||
|
||||
# compile phonegap.js and phonegap.jar
|
||||
# compile cordova.js and cordova.jar
|
||||
cd ./framework && ant jar && cd ../
|
||||
|
||||
# copy all the bin scripts etc in there
|
||||
cp -R ./bin/templates/project/ $PROJECT_PATH
|
||||
|
||||
# copy in phonegap.js
|
||||
cp ./framework/assets/www/phonegap-$VERSION.js $PROJECT_PATH/.phonegap/android/phonegap-$VERSION.js
|
||||
# copy in cordova.js
|
||||
cp ./framework/assets/www/cordova-$VERSION.js $PROJECT_PATH/.cordova/android/cordova-$VERSION.js
|
||||
|
||||
# copy in phonegap.jar
|
||||
cp ./framework/phonegap-$VERSION.jar $PROJECT_PATH/.phonegap/android/phonegap-$VERSION.jar
|
||||
# copy in cordova.jar
|
||||
cp ./framework/cordova-$VERSION.jar $PROJECT_PATH/.cordova/android/cordova-$VERSION.jar
|
||||
|
||||
# app properties
|
||||
cat > $PROJECT_PATH/.phonegap/config <<eom
|
||||
cat > $PROJECT_PATH/.cordova/config <<eom
|
||||
VERSION=$VERSION
|
||||
PROJECT_PATH=$PROJECT_PATH
|
||||
PACKAGE=$PACKAGE
|
||||
@@ -43,4 +43,4 @@ ACTIVITY=$ACTIVITY
|
||||
TARGET=$TARGET
|
||||
eom
|
||||
|
||||
(cd $PROJECT_PATH && ./phonegap/create)
|
||||
(cd $PROJECT_PATH && ./cordova/create)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* create a phonegap/android project
|
||||
* create a cordova/android project
|
||||
*
|
||||
* USAGE
|
||||
* ./create [path package activity]
|
||||
@@ -26,7 +26,7 @@ function exec(s) {
|
||||
}
|
||||
|
||||
var args = WScript.Arguments, PROJECT_PATH="example",
|
||||
PACKAGE="com.phonegap.example", ACTIVITY="PhoneGapExample",
|
||||
PACKAGE="org.apache.cordova.example", ACTIVITY="cordovaExample",
|
||||
shell=WScript.CreateObject("WScript.Shell");
|
||||
|
||||
if (args.Count() == 3) {
|
||||
@@ -54,10 +54,10 @@ fi
|
||||
// create the project
|
||||
exec('android.bat create project --target '+TARGET+' --path '+PROJECT_PATH+' --package '+PACKAGE+' --activity '+ACTIVITY);
|
||||
|
||||
// update the phonegap framework project to a target that exists on this machine
|
||||
// update the cordova framework project to a target that exists on this machine
|
||||
exec('android.bat update project --target '+TARGET+' --path framework');
|
||||
|
||||
// compile phonegap.js and phonegap.jar
|
||||
// compile cordova.js and cordova.jar
|
||||
// if you see an error about "Unable to resolve target" then you may need to
|
||||
// update your android tools or install an additional Android platform version
|
||||
exec('ant.bat -f framework\\build.xml jar');
|
||||
@@ -65,11 +65,11 @@ exec('ant.bat -f framework\\build.xml jar');
|
||||
// copy in the project template
|
||||
exec('cmd /c xcopy bin\\templates\\project '+PROJECT_PATH+' /S /Y');
|
||||
|
||||
// copy in phonegap.js
|
||||
exec('cmd /c copy framework\\assets\\www\\phonegap-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\phonegap-'+VERSION+'.js /Y');
|
||||
// copy in cordova.js
|
||||
exec('cmd /c copy framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y');
|
||||
|
||||
// copy in phonegap.jar
|
||||
exec('cmd /c copy framework\\phonegap-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\phonegap-'+VERSION+'.jar /Y');
|
||||
// copy in cordova.jar
|
||||
exec('cmd /c copy framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y');
|
||||
|
||||
// copy in default activity
|
||||
exec('cmd /c copy bin\\templates\\Activity.java '+ACTIVITY_PATH+' /Y');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="PhoneGap" default="create" basedir="../">
|
||||
<project name="cordova" default="create" basedir="../">
|
||||
|
||||
<property name="project.path" value="${basedir}/example"/>
|
||||
<property name="package" value="com.phonegap.example"/>
|
||||
<property name="activity" value="PhoneGapExample"/>
|
||||
<property name="package" value="org.apache.cordova.example"/>
|
||||
<property name="activity" value="cordovaExample"/>
|
||||
|
||||
<target name="create">
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<arg line="update project --target ${target} --path ${basedir}/framework"/>
|
||||
</exec>
|
||||
|
||||
<!-- compile phonegap.js and phonegap.jar -->
|
||||
<!-- compile cordova.js and cordova.jar -->
|
||||
<!-- // if you see an error about "Unable to resolve target" then you may need to
|
||||
// update your android tools or install an additional Android platform version -->
|
||||
<ant antfile="${basedir}/framework/build.xml" useNativeBasedir="true" inheritAll="false" />
|
||||
@@ -60,11 +60,11 @@
|
||||
<fileset dir="${basedir}/bin/templates/project"/>
|
||||
</copy>
|
||||
|
||||
<!-- copy in phonegap.js -->
|
||||
<copy file="${basedir}/framework/assets/www/phonegap-${version}.js" todir="${project.path}/assets/www/" />
|
||||
<!-- copy in cordova.js -->
|
||||
<copy file="${basedir}/framework/assets/www/cordova-${version}.js" todir="${project.path}/assets/www/" />
|
||||
|
||||
<!-- copy in phonegap.jar -->
|
||||
<copy file="${basedir}/framework/phonegap-${version}.jar" todir="${project.path}/libs/" />
|
||||
<!-- copy in cordova.jar -->
|
||||
<copy file="${basedir}/framework/cordova-${version}.jar" todir="${project.path}/libs/" />
|
||||
|
||||
<!-- copy in default activity -->
|
||||
<copy file="${basedir}/bin/templates/Activity.java" tofile="${activity.path}" overwrite="true" />
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
this is local config for phonegap stuff to be eventually moved to
|
||||
this is local config for cordova stuff to be eventually moved to
|
||||
config.xml ...we think. feedback to @davejohnson/@brianleroux
|
||||
appreciated here!
|
||||
@@ -1,13 +1,13 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# create a phonegap/android project
|
||||
# create a cordova/android project
|
||||
#
|
||||
# USAGE
|
||||
# ./create [path package activity]
|
||||
#
|
||||
|
||||
# load up the config
|
||||
. ./.phonegap/config
|
||||
. ./.cordova/config
|
||||
|
||||
PACKAGE_AS_PATH=$(echo $PACKAGE | sed 's/\./\//g')
|
||||
ACTIVITY_PATH=./src/$PACKAGE_AS_PATH/$ACTIVITY.java
|
||||
@@ -16,17 +16,17 @@ MANIFEST_PATH=./AndroidManifest.xml
|
||||
# create the project
|
||||
android create project --target $TARGET --path . --package $PACKAGE --activity $ACTIVITY
|
||||
|
||||
# copy all the phonegap scripts etc in there
|
||||
cp -R ./phonegap/templates/project/* .
|
||||
# copy all the cordova scripts etc in there
|
||||
cp -R ./cordova/templates/project/* .
|
||||
|
||||
# copy in phonegap.js
|
||||
cp ./.phonegap/android/phonegap-$VERSION.js ./assets/www
|
||||
# copy in cordova.js
|
||||
cp ./.cordova/android/cordova-$VERSION.js ./assets/www
|
||||
|
||||
# copy in phonegap.jar
|
||||
cp ./.phonegap/android/phonegap-$VERSION.jar ./libs
|
||||
# copy in cordova.jar
|
||||
cp ./.cordova/android/cordova-$VERSION.jar ./libs
|
||||
|
||||
# copy in default activity
|
||||
cat ./phonegap/templates/Activity.java > $ACTIVITY_PATH
|
||||
cat ./cordova/templates/Activity.java > $ACTIVITY_PATH
|
||||
|
||||
# interpolate the acivity name and package
|
||||
find "$ACTIVITY_PATH" | xargs grep '__ACTIVITY__' -sl | xargs -L1 sed -i -e "s/__ACTIVITY__/${ACTIVITY}/g"
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
|
||||
. ./.phonegap/config
|
||||
. ./.cordova/config
|
||||
|
||||
# if there are no devices listed then emulate
|
||||
|
||||
@@ -2,7 +2,7 @@ package __ID__;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import com.phonegap.*;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class __ACTIVITY__ extends DroidGap
|
||||
{
|
||||
@@ -39,7 +39,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"
|
||||
<activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
</intent-filter>
|
||||
@@ -4,8 +4,8 @@
|
||||
<meta name="viewport" content="width=320; user-scalable=no" />
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>PhoneGap</title>
|
||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0rc2.js"></script>
|
||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
|
||||
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
||||
|
||||
</head>
|
||||
@@ -29,8 +29,12 @@
|
||||
<a href="#" class="btn large" onclick="beep();">Beep</a>
|
||||
<a href="#" class="btn large" onclick="vibrate();">Vibrate</a>
|
||||
<a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
|
||||
<a href="#" class="btn large" onclick="get_contacts();">Get Phone's Contacts</a>
|
||||
<a href="#" class="btn large" onclick="check_network();">Check Network</a>
|
||||
<a href="#" class="btn large" onclick="get_contacts();return false;">Get Phone's Contacts</a>
|
||||
<a href="#" class="btn large" onclick="check_network();return false;">Check Network</a>
|
||||
<dl>
|
||||
<dt>Compass Heading:</dt><dd id="h">Off</dd>
|
||||
</dl>
|
||||
<a href="#" class="btn large" onclick="toggleCompass();return false;">Toggle Compass</a>
|
||||
<div id="viewport" class="viewport" style="display: none;">
|
||||
<img style="width:60px;height:60px" id="test_img" src="" />
|
||||
</div>
|
||||
@@ -119,6 +119,25 @@ function check_network() {
|
||||
confirm('Connection type:\n ' + states[networkState]);
|
||||
}
|
||||
|
||||
var watchID = null;
|
||||
|
||||
function updateHeading(h) {
|
||||
document.getElementById('h').innerHTML = h.magneticHeading;
|
||||
}
|
||||
|
||||
function toggleCompass() {
|
||||
if (watchID !== null) {
|
||||
navigator.compass.clearWatch(watchID);
|
||||
watchID = null;
|
||||
updateHeading({ magneticHeading : "Off"});
|
||||
} else {
|
||||
var options = { frequency: 1000 };
|
||||
watchID = navigator.compass.watchHeading(updateHeading, function(e) {
|
||||
alert('Compass Error: ' + e.code);
|
||||
}, options);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
// the next line makes it impossible to see Contacts on the HTC Evo since it
|
||||
// doesn't have a scroll button
|
||||
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
4
framework/res/xml/phonegap.xml → bin/templates/project/cordova/templates/project/res/xml/cordova.xml
Normal file → Executable file
4
framework/res/xml/phonegap.xml → bin/templates/project/cordova/templates/project/res/xml/cordova.xml
Normal file → Executable file
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phonegap>
|
||||
<cordova>
|
||||
<access origin="http://127.0.0.1*"/>
|
||||
<log level="DEBUG"/>
|
||||
</phonegap>
|
||||
</cordova>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<plugins>
|
||||
<plugin name="App" value="org.apache.cordova.App"/>
|
||||
<plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
|
||||
<plugin name="Device" value="org.apache.cordova.Device"/>
|
||||
<plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/>
|
||||
<plugin name="Compass" value="org.apache.cordova.CompassListener"/>
|
||||
<plugin name="Media" value="org.apache.cordova.AudioHandler"/>
|
||||
<plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="org.apache.cordova.ContactManager"/>
|
||||
<plugin name="File" value="org.apache.cordova.FileUtils"/>
|
||||
<plugin name="Network Status" value="org.apache.cordova.NetworkManager"/>
|
||||
<plugin name="Notification" value="org.apache.cordova.Notification"/>
|
||||
<plugin name="Storage" value="org.apache.cordova.Storage"/>
|
||||
<plugin name="Temperature" value="org.apache.cordova.TempListener"/>
|
||||
<plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
|
||||
<plugin name="Capture" value="org.apache.cordova.Capture"/>
|
||||
<plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
|
||||
</plugins>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phonegap>
|
||||
<access origin="http://127.0.0.1*"/>
|
||||
<log level="DEBUG"/>
|
||||
</phonegap>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<plugins>
|
||||
<plugin name="App" value="com.phonegap.App"/>
|
||||
<plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
|
||||
<plugin name="Device" value="com.phonegap.Device"/>
|
||||
<plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
|
||||
<plugin name="Compass" value="com.phonegap.CompassListener"/>
|
||||
<plugin name="Media" value="com.phonegap.AudioHandler"/>
|
||||
<plugin name="Camera" value="com.phonegap.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="com.phonegap.ContactManager"/>
|
||||
<plugin name="Crypto" value="com.phonegap.CryptoHandler"/>
|
||||
<plugin name="File" value="com.phonegap.FileUtils"/>
|
||||
<plugin name="Network Status" value="com.phonegap.NetworkManager"/>
|
||||
<plugin name="Notification" value="com.phonegap.Notification"/>
|
||||
<plugin name="Storage" value="com.phonegap.Storage"/>
|
||||
<plugin name="Temperature" value="com.phonegap.TempListener"/>
|
||||
<plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
|
||||
<plugin name="Capture" value="com.phonegap.Capture"/>
|
||||
</plugins>
|
||||
8
bin/test
8
bin/test
@@ -13,14 +13,14 @@ then
|
||||
fi
|
||||
|
||||
# generate a working proj
|
||||
./bin/create ./test com.phonegap.test PhoneGapTest
|
||||
./bin/create ./test org.apache.cordova.test CordovaTest
|
||||
|
||||
# kill the default app and replace it w/ mobile-spec
|
||||
rm -rf ./test/assets/www
|
||||
mv ./callback-test ./test/assets/www
|
||||
|
||||
# copy in phonegap.js since www dir was replaced above
|
||||
cp ./framework/assets/www/phonegap-$VERSION.js ./test/assets/www/phonegap-$VERSION.js
|
||||
# copy in cordova.js since www dir was replaced above
|
||||
cp ./framework/assets/www/cordova-$VERSION.js ./test/assets/www/cordova-$VERSION.js
|
||||
|
||||
# build it, launch it and start logging on stdout
|
||||
cd ./test && ./phonegap/debug && ./phonegap/log
|
||||
cd ./test && ./cordova/debug && ./cordova/log
|
||||
|
||||
@@ -8,14 +8,14 @@ exports['default example project is generated'] = (test) ->
|
||||
test.ok true, "this assertion should pass" unless error?
|
||||
test.done()
|
||||
|
||||
exports['default example project has a ./.phonegap folder'] = (test) ->
|
||||
exports['default example project has a ./.cordova folder'] = (test) ->
|
||||
test.expect 1
|
||||
path.exists './example/.phonegap', (exists) ->
|
||||
test.ok exists, 'the phonegap folder exists'
|
||||
path.exists './example/.cordova', (exists) ->
|
||||
test.ok exists, 'the cordova folder exists'
|
||||
test.done()
|
||||
|
||||
exports['default example project has a /phonegap folder'] = (test) ->
|
||||
exports['default example project has a /cordova folder'] = (test) ->
|
||||
test.expect 1
|
||||
path.exists './example/phonegap', (exists) ->
|
||||
test.ok exists, 'the other phonegap folder exists'
|
||||
path.exists './example/cordova', (exists) ->
|
||||
test.ok exists, 'the other cordova folder exists'
|
||||
test.done()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>PhoneGap</name>
|
||||
<name>Cordova</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
<?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.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
|
||||
package="com.phonegap" android:versionName="1.1" android:versionCode="5">
|
||||
package="org.apache.cordova" android:versionName="1.1" android:versionCode="5">
|
||||
<supports-screens
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
@@ -39,7 +57,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"
|
||||
<activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
</intent-filter>
|
||||
|
||||
@@ -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.
|
||||
#
|
||||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked in Version Control Systems, as it is
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("accelerometer")) {
|
||||
PhoneGap.addResource("accelerometer");
|
||||
if (!Cordova.hasResource("accelerometer")) {
|
||||
Cordova.addResource("accelerometer");
|
||||
|
||||
/** @constructor */
|
||||
var Acceleration = function(x, y, z) {
|
||||
@@ -69,7 +69,7 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error
|
||||
}
|
||||
|
||||
// Get acceleration
|
||||
PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
||||
Cordova.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -98,18 +98,18 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb
|
||||
}
|
||||
|
||||
// Make sure accelerometer timeout > frequency + 10 sec
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
function(timeout) {
|
||||
if (timeout < (frequency + 10000)) {
|
||||
PhoneGap.exec(null, null, "Accelerometer", "setTimeout", [frequency + 10000]);
|
||||
Cordova.exec(null, null, "Accelerometer", "setTimeout", [frequency + 10000]);
|
||||
}
|
||||
},
|
||||
function(e) { }, "Accelerometer", "getTimeout", []);
|
||||
|
||||
// Start watch timer
|
||||
var id = PhoneGap.createUUID();
|
||||
var id = Cordova.createUUID();
|
||||
navigator.accelerometer.timers[id] = setInterval(function() {
|
||||
PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
||||
Cordova.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
||||
}, (frequency ? frequency : 1));
|
||||
|
||||
return id;
|
||||
@@ -129,7 +129,7 @@ Accelerometer.prototype.clearWatch = function(id) {
|
||||
}
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.accelerometer === "undefined") {
|
||||
navigator.accelerometer = new Accelerometer();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("app")) {
|
||||
PhoneGap.addResource("app");
|
||||
if (!Cordova.hasResource("app")) {
|
||||
Cordova.addResource("app");
|
||||
(function() {
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ var App = function() {};
|
||||
* Clear the resource cache.
|
||||
*/
|
||||
App.prototype.clearCache = function() {
|
||||
PhoneGap.exec(null, null, "App", "clearCache", []);
|
||||
Cordova.exec(null, null, "App", "clearCache", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -49,14 +49,14 @@ App.prototype.clearCache = function() {
|
||||
* navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
|
||||
*/
|
||||
App.prototype.loadUrl = function(url, props) {
|
||||
PhoneGap.exec(null, null, "App", "loadUrl", [url, props]);
|
||||
Cordova.exec(null, null, "App", "loadUrl", [url, props]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel loadUrl that is waiting to be loaded.
|
||||
*/
|
||||
App.prototype.cancelLoadUrl = function() {
|
||||
PhoneGap.exec(null, null, "App", "cancelLoadUrl", []);
|
||||
Cordova.exec(null, null, "App", "cancelLoadUrl", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ App.prototype.cancelLoadUrl = function() {
|
||||
* Instead of BACK button loading the previous web page, it will exit the app.
|
||||
*/
|
||||
App.prototype.clearHistory = function() {
|
||||
PhoneGap.exec(null, null, "App", "clearHistory", []);
|
||||
Cordova.exec(null, null, "App", "clearHistory", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -72,30 +72,17 @@ App.prototype.clearHistory = function() {
|
||||
* This is the same as pressing the backbutton on Android device.
|
||||
*/
|
||||
App.prototype.backHistory = function() {
|
||||
PhoneGap.exec(null, null, "App", "backHistory", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Override the default behavior of the Android back button.
|
||||
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
|
||||
*
|
||||
* Note: The user should not have to call this method. Instead, when the user
|
||||
* registers for the "backbutton" event, this is automatically done.
|
||||
*
|
||||
* @param override T=override, F=cancel override
|
||||
*/
|
||||
App.prototype.overrideBackbutton = function(override) {
|
||||
PhoneGap.exec(null, null, "App", "overrideBackbutton", [override]);
|
||||
Cordova.exec(null, null, "App", "backHistory", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Exit and terminate the application.
|
||||
*/
|
||||
App.prototype.exitApp = function() {
|
||||
return PhoneGap.exec(null, null, "App", "exitApp", []);
|
||||
return Cordova.exec(null, null, "App", "exitApp", []);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
navigator.app = new App();
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("battery")) {
|
||||
PhoneGap.addResource("battery");
|
||||
if (!Cordova.hasResource("battery")) {
|
||||
Cordova.addResource("battery");
|
||||
|
||||
/**
|
||||
* This class contains information about the current battery status.
|
||||
@@ -44,7 +44,7 @@ Battery.prototype.eventHandler = function(eventType, handler, add) {
|
||||
if (add) {
|
||||
// If there are no current registered event listeners start the battery listener on native side.
|
||||
if (me._batteryListener.length === 0 && me._lowListener.length === 0 && me._criticalListener.length === 0) {
|
||||
PhoneGap.exec(me._status, me._error, "Battery", "start", []);
|
||||
Cordova.exec(me._status, me._error, "Battery", "start", []);
|
||||
}
|
||||
|
||||
// Register the event listener in the proper array
|
||||
@@ -83,7 +83,7 @@ Battery.prototype.eventHandler = function(eventType, handler, add) {
|
||||
|
||||
// If there are no more registered event listeners stop the battery listener on native side.
|
||||
if (me._batteryListener.length === 0 && me._lowListener.length === 0 && me._criticalListener.length === 0) {
|
||||
PhoneGap.exec(null, null, "Battery", "stop", []);
|
||||
Cordova.exec(null, null, "Battery", "stop", []);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -99,15 +99,15 @@ Battery.prototype._status = function(info) {
|
||||
var level = info.level;
|
||||
if (me._level !== level || me._isPlugged !== info.isPlugged) {
|
||||
// Fire batterystatus event
|
||||
PhoneGap.fireWindowEvent("batterystatus", info);
|
||||
Cordova.fireWindowEvent("batterystatus", info);
|
||||
|
||||
// Fire low battery event
|
||||
if (level === 20 || level === 5) {
|
||||
if (level === 20) {
|
||||
PhoneGap.fireWindowEvent("batterylow", info);
|
||||
Cordova.fireWindowEvent("batterylow", info);
|
||||
}
|
||||
else {
|
||||
PhoneGap.fireWindowEvent("batterycritical", info);
|
||||
Cordova.fireWindowEvent("batterycritical", info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,12 +123,12 @@ Battery.prototype._error = function(e) {
|
||||
console.log("Error initializing Battery: " + e);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.battery === "undefined") {
|
||||
navigator.battery = new Battery();
|
||||
PhoneGap.addWindowEventHandler("batterystatus", navigator.battery.eventHandler);
|
||||
PhoneGap.addWindowEventHandler("batterylow", navigator.battery.eventHandler);
|
||||
PhoneGap.addWindowEventHandler("batterycritical", navigator.battery.eventHandler);
|
||||
Cordova.addWindowEventHandler("batterystatus", navigator.battery.eventHandler);
|
||||
Cordova.addWindowEventHandler("batterylow", navigator.battery.eventHandler);
|
||||
Cordova.addWindowEventHandler("batterycritical", navigator.battery.eventHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("camera")) {
|
||||
PhoneGap.addResource("camera");
|
||||
if (!Cordova.hasResource("camera")) {
|
||||
Cordova.addResource("camera");
|
||||
|
||||
/**
|
||||
* This class provides access to the device camera.
|
||||
@@ -127,7 +127,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
||||
options.maxResolution = 0;
|
||||
}
|
||||
if (options.destinationType === null || typeof options.destinationType === "undefined") {
|
||||
options.destinationType = Camera.DestinationType.DATA_URL;
|
||||
options.destinationType = Camera.DestinationType.FILE_URI;
|
||||
}
|
||||
if (options.sourceType === null || typeof options.sourceType === "undefined") {
|
||||
options.sourceType = Camera.PictureSourceType.CAMERA;
|
||||
@@ -157,10 +157,10 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [options]);
|
||||
Cordova.exec(successCallback, errorCallback, "Camera", "takePicture", [options]);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.camera === "undefined") {
|
||||
navigator.camera = new Camera();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("capture")) {
|
||||
PhoneGap.addResource("capture");
|
||||
if (!Cordova.hasResource("capture")) {
|
||||
Cordova.addResource("capture");
|
||||
|
||||
/**
|
||||
* Represents a single file.
|
||||
@@ -44,7 +44,7 @@ var MediaFile = function(name, fullPath, type, lastModifiedDate, size){
|
||||
* @param {Function} errorCB
|
||||
*/
|
||||
MediaFile.prototype.getFormatData = function(successCallback, errorCallback){
|
||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
|
||||
Cordova.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ var Capture = function(){
|
||||
* @param {CaptureAudioOptions} options
|
||||
*/
|
||||
Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
|
||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]);
|
||||
navigator.device.capture._capture("captureAudio", successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -106,30 +106,7 @@ Capture.prototype.captureAudio = function(successCallback, errorCallback, option
|
||||
* @param {CaptureImageOptions} options
|
||||
*/
|
||||
Capture.prototype.captureImage = function(successCallback, errorCallback, options){
|
||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch camera application for taking image(s).
|
||||
*
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureImageOptions} options
|
||||
*/
|
||||
Capture.prototype._castMediaFile = function(pluginResult){
|
||||
var mediaFiles = [];
|
||||
var i;
|
||||
for (i = 0; i < pluginResult.message.length; i++) {
|
||||
var mediaFile = new MediaFile();
|
||||
mediaFile.name = pluginResult.message[i].name;
|
||||
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
||||
mediaFile.type = pluginResult.message[i].type;
|
||||
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
||||
mediaFile.size = pluginResult.message[i].size;
|
||||
mediaFiles.push(mediaFile);
|
||||
}
|
||||
pluginResult.message = mediaFiles;
|
||||
return pluginResult;
|
||||
navigator.device.capture._capture("captureImage", successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -140,9 +117,36 @@ Capture.prototype._castMediaFile = function(pluginResult){
|
||||
* @param {CaptureVideoOptions} options
|
||||
*/
|
||||
Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
|
||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureVideo", [options]);
|
||||
navigator.device.capture._capture("captureVideo", successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Launches the correct capture.
|
||||
*
|
||||
* @param (DOMString} type
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureVideoOptions} options
|
||||
*/
|
||||
Capture.prototype._capture = function(type, successCallback, errorCallback, options){
|
||||
var win = function(result) {
|
||||
var mediaFiles = [];
|
||||
var i;
|
||||
for (i = 0; i < pluginResult.message.length; i++) {
|
||||
var mediaFile = new MediaFile();
|
||||
mediaFile.name = pluginResult.message[i].name;
|
||||
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
||||
mediaFile.type = pluginResult.message[i].type;
|
||||
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
||||
mediaFile.size = pluginResult.message[i].size;
|
||||
mediaFiles.push(mediaFile);
|
||||
}
|
||||
successCallback(mediaFiles);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "Capture", type, [options]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encapsulates a set of parameters that the capture device supports.
|
||||
*/
|
||||
@@ -191,7 +195,7 @@ var CaptureAudioOptions = function(){
|
||||
this.mode = null;
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function(){
|
||||
Cordova.addConstructor(function(){
|
||||
if (typeof navigator.device.capture === "undefined") {
|
||||
navigator.device.capture = window.device.capture = new Capture();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("compass")) {
|
||||
PhoneGap.addResource("compass");
|
||||
if (!Cordova.hasResource("compass")) {
|
||||
Cordova.addResource("compass");
|
||||
|
||||
var CompassError = function(){
|
||||
this.code = null;
|
||||
@@ -73,9 +73,17 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o
|
||||
console.log("Compass Error: errorCallback is not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
var win = function(result) {
|
||||
if (result.timestamp) {
|
||||
var timestamp = new Date(result.timestamp);
|
||||
result.timestamp = timestamp;
|
||||
}
|
||||
successCallback(result);
|
||||
};
|
||||
|
||||
// Get heading
|
||||
PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []);
|
||||
Cordova.exec(win, errorCallback, "Compass", "getHeading", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -104,19 +112,26 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options
|
||||
}
|
||||
|
||||
// Make sure compass timeout > frequency + 10 sec
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
function(timeout) {
|
||||
if (timeout < (frequency + 10000)) {
|
||||
PhoneGap.exec(null, null, "Compass", "setTimeout", [frequency + 10000]);
|
||||
Cordova.exec(null, null, "Compass", "setTimeout", [frequency + 10000]);
|
||||
}
|
||||
},
|
||||
function(e) { }, "Compass", "getTimeout", []);
|
||||
|
||||
// Start watch timer to get headings
|
||||
var id = PhoneGap.createUUID();
|
||||
var id = Cordova.createUUID();
|
||||
navigator.compass.timers[id] = setInterval(
|
||||
function() {
|
||||
PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []);
|
||||
var win = function(result) {
|
||||
if (result.timestamp) {
|
||||
var timestamp = new Date(result.timestamp);
|
||||
result.timestamp = timestamp;
|
||||
}
|
||||
successCallback(result);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "Compass", "getHeading", []);
|
||||
}, (frequency ? frequency : 1));
|
||||
|
||||
return id;
|
||||
@@ -145,7 +160,7 @@ Compass.prototype._castDate = function(pluginResult) {
|
||||
return pluginResult;
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.compass === "undefined") {
|
||||
navigator.compass = new Compass();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("contact")) {
|
||||
PhoneGap.addResource("contact");
|
||||
if (!Cordova.hasResource("contact")) {
|
||||
Cordova.addResource("contact");
|
||||
|
||||
/**
|
||||
* Contains information about a single contact.
|
||||
@@ -89,7 +89,7 @@ Contact.prototype.remove = function(successCB, errorCB) {
|
||||
errorCB(errorObj);
|
||||
}
|
||||
else {
|
||||
PhoneGap.exec(successCB, errorCB, "Contacts", "remove", [this.id]);
|
||||
Cordova.exec(successCB, errorCB, "Contacts", "remove", [this.id]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -99,7 +99,7 @@ Contact.prototype.remove = function(successCB, errorCB) {
|
||||
* @return copy of this Contact
|
||||
*/
|
||||
Contact.prototype.clone = function() {
|
||||
var clonedContact = PhoneGap.clone(this);
|
||||
var clonedContact = Cordova.clone(this);
|
||||
var i;
|
||||
clonedContact.id = null;
|
||||
clonedContact.rawId = null;
|
||||
@@ -153,7 +153,7 @@ Contact.prototype.clone = function() {
|
||||
* @param errorCB error callback
|
||||
*/
|
||||
Contact.prototype.save = function(successCB, errorCB) {
|
||||
PhoneGap.exec(successCB, errorCB, "Contacts", "save", [this]);
|
||||
Cordova.exec(successCB, errorCB, "Contacts", "save", [this]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -259,7 +259,14 @@ Contacts.prototype.find = function(fields, successCB, errorCB, options) {
|
||||
errorCB({"code": ContactError.INVALID_ARGUMENT_ERROR});
|
||||
}
|
||||
} else {
|
||||
PhoneGap.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
|
||||
var win = function(result) {
|
||||
var cs = [];
|
||||
for (var i = 0, l = result.length; i < l; i++) {
|
||||
cs.push(navigator.contacts.create(result[i]));
|
||||
}
|
||||
successCB(cs);
|
||||
};
|
||||
Cordova.exec(win, errorCB, "Contacts", "search", [fields, options]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -281,24 +288,6 @@ Contacts.prototype.create = function(properties) {
|
||||
return contact;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function returns and array of contacts. It is required as we need to convert raw
|
||||
* JSON objects into concrete Contact objects. Currently this method is called after
|
||||
* navigator.contacts.find but before the find methods success call back.
|
||||
*
|
||||
* @param jsonArray an array of JSON Objects that need to be converted to Contact objects.
|
||||
* @returns an array of Contact objects
|
||||
*/
|
||||
Contacts.prototype.cast = function(pluginResult) {
|
||||
var contacts = [];
|
||||
var i;
|
||||
for (i=0; i<pluginResult.message.length; i++) {
|
||||
contacts.push(navigator.contacts.create(pluginResult.message[i]));
|
||||
}
|
||||
pluginResult.message = contacts;
|
||||
return pluginResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* ContactFindOptions.
|
||||
* @constructor
|
||||
@@ -313,7 +302,7 @@ var ContactFindOptions = function(filter, multiple) {
|
||||
/**
|
||||
* Add the contact interface into the browser.
|
||||
*/
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if(typeof navigator.contacts === "undefined") {
|
||||
navigator.contacts = new Contacts();
|
||||
}
|
||||
|
||||
4841
framework/assets/js/cordova.android.js
Normal file
4841
framework/assets/js/cordova.android.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,26 +17,24 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// Version 1.2.0
|
||||
|
||||
if (typeof PhoneGap === "undefined") {
|
||||
if (typeof Cordova === "undefined") {
|
||||
|
||||
/**
|
||||
* The order of events during page load and PhoneGap startup is as follows:
|
||||
* The order of events during page load and Cordova startup is as follows:
|
||||
*
|
||||
* onDOMContentLoaded Internal event that is received when the web page is loaded and parsed.
|
||||
* window.onload Body onload event.
|
||||
* onNativeReady Internal event that indicates the PhoneGap native side is ready.
|
||||
* onPhoneGapInit Internal event that kicks off creation of all PhoneGap JavaScript objects (runs constructors).
|
||||
* onPhoneGapReady Internal event fired when all PhoneGap JavaScript objects have been created
|
||||
* onPhoneGapInfoReady Internal event fired when device properties are available
|
||||
* onDeviceReady User event fired to indicate that PhoneGap is ready
|
||||
* onNativeReady Internal event that indicates the Cordova native side is ready.
|
||||
* onCordovaInit Internal event that kicks off creation of all Cordova JavaScript objects (runs constructors).
|
||||
* onCordovaReady Internal event fired when all Cordova JavaScript objects have been created
|
||||
* onCordovaInfoReady Internal event fired when device properties are available
|
||||
* onDeviceReady User event fired to indicate that Cordova is ready
|
||||
* onResume User event fired to indicate a start/resume lifecycle event
|
||||
* onPause User event fired to indicate a pause lifecycle event
|
||||
* onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
|
||||
*
|
||||
* The only PhoneGap events that user code should register for are:
|
||||
* deviceready PhoneGap native code is initialized and PhoneGap APIs can be called from JavaScript
|
||||
* The only Cordova events that user code should register for are:
|
||||
* deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
|
||||
* pause App has moved to background
|
||||
* resume App has returned to foreground
|
||||
*
|
||||
@@ -51,45 +49,45 @@ if (typeof PhoneGap === "undefined") {
|
||||
*/
|
||||
|
||||
/**
|
||||
* This represents the PhoneGap API itself, and provides a global namespace for accessing
|
||||
* information about the state of PhoneGap.
|
||||
* This represents the Cordova API itself, and provides a global namespace for accessing
|
||||
* information about the state of Cordova.
|
||||
* @class
|
||||
*/
|
||||
var PhoneGap = {
|
||||
var Cordova = {
|
||||
documentEventHandler: {}, // Collection of custom document event handlers
|
||||
windowEventHandler: {} // Collection of custom window event handlers
|
||||
};
|
||||
|
||||
/**
|
||||
* List of resource files loaded by PhoneGap.
|
||||
* List of resource files loaded by Cordova.
|
||||
* This is used to ensure JS and other files are loaded only once.
|
||||
*/
|
||||
PhoneGap.resources = {base: true};
|
||||
Cordova.resources = {base: true};
|
||||
|
||||
/**
|
||||
* Determine if resource has been loaded by PhoneGap
|
||||
* Determine if resource has been loaded by Cordova
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
PhoneGap.hasResource = function(name) {
|
||||
return PhoneGap.resources[name];
|
||||
Cordova.hasResource = function(name) {
|
||||
return Cordova.resources[name];
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a resource to list of loaded resources by PhoneGap
|
||||
* Add a resource to list of loaded resources by Cordova
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
PhoneGap.addResource = function(name) {
|
||||
PhoneGap.resources[name] = true;
|
||||
Cordova.addResource = function(name) {
|
||||
Cordova.resources[name] = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Custom pub-sub channel that can have functions subscribed to it
|
||||
* @constructor
|
||||
*/
|
||||
PhoneGap.Channel = function (type)
|
||||
Cordova.Channel = function (type)
|
||||
{
|
||||
this.type = type;
|
||||
this.handlers = {};
|
||||
@@ -105,12 +103,12 @@ PhoneGap.Channel = function (type)
|
||||
* and a guid that can be used to stop subscribing to the channel.
|
||||
* Returns the guid.
|
||||
*/
|
||||
PhoneGap.Channel.prototype.subscribe = function(f, c, g) {
|
||||
Cordova.Channel.prototype.subscribe = function(f, c, g) {
|
||||
// need a function to call
|
||||
if (f === null) { return; }
|
||||
|
||||
var func = f;
|
||||
if (typeof c === "object" && typeof f === "function") { func = PhoneGap.close(c, f); }
|
||||
if (typeof c === "object" && typeof f === "function") { func = Cordova.close(c, f); }
|
||||
|
||||
g = g || func.observer_guid || f.observer_guid || this.guid++;
|
||||
func.observer_guid = g;
|
||||
@@ -123,7 +121,7 @@ PhoneGap.Channel.prototype.subscribe = function(f, c, g) {
|
||||
* Like subscribe but the function is only called once and then it
|
||||
* auto-unsubscribes itself.
|
||||
*/
|
||||
PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
|
||||
Cordova.Channel.prototype.subscribeOnce = function(f, c) {
|
||||
var g = null;
|
||||
var _this = this;
|
||||
var m = function() {
|
||||
@@ -131,7 +129,7 @@ PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
|
||||
_this.unsubscribe(g);
|
||||
};
|
||||
if (this.fired) {
|
||||
if (typeof c === "object" && typeof f === "function") { f = PhoneGap.close(c, f); }
|
||||
if (typeof c === "object" && typeof f === "function") { f = Cordova.close(c, f); }
|
||||
f.apply(this, this.fireArgs);
|
||||
} else {
|
||||
g = this.subscribe(m);
|
||||
@@ -142,7 +140,7 @@ PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
|
||||
/**
|
||||
* Unsubscribes the function with the given guid from the channel.
|
||||
*/
|
||||
PhoneGap.Channel.prototype.unsubscribe = function(g) {
|
||||
Cordova.Channel.prototype.unsubscribe = function(g) {
|
||||
if (typeof g === "function") { g = g.observer_guid; }
|
||||
this.handlers[g] = null;
|
||||
delete this.handlers[g];
|
||||
@@ -151,7 +149,7 @@ PhoneGap.Channel.prototype.unsubscribe = function(g) {
|
||||
/**
|
||||
* Calls all functions subscribed to this channel.
|
||||
*/
|
||||
PhoneGap.Channel.prototype.fire = function(e) {
|
||||
Cordova.Channel.prototype.fire = function(e) {
|
||||
if (this.enabled) {
|
||||
var fail = false;
|
||||
var item, handler, rv;
|
||||
@@ -175,7 +173,7 @@ PhoneGap.Channel.prototype.fire = function(e) {
|
||||
* Calls the provided function only after all of the channels specified
|
||||
* have been fired.
|
||||
*/
|
||||
PhoneGap.Channel.join = function(h, c) {
|
||||
Cordova.Channel.join = function(h, c) {
|
||||
var i = c.length;
|
||||
var f = function() {
|
||||
if (!(--i)) {
|
||||
@@ -199,11 +197,11 @@ PhoneGap.Channel.join = function(h, c) {
|
||||
|
||||
/**
|
||||
* Add an initialization function to a queue that ensures it will run and initialize
|
||||
* application constructors only once PhoneGap has been initialized.
|
||||
* @param {Function} func The function callback you want run once PhoneGap is initialized
|
||||
* application constructors only once Cordova has been initialized.
|
||||
* @param {Function} func The function callback you want run once Cordova is initialized
|
||||
*/
|
||||
PhoneGap.addConstructor = function(func) {
|
||||
PhoneGap.onPhoneGapInit.subscribeOnce(function() {
|
||||
Cordova.addConstructor = function(func) {
|
||||
Cordova.onCordovaInit.subscribeOnce(function() {
|
||||
try {
|
||||
func();
|
||||
} catch(e) {
|
||||
@@ -226,7 +224,7 @@ if (!window.plugins) {
|
||||
* @param name The plugin name
|
||||
* @param obj The plugin object
|
||||
*/
|
||||
PhoneGap.addPlugin = function(name, obj) {
|
||||
Cordova.addPlugin = function(name, obj) {
|
||||
if (!window.plugins[name]) {
|
||||
window.plugins[name] = obj;
|
||||
}
|
||||
@@ -239,78 +237,78 @@ PhoneGap.addPlugin = function(name, obj) {
|
||||
* onDOMContentLoaded channel is fired when the DOM content
|
||||
* of the page has been parsed.
|
||||
*/
|
||||
PhoneGap.onDOMContentLoaded = new PhoneGap.Channel('onDOMContentLoaded');
|
||||
Cordova.onDOMContentLoaded = new Cordova.Channel('onDOMContentLoaded');
|
||||
|
||||
/**
|
||||
* onNativeReady channel is fired when the PhoneGap native code
|
||||
* onNativeReady channel is fired when the Cordova native code
|
||||
* has been initialized.
|
||||
*/
|
||||
PhoneGap.onNativeReady = new PhoneGap.Channel('onNativeReady');
|
||||
Cordova.onNativeReady = new Cordova.Channel('onNativeReady');
|
||||
|
||||
/**
|
||||
* onPhoneGapInit channel is fired when the web page is fully loaded and
|
||||
* PhoneGap native code has been initialized.
|
||||
* onCordovaInit channel is fired when the web page is fully loaded and
|
||||
* Cordova native code has been initialized.
|
||||
*/
|
||||
PhoneGap.onPhoneGapInit = new PhoneGap.Channel('onPhoneGapInit');
|
||||
Cordova.onCordovaInit = new Cordova.Channel('onCordovaInit');
|
||||
|
||||
/**
|
||||
* onPhoneGapReady channel is fired when the JS PhoneGap objects have been created.
|
||||
* onCordovaReady channel is fired when the JS Cordova objects have been created.
|
||||
*/
|
||||
PhoneGap.onPhoneGapReady = new PhoneGap.Channel('onPhoneGapReady');
|
||||
Cordova.onCordovaReady = new Cordova.Channel('onCordovaReady');
|
||||
|
||||
/**
|
||||
* onPhoneGapInfoReady channel is fired when the PhoneGap device properties
|
||||
* onCordovaInfoReady channel is fired when the Cordova device properties
|
||||
* has been set.
|
||||
*/
|
||||
PhoneGap.onPhoneGapInfoReady = new PhoneGap.Channel('onPhoneGapInfoReady');
|
||||
Cordova.onCordovaInfoReady = new Cordova.Channel('onCordovaInfoReady');
|
||||
|
||||
/**
|
||||
* onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties
|
||||
* onCordovaConnectionReady channel is fired when the Cordova connection properties
|
||||
* has been set.
|
||||
*/
|
||||
PhoneGap.onPhoneGapConnectionReady = new PhoneGap.Channel('onPhoneGapConnectionReady');
|
||||
Cordova.onCordovaConnectionReady = new Cordova.Channel('onCordovaConnectionReady');
|
||||
|
||||
/**
|
||||
* onDestroy channel is fired when the PhoneGap native code
|
||||
* onDestroy channel is fired when the Cordova native code
|
||||
* is destroyed. It is used internally.
|
||||
* Window.onunload should be used by the user.
|
||||
*/
|
||||
PhoneGap.onDestroy = new PhoneGap.Channel('onDestroy');
|
||||
PhoneGap.onDestroy.subscribeOnce(function() {
|
||||
PhoneGap.shuttingDown = true;
|
||||
Cordova.onDestroy = new Cordova.Channel('onDestroy');
|
||||
Cordova.onDestroy.subscribeOnce(function() {
|
||||
Cordova.shuttingDown = true;
|
||||
});
|
||||
PhoneGap.shuttingDown = false;
|
||||
Cordova.shuttingDown = false;
|
||||
|
||||
// _nativeReady is global variable that the native side can set
|
||||
// to signify that the native code is ready. It is a global since
|
||||
// it may be called before any PhoneGap JS is ready.
|
||||
if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
|
||||
// it may be called before any Cordova JS is ready.
|
||||
if (typeof _nativeReady !== 'undefined') { Cordova.onNativeReady.fire(); }
|
||||
|
||||
/**
|
||||
* onDeviceReady is fired only after all PhoneGap objects are created and
|
||||
* onDeviceReady is fired only after all Cordova objects are created and
|
||||
* the device properties are set.
|
||||
*/
|
||||
PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady');
|
||||
Cordova.onDeviceReady = new Cordova.Channel('onDeviceReady');
|
||||
|
||||
|
||||
// Array of channels that must fire before "deviceready" is fired
|
||||
PhoneGap.deviceReadyChannelsArray = [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady, PhoneGap.onPhoneGapConnectionReady];
|
||||
Cordova.deviceReadyChannelsArray = [ Cordova.onCordovaReady, Cordova.onCordovaInfoReady, Cordova.onCordovaConnectionReady];
|
||||
|
||||
// Hashtable of user defined channels that must also fire before "deviceready" is fired
|
||||
PhoneGap.deviceReadyChannelsMap = {};
|
||||
Cordova.deviceReadyChannelsMap = {};
|
||||
|
||||
/**
|
||||
* Indicate that a feature needs to be initialized before it is ready to be used.
|
||||
* This holds up PhoneGap's "deviceready" event until the feature has been initialized
|
||||
* and PhoneGap.initComplete(feature) is called.
|
||||
* This holds up Cordova's "deviceready" event until the feature has been initialized
|
||||
* and Cordova.initComplete(feature) is called.
|
||||
*
|
||||
* @param feature {String} The unique feature name
|
||||
*/
|
||||
PhoneGap.waitForInitialization = function(feature) {
|
||||
Cordova.waitForInitialization = function(feature) {
|
||||
if (feature) {
|
||||
var channel = new PhoneGap.Channel(feature);
|
||||
PhoneGap.deviceReadyChannelsMap[feature] = channel;
|
||||
PhoneGap.deviceReadyChannelsArray.push(channel);
|
||||
var channel = new Cordova.Channel(feature);
|
||||
Cordova.deviceReadyChannelsMap[feature] = channel;
|
||||
Cordova.deviceReadyChannelsArray.push(channel);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -319,64 +317,64 @@ PhoneGap.waitForInitialization = function(feature) {
|
||||
*
|
||||
* @param feature {String} The unique feature name
|
||||
*/
|
||||
PhoneGap.initializationComplete = function(feature) {
|
||||
var channel = PhoneGap.deviceReadyChannelsMap[feature];
|
||||
Cordova.initializationComplete = function(feature) {
|
||||
var channel = Cordova.deviceReadyChannelsMap[feature];
|
||||
if (channel) {
|
||||
channel.fire();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create all PhoneGap objects once page has fully loaded and native side is ready.
|
||||
* Create all Cordova objects once page has fully loaded and native side is ready.
|
||||
*/
|
||||
PhoneGap.Channel.join(function() {
|
||||
Cordova.Channel.join(function() {
|
||||
|
||||
// Start listening for XHR callbacks
|
||||
setTimeout(function() {
|
||||
if (PhoneGap.UsePolling) {
|
||||
PhoneGap.JSCallbackPolling();
|
||||
if (Cordova.UsePolling) {
|
||||
Cordova.JSCallbackPolling();
|
||||
}
|
||||
else {
|
||||
var polling = prompt("usePolling", "gap_callbackServer:");
|
||||
PhoneGap.UsePolling = polling;
|
||||
Cordova.UsePolling = polling;
|
||||
if (polling == "true") {
|
||||
PhoneGap.UsePolling = true;
|
||||
PhoneGap.JSCallbackPolling();
|
||||
Cordova.UsePolling = true;
|
||||
Cordova.JSCallbackPolling();
|
||||
}
|
||||
else {
|
||||
PhoneGap.UsePolling = false;
|
||||
PhoneGap.JSCallback();
|
||||
Cordova.UsePolling = false;
|
||||
Cordova.JSCallback();
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// Run PhoneGap constructors
|
||||
PhoneGap.onPhoneGapInit.fire();
|
||||
// Run Cordova constructors
|
||||
Cordova.onCordovaInit.fire();
|
||||
|
||||
// Fire event to notify that all objects are created
|
||||
PhoneGap.onPhoneGapReady.fire();
|
||||
Cordova.onCordovaReady.fire();
|
||||
|
||||
// Fire onDeviceReady event once all constructors have run and PhoneGap info has been
|
||||
// Fire onDeviceReady event once all constructors have run and Cordova info has been
|
||||
// received from native side, and any user defined initialization channels.
|
||||
PhoneGap.Channel.join(function() {
|
||||
Cordova.Channel.join(function() {
|
||||
// Let native code know we are inited on JS side
|
||||
prompt("", "gap_init:");
|
||||
|
||||
PhoneGap.onDeviceReady.fire();
|
||||
}, PhoneGap.deviceReadyChannelsArray);
|
||||
Cordova.onDeviceReady.fire();
|
||||
}, Cordova.deviceReadyChannelsArray);
|
||||
|
||||
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
||||
}, [ Cordova.onDOMContentLoaded, Cordova.onNativeReady ]);
|
||||
|
||||
// Listen for DOMContentLoaded and notify our channel subscribers
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
PhoneGap.onDOMContentLoaded.fire();
|
||||
Cordova.onDOMContentLoaded.fire();
|
||||
}, false);
|
||||
|
||||
// Intercept calls to document.addEventListener and watch for deviceready
|
||||
PhoneGap.m_document_addEventListener = document.addEventListener;
|
||||
Cordova.m_document_addEventListener = document.addEventListener;
|
||||
|
||||
// Intercept calls to window.addEventListener
|
||||
PhoneGap.m_window_addEventListener = window.addEventListener;
|
||||
Cordova.m_window_addEventListener = window.addEventListener;
|
||||
|
||||
/**
|
||||
* Add a custom window event handler.
|
||||
@@ -384,8 +382,8 @@ PhoneGap.m_window_addEventListener = window.addEventListener;
|
||||
* @param {String} event The event name that callback handles
|
||||
* @param {Function} callback The event handler
|
||||
*/
|
||||
PhoneGap.addWindowEventHandler = function(event, callback) {
|
||||
PhoneGap.windowEventHandler[event] = callback;
|
||||
Cordova.addWindowEventHandler = function(event, callback) {
|
||||
Cordova.windowEventHandler[event] = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -394,8 +392,8 @@ PhoneGap.addWindowEventHandler = function(event, callback) {
|
||||
* @param {String} event The event name that callback handles
|
||||
* @param {Function} callback The event handler
|
||||
*/
|
||||
PhoneGap.addDocumentEventHandler = function(event, callback) {
|
||||
PhoneGap.documentEventHandler[event] = callback;
|
||||
Cordova.addDocumentEventHandler = function(event, callback) {
|
||||
Cordova.documentEventHandler[event] = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -408,22 +406,22 @@ PhoneGap.addDocumentEventHandler = function(event, callback) {
|
||||
document.addEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
if (e === 'deviceready') {
|
||||
PhoneGap.onDeviceReady.subscribeOnce(handler);
|
||||
Cordova.onDeviceReady.subscribeOnce(handler);
|
||||
}
|
||||
else {
|
||||
// If subscribing to Android backbutton
|
||||
if (e === 'backbutton') {
|
||||
PhoneGap.exec(null, null, "App", "overrideBackbutton", [true]);
|
||||
Cordova.exec(null, null, "App", "overrideBackbutton", [true]);
|
||||
}
|
||||
|
||||
// If subscribing to an event that is handled by a plugin
|
||||
else if (typeof PhoneGap.documentEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.documentEventHandler[e](e, handler, true)) {
|
||||
else if (typeof Cordova.documentEventHandler[e] !== "undefined") {
|
||||
if (Cordova.documentEventHandler[e](e, handler, true)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_document_addEventListener.call(document, evt, handler, capture);
|
||||
Cordova.m_document_addEventListener.call(document, evt, handler, capture);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -438,21 +436,21 @@ window.addEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
|
||||
// If subscribing to an event that is handled by a plugin
|
||||
if (typeof PhoneGap.windowEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.windowEventHandler[e](e, handler, true)) {
|
||||
if (typeof Cordova.windowEventHandler[e] !== "undefined") {
|
||||
if (Cordova.windowEventHandler[e](e, handler, true)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_window_addEventListener.call(window, evt, handler, capture);
|
||||
Cordova.m_window_addEventListener.call(window, evt, handler, capture);
|
||||
};
|
||||
|
||||
// Intercept calls to document.removeEventListener and watch for events that
|
||||
// are generated by PhoneGap native code
|
||||
PhoneGap.m_document_removeEventListener = document.removeEventListener;
|
||||
// are generated by Cordova native code
|
||||
Cordova.m_document_removeEventListener = document.removeEventListener;
|
||||
|
||||
// Intercept calls to window.removeEventListener
|
||||
PhoneGap.m_window_removeEventListener = window.removeEventListener;
|
||||
Cordova.m_window_removeEventListener = window.removeEventListener;
|
||||
|
||||
/**
|
||||
* Intercept removing document event listeners and handle our own
|
||||
@@ -466,17 +464,17 @@ document.removeEventListener = function(evt, handler, capture) {
|
||||
|
||||
// If unsubscribing to Android backbutton
|
||||
if (e === 'backbutton') {
|
||||
PhoneGap.exec(null, null, "App", "overrideBackbutton", [false]);
|
||||
Cordova.exec(null, null, "App", "overrideBackbutton", [false]);
|
||||
}
|
||||
|
||||
// If unsubcribing from an event that is handled by a plugin
|
||||
if (typeof PhoneGap.documentEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.documentEventHandler[e](e, handler, false)) {
|
||||
if (typeof Cordova.documentEventHandler[e] !== "undefined") {
|
||||
if (Cordova.documentEventHandler[e](e, handler, false)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_document_removeEventListener.call(document, evt, handler, capture);
|
||||
Cordova.m_document_removeEventListener.call(document, evt, handler, capture);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -490,13 +488,13 @@ window.removeEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
|
||||
// If unsubcribing from an event that is handled by a plugin
|
||||
if (typeof PhoneGap.windowEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.windowEventHandler[e](e, handler, false)) {
|
||||
if (typeof Cordova.windowEventHandler[e] !== "undefined") {
|
||||
if (Cordova.windowEventHandler[e](e, handler, false)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_window_removeEventListener.call(window, evt, handler, capture);
|
||||
Cordova.m_window_removeEventListener.call(window, evt, handler, capture);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -505,7 +503,7 @@ window.removeEventListener = function(evt, handler, capture) {
|
||||
* @param {String} type The event type to fire
|
||||
* @param {Object} data Data to send with event
|
||||
*/
|
||||
PhoneGap.fireDocumentEvent = function(type, data) {
|
||||
Cordova.fireDocumentEvent = function(type, data) {
|
||||
var e = document.createEvent('Events');
|
||||
e.initEvent(type);
|
||||
if (data) {
|
||||
@@ -522,7 +520,7 @@ PhoneGap.fireDocumentEvent = function(type, data) {
|
||||
* @param {String} type The event type to fire
|
||||
* @param {Object} data Data to send with event
|
||||
*/
|
||||
PhoneGap.fireWindowEvent = function(type, data) {
|
||||
Cordova.fireWindowEvent = function(type, data) {
|
||||
var e = document.createEvent('Events');
|
||||
e.initEvent(type);
|
||||
if (data) {
|
||||
@@ -539,7 +537,7 @@ PhoneGap.fireWindowEvent = function(type, data) {
|
||||
* @param obj
|
||||
* @return {Object}
|
||||
*/
|
||||
PhoneGap.clone = function(obj) {
|
||||
Cordova.clone = function(obj) {
|
||||
var i, retVal;
|
||||
if(!obj) {
|
||||
return obj;
|
||||
@@ -548,7 +546,7 @@ PhoneGap.clone = function(obj) {
|
||||
if(obj instanceof Array){
|
||||
retVal = [];
|
||||
for(i = 0; i < obj.length; ++i){
|
||||
retVal.push(PhoneGap.clone(obj[i]));
|
||||
retVal.push(Cordova.clone(obj[i]));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
@@ -568,15 +566,15 @@ PhoneGap.clone = function(obj) {
|
||||
retVal = {};
|
||||
for(i in obj){
|
||||
if(!(i in retVal) || retVal[i] !== obj[i]) {
|
||||
retVal[i] = PhoneGap.clone(obj[i]);
|
||||
retVal[i] = Cordova.clone(obj[i]);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
};
|
||||
|
||||
PhoneGap.callbackId = 0;
|
||||
PhoneGap.callbacks = {};
|
||||
PhoneGap.callbackStatus = {
|
||||
Cordova.callbackId = 0;
|
||||
Cordova.callbacks = {};
|
||||
Cordova.callbackStatus = {
|
||||
NO_RESULT: 0,
|
||||
OK: 1,
|
||||
CLASS_NOT_FOUND_EXCEPTION: 2,
|
||||
@@ -591,24 +589,24 @@ PhoneGap.callbackStatus = {
|
||||
|
||||
|
||||
/**
|
||||
* Execute a PhoneGap command. It is up to the native side whether this action is synch or async.
|
||||
* Execute a Cordova command. It is up to the native side whether this action is synch or async.
|
||||
* The native side can return:
|
||||
* Synchronous: PluginResult object as a JSON string
|
||||
* Asynchrounous: Empty string ""
|
||||
* If async, the native side will PhoneGap.callbackSuccess or PhoneGap.callbackError,
|
||||
* If async, the native side will Cordova.callbackSuccess or Cordova.callbackError,
|
||||
* depending upon the result of the action.
|
||||
*
|
||||
* @param {Function} success The success callback
|
||||
* @param {Function} fail The fail callback
|
||||
* @param {String} service The name of the service to use
|
||||
* @param {String} action Action to be run in PhoneGap
|
||||
* @param {String} action Action to be run in Cordova
|
||||
* @param {Array.<String>} [args] Zero or more arguments to pass to the method
|
||||
*/
|
||||
PhoneGap.exec = function(success, fail, service, action, args) {
|
||||
Cordova.exec = function(success, fail, service, action, args) {
|
||||
try {
|
||||
var callbackId = service + PhoneGap.callbackId++;
|
||||
var callbackId = service + Cordova.callbackId++;
|
||||
if (success || fail) {
|
||||
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
|
||||
Cordova.callbacks[callbackId] = {success:success, fail:fail};
|
||||
}
|
||||
|
||||
var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true]));
|
||||
@@ -618,7 +616,7 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
||||
eval("var v="+r+";");
|
||||
|
||||
// If status is OK, then return value back to caller
|
||||
if (v.status === PhoneGap.callbackStatus.OK) {
|
||||
if (v.status === Cordova.callbackStatus.OK) {
|
||||
|
||||
// If there is a success callback, then call it now with
|
||||
// returned value
|
||||
@@ -631,18 +629,18 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
if (!v.keepCallback) {
|
||||
delete PhoneGap.callbacks[callbackId];
|
||||
delete Cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
return v.message;
|
||||
}
|
||||
|
||||
// If no result
|
||||
else if (v.status === PhoneGap.callbackStatus.NO_RESULT) {
|
||||
else if (v.status === Cordova.callbackStatus.NO_RESULT) {
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
if (!v.keepCallback) {
|
||||
delete PhoneGap.callbacks[callbackId];
|
||||
delete Cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,7 +659,7 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
if (!v.keepCallback) {
|
||||
delete PhoneGap.callbacks[callbackId];
|
||||
delete Cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -678,14 +676,14 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
||||
* @param callbackId
|
||||
* @param args
|
||||
*/
|
||||
PhoneGap.callbackSuccess = function(callbackId, args) {
|
||||
if (PhoneGap.callbacks[callbackId]) {
|
||||
Cordova.callbackSuccess = function(callbackId, args) {
|
||||
if (Cordova.callbacks[callbackId]) {
|
||||
|
||||
// If result is to be sent to callback
|
||||
if (args.status === PhoneGap.callbackStatus.OK) {
|
||||
if (args.status === Cordova.callbackStatus.OK) {
|
||||
try {
|
||||
if (PhoneGap.callbacks[callbackId].success) {
|
||||
PhoneGap.callbacks[callbackId].success(args.message);
|
||||
if (Cordova.callbacks[callbackId].success) {
|
||||
Cordova.callbacks[callbackId].success(args.message);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
@@ -695,7 +693,7 @@ PhoneGap.callbackSuccess = function(callbackId, args) {
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
if (!args.keepCallback) {
|
||||
delete PhoneGap.callbacks[callbackId];
|
||||
delete Cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -706,11 +704,11 @@ PhoneGap.callbackSuccess = function(callbackId, args) {
|
||||
* @param callbackId
|
||||
* @param args
|
||||
*/
|
||||
PhoneGap.callbackError = function(callbackId, args) {
|
||||
if (PhoneGap.callbacks[callbackId]) {
|
||||
Cordova.callbackError = function(callbackId, args) {
|
||||
if (Cordova.callbacks[callbackId]) {
|
||||
try {
|
||||
if (PhoneGap.callbacks[callbackId].fail) {
|
||||
PhoneGap.callbacks[callbackId].fail(args.message);
|
||||
if (Cordova.callbacks[callbackId].fail) {
|
||||
Cordova.callbacks[callbackId].fail(args.message);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
@@ -719,31 +717,31 @@ PhoneGap.callbackError = function(callbackId, args) {
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
if (!args.keepCallback) {
|
||||
delete PhoneGap.callbacks[callbackId];
|
||||
delete Cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PhoneGap.JSCallbackPort = null;
|
||||
PhoneGap.JSCallbackToken = null;
|
||||
Cordova.JSCallbackPort = null;
|
||||
Cordova.JSCallbackToken = null;
|
||||
|
||||
/**
|
||||
* This is only for Android.
|
||||
*
|
||||
* Internal function that uses XHR to call into PhoneGap Java code and retrieve
|
||||
* Internal function that uses XHR to call into Cordova Java code and retrieve
|
||||
* any JavaScript code that needs to be run. This is used for callbacks from
|
||||
* Java to JavaScript.
|
||||
*/
|
||||
PhoneGap.JSCallback = function() {
|
||||
Cordova.JSCallback = function() {
|
||||
|
||||
// Exit if shutting down app
|
||||
if (PhoneGap.shuttingDown) {
|
||||
if (Cordova.shuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If polling flag was changed, start using polling from now on
|
||||
if (PhoneGap.UsePolling) {
|
||||
PhoneGap.JSCallbackPolling();
|
||||
if (Cordova.UsePolling) {
|
||||
Cordova.JSCallbackPolling();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -754,7 +752,7 @@ PhoneGap.JSCallback = function() {
|
||||
if(xmlhttp.readyState === 4){
|
||||
|
||||
// Exit if shutting down app
|
||||
if (PhoneGap.shuttingDown) {
|
||||
if (Cordova.shuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -773,12 +771,12 @@ PhoneGap.JSCallback = function() {
|
||||
console.log("JSCallback Error: "+e);
|
||||
}
|
||||
}, 1);
|
||||
setTimeout(PhoneGap.JSCallback, 1);
|
||||
setTimeout(Cordova.JSCallback, 1);
|
||||
}
|
||||
|
||||
// If callback ping (used to keep XHR request from timing out)
|
||||
else if (xmlhttp.status === 404) {
|
||||
setTimeout(PhoneGap.JSCallback, 10);
|
||||
setTimeout(Cordova.JSCallback, 10);
|
||||
}
|
||||
|
||||
// If security error
|
||||
@@ -799,19 +797,19 @@ PhoneGap.JSCallback = function() {
|
||||
// If error, revert to polling
|
||||
else {
|
||||
console.log("JSCallback Error: Request failed.");
|
||||
PhoneGap.UsePolling = true;
|
||||
PhoneGap.JSCallbackPolling();
|
||||
Cordova.UsePolling = true;
|
||||
Cordova.JSCallbackPolling();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (PhoneGap.JSCallbackPort === null) {
|
||||
PhoneGap.JSCallbackPort = prompt("getPort", "gap_callbackServer:");
|
||||
if (Cordova.JSCallbackPort === null) {
|
||||
Cordova.JSCallbackPort = prompt("getPort", "gap_callbackServer:");
|
||||
}
|
||||
if (PhoneGap.JSCallbackToken === null) {
|
||||
PhoneGap.JSCallbackToken = prompt("getToken", "gap_callbackServer:");
|
||||
if (Cordova.JSCallbackToken === null) {
|
||||
Cordova.JSCallbackToken = prompt("getToken", "gap_callbackServer:");
|
||||
}
|
||||
xmlhttp.open("GET", "http://127.0.0.1:"+PhoneGap.JSCallbackPort+"/"+PhoneGap.JSCallbackToken , true);
|
||||
xmlhttp.open("GET", "http://127.0.0.1:"+Cordova.JSCallbackPort+"/"+Cordova.JSCallbackToken , true);
|
||||
xmlhttp.send();
|
||||
};
|
||||
|
||||
@@ -819,30 +817,30 @@ PhoneGap.JSCallback = function() {
|
||||
* The polling period to use with JSCallbackPolling.
|
||||
* This can be changed by the application. The default is 50ms.
|
||||
*/
|
||||
PhoneGap.JSCallbackPollingPeriod = 50;
|
||||
Cordova.JSCallbackPollingPeriod = 50;
|
||||
|
||||
/**
|
||||
* Flag that can be set by the user to force polling to be used or force XHR to be used.
|
||||
*/
|
||||
PhoneGap.UsePolling = false; // T=use polling, F=use XHR
|
||||
Cordova.UsePolling = false; // T=use polling, F=use XHR
|
||||
|
||||
/**
|
||||
* This is only for Android.
|
||||
*
|
||||
* Internal function that uses polling to call into PhoneGap Java code and retrieve
|
||||
* Internal function that uses polling to call into Cordova Java code and retrieve
|
||||
* any JavaScript code that needs to be run. This is used for callbacks from
|
||||
* Java to JavaScript.
|
||||
*/
|
||||
PhoneGap.JSCallbackPolling = function() {
|
||||
Cordova.JSCallbackPolling = function() {
|
||||
|
||||
// Exit if shutting down app
|
||||
if (PhoneGap.shuttingDown) {
|
||||
if (Cordova.shuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If polling flag was changed, stop using polling from now on
|
||||
if (!PhoneGap.UsePolling) {
|
||||
PhoneGap.JSCallback();
|
||||
if (!Cordova.UsePolling) {
|
||||
Cordova.JSCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -857,10 +855,10 @@ PhoneGap.JSCallbackPolling = function() {
|
||||
console.log("JSCallbackPolling Error: "+e);
|
||||
}
|
||||
}, 1);
|
||||
setTimeout(PhoneGap.JSCallbackPolling, 1);
|
||||
setTimeout(Cordova.JSCallbackPolling, 1);
|
||||
}
|
||||
else {
|
||||
setTimeout(PhoneGap.JSCallbackPolling, PhoneGap.JSCallbackPollingPeriod);
|
||||
setTimeout(Cordova.JSCallbackPolling, Cordova.JSCallbackPollingPeriod);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -869,15 +867,15 @@ PhoneGap.JSCallbackPolling = function() {
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
PhoneGap.createUUID = function() {
|
||||
return PhoneGap.UUIDcreatePart(4) + '-' +
|
||||
PhoneGap.UUIDcreatePart(2) + '-' +
|
||||
PhoneGap.UUIDcreatePart(2) + '-' +
|
||||
PhoneGap.UUIDcreatePart(2) + '-' +
|
||||
PhoneGap.UUIDcreatePart(6);
|
||||
Cordova.createUUID = function() {
|
||||
return Cordova.UUIDcreatePart(4) + '-' +
|
||||
Cordova.UUIDcreatePart(2) + '-' +
|
||||
Cordova.UUIDcreatePart(2) + '-' +
|
||||
Cordova.UUIDcreatePart(2) + '-' +
|
||||
Cordova.UUIDcreatePart(6);
|
||||
};
|
||||
|
||||
PhoneGap.UUIDcreatePart = function(length) {
|
||||
Cordova.UUIDcreatePart = function(length) {
|
||||
var uuidpart = "";
|
||||
var i, uuidchar;
|
||||
for (i=0; i<length; i++) {
|
||||
@@ -890,7 +888,7 @@ PhoneGap.UUIDcreatePart = function(length) {
|
||||
return uuidpart;
|
||||
};
|
||||
|
||||
PhoneGap.close = function(context, func, params) {
|
||||
Cordova.close = function(context, func, params) {
|
||||
if (typeof params === 'undefined') {
|
||||
return function() {
|
||||
return func.apply(context, arguments);
|
||||
@@ -908,7 +906,7 @@ PhoneGap.close = function(context, func, params) {
|
||||
* @param {String} jsfile The url of the JavaScript file to load.
|
||||
* @param {Function} successCallback The callback to call when the file has been loaded.
|
||||
*/
|
||||
PhoneGap.includeJavascript = function(jsfile, successCallback) {
|
||||
Cordova.includeJavascript = function(jsfile, successCallback) {
|
||||
var id = document.getElementsByTagName("head")[0];
|
||||
var el = document.createElement('script');
|
||||
el.type = 'text/javascript';
|
||||
@@ -919,4 +917,8 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) {
|
||||
id.appendChild(el);
|
||||
};
|
||||
|
||||
/**
|
||||
* Legacy variable for old plugins.
|
||||
*/
|
||||
var PhoneGap = Cordova;
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
// TODO: Needs to be commented
|
||||
|
||||
if (!PhoneGap.hasResource("crypto")) {
|
||||
PhoneGap.addResource("crypto");
|
||||
if (!Cordova.hasResource("crypto")) {
|
||||
Cordova.addResource("crypto");
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -30,12 +30,12 @@ var Crypto = function() {
|
||||
|
||||
Crypto.prototype.encrypt = function(seed, string, callback) {
|
||||
this.encryptWin = callback;
|
||||
PhoneGap.exec(null, null, "Crypto", "encrypt", [seed, string]);
|
||||
Cordova.exec(null, null, "Crypto", "encrypt", [seed, string]);
|
||||
};
|
||||
|
||||
Crypto.prototype.decrypt = function(seed, string, callback) {
|
||||
this.decryptWin = callback;
|
||||
PhoneGap.exec(null, null, "Crypto", "decrypt", [seed, string]);
|
||||
Cordova.exec(null, null, "Crypto", "decrypt", [seed, string]);
|
||||
};
|
||||
|
||||
Crypto.prototype.gotCryptedString = function(string) {
|
||||
@@ -46,7 +46,7 @@ Crypto.prototype.getPlainString = function(string) {
|
||||
this.decryptWin(string);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.Crypto === "undefined") {
|
||||
navigator.Crypto = new Crypto();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("device")) {
|
||||
PhoneGap.addResource("device");
|
||||
if (!Cordova.hasResource("device")) {
|
||||
Cordova.addResource("device");
|
||||
|
||||
/**
|
||||
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
|
||||
@@ -26,12 +26,12 @@ PhoneGap.addResource("device");
|
||||
* @constructor
|
||||
*/
|
||||
var Device = function() {
|
||||
this.available = PhoneGap.available;
|
||||
this.available = Cordova.available;
|
||||
this.platform = null;
|
||||
this.version = null;
|
||||
this.name = null;
|
||||
this.uuid = null;
|
||||
this.phonegap = null;
|
||||
this.cordova = null;
|
||||
|
||||
var me = this;
|
||||
this.getInfo(
|
||||
@@ -41,13 +41,13 @@ var Device = function() {
|
||||
me.version = info.version;
|
||||
me.name = info.name;
|
||||
me.uuid = info.uuid;
|
||||
me.phonegap = info.phonegap;
|
||||
PhoneGap.onPhoneGapInfoReady.fire();
|
||||
me.cordova = info.cordova;
|
||||
Cordova.onCordovaInfoReady.fire();
|
||||
},
|
||||
function(e) {
|
||||
me.available = false;
|
||||
console.log("Error initializing PhoneGap: " + e);
|
||||
alert("Error initializing PhoneGap: "+e);
|
||||
console.log("Error initializing Cordova: " + e);
|
||||
alert("Error initializing Cordova: "+e);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -72,43 +72,10 @@ Device.prototype.getInfo = function(successCallback, errorCallback) {
|
||||
}
|
||||
|
||||
// Get info
|
||||
PhoneGap.exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
|
||||
Cordova.exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
|
||||
};
|
||||
|
||||
/*
|
||||
* DEPRECATED
|
||||
* This is only for Android.
|
||||
*
|
||||
* You must explicitly override the back button.
|
||||
*/
|
||||
Device.prototype.overrideBackButton = function() {
|
||||
console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true).");
|
||||
navigator.app.overrideBackbutton(true);
|
||||
};
|
||||
|
||||
/*
|
||||
* DEPRECATED
|
||||
* This is only for Android.
|
||||
*
|
||||
* This resets the back button to the default behaviour
|
||||
*/
|
||||
Device.prototype.resetBackButton = function() {
|
||||
console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false).");
|
||||
navigator.app.overrideBackbutton(false);
|
||||
};
|
||||
|
||||
/*
|
||||
* DEPRECATED
|
||||
* This is only for Android.
|
||||
*
|
||||
* This terminates the activity!
|
||||
*/
|
||||
Device.prototype.exitApp = function() {
|
||||
console.log("Device.exitApp() is deprecated. Use App.exitApp().");
|
||||
navigator.app.exitApp();
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.device === "undefined") {
|
||||
navigator.device = window.device = new Device();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("file")) {
|
||||
PhoneGap.addResource("file");
|
||||
if (!Cordova.hasResource("file")) {
|
||||
Cordova.addResource("file");
|
||||
|
||||
/**
|
||||
* This class provides some useful information about a file.
|
||||
@@ -162,7 +162,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
||||
var me = this;
|
||||
|
||||
// Read file
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
@@ -241,7 +241,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
||||
var me = this;
|
||||
|
||||
// Read file
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
@@ -412,7 +412,7 @@ FileWriter.prototype.write = function(text) {
|
||||
}
|
||||
|
||||
// Write file
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
@@ -523,7 +523,7 @@ FileWriter.prototype.truncate = function(size) {
|
||||
}
|
||||
|
||||
// Write file
|
||||
PhoneGap.exec(
|
||||
Cordova.exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
@@ -624,7 +624,25 @@ var DirectoryReader = function(fullPath){
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "readEntries", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
var retVal = [];
|
||||
for (var i=0; i<result.length; i++) {
|
||||
var entry = null;
|
||||
if (result[i].isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result[i].isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result[i].isDirectory;
|
||||
entry.isFile = result[i].isFile;
|
||||
entry.name = result[i].name;
|
||||
entry.fullPath = result[i].fullPath;
|
||||
retVal.push(entry);
|
||||
}
|
||||
successCallback(retVal);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "readEntries", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -654,7 +672,21 @@ var DirectoryEntry = function() {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -664,7 +696,11 @@ DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, err
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
result.modificationTime = new Date(result.modificationTime);
|
||||
successCallback(result);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -674,7 +710,16 @@ DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback)
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getParent", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
entry = new DirectoryEntry();
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -686,7 +731,21 @@ DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -696,7 +755,7 @@ DirectoryEntry.prototype.moveTo = function(parent, newName, successCallback, err
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.remove = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
|
||||
Cordova.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -725,7 +784,16 @@ DirectoryEntry.prototype.createReader = function(successCallback, errorCallback)
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
entry = new DirectoryEntry();
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -737,7 +805,16 @@ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback,
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getFile", [this.fullPath, path, options]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
entry = new FileEntry();
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getFile", [this.fullPath, path, options]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -747,7 +824,7 @@ DirectoryEntry.prototype.getFile = function(path, options, successCallback, erro
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
|
||||
Cordova.exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -777,7 +854,21 @@ var FileEntry = function() {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -787,7 +878,11 @@ FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCal
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
result.modificationTime = new Date(result.modificationTime);
|
||||
successCallback(result);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -797,7 +892,16 @@ FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getParent", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
entry = new DirectoryEntry();
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -809,7 +913,21 @@ FileEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -819,7 +937,7 @@ FileEntry.prototype.moveTo = function(parent, newName, successCallback, errorCal
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.remove = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
|
||||
Cordova.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -863,7 +981,16 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
||||
var win = function(result) {
|
||||
var file = new File();
|
||||
file.size = result.size;
|
||||
file.type = result.type;
|
||||
file.name = result.name;
|
||||
file.fullPath = result.fullPath;
|
||||
file.lastModifiedDate = new Date(result.lastModifiedDate);
|
||||
successCallback(file);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
||||
};
|
||||
|
||||
/** @constructor */
|
||||
@@ -892,7 +1019,20 @@ LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallba
|
||||
}
|
||||
}
|
||||
else {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]);
|
||||
var win = function(result){
|
||||
console.log("in win of requestFileSystem");
|
||||
console.log("Result: " + JSON.stringify(result));
|
||||
var entry = null;
|
||||
entry = new DirectoryEntry();
|
||||
entry.isDirectory = result.root.isDirectory;
|
||||
entry.isFile = result.root.isFile;
|
||||
entry.name = result.root.name;
|
||||
entry.fullPath = result.root.fullPath;
|
||||
result.root = entry;
|
||||
successCallback(result);
|
||||
};
|
||||
console.log("about to call requestFileSystem");
|
||||
Cordova.exec(win, errorCallback, "File", "requestFileSystem", [type, size]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -903,94 +1043,30 @@ LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallba
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
||||
};
|
||||
|
||||
/**
|
||||
* This function returns and array of contacts. It is required as we need to convert raw
|
||||
* JSON objects into concrete Contact objects. Currently this method is called after
|
||||
* navigator.service.contacts.find but before the find methods success call back.
|
||||
*
|
||||
* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects.
|
||||
* @returns an entry
|
||||
*/
|
||||
LocalFileSystem.prototype._castFS = function(pluginResult) {
|
||||
var entry = null;
|
||||
entry = new DirectoryEntry();
|
||||
entry.isDirectory = pluginResult.message.root.isDirectory;
|
||||
entry.isFile = pluginResult.message.root.isFile;
|
||||
entry.name = pluginResult.message.root.name;
|
||||
entry.fullPath = pluginResult.message.root.fullPath;
|
||||
pluginResult.message.root = entry;
|
||||
return pluginResult;
|
||||
};
|
||||
|
||||
LocalFileSystem.prototype._castEntry = function(pluginResult) {
|
||||
var entry = null;
|
||||
if (pluginResult.message.isDirectory) {
|
||||
console.log("This is a dir");
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (pluginResult.message.isFile) {
|
||||
console.log("This is a file");
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = pluginResult.message.isDirectory;
|
||||
entry.isFile = pluginResult.message.isFile;
|
||||
entry.name = pluginResult.message.name;
|
||||
entry.fullPath = pluginResult.message.fullPath;
|
||||
pluginResult.message = entry;
|
||||
return pluginResult;
|
||||
};
|
||||
|
||||
LocalFileSystem.prototype._castEntries = function(pluginResult) {
|
||||
var entries = pluginResult.message;
|
||||
var retVal = [];
|
||||
for (var i=0; i<entries.length; i++) {
|
||||
retVal.push(window.localFileSystem._createEntry(entries[i]));
|
||||
}
|
||||
pluginResult.message = retVal;
|
||||
return pluginResult;
|
||||
};
|
||||
|
||||
LocalFileSystem.prototype._createEntry = function(castMe) {
|
||||
var entry = null;
|
||||
if (castMe.isDirectory) {
|
||||
console.log("This is a dir");
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (castMe.isFile) {
|
||||
console.log("This is a file");
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = castMe.isDirectory;
|
||||
entry.isFile = castMe.isFile;
|
||||
entry.name = castMe.name;
|
||||
entry.fullPath = castMe.fullPath;
|
||||
return entry;
|
||||
};
|
||||
|
||||
LocalFileSystem.prototype._castDate = function(pluginResult) {
|
||||
if (pluginResult.message.modificationTime) {
|
||||
var modTime = new Date(pluginResult.message.modificationTime);
|
||||
pluginResult.message.modificationTime = modTime;
|
||||
}
|
||||
else if (pluginResult.message.lastModifiedDate) {
|
||||
var file = new File();
|
||||
file.size = pluginResult.message.size;
|
||||
file.type = pluginResult.message.type;
|
||||
file.name = pluginResult.message.name;
|
||||
file.fullPath = pluginResult.message.fullPath;
|
||||
file.lastModifiedDate = new Date(pluginResult.message.lastModifiedDate);
|
||||
pluginResult.message = file;
|
||||
}
|
||||
return pluginResult;
|
||||
var win = function(result) {
|
||||
console.log("in win of resolveLocalFileSystemURI");
|
||||
console.log("Result: " + JSON.stringify(result));
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
console.log("about to call resolveLocalFileSystemURI");
|
||||
Cordova.exec(win, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add the FileSystem interface into the browser.
|
||||
*/
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
var pgLocalFileSystem = new LocalFileSystem();
|
||||
// Needed for cast methods
|
||||
if (typeof window.localFileSystem === "undefined") {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("filetransfer")) {
|
||||
PhoneGap.addResource("filetransfer");
|
||||
if (!Cordova.hasResource("filetransfer")) {
|
||||
Cordova.addResource("filetransfer");
|
||||
|
||||
/**
|
||||
* FileTransfer uploads a file to a remote server.
|
||||
@@ -80,7 +80,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, debug, chunkedMode]);
|
||||
Cordova.exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, debug, chunkedMode]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,21 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
||||
* @param errorCallback {Function} Callback to be invoked upon error
|
||||
*/
|
||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) {
|
||||
PhoneGap.exec(successCallback, errorCallback, 'FileTransfer', 'download', [source, target]);
|
||||
var win = function(result) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new DirectoryEntry();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new FileEntry();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
successCallback(entry);
|
||||
};
|
||||
Cordova.exec(win, errorCallback, 'FileTransfer', 'download', [source, target]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("geolocation")) {
|
||||
PhoneGap.addResource("geolocation");
|
||||
if (!Cordova.hasResource("geolocation")) {
|
||||
Cordova.addResource("geolocation");
|
||||
|
||||
/**
|
||||
* This class provides access to device GPS data.
|
||||
@@ -80,7 +80,7 @@ Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallba
|
||||
}
|
||||
}
|
||||
navigator._geo.listeners.global = {"success" : successCallback, "fail" : errorCallback };
|
||||
PhoneGap.exec(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
|
||||
Cordova.exec(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -110,9 +110,9 @@ Geolocation.prototype.watchPosition = function(successCallback, errorCallback, o
|
||||
timeout = options.timeout;
|
||||
}
|
||||
}
|
||||
var id = PhoneGap.createUUID();
|
||||
var id = Cordova.createUUID();
|
||||
navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
|
||||
PhoneGap.exec(null, null, "Geolocation", "start", [id, enableHighAccuracy, timeout, maximumAge]);
|
||||
Cordova.exec(null, null, "Geolocation", "start", [id, enableHighAccuracy, timeout, maximumAge]);
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -173,19 +173,19 @@ Geolocation.prototype.fail = function(id, code, msg) {
|
||||
* @param {String} id The ID of the watch returned from #watchPosition
|
||||
*/
|
||||
Geolocation.prototype.clearWatch = function(id) {
|
||||
PhoneGap.exec(null, null, "Geolocation", "stop", [id]);
|
||||
Cordova.exec(null, null, "Geolocation", "stop", [id]);
|
||||
delete navigator._geo.listeners[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Force the PhoneGap geolocation to be used instead of built-in.
|
||||
* Force the Cordova geolocation to be used instead of built-in.
|
||||
*/
|
||||
Geolocation.usingPhoneGap = false;
|
||||
Geolocation.usePhoneGap = function() {
|
||||
if (Geolocation.usingPhoneGap) {
|
||||
Geolocation.usingCordova = false;
|
||||
Geolocation.useCordova = function() {
|
||||
if (Geolocation.usingCordova) {
|
||||
return;
|
||||
}
|
||||
Geolocation.usingPhoneGap = true;
|
||||
Geolocation.usingCordova = true;
|
||||
|
||||
// Set built-in geolocation methods to our own implementations
|
||||
// (Cannot replace entire geolocation, but can replace individual methods)
|
||||
@@ -197,13 +197,13 @@ Geolocation.usePhoneGap = function() {
|
||||
navigator.geolocation.stop = navigator._geo.stop;
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
navigator._geo = new Geolocation();
|
||||
|
||||
// No native geolocation object for Android 1.x, so use PhoneGap geolocation
|
||||
// No native geolocation object for Android 1.x, so use Cordova geolocation
|
||||
if (typeof navigator.geolocation === 'undefined') {
|
||||
navigator.geolocation = navigator._geo;
|
||||
Geolocation.usingPhoneGap = true;
|
||||
Geolocation.usingCordova = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("media")) {
|
||||
PhoneGap.addResource("media");
|
||||
if (!Cordova.hasResource("media")) {
|
||||
Cordova.addResource("media");
|
||||
|
||||
/**
|
||||
* This class provides access to the device media, interfaces to both sound and video
|
||||
@@ -60,8 +60,8 @@ var Media = function(src, successCallback, errorCallback, statusCallback, positi
|
||||
return;
|
||||
}
|
||||
|
||||
this.id = PhoneGap.createUUID();
|
||||
PhoneGap.mediaObjects[this.id] = this;
|
||||
this.id = Cordova.createUUID();
|
||||
Cordova.mediaObjects[this.id] = this;
|
||||
this.src = src;
|
||||
this.successCallback = successCallback;
|
||||
this.errorCallback = errorCallback;
|
||||
@@ -105,28 +105,28 @@ MediaError.MEDIA_ERR_NONE_SUPPORTED = 4;
|
||||
* Start or resume playing audio file.
|
||||
*/
|
||||
Media.prototype.play = function() {
|
||||
PhoneGap.exec(null, null, "Media", "startPlayingAudio", [this.id, this.src]);
|
||||
Cordova.exec(null, null, "Media", "startPlayingAudio", [this.id, this.src]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop playing audio file.
|
||||
*/
|
||||
Media.prototype.stop = function() {
|
||||
return PhoneGap.exec(null, null, "Media", "stopPlayingAudio", [this.id]);
|
||||
return Cordova.exec(null, null, "Media", "stopPlayingAudio", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Seek or jump to a new time in the track..
|
||||
*/
|
||||
Media.prototype.seekTo = function(milliseconds) {
|
||||
PhoneGap.exec(null, null, "Media", "seekToAudio", [this.id, milliseconds]);
|
||||
Cordova.exec(null, null, "Media", "seekToAudio", [this.id, milliseconds]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Pause playing audio file.
|
||||
*/
|
||||
Media.prototype.pause = function() {
|
||||
PhoneGap.exec(null, null, "Media", "pausePlayingAudio", [this.id]);
|
||||
Cordova.exec(null, null, "Media", "pausePlayingAudio", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -143,49 +143,49 @@ Media.prototype.getDuration = function() {
|
||||
* Get position of audio.
|
||||
*/
|
||||
Media.prototype.getCurrentPosition = function(success, fail) {
|
||||
PhoneGap.exec(success, fail, "Media", "getCurrentPositionAudio", [this.id]);
|
||||
Cordova.exec(success, fail, "Media", "getCurrentPositionAudio", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Start recording audio file.
|
||||
*/
|
||||
Media.prototype.startRecord = function() {
|
||||
PhoneGap.exec(null, null, "Media", "startRecordingAudio", [this.id, this.src]);
|
||||
Cordova.exec(null, null, "Media", "startRecordingAudio", [this.id, this.src]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop recording audio file.
|
||||
*/
|
||||
Media.prototype.stopRecord = function() {
|
||||
PhoneGap.exec(null, null, "Media", "stopRecordingAudio", [this.id]);
|
||||
Cordova.exec(null, null, "Media", "stopRecordingAudio", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Release the resources.
|
||||
*/
|
||||
Media.prototype.release = function() {
|
||||
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
||||
Cordova.exec(null, null, "Media", "release", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust the volume.
|
||||
*/
|
||||
Media.prototype.setVolume = function(volume) {
|
||||
PhoneGap.exec(null, null, "Media", "setVolume", [this.id, volume]);
|
||||
Cordova.exec(null, null, "Media", "setVolume", [this.id, volume]);
|
||||
};
|
||||
|
||||
/**
|
||||
* List of media objects.
|
||||
* PRIVATE
|
||||
*/
|
||||
PhoneGap.mediaObjects = {};
|
||||
Cordova.mediaObjects = {};
|
||||
|
||||
/**
|
||||
* Object that receives native callbacks.
|
||||
* PRIVATE
|
||||
* @constructor
|
||||
*/
|
||||
PhoneGap.Media = function() {};
|
||||
Cordova.Media = function() {};
|
||||
|
||||
/**
|
||||
* Get the media object.
|
||||
@@ -193,8 +193,8 @@ PhoneGap.Media = function() {};
|
||||
*
|
||||
* @param id The media object id (string)
|
||||
*/
|
||||
PhoneGap.Media.getMediaObject = function(id) {
|
||||
return PhoneGap.mediaObjects[id];
|
||||
Cordova.Media.getMediaObject = function(id) {
|
||||
return Cordova.mediaObjects[id];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -205,8 +205,8 @@ PhoneGap.Media.getMediaObject = function(id) {
|
||||
* @param status The status code (int)
|
||||
* @param msg The status message (string)
|
||||
*/
|
||||
PhoneGap.Media.onStatus = function(id, msg, value) {
|
||||
var media = PhoneGap.mediaObjects[id];
|
||||
Cordova.Media.onStatus = function(id, msg, value) {
|
||||
var media = Cordova.mediaObjects[id];
|
||||
// If state update
|
||||
if (msg === Media.MEDIA_STATE) {
|
||||
if (value === Media.MEDIA_STOPPED) {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
|
||||
if (!PhoneGap.hasResource("network")) {
|
||||
PhoneGap.addResource("network");
|
||||
if (!Cordova.hasResource("network")) {
|
||||
Cordova.addResource("network");
|
||||
|
||||
/**
|
||||
* This class contains information about the current network Connection.
|
||||
@@ -39,7 +39,7 @@ var Connection = function() {
|
||||
// set a timer if still offline at the end of timer send the offline event
|
||||
me._timer = setTimeout(function(){
|
||||
me.type = type;
|
||||
PhoneGap.fireDocumentEvent('offline');
|
||||
Cordova.fireDocumentEvent('offline');
|
||||
me._timer = null;
|
||||
}, me.timeout);
|
||||
} else {
|
||||
@@ -49,21 +49,21 @@ var Connection = function() {
|
||||
me._timer = null;
|
||||
}
|
||||
me.type = type;
|
||||
PhoneGap.fireDocumentEvent('online');
|
||||
Cordova.fireDocumentEvent('online');
|
||||
}
|
||||
|
||||
// should only fire this once
|
||||
if (me._firstRun) {
|
||||
me._firstRun = false;
|
||||
PhoneGap.onPhoneGapConnectionReady.fire();
|
||||
Cordova.onCordovaConnectionReady.fire();
|
||||
}
|
||||
},
|
||||
function(e) {
|
||||
// If we can't get the network info we should still tell PhoneGap
|
||||
// If we can't get the network info we should still tell Cordova
|
||||
// to fire the deviceready event.
|
||||
if (me._firstRun) {
|
||||
me._firstRun = false;
|
||||
PhoneGap.onPhoneGapConnectionReady.fire();
|
||||
Cordova.onCordovaConnectionReady.fire();
|
||||
}
|
||||
console.log("Error initializing Network Connection: " + e);
|
||||
});
|
||||
@@ -85,11 +85,11 @@ Connection.NONE = "none";
|
||||
*/
|
||||
Connection.prototype.getInfo = function(successCallback, errorCallback) {
|
||||
// Get info
|
||||
PhoneGap.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
|
||||
Cordova.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
|
||||
};
|
||||
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.network === "undefined") {
|
||||
navigator.network = {};
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("notification")) {
|
||||
PhoneGap.addResource("notification");
|
||||
if (!Cordova.hasResource("notification")) {
|
||||
Cordova.addResource("notification");
|
||||
|
||||
/**
|
||||
* This class provides access to notifications on the device.
|
||||
@@ -38,7 +38,7 @@ var Notification = function() {
|
||||
Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
|
||||
var _title = (title || "Alert");
|
||||
var _buttonLabel = (buttonLabel || "OK");
|
||||
PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
||||
Cordova.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -53,21 +53,21 @@ Notification.prototype.alert = function(message, completeCallback, title, button
|
||||
Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) {
|
||||
var _title = (title || "Confirm");
|
||||
var _buttonLabels = (buttonLabels || "OK,Cancel");
|
||||
PhoneGap.exec(resultCallback, null, "Notification", "confirm", [message,_title,_buttonLabels]);
|
||||
Cordova.exec(resultCallback, null, "Notification", "confirm", [message,_title,_buttonLabels]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Start spinning the activity indicator on the statusbar
|
||||
*/
|
||||
Notification.prototype.activityStart = function() {
|
||||
PhoneGap.exec(null, null, "Notification", "activityStart", ["Busy","Please wait..."]);
|
||||
Cordova.exec(null, null, "Notification", "activityStart", ["Busy","Please wait..."]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop spinning the activity indicator on the statusbar, if it's currently spinning
|
||||
*/
|
||||
Notification.prototype.activityStop = function() {
|
||||
PhoneGap.exec(null, null, "Notification", "activityStop", []);
|
||||
Cordova.exec(null, null, "Notification", "activityStop", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ Notification.prototype.activityStop = function() {
|
||||
* @param {String} message Message to display in the dialog.
|
||||
*/
|
||||
Notification.prototype.progressStart = function(title, message) {
|
||||
PhoneGap.exec(null, null, "Notification", "progressStart", [title, message]);
|
||||
Cordova.exec(null, null, "Notification", "progressStart", [title, message]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -86,14 +86,14 @@ Notification.prototype.progressStart = function(title, message) {
|
||||
* @param {Number} value 0-100
|
||||
*/
|
||||
Notification.prototype.progressValue = function(value) {
|
||||
PhoneGap.exec(null, null, "Notification", "progressValue", [value]);
|
||||
Cordova.exec(null, null, "Notification", "progressValue", [value]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the progress dialog.
|
||||
*/
|
||||
Notification.prototype.progressStop = function() {
|
||||
PhoneGap.exec(null, null, "Notification", "progressStop", []);
|
||||
Cordova.exec(null, null, "Notification", "progressStop", []);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ Notification.prototype.blink = function(count, colour) {
|
||||
* @param {Integer} mills The number of milliseconds to vibrate for.
|
||||
*/
|
||||
Notification.prototype.vibrate = function(mills) {
|
||||
PhoneGap.exec(null, null, "Notification", "vibrate", [mills]);
|
||||
Cordova.exec(null, null, "Notification", "vibrate", [mills]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -122,10 +122,10 @@ Notification.prototype.vibrate = function(mills) {
|
||||
* @param {Integer} count The number of beeps.
|
||||
*/
|
||||
Notification.prototype.beep = function(count) {
|
||||
PhoneGap.exec(null, null, "Notification", "beep", [count]);
|
||||
Cordova.exec(null, null, "Notification", "beep", [count]);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
if (typeof navigator.notification === "undefined") {
|
||||
navigator.notification = new Notification();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("position")) {
|
||||
PhoneGap.addResource("position");
|
||||
if (!Cordova.hasResource("position")) {
|
||||
Cordova.addResource("position");
|
||||
|
||||
/**
|
||||
* This class contains position information.
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
* most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("storage")) {
|
||||
PhoneGap.addResource("storage");
|
||||
if (!Cordova.hasResource("storage")) {
|
||||
Cordova.addResource("storage");
|
||||
|
||||
/**
|
||||
* SQL result set object
|
||||
@@ -153,7 +153,7 @@ DroidDB.prototype.fail = function(reason, id) {
|
||||
var DroidDB_Query = function(tx) {
|
||||
|
||||
// Set the id of the query
|
||||
this.id = PhoneGap.createUUID();
|
||||
this.id = Cordova.createUUID();
|
||||
|
||||
// Add this query to the queue
|
||||
droiddb.queryQueue[this.id] = this;
|
||||
@@ -181,7 +181,7 @@ var DroidDB_Query = function(tx) {
|
||||
var DroidDB_Tx = function() {
|
||||
|
||||
// Set the id of the transaction
|
||||
this.id = PhoneGap.createUUID();
|
||||
this.id = Cordova.createUUID();
|
||||
|
||||
// Callbacks
|
||||
this.successCallback = null;
|
||||
@@ -266,7 +266,7 @@ DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCa
|
||||
query.errorCallback = errorCallback;
|
||||
|
||||
// Call native code
|
||||
PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
|
||||
Cordova.exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
|
||||
};
|
||||
|
||||
var DatabaseShell = function() {
|
||||
@@ -308,7 +308,7 @@ DatabaseShell.prototype.transaction = function(process, errorCallback, successCa
|
||||
* @return Database object
|
||||
*/
|
||||
var DroidDB_openDatabase = function(name, version, display_name, size) {
|
||||
PhoneGap.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
|
||||
Cordova.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
|
||||
var db = new DatabaseShell();
|
||||
return db;
|
||||
};
|
||||
@@ -340,7 +340,7 @@ var CupcakeLocalStorage = function() {
|
||||
storage[result.rows.item(i)['id']] = result.rows.item(i)['body'];
|
||||
}
|
||||
setLength(result.rows.length);
|
||||
PhoneGap.initializationComplete("cupcakeStorage");
|
||||
Cordova.initializationComplete("cupcakeStorage");
|
||||
});
|
||||
|
||||
},
|
||||
@@ -401,7 +401,7 @@ var CupcakeLocalStorage = function() {
|
||||
}
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
Cordova.addConstructor(function() {
|
||||
var setupDroidDB = function() {
|
||||
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
||||
window.droiddb = new DroidDB();
|
||||
@@ -433,7 +433,7 @@ PhoneGap.addConstructor(function() {
|
||||
|
||||
if ((typeof window.localStorage == "undefined") || (window.localStorage == null)) {
|
||||
navigator.localStorage = window.localStorage = new CupcakeLocalStorage();
|
||||
PhoneGap.waitForInitialization("cupcakeStorage");
|
||||
Cordova.waitForInitialization("cupcakeStorage");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="phonegap-1.3.0rc2.js"></script>
|
||||
<script src="cordova-1.5.0.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="PhoneGap" default="jar">
|
||||
<!--
|
||||
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 name="Cordova" default="jar">
|
||||
|
||||
<!-- LOAD VERSION -->
|
||||
<loadfile property="version" srcFile="../VERSION">
|
||||
@@ -92,15 +110,16 @@
|
||||
|
||||
|
||||
<target name="check-javascript" depends="build-javascript">
|
||||
<!--
|
||||
<delete dir="assets/lib"/>
|
||||
<mkdir dir="assets/lib"/>
|
||||
<echo file="assets/lib/lint.js">var alert=function(){},device={},Element={},debug={};</echo>
|
||||
<concat destfile="assets/lib/phonegap-lint.js" append="true">
|
||||
<concat destfile="assets/lib/cordova-lint.js" append="true">
|
||||
<fileset dir="assets/lib">
|
||||
<include name="lint.js" />
|
||||
</fileset>
|
||||
<fileset dir="assets/www">
|
||||
<include name="phonegap-${version}.js" />
|
||||
<include name="cordova-${version}.js" />
|
||||
</fileset>
|
||||
</concat>
|
||||
|
||||
@@ -111,54 +130,87 @@
|
||||
<arg value="${basedir}/util/js.jar"/>
|
||||
<arg value="org.mozilla.javascript.tools.shell.Main"/>
|
||||
<arg value="${basedir}/util/jslint.js"/>
|
||||
<arg value="${basedir}/js/lib/phonegap-lint.js"/>
|
||||
<arg value="${basedir}/js/lib/cordova-lint.js"/>
|
||||
</exec>
|
||||
<exec executable="java" os="Mac OS X">
|
||||
<arg value="-cp"/>
|
||||
<arg value="../util/js.jar"/>
|
||||
<arg value="org.mozilla.javascript.tools.shell.Main"/>
|
||||
<arg value="../util/jslint.js"/>
|
||||
<arg value="assets/lib/phonegap-lint.js"/>
|
||||
<arg value="assets/lib/cordova-lint.js"/>
|
||||
</exec>
|
||||
-->
|
||||
</target>
|
||||
|
||||
<!-- Combine JavaScript files into one phonegap-uncompressed.js file. -->
|
||||
<target name="build-javascript">
|
||||
<!-- Combine JavaScript files into one cordova-uncompressed.js file. -->
|
||||
<target name="build-javascript" depends="clean">
|
||||
|
||||
<!-- Clean up existing files -->
|
||||
<!--<delete file="assets/www/phonegap_${version}.js"/>-->
|
||||
<!--<delete file="assets/www/cordova_${version}.js"/>-->
|
||||
|
||||
<!-- Create uncompressed JS file -->
|
||||
<concat destfile="assets/www/phonegap-${version}.js">
|
||||
<filelist dir="assets/js" files="phonegap.js.base,device.js"/>
|
||||
<fileset dir="assets/js" includes="*.js" excludes="phonegap.js.base,device.js"/>
|
||||
<concat destfile="assets/www/cordova-${version}.js">
|
||||
<filelist dir="assets/js" files="cordova.android.js"/>
|
||||
<!--
|
||||
<filelist dir="assets/js" files="cordova.js.base,device.js"/>
|
||||
<fileset dir="assets/js" includes="*.js" excludes="cordova.js.base,device.js"/>
|
||||
-->
|
||||
</concat>
|
||||
|
||||
<!-- update project files to reference phonegap-x.x.x.min.js -->
|
||||
<replaceregexp match="phonegap(.*)\.js" replace="phonegap-${version}.js" byline="true">
|
||||
<!-- update project files to reference cordova-x.x.x.min.js -->
|
||||
<replaceregexp match="cordova(.*)\.js" replace="cordova-${version}.js" byline="true">
|
||||
<fileset file="assets/www/index.html" />
|
||||
<!-- <fileset file="../bin/templates/project/assets/www/index.html" /> -->
|
||||
</replaceregexp>
|
||||
<!-- This is sketchy, but it works, ${dblQuote} does not -->
|
||||
<replaceregexp match="phonegapVersion = [\u0022].*[\u0022];" replace='phonegapVersion = ${dblQuote}${version}${dblQuote};' byline="true">
|
||||
<fileset file="src/com/phonegap/Device.java" />
|
||||
<replaceregexp match="cordovaVersion = [\u0022].*[\u0022];" replace='cordovaVersion = ${dblQuote}${version}${dblQuote};' byline="true">
|
||||
<fileset file="src/org/apache/cordova/Device.java" />
|
||||
</replaceregexp>
|
||||
|
||||
<!-- Delete temp file -->
|
||||
<!--<delete file="assets/www/phonegap-tmp.js"/>-->
|
||||
<!--<delete file="assets/www/cordova-tmp.js"/>-->
|
||||
</target>
|
||||
|
||||
<!-- Build PhoneGap jar file that includes all native code, and PhoneGap JS file
|
||||
<!-- Build Cordova jar file that includes all native code, and Cordova JS file
|
||||
that includes all JavaScript code.
|
||||
-->
|
||||
<target name="jar" depends="build-javascript, -compile">
|
||||
<jar jarfile="phonegap-${version}.jar" basedir="bin/classes" excludes="com/phonegap/R.class,com/phonegap/R$*.class"/>
|
||||
<jar jarfile="cordova-${version}.jar" basedir="bin/classes" excludes="org/apache/cordova/R.class,org/apache/cordova/R$*.class"/>
|
||||
</target>
|
||||
|
||||
<target name="phonegap_debug" depends="build-javascript, debug">
|
||||
<!-- tests for Java files -->
|
||||
<property name="test.dir" location="test/org/apache/cordova" />
|
||||
|
||||
<path id="test.classpath">
|
||||
<!-- requires both junit and cordova -->
|
||||
<pathelement location="libs/junit-4.10.jar" />
|
||||
<pathelement location="cordova-${version}.jar" />
|
||||
<pathelement location="${test.dir}" />
|
||||
</path>
|
||||
|
||||
<target name="compile-test">
|
||||
<javac srcdir="${test.dir}" >
|
||||
<classpath refid="test.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="phonegap_release" depends="build-javascript, release">
|
||||
<target name="test" depends="jar, compile-test">
|
||||
<junit showoutput="true">
|
||||
<classpath refid="test.classpath" />
|
||||
<formatter type="brief" usefile="false" />
|
||||
<batchtest fork="yes">
|
||||
<fileset dir="${test.dir}">
|
||||
<include name="*Test.java" />
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="cordova_debug" depends="build-javascript, debug">
|
||||
</target>
|
||||
|
||||
<target name="cordova_release" depends="build-javascript, release">
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
<?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.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name">PhoneGap</string>
|
||||
<string name="app_name">Cordova</string>
|
||||
<string name="go">Snap</string>
|
||||
</resources>
|
||||
|
||||
37
framework/res/xml/cordova.xml
Normal file
37
framework/res/xml/cordova.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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.
|
||||
-->
|
||||
<cordova>
|
||||
<!--
|
||||
access elements control the Android whitelist.
|
||||
Domains are assumed blocked unless set otherwise
|
||||
-->
|
||||
|
||||
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
|
||||
|
||||
<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
|
||||
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
|
||||
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->
|
||||
|
||||
<log level="DEBUG"/>
|
||||
<preference name="classicRender" value="true" />
|
||||
</cordova>
|
||||
|
||||
|
||||
|
||||
50
framework/res/xml/plugins.xml
Normal file → Executable file
50
framework/res/xml/plugins.xml
Normal file → Executable file
@@ -1,19 +1,37 @@
|
||||
<?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.
|
||||
-->
|
||||
<plugins>
|
||||
<plugin name="App" value="com.phonegap.App"/>
|
||||
<plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
|
||||
<plugin name="Device" value="com.phonegap.Device"/>
|
||||
<plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
|
||||
<plugin name="Compass" value="com.phonegap.CompassListener"/>
|
||||
<plugin name="Media" value="com.phonegap.AudioHandler"/>
|
||||
<plugin name="Camera" value="com.phonegap.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="com.phonegap.ContactManager"/>
|
||||
<plugin name="File" value="com.phonegap.FileUtils"/>
|
||||
<plugin name="Network Status" value="com.phonegap.NetworkManager"/>
|
||||
<plugin name="Notification" value="com.phonegap.Notification"/>
|
||||
<plugin name="Storage" value="com.phonegap.Storage"/>
|
||||
<plugin name="Temperature" value="com.phonegap.TempListener"/>
|
||||
<plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
|
||||
<plugin name="Capture" value="com.phonegap.Capture"/>
|
||||
<plugin name="Battery" value="com.phonegap.BatteryListener"/>
|
||||
<plugin name="App" value="org.apache.cordova.App"/>
|
||||
<plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
|
||||
<plugin name="Device" value="org.apache.cordova.Device"/>
|
||||
<plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/>
|
||||
<plugin name="Compass" value="org.apache.cordova.CompassListener"/>
|
||||
<plugin name="Media" value="org.apache.cordova.AudioHandler"/>
|
||||
<plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="org.apache.cordova.ContactManager"/>
|
||||
<plugin name="File" value="org.apache.cordova.FileUtils"/>
|
||||
<plugin name="Network Status" value="org.apache.cordova.NetworkManager"/>
|
||||
<plugin name="Notification" value="org.apache.cordova.Notification"/>
|
||||
<plugin name="Storage" value="org.apache.cordova.Storage"/>
|
||||
<plugin name="Temperature" value="org.apache.cordova.TempListener"/>
|
||||
<plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
|
||||
<plugin name="Capture" value="org.apache.cordova.Capture"/>
|
||||
<plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
|
||||
</plugins>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.phonegap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class GapView extends WebView {
|
||||
|
||||
public GapView(Context context) {
|
||||
super(context);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
|
||||
{
|
||||
if(child.getClass() != EditText.class)
|
||||
super.attachViewToParent(child, index, params);
|
||||
else
|
||||
{
|
||||
super.attachViewToParent(child, index, params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
|
||||
{
|
||||
return super.addViewInLayout(child, index, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout)
|
||||
{
|
||||
return super.addViewInLayout(child, index, params);
|
||||
}
|
||||
}
|
||||
@@ -1,366 +0,0 @@
|
||||
/*
|
||||
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 com.phonegap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Vibrator;
|
||||
|
||||
/**
|
||||
* This class provides access to notifications on the device.
|
||||
*/
|
||||
public class Notification extends Plugin {
|
||||
|
||||
public int confirmResult = -1;
|
||||
public ProgressDialog spinnerDialog = null;
|
||||
public ProgressDialog progressDialog = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Notification() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("beep")) {
|
||||
this.beep(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("vibrate")) {
|
||||
this.vibrate(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("alert")) {
|
||||
this.alert(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
this.confirm(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
this.activityStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
this.activityStop();
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
this.progressStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
this.progressValue(args.getInt(0));
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
this.progressStop();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action) {
|
||||
if (action.equals("alert")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// LOCAL METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Beep plays the default notification ringtone.
|
||||
*
|
||||
* @param count Number of times to play notification
|
||||
*/
|
||||
public void beep(long count) {
|
||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);
|
||||
|
||||
// If phone is not set to silent mode
|
||||
if (notification != null) {
|
||||
for (long i = 0; i < count; ++i) {
|
||||
notification.play();
|
||||
long timeout = 5000;
|
||||
while (notification.isPlaying() && (timeout > 0)) {
|
||||
timeout = timeout - 100;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vibrates the device for the specified amount of time.
|
||||
*
|
||||
* @param time Time to vibrate in ms.
|
||||
*/
|
||||
public void vibrate(long time){
|
||||
// Start the vibration, 0 defaults to half a second.
|
||||
if (time == 0) {
|
||||
time = 500;
|
||||
}
|
||||
Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android alert with given Strings
|
||||
* @param message The message the alert should display
|
||||
* @param title The title of the alert
|
||||
* @param buttonLabel The label of the button
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||
|
||||
final PhonegapActivity ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
dlg.setPositiveButton(buttonLabel,
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 0), callbackId);
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android confirm dialog with given title, message, buttons.
|
||||
* This dialog only shows up to 3 buttons. Any labels after that will be ignored.
|
||||
* The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
|
||||
*
|
||||
* @param message The message the dialog should display
|
||||
* @param title The title of the dialog
|
||||
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||
|
||||
final PhonegapActivity ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
final String[] fButtons = buttonLabels.split(",");
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
|
||||
// First button
|
||||
if (fButtons.length > 0) {
|
||||
dlg.setPositiveButton(fButtons[0],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Second button
|
||||
if (fButtons.length > 1) {
|
||||
dlg.setNeutralButton(fButtons[1],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Third button
|
||||
if (fButtons.length > 2) {
|
||||
dlg.setNegativeButton(fButtons[2],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the spinner.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void activityStart(final String title, final String message) {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final PhonegapActivity ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true,
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.spinnerDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop spinner.
|
||||
*/
|
||||
public synchronized void activityStop() {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the progress dialog.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void progressStart(final String title, final String message) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final PhonegapActivity ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.progressDialog = new ProgressDialog(ctx);
|
||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
notification.progressDialog.setTitle(title);
|
||||
notification.progressDialog.setMessage(message);
|
||||
notification.progressDialog.setCancelable(true);
|
||||
notification.progressDialog.setMax(100);
|
||||
notification.progressDialog.setProgress(0);
|
||||
notification.progressDialog.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.progressDialog = null;
|
||||
}
|
||||
});
|
||||
notification.progressDialog.show();
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of progress bar.
|
||||
*
|
||||
* @param value 0-100
|
||||
*/
|
||||
public synchronized void progressValue(int value) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop progress dialog.
|
||||
*/
|
||||
public synchronized void progressStop() {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,99 +18,10 @@
|
||||
*/
|
||||
package com.phonegap.api;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import android.content.Intent;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
* Plugin interface must be implemented by any plugin classes.
|
||||
*
|
||||
* The execute method is called by the PluginManager.
|
||||
*/
|
||||
public interface IPlugin {
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
PluginResult execute(String action, JSONArray args, String callbackId);
|
||||
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setContext(PhonegapActivity ctx);
|
||||
|
||||
/**
|
||||
* Sets the main View of the application, this is the WebView within which
|
||||
* a PhoneGap app runs.
|
||||
*
|
||||
* @param webView The PhoneGap WebView
|
||||
*/
|
||||
void setView(WebView webView);
|
||||
|
||||
/**
|
||||
* Called when the system is about to start resuming a previous activity.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
void onPause(boolean multitasking);
|
||||
|
||||
/**
|
||||
* Called when the activity will start interacting with the user.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
void onResume(boolean multitasking);
|
||||
|
||||
/**
|
||||
* Called when the activity receives a new intent.
|
||||
*/
|
||||
void onNewIntent(Intent intent);
|
||||
|
||||
/**
|
||||
* The final call you receive before your activity is destroyed.
|
||||
*/
|
||||
void onDestroy();
|
||||
|
||||
/**
|
||||
* Called when a message is sent to plugin.
|
||||
*
|
||||
* @param id The message id
|
||||
* @param data The message data
|
||||
*/
|
||||
public void onMessage(String id, Object data);
|
||||
|
||||
/**
|
||||
* Called when an activity you launched exits, giving you the requestCode you started it with,
|
||||
* the resultCode it returned, and any additional data from it.
|
||||
*
|
||||
* @param requestCode The request code originally supplied to startActivityForResult(),
|
||||
* allowing you to identify who this result came from.
|
||||
* @param resultCode The integer result code returned by the child activity through its setResult().
|
||||
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||
*/
|
||||
void onActivityResult(int requestCode, int resultCode, Intent intent);
|
||||
|
||||
/**
|
||||
* By specifying a <url-filter> in plugins.xml you can map a URL (using startsWith atm) to this method.
|
||||
*
|
||||
* @param url The URL that is trying to be loaded in the PhoneGap webview.
|
||||
* @return Return true to prevent the URL from loading. Default is false.
|
||||
*/
|
||||
boolean onOverrideUrlLoading(String url);
|
||||
public interface IPlugin extends org.apache.cordova.api.IPlugin {
|
||||
}
|
||||
|
||||
@@ -18,217 +18,11 @@
|
||||
*/
|
||||
package com.phonegap.api;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Log to Android logging system.
|
||||
*
|
||||
* Log message can be a string or a printf formatted string with arguments.
|
||||
* See http://developer.android.com/reference/java/util/Formatter.html
|
||||
*/
|
||||
public class LOG {
|
||||
|
||||
public static final int VERBOSE = Log.VERBOSE;
|
||||
public static final int DEBUG = Log.DEBUG;
|
||||
public static final int INFO = Log.INFO;
|
||||
public static final int WARN = Log.WARN;
|
||||
public static final int ERROR = Log.ERROR;
|
||||
|
||||
// Current log level
|
||||
public static int LOGLEVEL = Log.ERROR;
|
||||
|
||||
/**
|
||||
* Set the current log level.
|
||||
*
|
||||
* @param logLevel
|
||||
*/
|
||||
public static void setLogLevel(int logLevel) {
|
||||
LOGLEVEL = logLevel;
|
||||
Log.i("PhoneGapLog", "Changing log level to " + logLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current log level.
|
||||
*
|
||||
* @param logLevel
|
||||
*/
|
||||
public static void setLogLevel(String logLevel) {
|
||||
if ("VERBOSE".equals(logLevel)) LOGLEVEL = VERBOSE;
|
||||
else if ("DEBUG".equals(logLevel)) LOGLEVEL = DEBUG;
|
||||
else if ("INFO".equals(logLevel)) LOGLEVEL = INFO;
|
||||
else if ("WARN".equals(logLevel)) LOGLEVEL = WARN;
|
||||
else if ("ERROR".equals(logLevel)) LOGLEVEL = ERROR;
|
||||
Log.i("PhoneGapLog", "Changing log level to " + logLevel + "(" + LOGLEVEL + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if log level will be logged
|
||||
*
|
||||
* @param logLevel
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLoggable(int logLevel) {
|
||||
return (logLevel >= LOGLEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verbose log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
*/
|
||||
public static void v(String tag, String s) {
|
||||
if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
*/
|
||||
public static void d(String tag, String s) {
|
||||
if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Info log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
*/
|
||||
public static void i(String tag, String s) {
|
||||
if (LOG.INFO >= LOGLEVEL) Log.i(tag, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
*/
|
||||
public static void w(String tag, String s) {
|
||||
if (LOG.WARN >= LOGLEVEL) Log.w(tag, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
*/
|
||||
public static void e(String tag, String s) {
|
||||
if (LOG.ERROR >= LOGLEVEL) Log.e(tag, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verbose log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param e
|
||||
*/
|
||||
public static void v(String tag, String s, Throwable e) {
|
||||
if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, s, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param e
|
||||
*/
|
||||
public static void d(String tag, String s, Throwable e) {
|
||||
if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, s, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Info log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param e
|
||||
*/
|
||||
public static void i(String tag, String s, Throwable e) {
|
||||
if (LOG.INFO >= LOGLEVEL) Log.i(tag, s, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param e
|
||||
*/
|
||||
public static void w(String tag, String s, Throwable e) {
|
||||
if (LOG.WARN >= LOGLEVEL) Log.w(tag, s, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error log message.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param e
|
||||
*/
|
||||
public static void e(String tag, String s, Throwable e) {
|
||||
if (LOG.ERROR >= LOGLEVEL) Log.e(tag, s, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verbose log message with printf formatting.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param args
|
||||
*/
|
||||
public static void v(String tag, String s, Object... args) {
|
||||
if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, String.format(s, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug log message with printf formatting.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param args
|
||||
*/
|
||||
public static void d(String tag, String s, Object... args) {
|
||||
if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, String.format(s, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Info log message with printf formatting.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param args
|
||||
*/
|
||||
public static void i(String tag, String s, Object... args) {
|
||||
if (LOG.INFO >= LOGLEVEL) Log.i(tag, String.format(s, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning log message with printf formatting.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param args
|
||||
*/
|
||||
public static void w(String tag, String s, Object... args) {
|
||||
if (LOG.WARN >= LOGLEVEL) Log.w(tag, String.format(s, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error log message with printf formatting.
|
||||
*
|
||||
* @param tag
|
||||
* @param s
|
||||
* @param args
|
||||
*/
|
||||
public static void e(String tag, String s, Object... args) {
|
||||
if (LOG.ERROR >= LOGLEVEL) Log.e(tag, String.format(s, args));
|
||||
}
|
||||
|
||||
public class LOG extends org.apache.cordova.api.LOG {
|
||||
}
|
||||
|
||||
@@ -19,62 +19,10 @@
|
||||
package com.phonegap.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* The Phonegap activity abstract class that is extended by DroidGap.
|
||||
* It is used to isolate plugin development, and remove dependency on entire Phonegap library.
|
||||
* The Cordova activity abstract class that is extended by DroidGap.
|
||||
* It is used to isolate plugin development, and remove dependency on entire Cordova library.
|
||||
*/
|
||||
public abstract class PhonegapActivity extends Activity {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Add services to res/xml/plugins.xml instead.
|
||||
*
|
||||
* Add a class that implements a service.
|
||||
*
|
||||
* @param serviceType
|
||||
* @param className
|
||||
*/
|
||||
@Deprecated
|
||||
abstract public void addService(String serviceType, String className);
|
||||
|
||||
/**
|
||||
* Send JavaScript statement back to JavaScript.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
abstract public void sendJavascript(String statement);
|
||||
|
||||
/**
|
||||
* Launch an activity for which you would like a result when it finished. When this activity exits,
|
||||
* your onActivityResult() method will be called.
|
||||
*
|
||||
* @param command The command object
|
||||
* @param intent The intent to start
|
||||
* @param requestCode The request code that is passed to callback to identify the activity
|
||||
*/
|
||||
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
|
||||
|
||||
/**
|
||||
* Set the plugin to be called when a sub-activity exits.
|
||||
*
|
||||
* @param plugin The plugin on which onActivityResult is to be called
|
||||
*/
|
||||
abstract public void setActivityResultCallback(IPlugin plugin);
|
||||
|
||||
/**
|
||||
* Load the specified URL in the PhoneGap webview.
|
||||
*
|
||||
* @param url The URL to load.
|
||||
*/
|
||||
abstract public void loadUrl(String url);
|
||||
|
||||
/**
|
||||
* Send a message to all plugins.
|
||||
*
|
||||
* @param id The message id
|
||||
* @param data The message data
|
||||
*/
|
||||
abstract public void postMessage(String id, Object data);
|
||||
public abstract class PhonegapActivity extends Activity implements org.apache.cordova.api.CordovaInterface {
|
||||
}
|
||||
|
||||
@@ -18,193 +18,10 @@
|
||||
*/
|
||||
package com.phonegap.api;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
* Plugin interface must be implemented by any plugin classes.
|
||||
*
|
||||
* The execute method is called by the PluginManager.
|
||||
*/
|
||||
public abstract class Plugin implements IPlugin {
|
||||
|
||||
public String id;
|
||||
public WebView webView; // WebView object
|
||||
public PhonegapActivity ctx; // PhonegapActivity object
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public abstract PluginResult execute(String action, JSONArray args, String callbackId);
|
||||
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(PhonegapActivity ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main View of the application, this is the WebView within which
|
||||
* a PhoneGap app runs.
|
||||
*
|
||||
* @param webView The PhoneGap WebView
|
||||
*/
|
||||
public void setView(WebView webView) {
|
||||
this.webView = webView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the system is about to start resuming a previous activity.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
public void onPause(boolean multitasking) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity will start interacting with the user.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
public void onResume(boolean multitasking) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity receives a new intent.
|
||||
*/
|
||||
public void onNewIntent(Intent intent) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The final call you receive before your activity is destroyed.
|
||||
*/
|
||||
public void onDestroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a message is sent to plugin.
|
||||
*
|
||||
* @param id The message id
|
||||
* @param data The message data
|
||||
*/
|
||||
public void onMessage(String id, Object data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an activity you launched exits, giving you the requestCode you started it with,
|
||||
* the resultCode it returned, and any additional data from it.
|
||||
*
|
||||
* @param requestCode The request code originally supplied to startActivityForResult(),
|
||||
* allowing you to identify who this result came from.
|
||||
* @param resultCode The integer result code returned by the child activity through its setResult().
|
||||
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||
*/
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
}
|
||||
|
||||
/**
|
||||
* By specifying a <url-filter> in plugins.xml you can map a URL (using startsWith atm) to this method.
|
||||
*
|
||||
* @param url The URL that is trying to be loaded in the PhoneGap webview.
|
||||
* @return Return true to prevent the URL from loading. Default is false.
|
||||
*/
|
||||
public boolean onOverrideUrlLoading(String url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send generic JavaScript statement back to JavaScript.
|
||||
* success(...) and error(...) should be used instead where possible.
|
||||
*
|
||||
* @param statement
|
||||
*/
|
||||
public void sendJavascript(String statement) {
|
||||
this.ctx.sendJavascript(statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.ctx.sendJavascript(pluginResult.toSuccessCallbackString(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.ctx.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(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.ctx.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(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.ctx.sendJavascript(pluginResult.toErrorCallbackString(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.ctx.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(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.ctx.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
|
||||
}
|
||||
public abstract class Plugin extends org.apache.cordova.api.Plugin {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*
|
||||
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
|
||||
@@ -18,342 +17,19 @@
|
||||
*/
|
||||
package com.phonegap.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
* PluginManager is exposed to JavaScript in the PhoneGap WebView.
|
||||
* PluginManager is exposed to JavaScript in the Cordova WebView.
|
||||
*
|
||||
* Calling native plugin code can be done by calling PluginManager.exec(...)
|
||||
* from JavaScript.
|
||||
*/
|
||||
public final class PluginManager {
|
||||
public class PluginManager extends org.apache.cordova.api.PluginManager {
|
||||
|
||||
private HashMap<String, IPlugin> plugins = new HashMap<String,IPlugin>();
|
||||
private HashMap<String, String> services = new HashMap<String,String>();
|
||||
|
||||
private final PhonegapActivity ctx;
|
||||
private final WebView app;
|
||||
|
||||
// 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>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param app
|
||||
* @param ctx
|
||||
*/
|
||||
public PluginManager(WebView app, PhonegapActivity ctx) {
|
||||
this.ctx = ctx;
|
||||
this.app = app;
|
||||
this.loadPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-init when loading a new HTML page into webview.
|
||||
*/
|
||||
public void reinit() {
|
||||
|
||||
// Stop plugins on current HTML page and discard
|
||||
this.onPause(false);
|
||||
this.onDestroy();
|
||||
this.plugins = new HashMap<String, IPlugin>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load plugins from res/xml/plugins.xml
|
||||
*/
|
||||
public void loadPlugins() {
|
||||
int id = ctx.getResources().getIdentifier("plugins", "xml", ctx.getPackageName());
|
||||
if (id == 0) { pluginConfigurationMissing(); }
|
||||
XmlResourceParser xml = ctx.getResources().getXml(id);
|
||||
int eventType = -1;
|
||||
String pluginClass = "", pluginName = "";
|
||||
while (eventType != XmlResourceParser.END_DOCUMENT) {
|
||||
if (eventType == XmlResourceParser.START_TAG) {
|
||||
String strNode = xml.getName();
|
||||
if (strNode.equals("plugin")) {
|
||||
pluginClass = xml.getAttributeValue(null, "value");
|
||||
pluginName = xml.getAttributeValue(null, "name");
|
||||
//System.out.println("Plugin: "+name+" => "+value);
|
||||
this.addService(pluginName, pluginClass);
|
||||
|
||||
// Create plugin at load time if attribute "onload"
|
||||
if ("true".equals(xml.getAttributeValue(null, "onload"))) {
|
||||
this.getPlugin(pluginName);
|
||||
}
|
||||
} else if (strNode.equals("url-filter")) {
|
||||
this.urlMap.put(xml.getAttributeValue(null, "value"), pluginName);
|
||||
}
|
||||
}
|
||||
try {
|
||||
eventType = xml.next();
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a request for execution and fulfills it by finding the appropriate
|
||||
* Java class and calling it's execute method.
|
||||
*
|
||||
* PluginManager.exec can be used either synchronously or async. In either case, a JSON encoded
|
||||
* string is returned that will indicate if any errors have occurred when trying to find
|
||||
* or execute the class denoted by the clazz argument.
|
||||
*
|
||||
* @param service String containing the service to run
|
||||
* @param action String containt the action that the class is supposed to perform. This is
|
||||
* passed to the plugin execute method and it is up to the plugin developer
|
||||
* how to deal with it.
|
||||
* @param callbackId String containing the id of the callback that is execute in JavaScript if
|
||||
* this is an async plugin call.
|
||||
* @param args An Array literal string containing any arguments needed in the
|
||||
* plugin execute method.
|
||||
* @param async Boolean indicating whether the calling JavaScript code is expecting an
|
||||
* immediate return value. If true, either PhoneGap.callbackSuccess(...) or
|
||||
* PhoneGap.callbackError(...) is called once the plugin code has executed.
|
||||
*
|
||||
* @return JSON encoded string with a response message and status.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
||||
PluginResult cr = null;
|
||||
boolean runAsync = async;
|
||||
try {
|
||||
final JSONArray args = new JSONArray(jsonArgs);
|
||||
final IPlugin plugin = this.getPlugin(service);
|
||||
final PhonegapActivity ctx = this.ctx;
|
||||
if (plugin != null) {
|
||||
runAsync = async && !plugin.isSynch(action);
|
||||
if (runAsync) {
|
||||
// Run this on a different thread so that this one can return back to JS
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
// Call execute on the plugin so that it can do it's thing
|
||||
PluginResult cr = plugin.execute(action, args, callbackId);
|
||||
int status = cr.getStatus();
|
||||
|
||||
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
||||
if ((status == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
||||
}
|
||||
|
||||
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
|
||||
else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
|
||||
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
||||
}
|
||||
|
||||
// If error
|
||||
else {
|
||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PluginResult cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
return "";
|
||||
} else {
|
||||
// Call execute on the plugin so that it can do it's thing
|
||||
cr = plugin.execute(action, args, callbackId);
|
||||
|
||||
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
||||
if ((cr.getStatus() == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
System.out.println("ERROR: "+e.toString());
|
||||
cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
// if async we have already returned at this point unless there was an error...
|
||||
if (runAsync) {
|
||||
if (cr == null) {
|
||||
cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
||||
}
|
||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||
}
|
||||
return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class.
|
||||
*
|
||||
* @param clazz
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class getClassByName(final String clazz) throws ClassNotFoundException {
|
||||
Class c = null;
|
||||
if (clazz != null) {
|
||||
c = Class.forName(clazz);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the interfaces that a class implements and see if it implements the
|
||||
* com.phonegap.api.Plugin interface.
|
||||
*
|
||||
* @param c The class to check the interfaces of.
|
||||
* @return Boolean indicating if the class implements com.phonegap.api.Plugin
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean isPhoneGapPlugin(Class c) {
|
||||
if (c != null) {
|
||||
return com.phonegap.api.Plugin.class.isAssignableFrom(c) || com.phonegap.api.IPlugin.class.isAssignableFrom(c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plugin to be loaded and cached. This creates an instance of the plugin.
|
||||
* If plugin is already created, then just return it.
|
||||
*
|
||||
* @param className The class to load
|
||||
* @param clazz The class object (must be a class object of the className)
|
||||
* @param callbackId The callback id to use when calling back into JavaScript
|
||||
* @return The plugin
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private IPlugin addPlugin(String pluginName, String className) {
|
||||
try {
|
||||
Class c = getClassByName(className);
|
||||
if (isPhoneGapPlugin(c)) {
|
||||
IPlugin plugin = (IPlugin)c.newInstance();
|
||||
this.plugins.put(className, plugin);
|
||||
plugin.setContext(this.ctx);
|
||||
plugin.setView(this.app);
|
||||
return plugin;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Error adding plugin "+className+".");
|
||||
}
|
||||
return null;
|
||||
public PluginManager(WebView app, CordovaInterface ctx) {
|
||||
super(app, ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the loaded plugin.
|
||||
*
|
||||
* If the plugin is not already loaded then load it.
|
||||
*
|
||||
* @param className The class of the loaded plugin.
|
||||
* @return
|
||||
*/
|
||||
private IPlugin getPlugin(String pluginName) {
|
||||
String className = this.services.get(pluginName);
|
||||
if (this.plugins.containsKey(className)) {
|
||||
return this.plugins.get(className);
|
||||
} else {
|
||||
return this.addPlugin(pluginName, className);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a class that implements a service.
|
||||
* This does not create the class instance. It just maps service name to class name.
|
||||
*
|
||||
* @param serviceType
|
||||
* @param className
|
||||
*/
|
||||
public void addService(String serviceType, String className) {
|
||||
this.services.put(serviceType, className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the system is about to start resuming a previous activity.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
public void onPause(boolean multitasking) {
|
||||
for (IPlugin plugin : this.plugins.values()) {
|
||||
plugin.onPause(multitasking);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity will start interacting with the user.
|
||||
*
|
||||
* @param multitasking Flag indicating if multitasking is turned on for app
|
||||
*/
|
||||
public void onResume(boolean multitasking) {
|
||||
for (IPlugin plugin : this.plugins.values()) {
|
||||
plugin.onResume(multitasking);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The final call you receive before your activity is destroyed.
|
||||
*/
|
||||
public void onDestroy() {
|
||||
for (IPlugin plugin : this.plugins.values()) {
|
||||
plugin.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to all plugins.
|
||||
*
|
||||
* @param id The message id
|
||||
* @param data The message data
|
||||
*/
|
||||
public void postMessage(String id, Object data) {
|
||||
for (IPlugin plugin : this.plugins.values()) {
|
||||
plugin.onMessage(id, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity receives a new intent.
|
||||
*/
|
||||
public void onNewIntent(Intent intent) {
|
||||
for (IPlugin plugin : this.plugins.values()) {
|
||||
plugin.onNewIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the URL of the webview changes.
|
||||
*
|
||||
* @param url The URL that is being changed to.
|
||||
* @return Return false to allow the URL to load, return true to prevent the URL from loading.
|
||||
*/
|
||||
public boolean onOverrideUrlLoading(String url) {
|
||||
Iterator<Entry<String, String>> it = this.urlMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
HashMap.Entry<String, String> pairs = it.next();
|
||||
if (url.startsWith(pairs.getKey())) {
|
||||
return this.getPlugin(pairs.getValue()).onOverrideUrlLoading(url);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void pluginConfigurationMissing() {
|
||||
System.err.println("=====================================================================================");
|
||||
System.err.println("ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.");
|
||||
System.err.println("https://raw.github.com/phonegap/phonegap-android/master/framework/res/xml/plugins.xml");
|
||||
System.err.println("=====================================================================================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,120 +21,33 @@ package com.phonegap.api;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class PluginResult {
|
||||
private final int status;
|
||||
private final String message;
|
||||
private boolean keepCallback = false;
|
||||
private String cast = null;
|
||||
public class PluginResult extends org.apache.cordova.api.PluginResult {
|
||||
|
||||
public PluginResult(Status status) {
|
||||
this.status = status.ordinal();
|
||||
this.message = "'" + PluginResult.StatusMessages[this.status] + "'";
|
||||
super(status);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, String message) {
|
||||
this.status = status.ordinal();
|
||||
this.message = JSONObject.quote(message);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, JSONArray message, String cast) {
|
||||
this.status = status.ordinal();
|
||||
this.message = message.toString();
|
||||
this.cast = cast;
|
||||
}
|
||||
|
||||
public PluginResult(Status status, JSONObject message, String cast) {
|
||||
this.status = status.ordinal();
|
||||
this.message = message.toString();
|
||||
this.cast = cast;
|
||||
super(status, message);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, JSONArray message) {
|
||||
this.status = status.ordinal();
|
||||
this.message = message.toString();
|
||||
super(status, message);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, JSONObject message) {
|
||||
this.status = status.ordinal();
|
||||
this.message = message.toString();
|
||||
super(status, message);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, int i) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+i;
|
||||
super(status, i);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, float f) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+f;
|
||||
super(status, f);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, boolean b) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+b;
|
||||
}
|
||||
|
||||
public void setKeepCallback(boolean b) {
|
||||
this.keepCallback = b;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean getKeepCallback() {
|
||||
return this.keepCallback;
|
||||
}
|
||||
|
||||
public String getJSONString() {
|
||||
return "{status:" + this.status + ",message:" + this.message + ",keepCallback:" + this.keepCallback + "}";
|
||||
}
|
||||
|
||||
public String toSuccessCallbackString(String callbackId) {
|
||||
StringBuffer buf = new StringBuffer("");
|
||||
if (cast != null) {
|
||||
buf.append("var temp = "+cast+"("+this.getJSONString() + ");\n");
|
||||
buf.append("PhoneGap.callbackSuccess('"+callbackId+"',temp);");
|
||||
}
|
||||
else {
|
||||
buf.append("PhoneGap.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String toErrorCallbackString(String callbackId) {
|
||||
return "PhoneGap.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
|
||||
}
|
||||
|
||||
public static String[] StatusMessages = new String[] {
|
||||
"No result",
|
||||
"OK",
|
||||
"Class not found",
|
||||
"Illegal access",
|
||||
"Instantiation error",
|
||||
"Malformed url",
|
||||
"IO error",
|
||||
"Invalid action",
|
||||
"JSON error",
|
||||
"Error"
|
||||
};
|
||||
|
||||
public enum Status {
|
||||
NO_RESULT,
|
||||
OK,
|
||||
CLASS_NOT_FOUND_EXCEPTION,
|
||||
ILLEGAL_ACCESS_EXCEPTION,
|
||||
INSTANTIATION_EXCEPTION,
|
||||
MALFORMED_URL_EXCEPTION,
|
||||
IO_EXCEPTION,
|
||||
INVALID_ACTION,
|
||||
JSON_EXCEPTION,
|
||||
ERROR
|
||||
super(status, b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
@@ -72,7 +72,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(PhonegapActivity ctx) {
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
super.setContext(ctx);
|
||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||
}
|
||||
@@ -148,7 +148,10 @@ public class AccelListener extends Plugin implements SensorEventListener {
|
||||
else if (action.equals("getTimeout")) {
|
||||
float f = this.getTimeout();
|
||||
return new PluginResult(status, f);
|
||||
}
|
||||
} else {
|
||||
// Unsupported action
|
||||
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
@@ -167,7 +170,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
|
||||
}
|
||||
else if (action.equals("getAcceleration")) {
|
||||
// Can only return value if RUNNING
|
||||
if (this.status == RUNNING) {
|
||||
if (this.status == AccelListener.RUNNING) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,14 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import com.phonegap.api.LOG;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@@ -16,22 +16,23 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.phonegap.api.LOG;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This class called by PhonegapActivity to play and record audio.
|
||||
* This class called by CordovaActivity to play and record audio.
|
||||
* The file can be local or over a network using http.
|
||||
*
|
||||
* Audio formats supported (tested):
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
@@ -31,8 +31,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class implements the audio playback and recording capabilities used by PhoneGap.
|
||||
* It is called by the AudioHandler PhoneGap class.
|
||||
* This class implements the audio playback and recording capabilities used by Cordova.
|
||||
* It is called by the AudioHandler Cordova class.
|
||||
* Only one file can be played or recorded per class instance.
|
||||
*
|
||||
* Local audio files must reside in one of two places:
|
||||
@@ -116,7 +116,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public void startRecording(String file) {
|
||||
if (this.mPlayer != null) {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
|
||||
// Make sure we're not already recording
|
||||
@@ -137,11 +137,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public void startPlaying(String file) {
|
||||
if (this.recorder != null) {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
|
||||
// If this is a new request to play audio, or stopped
|
||||
@@ -228,7 +228,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
if (this.mPlayer != null) {
|
||||
this.mPlayer.seekTo(milliseconds);
|
||||
Log.d(LOG_TAG, "Send a onStatus update for the new seek");
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public long getCurrentPosition() {
|
||||
if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
|
||||
int curPos = this.mPlayer.getCurrentPosition();
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
|
||||
return curPos;
|
||||
}
|
||||
else {
|
||||
@@ -384,7 +384,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
this.prepareOnly = false;
|
||||
|
||||
// Send status notification to JavaScript
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
|
||||
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
this.mPlayer.release();
|
||||
|
||||
// Send error notification to JavaScript
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
*/
|
||||
private void setState(int state) {
|
||||
if (this.state != state) {
|
||||
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
|
||||
}
|
||||
|
||||
this.state = state;
|
||||
69
framework/src/org/apache/cordova/AuthenticationToken.java
Normal file
69
framework/src/org/apache/cordova/AuthenticationToken.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
/**
|
||||
* The Class AuthenticationToken defines the userName and password to be used for authenticating a web resource
|
||||
*/
|
||||
public class AuthenticationToken {
|
||||
private String userName;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Gets the user name.
|
||||
*
|
||||
* @return the user name
|
||||
*/
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user name.
|
||||
*
|
||||
* @param userName
|
||||
* the new user name
|
||||
*/
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password.
|
||||
*
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password.
|
||||
*
|
||||
* @param password
|
||||
* the new password
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -16,14 +16,14 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -31,7 +31,7 @@ import java.util.LinkedList;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* This class provides a way for Java to run JavaScript in the web page that has loaded PhoneGap.
|
||||
* This class provides a way for Java to run JavaScript in the web page that has loaded Cordova.
|
||||
* The CallbackServer class implements an XHR server and a polling server with a list of JavaScript
|
||||
* statements that are to be executed on the web page.
|
||||
*
|
||||
@@ -107,10 +107,10 @@ public class CallbackServer implements Runnable {
|
||||
/**
|
||||
* Init callback server and start XHR if running local app.
|
||||
*
|
||||
* If PhoneGap app is loaded from file://, then we can use XHR
|
||||
* If Cordova app is loaded from file://, then we can use XHR
|
||||
* otherwise we have to use polling due to cross-domain security restrictions.
|
||||
*
|
||||
* @param url The URL of the PhoneGap app being loaded
|
||||
* @param url The URL of the Cordova app being loaded
|
||||
*/
|
||||
public void init(String url) {
|
||||
//System.out.println("CallbackServer.start("+url+")");
|
||||
@@ -137,7 +137,7 @@ public class CallbackServer implements Runnable {
|
||||
/**
|
||||
* Re-init when loading a new HTML page into webview.
|
||||
*
|
||||
* @param url The URL of the PhoneGap app being loaded
|
||||
* @param url The URL of the Cordova app being loaded
|
||||
*/
|
||||
public void reinit(String url) {
|
||||
this.stopServer();
|
||||
@@ -314,9 +314,10 @@ public class CallbackServer implements Runnable {
|
||||
* @return int
|
||||
*/
|
||||
public int getSize() {
|
||||
int size = this.javascript.size();
|
||||
//System.out.println("getSize() = " + size);
|
||||
return size;
|
||||
synchronized(this) {
|
||||
int size = this.javascript.size();
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,17 +326,16 @@ public class CallbackServer implements Runnable {
|
||||
* @return String
|
||||
*/
|
||||
public String getJavascript() {
|
||||
if (this.javascript.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
String statement = this.javascript.remove(0);
|
||||
//System.out.println("CallbackServer.getJavascript() = " + statement);
|
||||
if (this.javascript.size() == 0) {
|
||||
synchronized (this) {
|
||||
this.empty = true;
|
||||
}
|
||||
}
|
||||
return statement;
|
||||
synchronized(this) {
|
||||
if (this.javascript.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
String statement = this.javascript.remove(0);
|
||||
if (this.javascript.size() == 0) {
|
||||
this.empty = true;
|
||||
}
|
||||
return statement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,12 +344,11 @@ public class CallbackServer implements Runnable {
|
||||
* @param statement
|
||||
*/
|
||||
public void sendJavascript(String statement) {
|
||||
//System.out.println("CallbackServer.sendJavascript("+statement+")");
|
||||
this.javascript.add(statement);
|
||||
synchronized (this) {
|
||||
this.empty = false;
|
||||
this.notify();
|
||||
}
|
||||
synchronized (this) {
|
||||
this.javascript.add(statement);
|
||||
this.empty = false;
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/* The Following code has been modified from original implementation of URLEncoder */
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -26,13 +26,13 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import com.phonegap.api.LOG;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentValues;
|
||||
@@ -101,23 +101,19 @@ public class CameraLauncher extends Plugin {
|
||||
try {
|
||||
if (action.equals("takePicture")) {
|
||||
int srcType = CAMERA;
|
||||
int destType = DATA_URL;
|
||||
int destType = FILE_URI;
|
||||
this.targetHeight = 0;
|
||||
this.targetWidth = 0;
|
||||
this.encodingType = JPEG;
|
||||
this.mediaType = PICTURE;
|
||||
this.mQuality = 80;
|
||||
|
||||
JSONObject options = args.optJSONObject(0);
|
||||
if (options != null) {
|
||||
srcType = options.getInt("sourceType");
|
||||
destType = options.getInt("destinationType");
|
||||
this.targetHeight = options.getInt("targetHeight");
|
||||
this.targetWidth = options.getInt("targetWidth");
|
||||
this.encodingType = options.getInt("encodingType");
|
||||
this.mediaType = options.getInt("mediaType");
|
||||
this.mQuality = options.getInt("quality");
|
||||
}
|
||||
this.mQuality = args.getInt(0);
|
||||
destType = args.getInt(1);
|
||||
srcType = args.getInt(2);
|
||||
this.targetWidth = args.getInt(3);
|
||||
this.targetHeight = args.getInt(4);
|
||||
this.encodingType = args.getInt(5);
|
||||
|
||||
if (srcType == CAMERA) {
|
||||
this.takePicture(destType, encodingType);
|
||||
@@ -143,7 +139,7 @@ public class CameraLauncher extends Plugin {
|
||||
/**
|
||||
* Take a picture with the camera.
|
||||
* When an image is captured or the camera view is cancelled, the result is returned
|
||||
* in PhonegapActivity.onActivityResult, which forwards the result to this.onActivityResult.
|
||||
* in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
|
||||
*
|
||||
* The image can either be returned as a base64 string or a URI that points to the file.
|
||||
* To display base64 string in an img tag, set the source to:
|
||||
@@ -179,9 +175,9 @@ public class CameraLauncher extends Plugin {
|
||||
private File createCaptureFile(int encodingType) {
|
||||
File photo = null;
|
||||
if (encodingType == JPEG) {
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.jpg");
|
||||
} else if (encodingType == PNG) {
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png");
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.png");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
|
||||
}
|
||||
@@ -285,7 +281,7 @@ public class CameraLauncher extends Plugin {
|
||||
// Create an ExifHelper to save the exif data that is lost during compression
|
||||
ExifHelper exif = new ExifHelper();
|
||||
if (this.encodingType == JPEG) {
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
|
||||
exif.readExifData();
|
||||
}
|
||||
|
||||
@@ -398,7 +394,7 @@ public class CameraLauncher extends Plugin {
|
||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||
bitmap = scaleBitmap(bitmap);
|
||||
|
||||
String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
|
||||
String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/resize.jpg";
|
||||
OutputStream os = new FileOutputStream(fileName);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||
os.close();
|
||||
@@ -501,4 +497,4 @@ public class CameraLauncher extends Plugin {
|
||||
public void failPicture(String err) {
|
||||
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -35,13 +38,11 @@ import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.phonegap.api.LOG;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
public class Capture extends Plugin {
|
||||
|
||||
private static final String VIDEO_3GPP = "video/3gpp";
|
||||
private static final String VIDEO_MP4 = "video/mp4";
|
||||
private static final String AUDIO_3GPP = "audio/3gpp";
|
||||
private static final String IMAGE_JPEG = "image/jpeg";
|
||||
|
||||
@@ -128,7 +129,7 @@ public class Capture extends Plugin {
|
||||
else if (mimeType.endsWith(AUDIO_3GPP)) {
|
||||
obj = getAudioVideoData(filePath, obj, false);
|
||||
}
|
||||
else if (mimeType.equals(VIDEO_3GPP)) {
|
||||
else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) {
|
||||
obj = getAudioVideoData(filePath, obj, true);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +168,7 @@ public class Capture extends Plugin {
|
||||
try {
|
||||
player.setDataSource(filePath);
|
||||
player.prepare();
|
||||
obj.put("duration", player.getDuration());
|
||||
obj.put("duration", player.getDuration()/1000);
|
||||
if (video) {
|
||||
obj.put("height", player.getVideoHeight());
|
||||
obj.put("width", player.getVideoWidth());
|
||||
@@ -195,7 +196,7 @@ public class Capture extends Plugin {
|
||||
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
|
||||
// Specify file so that large image is captured and returned
|
||||
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Capture.jpg");
|
||||
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Capture.jpg");
|
||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||
this.imageUri = Uri.fromFile(photo);
|
||||
|
||||
@@ -235,7 +236,7 @@ public class Capture extends Plugin {
|
||||
|
||||
if (results.length() >= limit) {
|
||||
// Send Uri back to JavaScript for listening to audio
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||
} else {
|
||||
// still need to capture more audio clips
|
||||
captureAudio();
|
||||
@@ -248,7 +249,7 @@ public class Capture extends Plugin {
|
||||
try {
|
||||
// Create an ExifHelper to save the exif data that is lost during compression
|
||||
ExifHelper exif = new ExifHelper();
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
|
||||
exif.readExifData();
|
||||
|
||||
// Read in bitmap of captured image
|
||||
@@ -290,7 +291,7 @@ public class Capture extends Plugin {
|
||||
|
||||
if (results.length() >= limit) {
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||
} else {
|
||||
// still need to capture more images
|
||||
captureImage();
|
||||
@@ -307,7 +308,7 @@ public class Capture extends Plugin {
|
||||
|
||||
if (results.length() >= limit) {
|
||||
// Send Uri back to JavaScript for viewing video
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||
} else {
|
||||
// still need to capture more video clips
|
||||
captureVideo(duration);
|
||||
@@ -318,7 +319,7 @@ public class Capture extends Plugin {
|
||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
// If we have partial results send them back to the user
|
||||
if (results.length() > 0) {
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||
}
|
||||
// user canceled the action
|
||||
else {
|
||||
@@ -329,7 +330,7 @@ public class Capture extends Plugin {
|
||||
else {
|
||||
// If we have partial results send them back to the user
|
||||
if (results.length() > 0) {
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||
}
|
||||
// something bad happened
|
||||
else {
|
||||
@@ -16,17 +16,17 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
@@ -59,6 +59,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
* Constructor.
|
||||
*/
|
||||
public CompassListener() {
|
||||
this.heading = 0;
|
||||
this.timeStamp = 0;
|
||||
this.setStatus(CompassListener.STOPPED);
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(PhonegapActivity ctx) {
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
super.setContext(ctx);
|
||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||
}
|
||||
@@ -99,10 +100,10 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
}
|
||||
else if (action.equals("getHeading")) {
|
||||
// If not running, then this is an async call, so don't worry about waiting
|
||||
if (this.status != RUNNING) {
|
||||
if (this.status != CompassListener.RUNNING) {
|
||||
int r = this.start();
|
||||
if (r == ERROR_FAILED_TO_START) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
|
||||
if (r == CompassListener.ERROR_FAILED_TO_START) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);
|
||||
}
|
||||
// Wait until running
|
||||
long timeout = 2000;
|
||||
@@ -115,11 +116,10 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
}
|
||||
}
|
||||
if (timeout == 0) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);
|
||||
}
|
||||
}
|
||||
//float f = this.getHeading();
|
||||
return new PluginResult(status, getCompassHeading(), "navigator.compass._castDate");
|
||||
return new PluginResult(status, getCompassHeading());
|
||||
}
|
||||
else if (action.equals("setTimeout")) {
|
||||
this.setTimeout(args.getLong(0));
|
||||
@@ -127,6 +127,9 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
else if (action.equals("getTimeout")) {
|
||||
long l = this.getTimeout();
|
||||
return new PluginResult(status, l);
|
||||
} else {
|
||||
// Unsupported action
|
||||
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
@@ -147,7 +150,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
}
|
||||
else if (action.equals("getHeading")) {
|
||||
// Can only return value if RUNNING
|
||||
if (this.status == RUNNING) {
|
||||
if (this.status == CompassListener.RUNNING) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -180,11 +183,11 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
// Get accelerometer from sensor manager
|
||||
// Get compass sensor from sensor manager
|
||||
List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
|
||||
|
||||
// If found, then register as listener
|
||||
if (list.size() > 0) {
|
||||
if (list != null && list.size() > 0) {
|
||||
this.mSensor = list.get(0);
|
||||
this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
this.lastAccessTime = System.currentTimeMillis();
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
@@ -36,7 +37,7 @@ import org.json.JSONObject;
|
||||
public abstract class ContactAccessor {
|
||||
|
||||
protected final String LOG_TAG = "ContactsAccessor";
|
||||
protected Activity mApp;
|
||||
protected Context mApp;
|
||||
protected WebView mView;
|
||||
|
||||
/**
|
||||
@@ -1,20 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
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
|
||||
|
||||
package com.phonegap;
|
||||
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.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
@@ -40,6 +43,7 @@ import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@@ -118,8 +122,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
/**
|
||||
* Create an contact accessor.
|
||||
*/
|
||||
public ContactAccessorSdk5(WebView view, Activity app) {
|
||||
mApp = app;
|
||||
public ContactAccessorSdk5(WebView view, Context context) {
|
||||
mApp = context;
|
||||
mView = view;
|
||||
}
|
||||
|
||||
@@ -819,50 +823,49 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
public String save(JSONObject contact) {
|
||||
AccountManager mgr = AccountManager.get(mApp);
|
||||
Account[] accounts = mgr.getAccounts();
|
||||
Account account = null;
|
||||
String accountName = null;
|
||||
String accountType = null;
|
||||
|
||||
if (accounts.length == 1)
|
||||
account = accounts[0];
|
||||
else if (accounts.length > 1) {
|
||||
for(Account a : accounts){
|
||||
if(a.type.contains("eas")&& a.name.matches(EMAIL_REGEXP)) /*Exchange ActiveSync*/
|
||||
{
|
||||
account = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(account == null){
|
||||
for(Account a : accounts){
|
||||
if(a.type.contains("com.google") && a.name.matches(EMAIL_REGEXP)) /*Google sync provider*/
|
||||
{
|
||||
account = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(account == null){
|
||||
for(Account a : accounts){
|
||||
if(a.name.matches(EMAIL_REGEXP)) /*Last resort, just look for an email address...*/
|
||||
{
|
||||
account = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accounts.length == 1) {
|
||||
accountName = accounts[0].name;
|
||||
accountType = accounts[0].type;
|
||||
}
|
||||
|
||||
if(account == null) {
|
||||
return null;
|
||||
else if (accounts.length > 1) {
|
||||
for(Account a : accounts) {
|
||||
if(a.type.contains("eas")&& a.name.matches(EMAIL_REGEXP)) /*Exchange ActiveSync*/ {
|
||||
accountName = a.name;
|
||||
accountType = a.type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(accountName == null){
|
||||
for(Account a : accounts){
|
||||
if(a.type.contains("com.google") && a.name.matches(EMAIL_REGEXP)) /*Google sync provider*/ {
|
||||
accountName = a.name;
|
||||
accountType = a.type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(accountName == null){
|
||||
for(Account a : accounts){
|
||||
if(a.name.matches(EMAIL_REGEXP)) /*Last resort, just look for an email address...*/ {
|
||||
accountName = a.name;
|
||||
accountType = a.type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String id = getJsonString(contact, "id");
|
||||
// Create new contact
|
||||
if (id == null) {
|
||||
return createNewContact(contact, account);
|
||||
return createNewContact(contact, accountType, accountName);
|
||||
}
|
||||
// Modify existing contact
|
||||
else {
|
||||
return modifyContact(id, contact, account);
|
||||
return modifyContact(id, contact, accountType, accountName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -873,7 +876,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
* @param contact the contact to be saved
|
||||
* @param account the account to be saved under
|
||||
*/
|
||||
private String modifyContact(String id, JSONObject contact, Account account) {
|
||||
private String modifyContact(String id, JSONObject contact, String accountType, String accountName) {
|
||||
// Get the RAW_CONTACT_ID which is needed to insert new values in an already existing contact.
|
||||
// But not needed to update existing values.
|
||||
int rawId = (new Integer(getJsonString(contact,"rawId"))).intValue();
|
||||
@@ -883,8 +886,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
|
||||
//Add contact type
|
||||
ops.add(ContentProviderOperation.newUpdate(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, account.name)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, accountName)
|
||||
.build());
|
||||
|
||||
// Modify name
|
||||
@@ -1427,14 +1430,14 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
* @param contact the contact to be saved
|
||||
* @param account the account to be saved under
|
||||
*/
|
||||
private String createNewContact(JSONObject contact, Account account) {
|
||||
private String createNewContact(JSONObject contact, String accountType, String accountName) {
|
||||
// Create a list of attributes to add to the contact database
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||
|
||||
//Add contact type
|
||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, account.name)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, accountName)
|
||||
.build());
|
||||
|
||||
// Add name
|
||||
@@ -1615,9 +1618,20 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
* @param id the unique ID of the contact to remove
|
||||
*/
|
||||
public boolean remove(String id) {
|
||||
int result = mApp.getContentResolver().delete(ContactsContract.Data.CONTENT_URI,
|
||||
ContactsContract.Data.CONTACT_ID + " = ?",
|
||||
new String[] {id});
|
||||
int result = 0;
|
||||
Cursor cursor = mApp.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
|
||||
null,
|
||||
ContactsContract.Contacts._ID + " = ?",
|
||||
new String[] {id}, null);
|
||||
if(cursor.getCount() == 1) {
|
||||
cursor.moveToFirst();
|
||||
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
|
||||
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
|
||||
result = mApp.getContentResolver().delete(uri, null, null);
|
||||
} else {
|
||||
Log.d(LOG_TAG, "Could not find contact with ID");
|
||||
}
|
||||
|
||||
return (result > 0) ? true : false;
|
||||
}
|
||||
|
||||
@@ -16,50 +16,50 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import android.util.Log;
|
||||
|
||||
public class ContactManager extends Plugin {
|
||||
|
||||
|
||||
private ContactAccessor contactAccessor;
|
||||
private static final String LOG_TAG = "Contact Query";
|
||||
private static final String LOG_TAG = "Contact Query";
|
||||
|
||||
public static final int UNKNOWN_ERROR = 0;
|
||||
public static final int INVALID_ARGUMENT_ERROR = 1;
|
||||
public static final int TIMEOUT_ERROR = 2;
|
||||
public static final int PENDING_OPERATION_ERROR = 3;
|
||||
public static final int IO_ERROR = 4;
|
||||
public static final int NOT_SUPPORTED_ERROR = 5;
|
||||
public static final int PERMISSION_DENIED_ERROR = 20;
|
||||
public static final int UNKNOWN_ERROR = 0;
|
||||
public static final int INVALID_ARGUMENT_ERROR = 1;
|
||||
public static final int TIMEOUT_ERROR = 2;
|
||||
public static final int PENDING_OPERATION_ERROR = 3;
|
||||
public static final int IO_ERROR = 4;
|
||||
public static final int NOT_SUPPORTED_ERROR = 5;
|
||||
public static final int PERMISSION_DENIED_ERROR = 20;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ContactManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ContactManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
/**
|
||||
* Check to see if we are on an Android 1.X device. If we are return an error as we
|
||||
* do not support this as of PhoneGap 1.0.
|
||||
* do not support this as of Cordova 1.0.
|
||||
*/
|
||||
if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
|
||||
JSONObject res = null;
|
||||
@@ -79,35 +79,35 @@ public class ContactManager extends Plugin {
|
||||
* older phones.
|
||||
*/
|
||||
if (this.contactAccessor == null) {
|
||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx);
|
||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
|
||||
}
|
||||
|
||||
try {
|
||||
if (action.equals("search")) {
|
||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||
return new PluginResult(status, res, "navigator.contacts.cast");
|
||||
}
|
||||
else if (action.equals("save")) {
|
||||
String id = contactAccessor.save(args.getJSONObject(0));
|
||||
if (id != null) {
|
||||
JSONObject res = contactAccessor.getContactById(id);
|
||||
if (res != null) {
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
if (contactAccessor.remove(args.getString(0))) {
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
// If we get to this point an error has occurred
|
||||
try {
|
||||
if (action.equals("search")) {
|
||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
else if (action.equals("save")) {
|
||||
String id = contactAccessor.save(args.getJSONObject(0));
|
||||
if (id != null) {
|
||||
JSONObject res = contactAccessor.getContactById(id);
|
||||
if (res != null) {
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
if (contactAccessor.remove(args.getString(0))) {
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
// If we get to this point an error has occurred
|
||||
JSONObject r = new JSONObject();
|
||||
r.put("code", UNKNOWN_ERROR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, r);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
314
framework/src/org/apache/cordova/CordovaChromeClient.java
Executable file
314
framework/src/org/apache/cordova/CordovaChromeClient.java
Executable file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
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 org.apache.cordova.api.LOG;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.JsPromptResult;
|
||||
import android.webkit.JsResult;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebStorage;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.GeolocationPermissions.Callback;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* This class is the WebChromeClient that implements callbacks for our web view.
|
||||
*/
|
||||
public class CordovaChromeClient extends WebChromeClient {
|
||||
|
||||
|
||||
private String TAG = "CordovaLog";
|
||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||
private DroidGap ctx;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ctx
|
||||
*/
|
||||
public CordovaChromeClient(Context ctx) {
|
||||
this.ctx = (DroidGap) ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the client to display a javascript alert dialog.
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param result
|
||||
*/
|
||||
@Override
|
||||
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle("Alert");
|
||||
//Don't let alerts break the back button
|
||||
dlg.setCancelable(true);
|
||||
dlg.setPositiveButton(android.R.string.ok,
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
result.confirm();
|
||||
}
|
||||
});
|
||||
dlg.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
result.confirm();
|
||||
}
|
||||
});
|
||||
dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
||||
//DO NOTHING
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
if(keyCode == KeyEvent.KEYCODE_BACK)
|
||||
{
|
||||
result.confirm();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the client to display a confirm dialog to the user.
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param result
|
||||
*/
|
||||
@Override
|
||||
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle("Confirm");
|
||||
dlg.setCancelable(true);
|
||||
dlg.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
result.confirm();
|
||||
}
|
||||
});
|
||||
dlg.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
result.cancel();
|
||||
}
|
||||
});
|
||||
dlg.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
result.cancel();
|
||||
}
|
||||
});
|
||||
dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
||||
//DO NOTHING
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
if(keyCode == KeyEvent.KEYCODE_BACK)
|
||||
{
|
||||
result.cancel();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the client to display a prompt dialog to the user.
|
||||
* If the client returns true, WebView will assume that the client will
|
||||
* handle the prompt dialog and call the appropriate JsPromptResult method.
|
||||
*
|
||||
* Since we are hacking prompts for our own purposes, we should not be using them for
|
||||
* this purpose, perhaps we should hack console.log to do this instead!
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param defaultValue
|
||||
* @param result
|
||||
*/
|
||||
@Override
|
||||
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
||||
|
||||
// Security check to make sure any requests are coming from the page initially
|
||||
// loaded in webview and not another loaded in an iframe.
|
||||
boolean reqOk = false;
|
||||
if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
||||
reqOk = true;
|
||||
}
|
||||
|
||||
// Calling PluginManager.exec() to call a native service using
|
||||
// prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
|
||||
if (reqOk && defaultValue != null && defaultValue.length() > 3 && defaultValue.substring(0, 4).equals("gap:")) {
|
||||
JSONArray array;
|
||||
try {
|
||||
array = new JSONArray(defaultValue.substring(4));
|
||||
String service = array.getString(0);
|
||||
String action = array.getString(1);
|
||||
String callbackId = array.getString(2);
|
||||
boolean async = array.getBoolean(3);
|
||||
String r = ctx.pluginManager.exec(service, action, callbackId, message, async);
|
||||
result.confirm(r);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Polling for JavaScript messages
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
|
||||
String r = ctx.callbackServer.getJavascript();
|
||||
result.confirm(r);
|
||||
}
|
||||
|
||||
// Calling into CallbackServer
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
|
||||
String r = "";
|
||||
if (message.equals("usePolling")) {
|
||||
r = ""+ ctx.callbackServer.usePolling();
|
||||
}
|
||||
else if (message.equals("restartServer")) {
|
||||
ctx.callbackServer.restartServer();
|
||||
}
|
||||
else if (message.equals("getPort")) {
|
||||
r = Integer.toString(ctx.callbackServer.getPort());
|
||||
}
|
||||
else if (message.equals("getToken")) {
|
||||
r = ctx.callbackServer.getToken();
|
||||
}
|
||||
result.confirm(r);
|
||||
}
|
||||
|
||||
// Cordova JS has initialized, so show webview
|
||||
// (This solves white flash seen when rendering HTML)
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
|
||||
ctx.appView.setVisibility(View.VISIBLE);
|
||||
ctx.spinnerStop();
|
||||
result.confirm("OK");
|
||||
}
|
||||
|
||||
// Show dialog
|
||||
else {
|
||||
final JsPromptResult res = result;
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||
dlg.setMessage(message);
|
||||
final EditText input = new EditText(this.ctx);
|
||||
if (defaultValue != null) {
|
||||
input.setText(defaultValue);
|
||||
}
|
||||
dlg.setView(input);
|
||||
dlg.setCancelable(false);
|
||||
dlg.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String usertext = input.getText().toString();
|
||||
res.confirm(usertext);
|
||||
}
|
||||
});
|
||||
dlg.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
res.cancel();
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle database quota exceeded notification.
|
||||
*
|
||||
* @param url
|
||||
* @param databaseIdentifier
|
||||
* @param currentQuota
|
||||
* @param estimatedSize
|
||||
* @param totalUsedQuota
|
||||
* @param quotaUpdater
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
|
||||
if( estimatedSize < MAX_QUOTA)
|
||||
{
|
||||
//increase for 1Mb
|
||||
long newQuota = estimatedSize;
|
||||
LOG.d(TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
|
||||
quotaUpdater.updateQuota(newQuota);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the quota to whatever it is and force an error
|
||||
// TODO: get docs on how to handle this properly
|
||||
quotaUpdater.updateQuota(currentQuota);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
|
||||
@Override
|
||||
public void onConsoleMessage(String message, int lineNumber, String sourceID)
|
||||
{
|
||||
LOG.d(TAG, "%s: Line %d : %s", sourceID, lineNumber, message);
|
||||
super.onConsoleMessage(message, lineNumber, sourceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage)
|
||||
{
|
||||
if(consoleMessage.message() != null)
|
||||
LOG.d(TAG, consoleMessage.message());
|
||||
return super.onConsoleMessage(consoleMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
|
||||
*
|
||||
* @param origin
|
||||
* @param callback
|
||||
*/
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
306
framework/src/org/apache/cordova/CordovaWebViewClient.java
Executable file
306
framework/src/org/apache/cordova/CordovaWebViewClient.java
Executable file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
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 org.apache.cordova.api.LOG;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.HttpAuthHandler;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
/**
|
||||
* This class is the WebViewClient that implements callbacks for our web view.
|
||||
*/
|
||||
public class CordovaWebViewClient extends WebViewClient {
|
||||
|
||||
private static final String TAG = "Cordova";
|
||||
DroidGap ctx;
|
||||
private boolean doClearHistory = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ctx
|
||||
*/
|
||||
public CordovaWebViewClient(DroidGap ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the host application a chance to take over the control when a new url
|
||||
* is about to be loaded in the current WebView.
|
||||
*
|
||||
* @param view The WebView that is initiating the callback.
|
||||
* @param url The url to be loaded.
|
||||
* @return true to override, false for default behavior
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
|
||||
// First give any plugins the chance to handle the url themselves
|
||||
if (this.ctx.pluginManager.onOverrideUrlLoading(url)) {
|
||||
}
|
||||
|
||||
// If dialing phone (tel:5551212)
|
||||
else if (url.startsWith(WebView.SCHEME_TEL)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse(url));
|
||||
ctx.startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error dialing "+url+": "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// If displaying map (geo:0,0?q=address)
|
||||
else if (url.startsWith("geo:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
ctx.startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error showing map "+url+": "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// If sending email (mailto:abc@corp.com)
|
||||
else if (url.startsWith(WebView.SCHEME_MAILTO)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
ctx.startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error sending email "+url+": "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// If sms:5551212?body=This is the message
|
||||
else if (url.startsWith("sms:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
// Get address
|
||||
String address = null;
|
||||
int parmIndex = url.indexOf('?');
|
||||
if (parmIndex == -1) {
|
||||
address = url.substring(4);
|
||||
}
|
||||
else {
|
||||
address = url.substring(4, parmIndex);
|
||||
|
||||
// If body, then set sms body
|
||||
Uri uri = Uri.parse(url);
|
||||
String query = uri.getQuery();
|
||||
if (query != null) {
|
||||
if (query.startsWith("body=")) {
|
||||
intent.putExtra("sms_body", query.substring(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
intent.setData(Uri.parse("sms:"+address));
|
||||
intent.putExtra("address", address);
|
||||
intent.setType("vnd.android-dir/mms-sms");
|
||||
ctx.startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error sending sms "+url+":"+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// All else
|
||||
else {
|
||||
|
||||
// If our app or file:, then load into a new Cordova webview container by starting a new instance of our activity.
|
||||
// Our app continues to run. When BACK is pressed, our app is redisplayed.
|
||||
if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
||||
this.ctx.loadUrl(url);
|
||||
}
|
||||
|
||||
// If not our application, let default viewer handle
|
||||
else {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
ctx.startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(TAG, "Error loading url "+url, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param view
|
||||
* the view
|
||||
* @param handler
|
||||
* the handler
|
||||
* @param host
|
||||
* the host
|
||||
* @param realm
|
||||
* the realm
|
||||
*/
|
||||
@Override
|
||||
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
|
||||
String realm) {
|
||||
|
||||
// get the authentication token
|
||||
AuthenticationToken token = ctx.getAuthenticationToken(host,realm);
|
||||
|
||||
if(token != null) {
|
||||
handler.proceed(token.getUserName(), token.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
// Clear history so history.back() doesn't do anything.
|
||||
// So we can reinit() native side CallbackServer & PluginManager.
|
||||
view.clearHistory();
|
||||
this.doClearHistory = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the host application that a page has finished loading.
|
||||
*
|
||||
* @param view The webview initiating the callback.
|
||||
* @param url The url of the page.
|
||||
*/
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
|
||||
/**
|
||||
* Because of a timing issue we need to clear this history in onPageFinished as well as
|
||||
* onPageStarted. However we only want to do this if the doClearHistory boolean is set to
|
||||
* true. You see when you load a url with a # in it which is common in jQuery applications
|
||||
* onPageStared is not called. Clearing the history at that point would break jQuery apps.
|
||||
*/
|
||||
if (this.doClearHistory) {
|
||||
view.clearHistory();
|
||||
this.doClearHistory = false;
|
||||
}
|
||||
|
||||
// Clear timeout flag
|
||||
this.ctx.loadUrlTimeout++;
|
||||
|
||||
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
||||
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
||||
// from the JS side when the JS gets to that code.
|
||||
if (!url.equals("about:blank")) {
|
||||
ctx.appView.loadUrl("javascript:try{ require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||
}
|
||||
|
||||
// Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
|
||||
if (ctx.appView.getVisibility() == View.INVISIBLE) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
ctx.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ctx.appView.setVisibility(View.VISIBLE);
|
||||
ctx.spinnerStop();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
||||
// Shutdown if blank loaded
|
||||
if (url.equals("about:blank")) {
|
||||
if (this.ctx.callbackServer != null) {
|
||||
this.ctx.callbackServer.destroy();
|
||||
}
|
||||
this.ctx.endActivity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
|
||||
* The errorCode parameter corresponds to one of the ERROR_* constants.
|
||||
*
|
||||
* @param view The WebView that is initiating the callback.
|
||||
* @param errorCode The error code corresponding to an ERROR_* value.
|
||||
* @param description A String describing the error.
|
||||
* @param failingUrl The url that failed to load.
|
||||
*/
|
||||
@Override
|
||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||
LOG.d(TAG, "DroidGap: GapViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
|
||||
|
||||
// Clear timeout flag
|
||||
this.ctx.loadUrlTimeout++;
|
||||
|
||||
// Stop "app loading" spinner if showing
|
||||
this.ctx.spinnerStop();
|
||||
|
||||
// Handle error
|
||||
this.ctx.onReceivedError(errorCode, description, failingUrl);
|
||||
}
|
||||
|
||||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
||||
|
||||
final String packageName = this.ctx.getPackageName();
|
||||
final PackageManager pm = this.ctx.getPackageManager();
|
||||
ApplicationInfo appInfo;
|
||||
try {
|
||||
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
||||
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
||||
// debug = true
|
||||
handler.proceed();
|
||||
return;
|
||||
} else {
|
||||
// debug = false
|
||||
super.onReceivedSslError(view, handler, error);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
// When it doubt, lock it out!
|
||||
super.onReceivedSslError(view, handler, error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
|
||||
/*
|
||||
* If you do a document.location.href the url does not get pushed on the stack
|
||||
* so we do a check here to see if the url should be pushed.
|
||||
*/
|
||||
if (!this.ctx.peekAtUrlStack().equals(url)) {
|
||||
this.ctx.pushUrl(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,17 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import com.phonegap.api.LOG;
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -37,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends Plugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String phonegapVersion = "1.3.0rc2"; // PhoneGap version
|
||||
public static String cordovaVersion = "1.5.0"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
@@ -55,7 +56,7 @@ public class Device extends Plugin {
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(PhonegapActivity ctx) {
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
super.setContext(ctx);
|
||||
Device.uuid = getUuid();
|
||||
this.initTelephonyReceiver();
|
||||
@@ -80,10 +81,10 @@ public class Device extends Plugin {
|
||||
r.put("version", this.getOSVersion());
|
||||
r.put("platform", Device.platform);
|
||||
r.put("name", this.getProductName());
|
||||
r.put("phonegap", Device.phonegapVersion);
|
||||
r.put("cordova", Device.cordovaVersion);
|
||||
//JSONObject pg = new JSONObject();
|
||||
//pg.put("version", Device.phonegapVersion);
|
||||
//r.put("phonegap", pg);
|
||||
//pg.put("version", Device.CordovaVersion);
|
||||
//r.put("cordova", pg);
|
||||
return new PluginResult(status, r);
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
@@ -124,7 +125,7 @@ public class Device extends Plugin {
|
||||
private void initTelephonyReceiver() {
|
||||
IntentFilter intentFilter = new IntentFilter() ;
|
||||
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||
final PhonegapActivity myctx = this.ctx;
|
||||
final CordovaInterface myctx = this.ctx;
|
||||
this.telephonyReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
@@ -175,12 +176,12 @@ public class Device extends Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PhoneGap version.
|
||||
* Get the Cordova version.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPhonegapVersion() {
|
||||
return Device.phonegapVersion;
|
||||
public String getCordovaVersion() {
|
||||
return Device.cordovaVersion;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -57,33 +57,41 @@ public class DirectoryManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the free disk space on the SD card
|
||||
* Get the free disk space
|
||||
*
|
||||
* @return Size in KB or -1 if not available
|
||||
*/
|
||||
protected static long getFreeDiskSpace() {
|
||||
protected static long getFreeDiskSpace(boolean checkInternal) {
|
||||
String status = Environment.getExternalStorageState();
|
||||
long freeSpace = 0;
|
||||
|
||||
// If SD card exists
|
||||
if (status.equals(Environment.MEDIA_MOUNTED)) {
|
||||
try {
|
||||
File path = Environment.getExternalStorageDirectory();
|
||||
StatFs stat = new StatFs(path.getPath());
|
||||
long blockSize = stat.getBlockSize();
|
||||
long availableBlocks = stat.getAvailableBlocks();
|
||||
freeSpace = availableBlocks*blockSize/1024;
|
||||
} catch (Exception e) {e.printStackTrace(); }
|
||||
freeSpace = freeSpaceCalculation(Environment.getExternalStorageDirectory().getPath());
|
||||
}
|
||||
|
||||
// If no SD card, then return -1
|
||||
else if (checkInternal) {
|
||||
freeSpace = freeSpaceCalculation("/");
|
||||
}
|
||||
// If no SD card and we haven't been asked to check the internal directory then return -1
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (freeSpace);
|
||||
return freeSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a path return the number of free KB
|
||||
*
|
||||
* @param path to the file system
|
||||
* @return free space in KB
|
||||
*/
|
||||
private static long freeSpaceCalculation(String path) {
|
||||
StatFs stat = new StatFs(path);
|
||||
long blockSize = stat.getBlockSize();
|
||||
long availableBlocks = stat.getAvailableBlocks();
|
||||
return availableBlocks*blockSize/1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if SD card exists.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -41,6 +41,8 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -49,12 +51,10 @@ import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
public class FileTransfer extends Plugin {
|
||||
|
||||
private static final String LOG_TAG = "FileUploader";
|
||||
private static final String LOG_TAG = "FileTransfer";
|
||||
private static final String LINE_START = "--";
|
||||
private static final String LINE_END = "\r\n";
|
||||
private static final String BOUNDRY = "*****";
|
||||
@@ -67,7 +67,7 @@ public class FileTransfer extends Plugin {
|
||||
private HostnameVerifier defaultHostnameVerifier = null;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.phonegap.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
|
||||
* @see org.apache.cordova.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
@@ -101,7 +101,7 @@ public class FileTransfer extends Plugin {
|
||||
} else if (action.equals("download")) {
|
||||
JSONObject r = download(source, target);
|
||||
Log.d(LOG_TAG, "****** About to return a result from download");
|
||||
return new PluginResult(PluginResult.Status.OK, r, "window.localFileSystem._castEntry");
|
||||
return new PluginResult(PluginResult.Status.OK, r);
|
||||
} else {
|
||||
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||
}
|
||||
@@ -276,7 +276,19 @@ public class FileTransfer extends Plugin {
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+BOUNDRY);
|
||||
|
||||
|
||||
// Handle the other headers
|
||||
try {
|
||||
JSONObject headers = params.getJSONObject("headers");
|
||||
for (Iterator iter = headers.keys(); iter.hasNext();)
|
||||
{
|
||||
String headerKey = iter.next().toString();
|
||||
conn.setRequestProperty(headerKey, headers.getString(headerKey));
|
||||
}
|
||||
} catch (JSONException e1) {
|
||||
// No headers to be manipulated!
|
||||
}
|
||||
|
||||
// Set the cookies on the response
|
||||
String cookie = CookieManager.getInstance().getCookie(server);
|
||||
if (cookie != null) {
|
||||
@@ -294,11 +306,14 @@ public class FileTransfer extends Plugin {
|
||||
try {
|
||||
for (Iterator iter = params.keys(); iter.hasNext();) {
|
||||
Object key = iter.next();
|
||||
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||
dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\";");
|
||||
dos.writeBytes(LINE_END + LINE_END);
|
||||
dos.write(params.getString(key.toString()).getBytes());
|
||||
dos.writeBytes(LINE_END);
|
||||
if(key.toString() != "headers")
|
||||
{
|
||||
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||
dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\";");
|
||||
dos.writeBytes(LINE_END + LINE_END);
|
||||
dos.write(params.getString(key.toString()).getBytes());
|
||||
dos.writeBytes(LINE_END);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
@@ -386,7 +401,6 @@ public class FileTransfer extends Plugin {
|
||||
URL url = new URL(source);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setDoOutput(true);
|
||||
connection.connect();
|
||||
|
||||
Log.d(LOG_TAG, "Download file:" + url);
|
||||
@@ -429,7 +443,12 @@ public class FileTransfer extends Plugin {
|
||||
return ctx.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
else if (path.startsWith("file://")) {
|
||||
return new FileInputStream(path.substring(7));
|
||||
int question = path.indexOf("?");
|
||||
if (question == -1) {
|
||||
return new FileInputStream(path.substring(7));
|
||||
} else {
|
||||
return new FileInputStream(path.substring(7, question));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new FileInputStream(path);
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -25,6 +25,14 @@ import java.net.URLDecoder;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.apache.cordova.file.EncodingException;
|
||||
import org.apache.cordova.file.FileExistsException;
|
||||
import org.apache.cordova.file.InvalidModificationException;
|
||||
import org.apache.cordova.file.NoModificationAllowedException;
|
||||
import org.apache.cordova.file.TypeMismatchException;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -36,14 +44,6 @@ import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import com.phonegap.file.EncodingException;
|
||||
import com.phonegap.file.FileExistsException;
|
||||
import com.phonegap.file.InvalidModificationException;
|
||||
import com.phonegap.file.NoModificationAllowedException;
|
||||
import com.phonegap.file.TypeMismatchException;
|
||||
|
||||
/**
|
||||
* This class provides SD card file and directory services to JavaScript.
|
||||
@@ -95,140 +95,123 @@ public class FileUtils extends Plugin {
|
||||
//System.out.println("FileUtils.execute("+action+")");
|
||||
|
||||
try {
|
||||
try {
|
||||
if (action.equals("testSaveLocationExists")) {
|
||||
boolean b = DirectoryManager.testSaveLocationExists();
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("getFreeDiskSpace")) {
|
||||
long l = DirectoryManager.getFreeDiskSpace();
|
||||
return new PluginResult(status, l);
|
||||
}
|
||||
else if (action.equals("testFileExists")) {
|
||||
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("testDirectoryExists")) {
|
||||
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("readAsText")) {
|
||||
String s = this.readAsText(args.getString(0), args.getString(1));
|
||||
return new PluginResult(status, s);
|
||||
}
|
||||
else if (action.equals("readAsDataURL")) {
|
||||
String s = this.readAsDataURL(args.getString(0));
|
||||
return new PluginResult(status, s);
|
||||
}
|
||||
else if (action.equals("write")) {
|
||||
long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2));
|
||||
return new PluginResult(status, fileSize);
|
||||
}
|
||||
else if (action.equals("truncate")) {
|
||||
long fileSize = this.truncateFile(args.getString(0), args.getLong(1));
|
||||
return new PluginResult(status, fileSize);
|
||||
}
|
||||
else if (action.equals("requestFileSystem")) {
|
||||
long size = args.optLong(1);
|
||||
if (size != 0) {
|
||||
if (size > (DirectoryManager.getFreeDiskSpace()*1024)) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.QUOTA_EXCEEDED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
}
|
||||
JSONObject obj = requestFileSystem(args.getInt(0));
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castFS");
|
||||
}
|
||||
else if (action.equals("resolveLocalFileSystemURI")) {
|
||||
JSONObject obj = resolveLocalFileSystemURI(args.getString(0));
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("getMetadata")) {
|
||||
JSONObject obj = getMetadata(args.getString(0));
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castDate");
|
||||
}
|
||||
else if (action.equals("getFileMetadata")) {
|
||||
JSONObject obj = getFileMetadata(args.getString(0));
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castDate");
|
||||
}
|
||||
else if (action.equals("getParent")) {
|
||||
JSONObject obj = getParent(args.getString(0));
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("getDirectory")) {
|
||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), true);
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("getFile")) {
|
||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), false);
|
||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
boolean success;
|
||||
|
||||
success = remove(args.getString(0));
|
||||
|
||||
if (success) {
|
||||
notifyDelete(args.getString(0));
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
}
|
||||
else if (action.equals("removeRecursively")) {
|
||||
boolean success = removeRecursively(args.getString(0));
|
||||
if (success) {
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
}
|
||||
else if (action.equals("moveTo")) {
|
||||
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), true);
|
||||
return new PluginResult(status, entry, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("copyTo")) {
|
||||
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), false);
|
||||
return new PluginResult(status, entry, "window.localFileSystem._castEntry");
|
||||
}
|
||||
else if (action.equals("readEntries")) {
|
||||
JSONArray entries = readEntries(args.getString(0));
|
||||
return new PluginResult(status, entries, "window.localFileSystem._castEntries");
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (FileNotFoundException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NOT_FOUND_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (FileExistsException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.PATH_EXISTS_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (NoModificationAllowedException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (JSONException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (InvalidModificationException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.INVALID_MODIFICATION_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (MalformedURLException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.ENCODING_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (IOException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.INVALID_MODIFICATION_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (EncodingException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.ENCODING_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
} catch (TypeMismatchException e) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.TYPE_MISMATCH_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
if (action.equals("testSaveLocationExists")) {
|
||||
boolean b = DirectoryManager.testSaveLocationExists();
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("getFreeDiskSpace")) {
|
||||
long l = DirectoryManager.getFreeDiskSpace(false);
|
||||
return new PluginResult(status, l);
|
||||
}
|
||||
else if (action.equals("testFileExists")) {
|
||||
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("testDirectoryExists")) {
|
||||
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||
return new PluginResult(status, b);
|
||||
}
|
||||
else if (action.equals("readAsText")) {
|
||||
String s = this.readAsText(args.getString(0), args.getString(1));
|
||||
return new PluginResult(status, s);
|
||||
}
|
||||
else if (action.equals("readAsDataURL")) {
|
||||
String s = this.readAsDataURL(args.getString(0));
|
||||
return new PluginResult(status, s);
|
||||
}
|
||||
else if (action.equals("write")) {
|
||||
long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2));
|
||||
return new PluginResult(status, fileSize);
|
||||
}
|
||||
else if (action.equals("truncate")) {
|
||||
long fileSize = this.truncateFile(args.getString(0), args.getLong(1));
|
||||
return new PluginResult(status, fileSize);
|
||||
}
|
||||
else if (action.equals("requestFileSystem")) {
|
||||
long size = args.optLong(1);
|
||||
if (size != 0) {
|
||||
if (size > (DirectoryManager.getFreeDiskSpace(true)*1024)) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.QUOTA_EXCEEDED_ERR);
|
||||
}
|
||||
}
|
||||
JSONObject obj = requestFileSystem(args.getInt(0));
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("resolveLocalFileSystemURI")) {
|
||||
JSONObject obj = resolveLocalFileSystemURI(args.getString(0));
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("getMetadata")) {
|
||||
JSONObject obj = getMetadata(args.getString(0));
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("getFileMetadata")) {
|
||||
JSONObject obj = getFileMetadata(args.getString(0));
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("getParent")) {
|
||||
JSONObject obj = getParent(args.getString(0));
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("getDirectory")) {
|
||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), true);
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("getFile")) {
|
||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), false);
|
||||
return new PluginResult(status, obj);
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
boolean success;
|
||||
|
||||
success = remove(args.getString(0));
|
||||
|
||||
if (success) {
|
||||
notifyDelete(args.getString(0));
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
}
|
||||
else if (action.equals("removeRecursively")) {
|
||||
boolean success = removeRecursively(args.getString(0));
|
||||
if (success) {
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
}
|
||||
else if (action.equals("moveTo")) {
|
||||
JSONObject entry = transferTo(args.getString(0), args.getString(1), args.getString(2), true);
|
||||
return new PluginResult(status, entry);
|
||||
}
|
||||
else if (action.equals("copyTo")) {
|
||||
JSONObject entry = transferTo(args.getString(0), args.getString(1), args.getString(2), false);
|
||||
return new PluginResult(status, entry);
|
||||
}
|
||||
else if (action.equals("readEntries")) {
|
||||
JSONArray entries = readEntries(args.getString(0));
|
||||
return new PluginResult(status, entries);
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (FileNotFoundException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
|
||||
} catch (FileExistsException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.PATH_EXISTS_ERR);
|
||||
} catch (NoModificationAllowedException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
} catch (InvalidModificationException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.INVALID_MODIFICATION_ERR);
|
||||
} catch (MalformedURLException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.ENCODING_ERR);
|
||||
} catch (IOException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.INVALID_MODIFICATION_ERR);
|
||||
} catch (EncodingException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.ENCODING_ERR);
|
||||
} catch (TypeMismatchException e) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.TYPE_MISMATCH_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +278,7 @@ public class FileUtils extends Plugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException {
|
||||
File fp = new File(fileName);
|
||||
File fp = createFileObject(fileName);
|
||||
|
||||
if (!fp.exists()) {
|
||||
// The directory we are listing doesn't exist so we should fail.
|
||||
@@ -328,7 +311,11 @@ public class FileUtils extends Plugin {
|
||||
* @throws EncodingException
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject transferTo(String fileName, JSONObject newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException {
|
||||
private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException {
|
||||
fileName = stripFileProtocol(fileName);
|
||||
newParent = stripFileProtocol(newParent);
|
||||
|
||||
|
||||
// Check for invalid file name
|
||||
if (newName != null && newName.contains(":")) {
|
||||
throw new EncodingException("Bad file name");
|
||||
@@ -341,7 +328,7 @@ public class FileUtils extends Plugin {
|
||||
throw new FileNotFoundException("The source does not exist");
|
||||
}
|
||||
|
||||
File destinationDir = new File(newParent.getString("fullPath"));
|
||||
File destinationDir = new File(newParent);
|
||||
if (!destinationDir.exists()) {
|
||||
// The destination does not exist so we should fail.
|
||||
throw new FileNotFoundException("The source does not exist");
|
||||
@@ -569,7 +556,7 @@ public class FileUtils extends Plugin {
|
||||
* @throws FileExistsException
|
||||
*/
|
||||
private boolean removeRecursively(String filePath) throws FileExistsException {
|
||||
File fp = new File(filePath);
|
||||
File fp = createFileObject(filePath);
|
||||
|
||||
// You can't delete the root directory.
|
||||
if (atRootDirectory(filePath)) {
|
||||
@@ -610,7 +597,7 @@ public class FileUtils extends Plugin {
|
||||
* @throws InvalidModificationException
|
||||
*/
|
||||
private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException {
|
||||
File fp = new File(filePath);
|
||||
File fp = createFileObject(filePath);
|
||||
|
||||
// You can't delete the root directory.
|
||||
if (atRootDirectory(filePath)) {
|
||||
@@ -701,6 +688,7 @@ public class FileUtils extends Plugin {
|
||||
if (fileName.startsWith("/")) {
|
||||
fp = new File(fileName);
|
||||
} else {
|
||||
dirPath = stripFileProtocol(dirPath);
|
||||
fp = new File(dirPath + File.separator + fileName);
|
||||
}
|
||||
return fp;
|
||||
@@ -715,6 +703,8 @@ public class FileUtils extends Plugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getParent(String filePath) throws JSONException {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
|
||||
if (atRootDirectory(filePath)) {
|
||||
return getEntry(filePath);
|
||||
}
|
||||
@@ -729,13 +719,42 @@ public class FileUtils extends Plugin {
|
||||
* @return true if we are at the root, false otherwise.
|
||||
*/
|
||||
private boolean atRootDirectory(String filePath) {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
|
||||
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getPackageName() + "/cache") ||
|
||||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath())) {
|
||||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
|
||||
filePath.equals("/data/data/" + ctx.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes the "file://" from the passed in filePath
|
||||
*
|
||||
* @param filePath to be checked.
|
||||
* @return
|
||||
*/
|
||||
private String stripFileProtocol(String filePath) {
|
||||
if (filePath.startsWith("file://")) {
|
||||
filePath = filePath.substring(7);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a File object from the passed in path
|
||||
*
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
private File createFileObject(String filePath) {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
|
||||
File file = new File(filePath);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up metadata about this entry.
|
||||
*
|
||||
@@ -745,7 +764,7 @@ public class FileUtils extends Plugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getMetadata(String filePath) throws FileNotFoundException, JSONException {
|
||||
File file = new File(filePath);
|
||||
File file = createFileObject(filePath);
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("Failed to find file in getMetadata");
|
||||
@@ -766,7 +785,7 @@ public class FileUtils extends Plugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException {
|
||||
File file = new File(filePath);
|
||||
File file = createFileObject(filePath);
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("File: " + filePath + " does not exist.");
|
||||
@@ -793,39 +812,34 @@ public class FileUtils extends Plugin {
|
||||
private JSONObject requestFileSystem(int type) throws IOException, JSONException {
|
||||
JSONObject fs = new JSONObject();
|
||||
if (type == TEMPORARY) {
|
||||
File fp;
|
||||
fs.put("name", "temporary");
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
fs.put("name", "temporary");
|
||||
fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
||||
// Create the cache dir if it doesn't exist.
|
||||
fp.mkdirs();
|
||||
fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/"));
|
||||
|
||||
// Create the cache dir if it doesn't exist.
|
||||
File fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
||||
fp.mkdirs();
|
||||
} else {
|
||||
throw new IOException("SD Card not mounted");
|
||||
fp = new File("/data/data/" + ctx.getPackageName() + "/cache/");
|
||||
// Create the cache dir if it doesn't exist.
|
||||
fp.mkdirs();
|
||||
fs.put("root", getEntry("/data/data/" + ctx.getPackageName() + "/cache/"));
|
||||
}
|
||||
}
|
||||
else if (type == PERSISTENT) {
|
||||
fs.put("name", "persistent");
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
fs.put("name", "persistent");
|
||||
fs.put("root", getEntry(Environment.getExternalStorageDirectory()));
|
||||
} else {
|
||||
throw new IOException("SD Card not mounted");
|
||||
fs.put("root", getEntry("/data/data/" + ctx.getPackageName()));
|
||||
}
|
||||
}
|
||||
else if (type == RESOURCE) {
|
||||
fs.put("name", "resource");
|
||||
|
||||
}
|
||||
else if (type == APPLICATION) {
|
||||
fs.put("name", "application");
|
||||
|
||||
}
|
||||
else {
|
||||
throw new IOException("No filesystem of type requested");
|
||||
}
|
||||
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
@@ -842,7 +856,7 @@ public class FileUtils extends Plugin {
|
||||
entry.put("isFile", file.isFile());
|
||||
entry.put("isDirectory", file.isDirectory());
|
||||
entry.put("name", file.getName());
|
||||
entry.put("fullPath", file.getAbsolutePath());
|
||||
entry.put("fullPath", "file://" + file.getAbsolutePath());
|
||||
// I can't add the next thing it as it would be an infinite loop
|
||||
//entry.put("filesystem", null);
|
||||
|
||||
@@ -897,8 +911,8 @@ public class FileUtils extends Plugin {
|
||||
*/
|
||||
public String readAsText(String filename, String encoding) throws FileNotFoundException, IOException {
|
||||
byte[] bytes = new byte[1000];
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
int numRead = 0;
|
||||
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
|
||||
bos.write(bytes, 0, numRead);
|
||||
@@ -915,8 +929,8 @@ public class FileUtils extends Plugin {
|
||||
*/
|
||||
public String readAsDataURL(String filename) throws FileNotFoundException, IOException {
|
||||
byte[] bytes = new byte[1000];
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
int numRead = 0;
|
||||
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
|
||||
bos.write(bytes, 0, numRead);
|
||||
@@ -958,20 +972,22 @@ public class FileUtils extends Plugin {
|
||||
*/
|
||||
/**/
|
||||
public long write(String filename, String data, int offset) throws FileNotFoundException, IOException {
|
||||
filename = stripFileProtocol(filename);
|
||||
|
||||
boolean append = false;
|
||||
if (offset > 0) {
|
||||
this.truncateFile(filename, offset);
|
||||
append = true;
|
||||
}
|
||||
|
||||
byte [] rawData = data.getBytes();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
|
||||
FileOutputStream out = new FileOutputStream(filename, append);
|
||||
byte buff[] = new byte[rawData.length];
|
||||
in.read(buff, 0, buff.length);
|
||||
out.write(buff, 0, rawData.length);
|
||||
out.flush();
|
||||
out.close();
|
||||
byte [] rawData = data.getBytes();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
|
||||
FileOutputStream out = new FileOutputStream(filename, append);
|
||||
byte buff[] = new byte[rawData.length];
|
||||
in.read(buff, 0, buff.length);
|
||||
out.write(buff, 0, rawData.length);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
return data.length();
|
||||
}
|
||||
@@ -984,6 +1000,8 @@ public class FileUtils extends Plugin {
|
||||
* @throws FileNotFoundException, IOException
|
||||
*/
|
||||
private long truncateFile(String filename, long size) throws FileNotFoundException, IOException {
|
||||
filename = stripFileProtocol(filename);
|
||||
|
||||
RandomAccessFile raf = new RandomAccessFile(filename, "rw");
|
||||
|
||||
if (raf.length() >= size) {
|
||||
@@ -1008,6 +1026,7 @@ public class FileUtils extends Plugin {
|
||||
return ctx.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
else {
|
||||
path = stripFileProtocol(path);
|
||||
return new FileInputStream(path);
|
||||
}
|
||||
}
|
||||
@@ -1019,7 +1038,7 @@ public class FileUtils extends Plugin {
|
||||
* @param ctx the current applicaiton context
|
||||
* @return the full path to the file
|
||||
*/
|
||||
protected static String getRealPathFromURI(Uri contentUri, PhonegapActivity ctx) {
|
||||
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) {
|
||||
String[] proj = { _DATA };
|
||||
Cursor cursor = ctx.managedQuery(contentUri, proj, null, null, null);
|
||||
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||
@@ -16,16 +16,16 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
/*
|
||||
* This class is the interface to the Geolocation. It's bound to the geo object.
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
@@ -17,9 +17,9 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
@@ -33,7 +33,7 @@ import android.os.Bundle;
|
||||
*/
|
||||
public class GpsListener implements LocationListener {
|
||||
|
||||
private PhonegapActivity mCtx; // PhonegapActivity object
|
||||
private CordovaInterface mCtx; // CordovaActivity object
|
||||
|
||||
private LocationManager mLocMan; // Location manager object
|
||||
private GeoListener owner; // Geolistener object (parent)
|
||||
@@ -49,7 +49,7 @@ public class GpsListener implements LocationListener {
|
||||
* @param interval
|
||||
* @param m
|
||||
*/
|
||||
public GpsListener(PhonegapActivity ctx, int interval, GeoListener m) {
|
||||
public GpsListener(CordovaInterface ctx, int interval, GeoListener m) {
|
||||
this.owner = m;
|
||||
this.mCtx = ctx;
|
||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
104
framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
Executable file
104
framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
Executable file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
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 org.apache.cordova.api.LOG;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View.MeasureSpec;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
/**
|
||||
* This class is used to detect when the soft keyboard is shown and hidden in the web view.
|
||||
*/
|
||||
public class LinearLayoutSoftKeyboardDetect extends LinearLayout {
|
||||
|
||||
private static final String TAG = "SoftKeyboardDetect";
|
||||
|
||||
private int oldHeight = 0; // Need to save the old height as not to send redundant events
|
||||
private int oldWidth = 0; // Need to save old width for orientation change
|
||||
private int screenWidth = 0;
|
||||
private int screenHeight = 0;
|
||||
private DroidGap app = null;
|
||||
|
||||
public LinearLayoutSoftKeyboardDetect(Context context, int width, int height) {
|
||||
super(context);
|
||||
screenWidth = width;
|
||||
screenHeight = height;
|
||||
app = (DroidGap) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Start listening to new measurement events. Fire events when the height
|
||||
* gets smaller fire a show keyboard event and when height gets bigger fire
|
||||
* a hide keyboard event.
|
||||
*
|
||||
* Note: We are using app.postMessage so that this is more compatible with the API
|
||||
*
|
||||
* @param widthMeasureSpec
|
||||
* @param heightMeasureSpec
|
||||
*/
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
LOG.v(TAG, "We are in our onMeasure method");
|
||||
|
||||
// Get the current height of the visible part of the screen.
|
||||
// This height will not included the status bar.\
|
||||
int width, height;
|
||||
|
||||
height = MeasureSpec.getSize(heightMeasureSpec);
|
||||
width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
LOG.v(TAG, "Old Height = %d", oldHeight);
|
||||
LOG.v(TAG, "Height = %d", height);
|
||||
LOG.v(TAG, "Old Width = %d", oldWidth);
|
||||
LOG.v(TAG, "Width = %d", width);
|
||||
|
||||
// If the oldHeight = 0 then this is the first measure event as the app starts up.
|
||||
// If oldHeight == height then we got a measurement change that doesn't affect us.
|
||||
if (oldHeight == 0 || oldHeight == height) {
|
||||
LOG.d(TAG, "Ignore this event");
|
||||
}
|
||||
// Account for orientation change and ignore this event/Fire orientation change
|
||||
else if(screenHeight == width)
|
||||
{
|
||||
int tmp_var = screenHeight;
|
||||
screenHeight = screenWidth;
|
||||
screenWidth = tmp_var;
|
||||
LOG.v(TAG, "Orientation Change");
|
||||
}
|
||||
// If the height as gotten bigger then we will assume the soft keyboard has
|
||||
// gone away.
|
||||
else if (height > oldHeight) {
|
||||
if(app != null)
|
||||
app.sendJavascript("require('cordova').fireDocumentEvent('hidekeyboard');");
|
||||
}
|
||||
// If the height as gotten smaller then we will assume the soft keyboard has
|
||||
// been displayed.
|
||||
else if (height < oldHeight) {
|
||||
if(app != null)
|
||||
app.sendJavascript("require('cordova').fireDocumentEvent('showkeyboard');");
|
||||
}
|
||||
|
||||
// Update the old height for the next event
|
||||
oldHeight = height;
|
||||
oldWidth = width;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,9 +16,9 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
@@ -28,13 +28,13 @@ import android.os.Bundle;
|
||||
|
||||
public class NetworkListener implements LocationListener {
|
||||
|
||||
private PhonegapActivity mCtx; // PhonegapActivity object
|
||||
private CordovaInterface mCtx; // CordovaActivity object
|
||||
|
||||
private LocationManager mLocMan; // Location manager object
|
||||
private GeoListener owner; // Geolistener object (parent)
|
||||
private boolean hasData = false; // Flag indicates if location data is available in cLoc
|
||||
private Location cLoc; // Last recieved location
|
||||
private boolean running = false; // Flag indicates if listener is running
|
||||
private LocationManager mLocMan; // Location manager object
|
||||
private GeoListener owner; // Geolistener object (parent)
|
||||
private boolean hasData = false; // Flag indicates if location data is available in cLoc
|
||||
private Location cLoc; // Last recieved location
|
||||
private boolean running = false; // Flag indicates if listener is running
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -44,7 +44,7 @@ public class NetworkListener implements LocationListener {
|
||||
* @param interval
|
||||
* @param m
|
||||
*/
|
||||
public NetworkListener(PhonegapActivity ctx, int interval, GeoListener m) {
|
||||
public NetworkListener(CordovaInterface ctx, int interval, GeoListener m) {
|
||||
this.owner = m;
|
||||
this.mCtx = ctx;
|
||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||
@@ -115,7 +115,7 @@ public class NetworkListener implements LocationListener {
|
||||
this.hasData = true;
|
||||
this.cLoc = location;
|
||||
|
||||
// The GPS is the primary form of Geolocation in PhoneGap.
|
||||
// The GPS is the primary form of Geolocation in Cordova.
|
||||
// Only fire the success variables if the GPS is down for some reason.
|
||||
if (!this.owner.mGps.hasLocation()) {
|
||||
this.owner.success(location);
|
||||
@@ -16,13 +16,13 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -87,7 +87,7 @@ public class NetworkManager extends Plugin {
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(PhonegapActivity ctx) {
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
super.setContext(ctx);
|
||||
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
this.connectionCallbackId = null;
|
||||
366
framework/src/org/apache/cordova/Notification.java
Executable file
366
framework/src/org/apache/cordova/Notification.java
Executable file
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
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 org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Vibrator;
|
||||
|
||||
/**
|
||||
* This class provides access to notifications on the device.
|
||||
*/
|
||||
public class Notification extends Plugin {
|
||||
|
||||
public int confirmResult = -1;
|
||||
public ProgressDialog spinnerDialog = null;
|
||||
public ProgressDialog progressDialog = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Notification() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("beep")) {
|
||||
this.beep(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("vibrate")) {
|
||||
this.vibrate(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("alert")) {
|
||||
this.alert(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
this.confirm(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
this.activityStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
this.activityStop();
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
this.progressStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
this.progressValue(args.getInt(0));
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
this.progressStop();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action) {
|
||||
if (action.equals("alert")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// LOCAL METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Beep plays the default notification ringtone.
|
||||
*
|
||||
* @param count Number of times to play notification
|
||||
*/
|
||||
public void beep(long count) {
|
||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
|
||||
|
||||
// If phone is not set to silent mode
|
||||
if (notification != null) {
|
||||
for (long i = 0; i < count; ++i) {
|
||||
notification.play();
|
||||
long timeout = 5000;
|
||||
while (notification.isPlaying() && (timeout > 0)) {
|
||||
timeout = timeout - 100;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vibrates the device for the specified amount of time.
|
||||
*
|
||||
* @param time Time to vibrate in ms.
|
||||
*/
|
||||
public void vibrate(long time){
|
||||
// Start the vibration, 0 defaults to half a second.
|
||||
if (time == 0) {
|
||||
time = 500;
|
||||
}
|
||||
Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android alert with given Strings
|
||||
* @param message The message the alert should display
|
||||
* @param title The title of the alert
|
||||
* @param buttonLabel The label of the button
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
dlg.setPositiveButton(buttonLabel,
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 0), callbackId);
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android confirm dialog with given title, message, buttons.
|
||||
* This dialog only shows up to 3 buttons. Any labels after that will be ignored.
|
||||
* The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
|
||||
*
|
||||
* @param message The message the dialog should display
|
||||
* @param title The title of the dialog
|
||||
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
final String[] fButtons = buttonLabels.split(",");
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
|
||||
// First button
|
||||
if (fButtons.length > 0) {
|
||||
dlg.setPositiveButton(fButtons[0],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Second button
|
||||
if (fButtons.length > 1) {
|
||||
dlg.setNeutralButton(fButtons[1],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Third button
|
||||
if (fButtons.length > 2) {
|
||||
dlg.setNegativeButton(fButtons[2],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the spinner.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void activityStart(final String title, final String message) {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), title , message, true, true,
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.spinnerDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop spinner.
|
||||
*/
|
||||
public synchronized void activityStop() {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the progress dialog.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void progressStart(final String title, final String message) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.progressDialog = new ProgressDialog(ctx.getContext());
|
||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
notification.progressDialog.setTitle(title);
|
||||
notification.progressDialog.setMessage(message);
|
||||
notification.progressDialog.setCancelable(true);
|
||||
notification.progressDialog.setMax(100);
|
||||
notification.progressDialog.setProgress(0);
|
||||
notification.progressDialog.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.progressDialog = null;
|
||||
}
|
||||
});
|
||||
notification.progressDialog.show();
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of progress bar.
|
||||
*
|
||||
* @param value 0-100
|
||||
*/
|
||||
public synchronized void progressValue(int value) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop progress dialog.
|
||||
*/
|
||||
public synchronized void progressStop() {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
34
framework/src/org/apache/cordova/PreferenceNode.java
Normal file
34
framework/src/org/apache/cordova/PreferenceNode.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
// represents the <preference> element from the W3C config.xml spec
|
||||
// see http://www.w3.org/TR/widgets/#the-preference-element-and-its-attributes
|
||||
public class PreferenceNode {
|
||||
public String name;
|
||||
public String value;
|
||||
public boolean readonly;
|
||||
|
||||
// constructor
|
||||
public PreferenceNode(String name, String value, boolean readonly) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.readonly = readonly;
|
||||
}
|
||||
}
|
||||
62
framework/src/org/apache/cordova/PreferenceSet.java
Normal file
62
framework/src/org/apache/cordova/PreferenceSet.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.HashSet;
|
||||
|
||||
import org.apache.cordova.PreferenceNode;
|
||||
|
||||
|
||||
public class PreferenceSet {
|
||||
private HashSet<PreferenceNode> innerSet;
|
||||
|
||||
public PreferenceSet() {
|
||||
this.innerSet = new HashSet<PreferenceNode>();
|
||||
}
|
||||
|
||||
public void add(PreferenceNode node) {
|
||||
this.innerSet.add(node);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.innerSet.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.innerSet.clear();
|
||||
}
|
||||
|
||||
public String pref(String prefName) {
|
||||
for (PreferenceNode n : innerSet)
|
||||
if (prefName.equals(n.name))
|
||||
return n.value;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean prefMatches(String prefName, String prefValue) {
|
||||
String value = pref(prefName);
|
||||
|
||||
if (value == null) {
|
||||
return false;
|
||||
} else {
|
||||
return value.equals(prefValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -16,19 +16,24 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.*;
|
||||
|
||||
/**
|
||||
* This class implements the HTML5 database support for Android 1.X devices. It
|
||||
* is not used for Android 2.X, since HTML5 database is built in to the browser.
|
||||
* This class implements the HTML5 database support to work around a bug for
|
||||
* Android 3.0 devices. It is not used for other versions of Android, since
|
||||
* HTML5 database is built in to the browser.
|
||||
*/
|
||||
public class Storage extends Plugin {
|
||||
|
||||
@@ -64,11 +69,7 @@ public class Storage extends Plugin {
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
// TODO: Do we want to allow a user to do this, since they could get
|
||||
// to other app databases?
|
||||
if (action.equals("setStorage")) {
|
||||
this.setStorage(args.getString(0));
|
||||
} else if (action.equals("openDatabase")) {
|
||||
if (action.equals("openDatabase")) {
|
||||
this.openDatabase(args.getString(0), args.getString(1),
|
||||
args.getString(2), args.getLong(3));
|
||||
} else if (action.equals("executeSql")) {
|
||||
@@ -118,21 +119,6 @@ public class Storage extends Plugin {
|
||||
// LOCAL METHODS
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the application package for the database. Each application saves its
|
||||
* database files in a directory with the application package as part of the
|
||||
* file name.
|
||||
*
|
||||
* For example, application "com.phonegap.demo.Demo" would save its database
|
||||
* files in "/data/data/com.phonegap.demo/databases/" directory.
|
||||
*
|
||||
* @param appPackage
|
||||
* The application package.
|
||||
*/
|
||||
public void setStorage(String appPackage) {
|
||||
this.path = "/data/data/" + appPackage + "/databases/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Open database.
|
||||
*
|
||||
@@ -155,12 +141,10 @@ public class Storage extends Plugin {
|
||||
|
||||
// If no database path, generate from application package
|
||||
if (this.path == null) {
|
||||
Package pack = this.ctx.getClass().getPackage();
|
||||
String appPackage = pack.getName();
|
||||
this.setStorage(appPackage);
|
||||
this.path = this.ctx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
||||
}
|
||||
|
||||
this.dbName = this.path + db + ".db";
|
||||
this.dbName = this.path + File.pathSeparator + db + ".db";
|
||||
this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
|
||||
}
|
||||
|
||||
@@ -178,7 +162,7 @@ public class Storage extends Plugin {
|
||||
try {
|
||||
if (isDDL(query)) {
|
||||
this.myDb.execSQL(query);
|
||||
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', '');");
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
|
||||
}
|
||||
else {
|
||||
Cursor myCursor = this.myDb.rawQuery(query, params);
|
||||
@@ -191,7 +175,7 @@ public class Storage extends Plugin {
|
||||
System.out.println("Storage.executeSql(): Error=" + ex.getMessage());
|
||||
|
||||
// Send error message back to JavaScript
|
||||
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,9 +233,7 @@ public class Storage extends Plugin {
|
||||
}
|
||||
|
||||
// Let JavaScript know that there are no more rows
|
||||
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result
|
||||
+ ");");
|
||||
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,15 +16,15 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package com.phonegap;
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
@@ -49,7 +49,7 @@ public class TempListener extends Plugin implements SensorEventListener {
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(PhonegapActivity ctx) {
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
super.setContext(ctx);
|
||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||
}
|
||||
145
framework/src/org/apache/cordova/api/CordovaInterface.java
Executable file
145
framework/src/org/apache/cordova/api/CordovaInterface.java
Executable file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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 java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.net.Uri;
|
||||
|
||||
|
||||
/**
|
||||
* The Cordova activity abstract class that is extended by DroidGap.
|
||||
* It is used to isolate plugin development, and remove dependency on entire Cordova library.
|
||||
*/
|
||||
public interface CordovaInterface {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Add services to res/xml/plugins.xml instead.
|
||||
*
|
||||
* Add a class that implements a service.
|
||||
*
|
||||
* @param serviceType
|
||||
* @param className
|
||||
*/
|
||||
@Deprecated
|
||||
abstract public void addService(String serviceType, String className);
|
||||
|
||||
/**
|
||||
* Send JavaScript statement back to JavaScript.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
abstract public void sendJavascript(String statement);
|
||||
|
||||
/**
|
||||
* Launch an activity for which you would like a result when it finished. When this activity exits,
|
||||
* your onActivityResult() method will be called.
|
||||
*
|
||||
* @param command The command object
|
||||
* @param intent The intent to start
|
||||
* @param requestCode The request code that is passed to callback to identify the activity
|
||||
*/
|
||||
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
|
||||
|
||||
/**
|
||||
* Launch an activity for which you would not like a result when it finished.
|
||||
*
|
||||
* @param intent The intent to start
|
||||
*/
|
||||
abstract public void startActivity(Intent intent);
|
||||
|
||||
/**
|
||||
* Set the plugin to be called when a sub-activity exits.
|
||||
*
|
||||
* @param plugin The plugin on which onActivityResult is to be called
|
||||
*/
|
||||
abstract public void setActivityResultCallback(IPlugin plugin);
|
||||
|
||||
/**
|
||||
* Load the specified URL in the Cordova webview.
|
||||
*
|
||||
* @param url The URL to load.
|
||||
*/
|
||||
abstract public void loadUrl(String url);
|
||||
|
||||
/**
|
||||
* Send a message to all plugins.
|
||||
*
|
||||
* @param id The message id
|
||||
* @param data The message data
|
||||
*/
|
||||
abstract public void postMessage(String id, Object data);
|
||||
|
||||
|
||||
public abstract Resources getResources();
|
||||
|
||||
public abstract String getPackageName();
|
||||
|
||||
public abstract Object getSystemService(String service);
|
||||
|
||||
public abstract Context getContext();
|
||||
|
||||
public abstract Context getBaseContext();
|
||||
|
||||
public abstract Intent registerReceiver(BroadcastReceiver receiver,
|
||||
IntentFilter intentFilter);
|
||||
|
||||
public abstract ContentResolver getContentResolver();
|
||||
|
||||
public abstract void unregisterReceiver(BroadcastReceiver receiver);
|
||||
|
||||
public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder);
|
||||
|
||||
public abstract void runOnUiThread(Runnable runnable);
|
||||
|
||||
public abstract AssetManager getAssets();
|
||||
|
||||
public abstract void clearCache();
|
||||
|
||||
public abstract void clearHistory();
|
||||
|
||||
public abstract boolean backHistory();
|
||||
|
||||
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
|
||||
|
||||
public abstract void bindBackButton(boolean override);
|
||||
|
||||
public abstract boolean isBackButtonBound();
|
||||
|
||||
public abstract void cancelLoadUrl();
|
||||
|
||||
public abstract void showWebPage(String url, boolean openExternal,
|
||||
boolean clearHistory, HashMap<String, Object> params);
|
||||
|
||||
public abstract Context getApplicationContext();
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user